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

p12.rb « secure_files « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1006a4d05b228d8bfd862d02915fda316cdbaa10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

module Gitlab
  module Ci
    module SecureFiles
      class P12
        include Gitlab::Utils::StrongMemoize

        attr_reader :error

        def initialize(filedata, password = nil)
          @filedata = filedata
          @password = password
        end

        def certificate_data
          OpenSSL::PKCS12.new(@filedata, @password).certificate
        rescue OpenSSL::PKCS12::PKCS12Error => err
          @error = err.to_s
          nil
        end
        strong_memoize_attr :certificate_data

        def metadata
          return {} unless certificate_data

          {
            issuer: issuer,
            subject: subject,
            id: serial,
            expires_at: expires_at
          }
        end
        strong_memoize_attr :metadata

        private

        def expires_at
          certificate_data.not_before
        end

        def serial
          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