diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 03:09:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 03:09:12 +0300 |
commit | 6168721025dd8e98caeb2bf6844273e6690eaf69 (patch) | |
tree | 8c4fb20d793669e488a739bc9951dab8b363eed4 /app/models/x509_certificate.rb | |
parent | a89cb5cbdd832d4d9e80517973aceda6bc0a3856 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/x509_certificate.rb')
-rw-r--r-- | app/models/x509_certificate.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/models/x509_certificate.rb b/app/models/x509_certificate.rb new file mode 100644 index 00000000000..43927e65db1 --- /dev/null +++ b/app/models/x509_certificate.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class X509Certificate < ApplicationRecord + include X509SerialNumberAttribute + + x509_serial_number_attribute :serial_number + + enum certificate_status: { + good: 0, + revoked: 1 + } + + belongs_to :x509_issuer, class_name: 'X509Issuer', foreign_key: 'x509_issuer_id', optional: false + + has_many :x509_commit_signatures, inverse_of: 'x509_certificate' + + # rfc 5280 - 4.2.1.2 Subject Key Identifier + validates :subject_key_identifier, presence: true, format: { with: /\A(\h{2}:){19}\h{2}\z/ } + # rfc 5280 - 4.1.2.6 Subject + validates :subject, presence: true + # rfc 5280 - 4.1.2.6 Subject (subjectAltName contains the email address) + validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP } + # rfc 5280 - 4.1.2.2 Serial number + validates :serial_number, presence: true, numericality: { only_integer: true } + + validates :x509_issuer_id, presence: true + + def self.safe_create!(attributes) + create_with(attributes) + .safe_find_or_create_by!(subject_key_identifier: attributes[:subject_key_identifier]) + end +end |