summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2017-09-27 19:45:19 -0500
committerRubén Dávila <ruben@gitlab.com>2017-10-05 08:25:27 -0500
commit9b4990a4d71b057f0fec14399cd1f2a421901963 (patch)
treee6e522b10f17325d0a8fcc86a2020210f285086b /app
parenta41e7e0105e238161ba697ebf26d8554ae59d295 (diff)
downloadgitlab-ce-9b4990a4d71b057f0fec14399cd1f2a421901963.tar.gz
Associate GgpSignature with GpgKeySubkey if comes from a subkey
Additionally we're delegating missing method calls on GpgKeySubkey to GpgKey since most of the info required when verifying a signature is found on GpgKey which is the parent of GpgKeySubkey
Diffstat (limited to 'app')
-rw-r--r--app/models/gpg_key.rb11
-rw-r--r--app/models/gpg_key_subkey.rb15
-rw-r--r--app/models/gpg_signature.rb16
3 files changed, 31 insertions, 11 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb
index 6d3537b6fcf..ed09b44027c 100644
--- a/app/models/gpg_key.rb
+++ b/app/models/gpg_key.rb
@@ -40,17 +40,6 @@ class GpgKey < ActiveRecord::Base
after_commit :update_invalid_gpg_signatures, on: :create
after_create :generate_subkeys
- def self.find_with_subkeys(fingerprint)
- keys_table = arel_table
- subkeys_table = GpgKeySubkey.arel_table
-
- condition = keys_table[:primary_keyid].eq(fingerprint).or(
- subkeys_table[:keyid].eq(fingerprint)
- )
-
- joins(:subkeys).where(condition).first
- end
-
def primary_keyid
super&.upcase
end
diff --git a/app/models/gpg_key_subkey.rb b/app/models/gpg_key_subkey.rb
index 4f967f1e47c..8222e5606aa 100644
--- a/app/models/gpg_key_subkey.rb
+++ b/app/models/gpg_key_subkey.rb
@@ -1,3 +1,18 @@
class GpgKeySubkey < ActiveRecord::Base
+ include ShaAttribute
+
+ sha_attribute :keyid
+ sha_attribute :fingerprint
+
belongs_to :gpg_key
+
+ def method_missing(m, *a, &b)
+ return super unless gpg_key.respond_to?(m)
+
+ gpg_key.public_send(m, *a, &b) # rubocop:disable GitlabSecurity/PublicSend
+ end
+
+ def respond_to_missing?(method, include_private = false)
+ gpg_key.respond_to?(method, include_private) || super
+ end
end
diff --git a/app/models/gpg_signature.rb b/app/models/gpg_signature.rb
index 1f047a32c84..c7f75288407 100644
--- a/app/models/gpg_signature.rb
+++ b/app/models/gpg_signature.rb
@@ -15,11 +15,27 @@ class GpgSignature < ActiveRecord::Base
belongs_to :project
belongs_to :gpg_key
+ belongs_to :gpg_key_subkey
validates :commit_sha, presence: true
validates :project_id, presence: true
validates :gpg_key_primary_keyid, presence: true
+ def gpg_key=(model)
+ case model
+ when GpgKey then super
+ when GpgKeySubkey then write_attribute(:gpg_key_subkey_id, model.id)
+ end
+ end
+
+ def gpg_key
+ if gpg_key_id
+ super
+ elsif gpg_key_subkey_id
+ gpg_key_subkey
+ end
+ end
+
def gpg_key_primary_keyid
super&.upcase
end