Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
3c42d730
Commit
3c42d730
authored
Jun 13, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add primary keyid attribute to gpg keys
parent
7e13d967
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
7 deletions
+73
-7
app/models/gpg_key.rb
app/models/gpg_key.rb
+14
-1
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
+17
-0
db/schema.rb
db/schema.rb
+2
-0
lib/gitlab/gpg.rb
lib/gitlab/gpg.rb
+12
-0
spec/features/commits_spec.rb
spec/features/commits_spec.rb
+2
-2
spec/lib/gitlab/gpg_spec.rb
spec/lib/gitlab/gpg_spec.rb
+14
-0
spec/models/gpg_key_spec.rb
spec/models/gpg_key_spec.rb
+8
-0
spec/support/gpg_helpers.rb
spec/support/gpg_helpers.rb
+4
-4
No files found.
app/models/gpg_key.rb
View file @
3c42d730
...
@@ -20,7 +20,14 @@ class GpgKey < ActiveRecord::Base
...
@@ -20,7 +20,14 @@ class GpgKey < ActiveRecord::Base
# the error about the fingerprint
# the error about the fingerprint
unless:
->
{
errors
.
has_key?
(
:key
)
}
unless:
->
{
errors
.
has_key?
(
:key
)
}
before_validation
:extract_fingerprint
validates
:primary_keyid
,
presence:
true
,
uniqueness:
true
,
# only validate when the `key` is valid, as we don't want the user to show
# the error about the fingerprint
unless:
->
{
errors
.
has_key?
(
:key
)
}
before_validation
:extract_fingerprint
,
:extract_primary_keyid
after_create
:notify_user
after_create
:notify_user
def
key
=
(
value
)
def
key
=
(
value
)
...
@@ -49,6 +56,12 @@ class GpgKey < ActiveRecord::Base
...
@@ -49,6 +56,12 @@ class GpgKey < ActiveRecord::Base
self
.
fingerprint
=
Gitlab
::
Gpg
.
fingerprints_from_key
(
key
).
first
self
.
fingerprint
=
Gitlab
::
Gpg
.
fingerprints_from_key
(
key
).
first
end
end
def
extract_primary_keyid
# we can assume that the result only contains one item as the validation
# only allows one key
self
.
primary_keyid
=
Gitlab
::
Gpg
.
primary_keyids_from_key
(
key
).
first
end
def
notify_user
def
notify_user
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
end
end
...
...
db/migrate/20170613103429_add_primary_keyid_to_gpg_keys.rb
0 → 100644
View file @
3c42d730
class
AddPrimaryKeyidToGpgKeys
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_column
:gpg_keys
,
:primary_keyid
,
:string
add_concurrent_index
:gpg_keys
,
:primary_keyid
end
def
down
remove_concurrent_index
:gpg_keys
,
:primary_keyid
if
index_exists?
(
:gpg_keys
,
:primary_keyid
)
remove_column
:gpg_keys
,
:primary_keyid
,
:string
end
end
db/schema.rb
View file @
3c42d730
...
@@ -546,8 +546,10 @@ ActiveRecord::Schema.define(version: 20170725145659) do
...
@@ -546,8 +546,10 @@ ActiveRecord::Schema.define(version: 20170725145659) do
t
.
integer
"user_id"
t
.
integer
"user_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"primary_keyid"
end
end
add_index
"gpg_keys"
,
[
"primary_keyid"
],
name:
"index_gpg_keys_on_primary_keyid"
,
using: :btree
add_index
"gpg_keys"
,
[
"user_id"
],
name:
"index_gpg_keys_on_user_id"
,
using: :btree
add_index
"gpg_keys"
,
[
"user_id"
],
name:
"index_gpg_keys_on_user_id"
,
using: :btree
create_table
"identities"
,
force: :cascade
do
|
t
|
create_table
"identities"
,
force: :cascade
do
|
t
|
...
...
lib/gitlab/gpg.rb
View file @
3c42d730
...
@@ -12,6 +12,18 @@ module Gitlab
...
@@ -12,6 +12,18 @@ module Gitlab
end
end
end
end
def
primary_keyids_from_key
(
key
)
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
return
[]
if
import
.
imported
==
0
fingerprints
=
import
.
imports
.
map
(
&
:fingerprint
)
GPGME
::
Key
.
find
(
:public
,
fingerprints
).
map
{
|
raw_key
|
raw_key
.
primary_subkey
.
keyid
}
end
end
def
emails_from_key
(
key
)
def
emails_from_key
(
key
)
using_tmp_keychain
do
using_tmp_keychain
do
import
=
GPGME
::
Key
.
import
(
key
)
import
=
GPGME
::
Key
.
import
(
key
)
...
...
spec/features/commits_spec.rb
View file @
3c42d730
...
@@ -220,8 +220,8 @@ describe 'Commits' do
...
@@ -220,8 +220,8 @@ describe 'Commits' do
Dir
.
mktmpdir
do
|
dir
|
Dir
.
mktmpdir
do
|
dir
|
FileUtils
.
cd
dir
do
FileUtils
.
cd
dir
do
`git clone --quiet
#{
remote_path
}
.`
`git clone --quiet
#{
remote_path
}
.`
`git commit --quiet -S
#{
GpgHelpers
::
User1
.
key_
id
}
--allow-empty -m "signed commit, verified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User1
.
primary_key
id
}
--allow-empty -m "signed commit, verified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User2
.
key_
id
}
--allow-empty -m "signed commit, unverified key/email"`
`git commit --quiet -S
#{
GpgHelpers
::
User2
.
primary_key
id
}
--allow-empty -m "signed commit, unverified key/email"`
`git push --quiet`
`git push --quiet`
end
end
end
end
...
...
spec/lib/gitlab/gpg_spec.rb
View file @
3c42d730
...
@@ -15,6 +15,20 @@ describe Gitlab::Gpg do
...
@@ -15,6 +15,20 @@ describe Gitlab::Gpg do
end
end
end
end
describe
'.primary_keyids_from_key'
do
it
'returns the keyid'
do
expect
(
described_class
.
primary_keyids_from_key
(
GpgHelpers
::
User1
.
public_key
)
).
to
eq
[
GpgHelpers
::
User1
.
primary_keyid
]
end
it
'returns an empty array when the key is invalid'
do
expect
(
described_class
.
primary_keyids_from_key
(
'bogus'
)
).
to
eq
[]
end
end
describe
'.emails_from_key'
do
describe
'.emails_from_key'
do
it
'returns the emails'
do
it
'returns the emails'
do
expect
(
expect
(
...
...
spec/models/gpg_key_spec.rb
View file @
3c42d730
...
@@ -21,6 +21,14 @@ describe GpgKey do
...
@@ -21,6 +21,14 @@ describe GpgKey do
expect
(
gpg_key
.
fingerprint
).
to
eq
GpgHelpers
::
User1
.
fingerprint
expect
(
gpg_key
.
fingerprint
).
to
eq
GpgHelpers
::
User1
.
fingerprint
end
end
end
end
describe
'extract_primary_keyid'
do
it
'extracts the primary keyid from the gpg key'
do
gpg_key
=
described_class
.
new
(
key:
GpgHelpers
::
User1
.
public_key
)
gpg_key
.
valid?
expect
(
gpg_key
.
primary_keyid
).
to
eq
GpgHelpers
::
User1
.
primary_keyid
end
end
end
end
describe
'#key='
do
describe
'#key='
do
...
...
spec/support/gpg_helpers.rb
View file @
3c42d730
...
@@ -90,8 +90,8 @@ module GpgHelpers
...
@@ -90,8 +90,8 @@ module GpgHelpers
KEY
KEY
end
end
def
key_
id
def
primary_key
id
'00AC8B1D'
fingerprint
[
-
16
..-
1
]
end
end
def
fingerprint
def
fingerprint
...
@@ -179,8 +179,8 @@ module GpgHelpers
...
@@ -179,8 +179,8 @@ module GpgHelpers
KEY
KEY
end
end
def
key_
id
def
primary_key
id
'911EFD65'
fingerprint
[
-
16
..-
1
]
end
end
def
fingerprint
def
fingerprint
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment