Class: Acme::Client::CertificateRequest

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/acme/client/certificate_request.rb

Constant Summary collapse

DEFAULT_KEY_LENGTH =
2048
DEFAULT_DIGEST =
OpenSSL::Digest::SHA256
SUBJECT_KEYS =
{
  common_name:         "CN",
  country_name:        "C",
  organization_name:   "O",
  organizational_unit: "OU",
  state_or_province:   "ST",
  locality_name:       "L"
}.freeze
SUBJECT_TYPES =
{
  "CN" => OpenSSL::ASN1::UTF8STRING,
  "C"  => OpenSSL::ASN1::UTF8STRING,
  "O"  => OpenSSL::ASN1::UTF8STRING,
  "OU" => OpenSSL::ASN1::UTF8STRING,
  "ST" => OpenSSL::ASN1::UTF8STRING,
  "L"  => OpenSSL::ASN1::UTF8STRING
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(common_name: nil, names: [], private_key: generate_private_key, subject: {}, digest: DEFAULT_DIGEST.new) ⇒ CertificateRequest

Returns a new instance of CertificateRequest.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/acme/client/certificate_request.rb', line 28

def initialize(common_name: nil,
               names: [],
               private_key: generate_private_key,
               subject: {},
               digest: DEFAULT_DIGEST.new)
  raise ArgumentError.new("Digest must be a OpenSSL::Digest") unless digest.is_a?(OpenSSL::Digest)
  @digest = digest

  @private_key = private_key

  @subject = normalize_subject(subject)
  @common_name = common_name || @subject[SUBJECT_KEYS[:common_name]] || @subject[:common_name]

  @names = names.to_a.dup
  normalize_names

  @subject[SUBJECT_KEYS[:common_name]] ||= @common_name
  validate_subject
end

Instance Attribute Details

#common_nameObject (readonly)

Returns the value of attribute common_name.



24
25
26
# File 'lib/acme/client/certificate_request.rb', line 24

def common_name
  @common_name
end

#namesObject (readonly)

Returns the value of attribute names.



24
25
26
# File 'lib/acme/client/certificate_request.rb', line 24

def names
  @names
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



24
25
26
# File 'lib/acme/client/certificate_request.rb', line 24

def private_key
  @private_key
end

#subjectObject (readonly)

Returns the value of attribute subject.



24
25
26
# File 'lib/acme/client/certificate_request.rb', line 24

def subject
  @subject
end

Instance Method Details

#csrObject



48
49
50
# File 'lib/acme/client/certificate_request.rb', line 48

def csr
  @csr ||= generate
end