Class: EaSSL::SigningRequest
- Inherits:
-
Object
- Object
- EaSSL::SigningRequest
- Defined in:
- lib/eassl/signing_request.rb
Overview
- Author
-
Paul Nicholson ([email protected])
- Co-Author
-
Adam Williams ([email protected])
- Copyright
-
Copyright © 2006 WebPower Design
- License
-
Distributes under the same terms as Ruby
Instance Attribute Summary collapse
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SigningRequest
constructor
A new instance of SigningRequest.
- #key ⇒ Object
- #load(pem_string) ⇒ Object
-
#method_missing(method) ⇒ Object
This method is used to intercept and pass-thru calls to openSSL methods and instance variables.
- #options ⇒ Object
- #ssl ⇒ Object
- #to_pem ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SigningRequest
Returns a new instance of SigningRequest.
11 12 13 14 15 16 17 18 19 |
# File 'lib/eassl/signing_request.rb', line 11 def initialize( = {}) = { :name => {}, #required, CertificateName :key => nil, #required :digest => OpenSSL::Digest::SHA512.new, :extensions => nil }.update() [:key] ||= Key.new() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
This method is used to intercept and pass-thru calls to openSSL methods and instance variables.
83 84 85 |
# File 'lib/eassl/signing_request.rb', line 83 def method_missing(method) ssl.send(method) end |
Instance Attribute Details
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
9 10 11 |
# File 'lib/eassl/signing_request.rb', line 9 def extensions @extensions end |
Class Method Details
.load(pem_file_path) ⇒ Object
87 88 89 |
# File 'lib/eassl/signing_request.rb', line 87 def self.load(pem_file_path) new.load(File.read(pem_file_path)) end |
Instance Method Details
#key ⇒ Object
69 70 71 |
# File 'lib/eassl/signing_request.rb', line 69 def key [:key] end |
#load(pem_string) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/eassl/signing_request.rb', line 91 def load(pem_string) begin @ssl = OpenSSL::X509::Request.new(pem_string) @extensions = begin if attr = ssl.attributes.detect { |a| ['extReq','msExtReq'].include?(a.oid)} set = OpenSSL::ASN1.decode(attr.value) seq = set.value.first seq.value.collect { |e| OpenSSL::X509::Extension.new(e) } end end rescue raise "SigningRequestLoader: Error loading signing request" end self end |
#options ⇒ Object
73 74 75 |
# File 'lib/eassl/signing_request.rb', line 73 def end |
#ssl ⇒ Object
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 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/eassl/signing_request.rb', line 21 def ssl unless @ssl @ssl = OpenSSL::X509::Request.new @ssl.version = 0 @ssl.subject = CertificateName.new([:name].).name @ssl.public_key = key.public_key @extensions = Array.new ef = OpenSSL::X509::ExtensionFactory.new case [:type] when 'subordinate' @extensions << ef.create_extension("basicConstraints","CA:TRUE") when 'server' @extensions << ef.create_extension("basicConstraints","CA:FALSE") @extensions << ef.create_extension("keyUsage", "digitalSignature,keyEncipherment") @extensions << ef.create_extension("extendedKeyUsage", "serverAuth") when 'client' @extensions << ef.create_extension("basicConstraints","CA:FALSE") @extensions << ef.create_extension("keyUsage", "nonRepudiation,digitalSignature,keyEncipherment") @extensions << ef.create_extension("extendedKeyUsage", "clientAuth,emailProtection") when 'peer' @extensions << ef.create_extension("basicConstraints","CA:FALSE") @extensions << ef.create_extension("keyUsage", "digitalSignature,keyEncipherment") @extensions << ef.create_extension("extendedKeyUsage", "serverAuth,clientAuth") when 'custom' [:extensions].each do |ext| @extensions << ef.create_extensions(ext[:name], ext[:value]) end end if [:subject_alt_name] subjectAltName = [:subject_alt_name].map {|d| d.is_a?(Hash) ? "#{d[:name]}: #{d[:value]}" : "DNS: #{d}" }.join(',') @extensions << ef.create_extension("subjectAltName", subjectAltName) end if @extensions.count > 0 seq = OpenSSL::ASN1::Sequence.new(extensions) set = OpenSSL::ASN1::Set.new([seq]) attr = OpenSSL::X509::Attribute.new('extReq', set) @ssl.add_attribute(attr) end @ssl.sign(key.private_key, [:digest]) end @ssl end |
#to_pem ⇒ Object
77 78 79 |
# File 'lib/eassl/signing_request.rb', line 77 def to_pem ssl.to_pem end |