Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/secure_files/cer.rb')
-rw-r--r--lib/gitlab/ci/secure_files/cer.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/gitlab/ci/secure_files/cer.rb b/lib/gitlab/ci/secure_files/cer.rb
new file mode 100644
index 00000000000..45d2898c29b
--- /dev/null
+++ b/lib/gitlab/ci/secure_files/cer.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module SecureFiles
+ class Cer
+ include Gitlab::Utils::StrongMemoize
+
+ attr_reader :error
+
+ def initialize(filedata)
+ @filedata = filedata
+ @error = nil
+ end
+
+ def certificate_data
+ OpenSSL::X509::Certificate.new(@filedata)
+ rescue OpenSSL::X509::CertificateError => err
+ @error = err.to_s
+ nil
+ end
+ strong_memoize_attr :certificate_data
+
+ def metadata
+ return {} unless certificate_data
+
+ {
+ issuer: issuer,
+ subject: subject,
+ id: id,
+ expires_at: expires_at
+ }
+ end
+ strong_memoize_attr :metadata
+
+ private
+
+ def expires_at
+ certificate_data.not_before
+ end
+
+ def id
+ certificate_data.serial.to_s
+ end
+
+ def issuer
+ X509Name.parse(certificate_data.issuer)
+ end
+
+ def subject
+ X509Name.parse(certificate_data.subject)
+ end
+ end
+ end
+ end
+end