Class: Confium::PKI::CertificateBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/confium/pki/certificate_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCertificateBuilder

Returns a new instance of CertificateBuilder.



24
25
26
27
28
29
30
# File 'lib/confium/pki/certificate_builder.rb', line 24

def initialize
  @subject = ""
  @issuer = nil  # nil = self-signed
  @serial = rand(1..(1 << 128))
  @not_before = Time.now
  @not_after = Time.now + (365 * 24 * 3600)
end

Instance Attribute Details

#issuerObject

Returns the value of attribute issuer.



22
23
24
# File 'lib/confium/pki/certificate_builder.rb', line 22

def issuer
  @issuer
end

#not_afterObject

Returns the value of attribute not_after.



22
23
24
# File 'lib/confium/pki/certificate_builder.rb', line 22

def not_after
  @not_after
end

#not_beforeObject

Returns the value of attribute not_before.



22
23
24
# File 'lib/confium/pki/certificate_builder.rb', line 22

def not_before
  @not_before
end

#serialObject

Returns the value of attribute serial.



22
23
24
# File 'lib/confium/pki/certificate_builder.rb', line 22

def serial
  @serial
end

#subjectObject

Returns the value of attribute subject.



22
23
24
# File 'lib/confium/pki/certificate_builder.rb', line 22

def subject
  @subject
end

Instance Method Details

#build_self_signed(algorithm:, private_key:) ⇒ Hash

Build a self-signed certificate.

Parameters:

  • algorithm (Symbol)

    :ed25519 or :ecdsa_p256

  • private_key (String)

    32-byte private key

Returns:

  • (Hash)

    metadata about the built cert (not a Certificate object yet — full DER construction needs x509-cert builder support in the Rust extension)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/confium/pki/certificate_builder.rb', line 39

def build_self_signed(algorithm:, private_key:)
  kp = case algorithm
       when :ed25519
         Confium::Composite.generate_ed25519_keypair
       when :ecdsa_p256
         Confium::TC::FrostP256.generate_keypair
       else
         raise ArgumentError, "unsupported algorithm: #{algorithm}"
       end

  {
    subject: @subject,
    serial: @serial.to_s(16),
    not_before: @not_before.iso8601,
    not_after: @not_after.iso8601,
    algorithm: algorithm.to_s,
    public_key_hex: kp["public_key"].unpack1("H*"),
  }
end