Class: R509::CertificateAuthority::Signer
- Inherits:
-
Object
- Object
- R509::CertificateAuthority::Signer
- Defined in:
- lib/r509/certificate_authority/signer.rb
Overview
Contains the certification authority signing operation methods
Class Method Summary (collapse)
-
+ (R509::Cert) selfsign(options)
Self-signs a CSR.
Instance Method Summary (collapse)
-
- (Signer) initialize(config)
constructor
A new instance of Signer.
-
- (R509::Cert) sign(options)
Signs a CSR.
Constructor Details
- (Signer) initialize(config)
A new instance of Signer
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/r509/certificate_authority/signer.rb', line 12 def initialize(config) @config = config if not @config.nil? and not @config.kind_of?(R509::Config::CAConfig) raise R509::R509Error, "config must be a kind of R509::Config::CAConfig" end if not @config.nil? and not @config.ca_cert.has_private_key? raise R509::R509Error, "You must have a private key associated with your CA certificate to issue" end end |
Class Method Details
+ (R509::Cert) selfsign(options)
Self-signs a CSR
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/r509/certificate_authority/signer.rb', line 70 def self.selfsign() if not .kind_of?(Hash) raise ArgumentError, "You must pass a hash of options consisting of at minimum :csr" end csr = [:csr] if csr.key.nil? raise ArgumentError, 'CSR must also have a private key to self sign' end subject, public_key = R509::CertificateAuthority::Signer.extract_public_key_subject() cert = self.build_cert( :subject => subject.name, :issuer => subject.name, :not_before => [:not_before], :not_after => [:not_after], :public_key => public_key, :serial => [:serial] ) cert.extensions = [:extensions] || [ R509::Cert::Extensions::BasicConstraints.new(:ca => true), R509::Cert::Extensions::SubjectKeyIdentifier.new(:public_key => public_key), R509::Cert::Extensions::AuthorityKeyIdentifier.new(:public_key => public_key) ] if .has_key?(:message_digest) = R509::MessageDigest.new([:message_digest]) else = R509::MessageDigest.new(R509::MessageDigest::DEFAULT_MD) end cert.sign( csr.key.key, .digest ) R509::Cert.new(:cert => cert, :key => csr.key) end |
Instance Method Details
- (R509::Cert) sign(options)
Signs a CSR
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/r509/certificate_authority/signer.rb', line 33 def sign() R509::CertificateAuthority::Signer.() = R509::MessageDigest.new([:message_digest]) subject, public_key = R509::CertificateAuthority::Signer.extract_public_key_subject() cert = R509::CertificateAuthority::Signer.build_cert( :subject => subject.name, :issuer => @config.ca_cert.subject.name, :not_before => [:not_before], :not_after => [:not_after], :public_key => public_key, :serial => [:serial] ) cert.extensions = [:extensions] || [ R509::Cert::Extensions::SubjectKeyIdentifier.new(:public_key => public_key), R509::Cert::Extensions::AuthorityKeyIdentifier.new(:public_key => @config.ca_cert.public_key) ] #@config.ca_cert.key.key ... ugly. ca_cert returns R509::Cert # #key returns R509::PrivateKey and #key on that returns OpenSSL object we need cert.sign( @config.ca_cert.key.key, .digest ) cert_opts = { :cert => cert } cert_opts[:key] = [:csr].key if not [:csr].nil? and not [:csr].key.nil? R509::Cert.new(cert_opts) end |