r509 0.8.1 → 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. data/README.md +343 -151
  2. data/Rakefile +26 -23
  3. data/bin/r509 +126 -112
  4. data/bin/r509-parse +24 -24
  5. data/doc/R509.html +169 -7
  6. data/doc/R509/ASN1.html +370 -0
  7. data/doc/R509/ASN1/GeneralName.html +1121 -0
  8. data/doc/R509/ASN1/GeneralNames.html +843 -0
  9. data/doc/R509/ASN1/NoticeReference.html +392 -0
  10. data/doc/R509/ASN1/PolicyInformation.html +387 -0
  11. data/doc/R509/ASN1/PolicyQualifiers.html +455 -0
  12. data/doc/R509/ASN1/UserNotice.html +386 -0
  13. data/doc/R509/{Crl.html → CRL.html} +7 -7
  14. data/doc/R509/CRL/Administrator.html +1559 -0
  15. data/doc/R509/{Crl/Parser.html → CRL/SignedList.html} +501 -210
  16. data/doc/R509/{Csr.html → CSR.html} +444 -314
  17. data/doc/R509/Cert.html +866 -617
  18. data/doc/R509/Cert/Extensions.html +52 -41
  19. data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +70 -35
  20. data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +387 -4
  21. data/doc/R509/Cert/Extensions/BasicConstraints.html +61 -25
  22. data/doc/R509/Cert/Extensions/CRLDistributionPoints.html +354 -0
  23. data/doc/R509/Cert/Extensions/CertificatePolicies.html +340 -0
  24. data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +440 -49
  25. data/doc/R509/Cert/Extensions/{CrlDistributionPoints.html → InhibitAnyPolicy.html} +52 -35
  26. data/doc/R509/Cert/Extensions/KeyUsage.html +247 -121
  27. data/doc/R509/Cert/Extensions/NameConstraints.html +445 -0
  28. data/doc/R509/Cert/Extensions/OCSPNoCheck.html +239 -0
  29. data/doc/R509/Cert/Extensions/PolicyConstraints.html +424 -0
  30. data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +437 -62
  31. data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +52 -10
  32. data/doc/R509/CertificateAuthority.html +4 -4
  33. data/doc/R509/CertificateAuthority/Signer.html +154 -187
  34. data/doc/R509/Config.html +6 -6
  35. data/doc/R509/Config/{CaConfig.html → CAConfig.html} +451 -348
  36. data/doc/R509/Config/{CaConfigPool.html → CAConfigPool.html} +47 -47
  37. data/doc/R509/Config/CAProfile.html +1015 -0
  38. data/doc/R509/Config/SubjectItemPolicy.html +86 -86
  39. data/doc/R509/IOHelpers.html +22 -22
  40. data/doc/R509/MessageDigest.html +14 -14
  41. data/doc/R509/NameSanitizer.html +53 -53
  42. data/doc/R509/{Ocsp.html → OCSP.html} +9 -9
  43. data/doc/R509/{Ocsp → OCSP}/Request.html +7 -7
  44. data/doc/R509/{Ocsp → OCSP}/Request/Nonce.html +56 -11
  45. data/doc/R509/{Ocsp → OCSP}/Response.html +44 -44
  46. data/doc/R509/{OidMapper.html → OIDMapper.html} +23 -39
  47. data/doc/R509/PrivateKey.html +415 -168
  48. data/doc/R509/R509Error.html +3 -3
  49. data/doc/R509/{Spki.html → SPKI.html} +354 -192
  50. data/doc/R509/Subject.html +224 -113
  51. data/doc/R509/Validity.html +27 -5
  52. data/doc/R509/Validity/Checker.html +13 -13
  53. data/doc/R509/Validity/DefaultChecker.html +13 -13
  54. data/doc/R509/Validity/DefaultWriter.html +14 -14
  55. data/doc/R509/Validity/Status.html +39 -39
  56. data/doc/R509/Validity/Writer.html +18 -18
  57. data/doc/_index.html +138 -35
  58. data/doc/class_list.html +1 -1
  59. data/doc/css/style.css +10 -0
  60. data/doc/file.README.html +368 -171
  61. data/doc/file.r509.html +92 -69
  62. data/doc/frames.html +1 -1
  63. data/doc/index.html +368 -171
  64. data/doc/method_list.html +910 -390
  65. data/doc/top-level-namespace.html +3 -3
  66. data/lib/r509.rb +32 -16
  67. data/lib/r509/asn1.rb +375 -0
  68. data/lib/r509/cert.rb +381 -364
  69. data/lib/r509/cert/extensions.rb +443 -76
  70. data/lib/r509/certificate_authority.rb +407 -0
  71. data/lib/r509/config.rb +547 -351
  72. data/lib/r509/crl.rb +336 -366
  73. data/lib/r509/csr.rb +278 -289
  74. data/lib/r509/ec-hack.rb +37 -0
  75. data/lib/r509/exceptions.rb +3 -3
  76. data/lib/r509/io_helpers.rb +44 -44
  77. data/lib/r509/message_digest.rb +53 -0
  78. data/lib/r509/ocsp.rb +80 -70
  79. data/lib/r509/oid_mapper.rb +32 -0
  80. data/lib/r509/private_key.rb +228 -0
  81. data/lib/r509/spki.rb +145 -93
  82. data/lib/r509/subject.rb +203 -110
  83. data/lib/r509/validity.rb +70 -68
  84. data/lib/r509/version.rb +2 -2
  85. data/r509.yaml +92 -69
  86. data/spec/asn1_spec.rb +402 -0
  87. data/spec/cert/extensions_spec.rb +957 -494
  88. data/spec/cert_spec.rb +382 -307
  89. data/spec/certificate_authority_spec.rb +668 -250
  90. data/spec/config_spec.rb +515 -302
  91. data/spec/crl_spec.rb +197 -198
  92. data/spec/csr_spec.rb +334 -289
  93. data/spec/fixtures.rb +247 -171
  94. data/spec/fixtures/cert1.der +0 -0
  95. data/spec/fixtures/cert1.pem +0 -0
  96. data/spec/fixtures/cert1_public_key_modulus.txt +0 -0
  97. data/spec/fixtures/cert3.p12 +0 -0
  98. data/spec/fixtures/cert3.pem +0 -0
  99. data/spec/fixtures/cert3_key.pem +0 -0
  100. data/spec/fixtures/cert3_key_des3.pem +0 -0
  101. data/spec/fixtures/cert4.pem +0 -0
  102. data/spec/fixtures/cert5.pem +0 -0
  103. data/spec/fixtures/cert6.pem +0 -0
  104. data/spec/fixtures/cert_expired.pem +0 -0
  105. data/spec/fixtures/cert_inhibit.pem +24 -0
  106. data/spec/fixtures/cert_name_constraints.pem +29 -0
  107. data/spec/fixtures/cert_not_yet_valid.pem +0 -0
  108. data/spec/fixtures/cert_ocsp_no_check.pem +18 -0
  109. data/spec/fixtures/cert_policy_constraints.pem +31 -0
  110. data/spec/fixtures/cert_san.pem +0 -0
  111. data/spec/fixtures/cert_san2.pem +0 -0
  112. data/spec/fixtures/cert_unknown_extension.pem +28 -0
  113. data/spec/fixtures/config_pool_test_minimal.yaml +11 -11
  114. data/spec/fixtures/config_test.yaml +54 -36
  115. data/spec/fixtures/config_test_dsa.yaml +35 -0
  116. data/spec/fixtures/config_test_ec.yaml +35 -0
  117. data/spec/fixtures/config_test_engine_key.yaml +5 -5
  118. data/spec/fixtures/config_test_engine_no_key_name.yaml +4 -4
  119. data/spec/fixtures/config_test_minimal.yaml +4 -4
  120. data/spec/fixtures/config_test_password.yaml +5 -5
  121. data/spec/fixtures/config_test_various.yaml +111 -74
  122. data/spec/fixtures/crl_list_file.txt +0 -0
  123. data/spec/fixtures/crl_with_reason.pem +0 -0
  124. data/spec/fixtures/csr1.der +0 -0
  125. data/spec/fixtures/csr1.pem +0 -0
  126. data/spec/fixtures/csr1_key.der +0 -0
  127. data/spec/fixtures/csr1_key.pem +0 -0
  128. data/spec/fixtures/csr1_key_encrypted_des3.pem +0 -0
  129. data/spec/fixtures/csr1_newlines.pem +0 -0
  130. data/spec/fixtures/csr1_no_begin_end.pem +0 -0
  131. data/spec/fixtures/csr1_public_key_modulus.txt +0 -0
  132. data/spec/fixtures/csr2.pem +0 -0
  133. data/spec/fixtures/csr2_key.pem +0 -0
  134. data/spec/fixtures/csr3.pem +0 -0
  135. data/spec/fixtures/csr4.pem +0 -0
  136. data/spec/fixtures/csr_dsa.pem +0 -0
  137. data/spec/fixtures/csr_invalid_signature.pem +0 -0
  138. data/spec/fixtures/dsa_key.pem +0 -0
  139. data/spec/fixtures/dsa_root.cer +28 -0
  140. data/spec/fixtures/dsa_root.key +20 -0
  141. data/spec/fixtures/ec_csr2.der +0 -0
  142. data/spec/fixtures/ec_csr2.pem +8 -0
  143. data/spec/fixtures/ec_key1.der +0 -0
  144. data/spec/fixtures/ec_key1.pem +6 -0
  145. data/spec/fixtures/ec_key1_encrypted.pem +9 -0
  146. data/spec/fixtures/ec_key2.pem +6 -0
  147. data/spec/fixtures/hmacsha1.sig +1 -0
  148. data/spec/fixtures/hmacsha512.sig +1 -0
  149. data/spec/fixtures/key4.pem +0 -0
  150. data/spec/fixtures/key4_encrypted_des3.pem +0 -0
  151. data/spec/fixtures/missing_key_identifier_ca.cer +0 -0
  152. data/spec/fixtures/missing_key_identifier_ca.key +0 -0
  153. data/spec/fixtures/ocsptest.r509.local.pem +0 -0
  154. data/spec/fixtures/ocsptest.r509.local_ocsp_request.der +0 -0
  155. data/spec/fixtures/ocsptest2.r509.local.pem +0 -0
  156. data/spec/fixtures/second_ca.cer +0 -0
  157. data/spec/fixtures/second_ca.key +0 -0
  158. data/spec/fixtures/spkac.der +0 -0
  159. data/spec/fixtures/spkac.txt +0 -0
  160. data/spec/fixtures/spkac_dsa.txt +1 -1
  161. data/spec/fixtures/spkac_dsa_no_verify.txt +1 -0
  162. data/spec/fixtures/spkac_ec.txt +1 -0
  163. data/spec/fixtures/spkac_rsa_newlines.txt +13 -0
  164. data/spec/fixtures/stca.pem +0 -0
  165. data/spec/fixtures/stca_ocsp_request.der +0 -0
  166. data/spec/fixtures/stca_ocsp_response.der +0 -0
  167. data/spec/fixtures/test1.csr +0 -0
  168. data/spec/fixtures/test_ca.cer +0 -0
  169. data/spec/fixtures/test_ca.key +0 -0
  170. data/spec/fixtures/test_ca.p12 +0 -0
  171. data/spec/fixtures/test_ca_des3.key +0 -0
  172. data/spec/fixtures/test_ca_ec.cer +14 -0
  173. data/spec/fixtures/test_ca_ec.key +6 -0
  174. data/spec/fixtures/test_ca_ec_ee.cer +22 -0
  175. data/spec/fixtures/test_ca_ec_ee.key +6 -0
  176. data/spec/fixtures/test_ca_ocsp.cer +0 -0
  177. data/spec/fixtures/test_ca_ocsp.key +0 -0
  178. data/spec/fixtures/test_ca_ocsp.p12 +0 -0
  179. data/spec/fixtures/test_ca_ocsp_chain.txt +0 -0
  180. data/spec/fixtures/test_ca_ocsp_response.der +0 -0
  181. data/spec/fixtures/test_ca_subroot.cer +0 -0
  182. data/spec/fixtures/test_ca_subroot.key +0 -0
  183. data/spec/fixtures/test_ca_subroot_ocsp.cer +0 -0
  184. data/spec/fixtures/test_ca_subroot_ocsp.key +0 -0
  185. data/spec/fixtures/test_ca_subroot_ocsp_response.der +0 -0
  186. data/spec/fixtures/unknown_oid.csr +0 -0
  187. data/spec/message_digest_spec.rb +104 -84
  188. data/spec/ocsp_spec.rb +105 -105
  189. data/spec/oid_mapper_spec.rb +21 -21
  190. data/spec/private_key_spec.rb +275 -0
  191. data/spec/r509_spec.rb +35 -0
  192. data/spec/spec_helper.rb +15 -6
  193. data/spec/spki_spec.rb +221 -142
  194. data/spec/subject_spec.rb +232 -164
  195. data/spec/validity_spec.rb +91 -91
  196. metadata +79 -25
  197. data/doc/R509/Config/CaProfile.html +0 -651
  198. data/doc/R509/Crl/Administrator.html +0 -2073
  199. data/lib/r509/certificateauthority.rb +0 -290
  200. data/lib/r509/messagedigest.rb +0 -49
  201. data/lib/r509/oidmapper.rb +0 -32
  202. data/lib/r509/privatekey.rb +0 -185
  203. data/spec/privatekey_spec.rb +0 -198
data/Rakefile CHANGED
@@ -5,34 +5,37 @@ require "#{File.dirname(__FILE__)}/lib/r509/version"
5
5
  task :default => :spec
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- desc 'Run all rspec tests with rcov (1.8 only)'
9
- RSpec::Core::RakeTask.new(:rcov) do |t|
10
- t.rcov_opts = %q[--exclude "spec,gems"]
11
- t.rcov = true
12
- end
13
-
14
-
15
8
  namespace :gem do
16
- desc 'Build the gem'
17
- task :build do
18
- puts `yard`
19
- puts `gem build r509.gemspec`
20
- end
21
-
22
- desc 'Install gem'
23
- task :install do
24
- puts `gem install r509-#{R509::VERSION}.gem`
25
- end
9
+ desc 'Build the gem'
10
+ task :build do
11
+ puts `yard`
12
+ puts `gem build r509.gemspec`
13
+ end
14
+
15
+ desc 'Install gem'
16
+ task :install do
17
+ puts `gem install r509-#{R509::VERSION}.gem`
18
+ end
19
+
20
+ desc 'Uninstall gem'
21
+ task :uninstall do
22
+ puts `gem uninstall r509`
23
+ end
24
+ end
26
25
 
27
- desc 'Uninstall gem'
28
- task :uninstall do
29
- puts `gem uninstall r509`
30
- end
26
+ desc "Open an irb session with the lib dir included"
27
+ task :irb do
28
+ $:.unshift File.expand_path("../../lib", __FILE__)
29
+ $:.unshift File.expand_path("../", __FILE__)
30
+ require 'r509'
31
+ require 'irb'
32
+ ARGV.clear
33
+ IRB.start
31
34
  end
32
35
 
33
36
 
34
37
  desc 'Build yard documentation'
35
38
  task :yard do
36
- puts `yard`
37
- `open doc/index.html`
39
+ puts `yard`
40
+ `open doc/index.html`
38
41
  end
data/bin/r509 CHANGED
@@ -1,143 +1,157 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'r509'
4
- require 'r509/version'
5
- require 'openssl'
6
4
  require 'trollop'
7
5
 
8
6
  opts = Trollop::options do
9
- opt :interactive, "Interactive CSR/self-signed certificate generation. Overrides all flags other than keyout and out."
10
- opt :subject, "X509 subject / delimited. Example: /CN=test.com/O=Org/C=US/ST=Illinois/L=Chicago", :type => :string
11
- opt :message_digest, "Message digest to use. sha1, sha256, sha512, md5", :type => :string, :default => 'sha1'
12
- opt :duration, "Self-sign the certificate with the duration (in days) specified.", :type => :integer
13
- opt :bits, "Bit length of generated key.", :type => :integer, :default => 2048
14
- opt :keyout, "File name to save generated key.", :type => :string
15
- opt :out, "File name to save generated CSR or self-signed certificate", :type => :string
16
- version "r509 #{R509::VERSION}"
7
+ opt :interactive, "Interactive CSR/self-signed certificate generation. Overrides all flags other than keyout and out."
8
+ opt :subject, "X509 subject / delimited. Example: /CN=test.com/O=Org/C=US/ST=Illinois/L=Chicago", :type => :string
9
+ opt :message_digest, "Message digest to use. sha1, sha224, sha256, sha384, sha512, md5", :type => :string, :default => 'sha1'
10
+ opt :duration, "Self-sign the certificate with the duration (in days) specified.", :type => :integer
11
+ opt :bits, "Bit length of generated key. Ignored for EC.", :type => :integer, :default => 2048
12
+ opt :curve_name, "Name of elliptic curve to use. Only used for EC.", :type => :string, :default => 'secp384r1'
13
+ opt :keyout, "File name to save generated key.", :type => :string
14
+ opt :out, "File name to save generated CSR or self-signed certificate", :type => :string
15
+ opt :type, "Type of key to generate. RSA/DSA/EC", :type => :string, :default => "RSA"
16
+ version "r509 #{R509::VERSION}"
17
17
  end
18
18
 
19
19
  if opts[:interactive] == true or opts[:subject].nil? then
20
+ if opts[:type].upcase == "RSA" or opts[:type].upcase == "DSA"
20
21
  print "CSR Bit Strength (2048):"
21
22
  bit_strength = gets.chomp
22
23
  bit_strength = (bit_strength.to_i > 0)? bit_strength.to_i : 2048
24
+ elsif opts[:type].upcase == "EC"
25
+ print "Curve Name (secp384r1):"
26
+ curve_name = gets.chomp
27
+ curve_name = (not curve_name.empty?)? curve_name : 'secp384r1'
28
+ else
29
+ puts "Invalid key type specified. RSA/DSA/EC"
30
+ exit
31
+ end
23
32
 
24
- print "Message Digest (sha1):"
25
- md = gets.chomp
26
- md = case md
27
- when 'sha1' then 'sha1'
28
- when 'sha256' then 'sha256'
29
- when 'sha512' then 'sha512'
30
- when 'md5' then 'md5'
31
- else 'sha1'
32
- end
33
+ print "Message Digest (sha1):"
34
+ md = gets.chomp
35
+ opts[:message_digest] = case md
36
+ when 'sha1' then 'sha1'
37
+ when 'sha224' then 'sha224'
38
+ when 'sha256' then 'sha256'
39
+ when 'sha384' then 'sha384'
40
+ when 'sha512' then 'sha512'
41
+ when 'md5' then 'md5'
42
+ else 'sha1'
43
+ end
33
44
 
34
- subject = []
35
- print "C (US): "
36
- c = gets.chomp
37
- c = c.empty? ? 'US':c;
38
- subject.push ['C',c]
45
+ subject = []
46
+ print "C (US): "
47
+ c = gets.chomp
48
+ c = c.empty? ? 'US':c;
49
+ subject.push ['C',c]
39
50
 
40
- print "ST (Illinois): "
41
- st = gets.chomp
42
- st = st.empty? ? 'Illinois':st;
43
- subject.push ['ST',st]
51
+ print "ST (Illinois): "
52
+ st = gets.chomp
53
+ st = st.empty? ? 'Illinois':st;
54
+ subject.push ['ST',st]
44
55
 
45
- print "L (Chicago): "
46
- l = gets.chomp
47
- l = l.empty? ? 'Chicago':l;
48
- subject.push ['L',l]
56
+ print "L (Chicago): "
57
+ l = gets.chomp
58
+ l = l.empty? ? 'Chicago':l;
59
+ subject.push ['L',l]
49
60
 
50
- print "O (r509 LLC): "
51
- o = gets.chomp
52
- o = o.empty? ? 'r509 LLC':o;
53
- subject.push ['O',o]
61
+ print "O (r509 LLC): "
62
+ o = gets.chomp
63
+ o = o.empty? ? 'r509 LLC':o;
64
+ subject.push ['O',o]
54
65
 
55
- print "OU (null by default): "
56
- ou = gets.chomp
57
- if(!ou.empty?) then
58
- subject.push ['OU',ou]
59
- end
66
+ print "OU (null by default): "
67
+ ou = gets.chomp
68
+ if(!ou.empty?) then
69
+ subject.push ['OU',ou]
70
+ end
60
71
 
61
- print "CN: "
62
- subject.push ['CN',gets.chomp]
63
- print "SAN Domains (comma separated):"
64
- san_domains = []
65
- san_domains = gets.chomp.split(',').collect { |domain| domain.strip }
66
- csr = R509::Csr.new(
67
- :subject => subject,
68
- :bit_strength => bit_strength,
69
- :san_names => san_domains,
70
- :message_digest => md
71
- )
72
+ print "CN: "
73
+ subject.push ['CN',gets.chomp]
74
+ print "SAN Domains (comma separated):"
75
+ san_domains = []
76
+ san_domains = gets.chomp.split(',').collect { |domain| domain.strip }
77
+ csr = R509::CSR.new(
78
+ :subject => subject,
79
+ :bit_strength => bit_strength,
80
+ :type => opts[:type].downcase.to_sym,
81
+ :curve_name => curve_name,
82
+ :san_names => san_domains,
83
+ :message_digest => opts[:message_digest]
84
+ )
72
85
 
73
- selfsign = 0
74
- print "Self-signed cert duration in days (null disables self-sign):"
75
- selfsign_input = gets.chomp
76
- if selfsign_input.to_i > 0
77
- selfsign = selfsign_input.to_i
78
- end
86
+ selfsign = 0
87
+ print "Self-signed cert duration in days (null disables self-sign):"
88
+ selfsign_input = gets.chomp
89
+ if selfsign_input.to_i > 0
90
+ selfsign = selfsign_input.to_i
91
+ end
79
92
  elsif not opts[:subject].nil?
80
- subject = OpenSSL::X509::Name.new
81
- opts[:subject].chomp.split('/').each { |item|
82
- if item != '' then
83
- value = item.split('=')
84
- subject.add_entry(value[0],value[1])
85
- end
86
- }
87
- bit_strength = opts[:bits]
88
- csr = R509::Csr.new(
89
- :subject => subject,
90
- :bit_strength => bit_strength,
91
- :message_digest => opts[:message_digest]
92
- )
93
- selfsign = opts[:duration] || 0
93
+ subject = OpenSSL::X509::Name.new
94
+ opts[:subject].chomp.split('/').each { |item|
95
+ if item != '' then
96
+ value = item.split('=')
97
+ subject.add_entry(value[0],value[1])
98
+ end
99
+ }
100
+ csr = R509::CSR.new(
101
+ :subject => subject,
102
+ :bit_strength => opts[:bits],
103
+ :type => opts[:type].downcase.to_sym,
104
+ :curve_name => opts[:curve_name],
105
+ :message_digest => opts[:message_digest]
106
+ )
107
+ selfsign = opts[:duration] || 0
94
108
  end
95
109
 
96
110
  if selfsign > 0
97
- ca = R509::CertificateAuthority::Signer.new
98
- cert = ca.selfsign(
99
- :csr => csr,
100
- :not_after => Time.now.to_i+86400*selfsign,
101
- :message_digest => opts[:message_digest]
102
- )
103
- if opts[:keyout].nil?
104
- puts csr.key.to_pem
105
- else
106
- File.open(opts[:keyout], 'w') {|f| f.write(csr.key.to_pem) }
107
- end
108
- if opts[:out].nil?
109
- puts cert.to_pem
110
- else
111
- File.open(opts[:out], 'w') {|f| f.write(cert.to_pem) }
112
- end
111
+ ca = R509::CertificateAuthority::Signer.new
112
+ cert = ca.selfsign(
113
+ :csr => csr,
114
+ :not_after => Time.now.to_i+86400*selfsign,
115
+ :message_digest => opts[:message_digest]
116
+ )
117
+ if opts[:keyout].nil?
118
+ puts csr.key.to_pem
119
+ else
120
+ File.open(opts[:keyout], 'w') {|f| f.write(csr.key.to_pem) }
121
+ end
122
+ if opts[:out].nil?
123
+ puts cert.to_pem
124
+ else
125
+ File.open(opts[:out], 'w') {|f| f.write(cert.to_pem) }
126
+ end
113
127
 
114
- puts cert.subject
115
- if not cert.san_names.empty?
116
- puts "SAN(s): "+cert.san_names.join(", ")
117
- end
128
+ puts cert.subject
129
+ if not cert.san.nil?
130
+ puts "SAN(s): "+cert.san.names.map { |n| n.value }.join(", ")
131
+ end
118
132
  else
119
- if opts[:keyout].nil?
120
- puts csr.key.to_pem
121
- else
122
- File.open(opts[:keyout], 'w') {|f| f.write(csr.key.to_pem) }
123
- end
133
+ if opts[:keyout].nil?
134
+ puts csr.key.to_pem
135
+ else
136
+ File.open(opts[:keyout], 'w') {|f| f.write(csr.key.to_pem) }
137
+ end
124
138
 
125
- if opts[:out].nil?
126
- puts csr.to_pem
127
- else
128
- File.open(opts[:out], 'w') {|f| f.write(csr.to_pem) }
129
- end
139
+ if opts[:out].nil?
140
+ puts csr.to_pem
141
+ else
142
+ File.open(opts[:out], 'w') {|f| f.write(csr.to_pem) }
143
+ end
130
144
 
131
- puts csr.subject
132
- if not csr.san_names.empty?
133
- puts "SAN(s): "+csr.san_names.join(", ")
134
- end
145
+ puts csr.subject
146
+ if not csr.san.nil?
147
+ puts "SAN(s): "+csr.san.names.map{|n| n.value}.join(", ")
148
+ end
135
149
  end
136
150
 
137
151
  if RUBY_PLATFORM.match('darwin') != nil then
138
- if selfsign > 0
139
- IO.popen('pbcopy','w').puts cert
140
- else
141
- IO.popen('pbcopy','w').puts csr
142
- end
152
+ if selfsign > 0
153
+ IO.popen('pbcopy','w').puts cert
154
+ else
155
+ IO.popen('pbcopy','w').puts csr
156
+ end
143
157
  end
data/bin/r509-parse CHANGED
@@ -1,35 +1,35 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'r509'
4
- require 'r509/version'
5
- require 'openssl'
6
4
 
7
5
  if ARGV[0].nil? then
8
- puts "CSR and certificate parsing using r509 v#{R509::VERSION}."
9
- puts "Usage: r509-parse <cert or csr>"
6
+ puts "CSR and certificate parsing using r509 v#{R509::VERSION}."
7
+ puts "Usage: r509-parse <cert or csr>"
10
8
  else
9
+ begin
10
+ csr = R509::CSR.load_from_file ARGV[0]
11
+ rescue
12
+ end
13
+ if not csr.nil?
14
+ puts "Subject: #{csr.subject}"
15
+ puts "Algorithm: #{csr.signature_algorithm}"
16
+ puts "SAN Names: #{csr.san.names.map { |n| n.value }.join(" , ")}"
17
+ else
11
18
  begin
12
- csr = R509::Csr.load_from_file ARGV[0]
19
+ cert = R509::Cert.load_from_file ARGV[0]
13
20
  rescue
14
21
  end
15
- if not csr.nil?
16
- puts "Subject: #{csr.subject}"
17
- puts "SAN Names: #{csr.san_names.join(" , ")}"
22
+ if not cert.nil?
23
+ puts "Subject: #{cert.subject}"
24
+ puts "Issuer: #{cert.issuer}"
25
+ puts "Algorithm: #{cert.signature_algorithm}"
26
+ puts "SAN Names: #{cert.san.names.map { |n| n.value }.join(" , ")}"
27
+ puts "Not Before: #{cert.not_before}"
28
+ puts "Not After: #{cert.not_after}"
29
+ puts "Serial (Hex): #{cert.hexserial}"
30
+ puts "Serial (Decimal): #{cert.serial}"
18
31
  else
19
- begin
20
- cert = R509::Cert.load_from_file ARGV[0]
21
- rescue
22
- end
23
- if not cert.nil?
24
- puts "Subject: #{cert.subject}"
25
- puts "Issuer: #{cert.issuer}"
26
- puts "SAN Names: #{cert.san_names.join(" , ")}"
27
- puts "Not Before: #{cert.not_before}"
28
- puts "Not After: #{cert.not_after}"
29
- puts "Serial (Hex): #{cert.serial.to_s(16).upcase}"
30
- puts "Serial (Decimal): #{cert.serial}"
31
- else
32
- puts "Failed to parse CSR or certificate"
33
- end
32
+ puts "Failed to parse CSR or certificate"
34
33
  end
34
+ end
35
35
  end
data/doc/R509.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Module: R509
8
8
 
9
- &mdash; Documentation by YARD 0.8.2.1
9
+ &mdash; Documentation by YARD 0.8.5
10
10
 
11
11
  </title>
12
12
 
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="r1 last">Defined in:</dt>
82
82
  <dd class="r1 last">lib/r509.rb<span class="defines">,<br />
83
- lib/r509/csr.rb,<br /> lib/r509/crl.rb,<br /> lib/r509/spki.rb,<br /> lib/r509/cert.rb,<br /> lib/r509/config.rb,<br /> lib/r509/version.rb,<br /> lib/r509/subject.rb,<br /> lib/r509/oidmapper.rb,<br /> lib/r509/privatekey.rb,<br /> lib/r509/exceptions.rb,<br /> lib/r509/io_helpers.rb,<br /> lib/r509/messagedigest.rb,<br /> lib/r509/cert/extensions.rb</span>
83
+ lib/r509/csr.rb,<br /> lib/r509/crl.rb,<br /> lib/r509/cert.rb,<br /> lib/r509/spki.rb,<br /> lib/r509/asn1.rb,<br /> lib/r509/config.rb,<br /> lib/r509/subject.rb,<br /> lib/r509/version.rb,<br /> lib/r509/oid_mapper.rb,<br /> lib/r509/exceptions.rb,<br /> lib/r509/io_helpers.rb,<br /> lib/r509/private_key.rb,<br /> lib/r509/message_digest.rb,<br /> lib/r509/cert/extensions.rb</span>
84
84
  </dd>
85
85
 
86
86
  </dl>
@@ -102,11 +102,11 @@ support.</p>
102
102
  <p class="children">
103
103
 
104
104
 
105
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="R509/CertificateAuthority.html" title="R509::CertificateAuthority (module)">CertificateAuthority</a></span>, <span class='object_link'><a href="R509/Config.html" title="R509::Config (module)">Config</a></span>, <span class='object_link'><a href="R509/Crl.html" title="R509::Crl (module)">Crl</a></span>, <span class='object_link'><a href="R509/IOHelpers.html" title="R509::IOHelpers (module)">IOHelpers</a></span>, <span class='object_link'><a href="R509/Ocsp.html" title="R509::Ocsp (module)">Ocsp</a></span>, <span class='object_link'><a href="R509/Validity.html" title="R509::Validity (module)">Validity</a></span>
105
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="R509/ASN1.html" title="R509::ASN1 (module)">ASN1</a></span>, <span class='object_link'><a href="R509/CRL.html" title="R509::CRL (module)">CRL</a></span>, <span class='object_link'><a href="R509/CertificateAuthority.html" title="R509::CertificateAuthority (module)">CertificateAuthority</a></span>, <span class='object_link'><a href="R509/Config.html" title="R509::Config (module)">Config</a></span>, <span class='object_link'><a href="R509/IOHelpers.html" title="R509::IOHelpers (module)">IOHelpers</a></span>, <span class='object_link'><a href="R509/OCSP.html" title="R509::OCSP (module)">OCSP</a></span>, <span class='object_link'><a href="R509/OIDMapper.html" title="R509::OIDMapper (module)">OIDMapper</a></span>, <span class='object_link'><a href="R509/Validity.html" title="R509::Validity (module)">Validity</a></span>
106
106
 
107
107
 
108
108
 
109
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="R509/Cert.html" title="R509::Cert (class)">Cert</a></span>, <span class='object_link'><a href="R509/Csr.html" title="R509::Csr (class)">Csr</a></span>, <span class='object_link'><a href="R509/MessageDigest.html" title="R509::MessageDigest (class)">MessageDigest</a></span>, <span class='object_link'><a href="R509/NameSanitizer.html" title="R509::NameSanitizer (class)">NameSanitizer</a></span>, <span class='object_link'><a href="R509/OidMapper.html" title="R509::OidMapper (class)">OidMapper</a></span>, <span class='object_link'><a href="R509/PrivateKey.html" title="R509::PrivateKey (class)">PrivateKey</a></span>, <span class='object_link'><a href="R509/R509Error.html" title="R509::R509Error (class)">R509Error</a></span>, <span class='object_link'><a href="R509/Spki.html" title="R509::Spki (class)">Spki</a></span>, <span class='object_link'><a href="R509/Subject.html" title="R509::Subject (class)">Subject</a></span>
109
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="R509/CSR.html" title="R509::CSR (class)">CSR</a></span>, <span class='object_link'><a href="R509/Cert.html" title="R509::Cert (class)">Cert</a></span>, <span class='object_link'><a href="R509/MessageDigest.html" title="R509::MessageDigest (class)">MessageDigest</a></span>, <span class='object_link'><a href="R509/NameSanitizer.html" title="R509::NameSanitizer (class)">NameSanitizer</a></span>, <span class='object_link'><a href="R509/PrivateKey.html" title="R509::PrivateKey (class)">PrivateKey</a></span>, <span class='object_link'><a href="R509/R509Error.html" title="R509::R509Error (class)">R509Error</a></span>, <span class='object_link'><a href="R509/SPKI.html" title="R509::SPKI (class)">SPKI</a></span>, <span class='object_link'><a href="R509/Subject.html" title="R509::Subject (class)">Subject</a></span>
110
110
 
111
111
 
112
112
  </p>
@@ -129,7 +129,7 @@ support.</p>
129
129
 
130
130
  </div>
131
131
  </dt>
132
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.8.1</span><span class='tstring_end'>&quot;</span></span></pre></dd>
132
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.9</span><span class='tstring_end'>&quot;</span></span></pre></dd>
133
133
 
134
134
  </dl>
135
135
 
@@ -140,14 +140,176 @@ support.</p>
140
140
 
141
141
 
142
142
 
143
+
144
+ <h2>
145
+ Class Method Summary
146
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
147
+ </h2>
148
+
149
+ <ul class="summary">
150
+
151
+ <li class="public ">
152
+ <span class="summary_signature">
153
+
154
+ <a href="#ec_supported%3F-class_method" title="ec_supported? (class method)">+ (Boolean) <strong>ec_supported?</strong> </a>
155
+
156
+
157
+
158
+ </span>
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+ <span class="summary_desc"><div class='inline'></div></span>
169
+
170
+ </li>
171
+
172
+
173
+ <li class="public ">
174
+ <span class="summary_signature">
175
+
176
+ <a href="#print_debug-class_method" title="print_debug (class method)">+ (Object) <strong>print_debug</strong> </a>
177
+
178
+
179
+
180
+ </span>
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+ <span class="summary_desc"><div class='inline'>
191
+ <p>print version information to console.</p>
192
+ </div></span>
193
+
194
+ </li>
195
+
196
+
197
+ </ul>
198
+
199
+
200
+
201
+
202
+ <div id="class_method_details" class="method_details_list">
203
+ <h2>Class Method Details</h2>
204
+
205
+
206
+ <div class="method_details first">
207
+ <h3 class="signature first" id="ec_supported?-class_method">
208
+
209
+ + (<tt>Boolean</tt>) <strong>ec_supported?</strong>
210
+
211
+
212
+
213
+
214
+
215
+ </h3><div class="docstring">
216
+ <div class="discussion">
217
+
218
+
219
+ </div>
220
+ </div>
221
+ <div class="tags">
222
+
223
+ <p class="tag_title">Returns:</p>
224
+ <ul class="return">
225
+
226
+ <li>
227
+
228
+
229
+ <span class='type'>(<tt>Boolean</tt>)</span>
230
+
231
+
232
+
233
+ </li>
234
+
235
+ </ul>
236
+
237
+ </div><table class="source_code">
238
+ <tr>
239
+ <td>
240
+ <pre class="lines">
241
+
242
+
243
+ 27
244
+ 28
245
+ 29</pre>
246
+ </td>
247
+ <td>
248
+ <pre class="code"><span class="info file"># File 'lib/r509.rb', line 27</span>
249
+
250
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_ec_supported?'>ec_supported?</span>
251
+ <span class='lparen'>(</span><span class='kw'>not</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>PKey</span><span class='op'>::</span><span class='const'>EC</span><span class='op'>::</span><span class='const'>UNSUPPORTED</span><span class='rparen'>)</span><span class='rparen'>)</span>
252
+ <span class='kw'>end</span></pre>
253
+ </td>
254
+ </tr>
255
+ </table>
256
+ </div>
257
+
258
+ <div class="method_details ">
259
+ <h3 class="signature " id="print_debug-class_method">
260
+
261
+ + (<tt>Object</tt>) <strong>print_debug</strong>
262
+
263
+
264
+
265
+
266
+
267
+ </h3><div class="docstring">
268
+ <div class="discussion">
269
+
270
+ <p>print version information to console</p>
271
+
272
+
273
+ </div>
274
+ </div>
275
+ <div class="tags">
276
+
143
277
 
278
+ </div><table class="source_code">
279
+ <tr>
280
+ <td>
281
+ <pre class="lines">
282
+
283
+
284
+ 20
285
+ 21
286
+ 22
287
+ 23
288
+ 24
289
+ 25</pre>
290
+ </td>
291
+ <td>
292
+ <pre class="code"><span class="info file"># File 'lib/r509.rb', line 20</span>
293
+
294
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_print_debug'>print_debug</span>
295
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>r509 v</span><span class='embexpr_beg'>#{</span><span class='const'>R509</span><span class='op'>::</span><span class='const'>VERSION</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
296
+ <span class='id identifier rubyid_puts'>puts</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>OPENSSL_VERSION</span>
297
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Ruby </span><span class='embexpr_beg'>#{</span><span class='const'>RUBY_VERSION</span><span class='rbrace'>}</span><span class='tstring_content'>-p</span><span class='embexpr_beg'>#{</span><span class='const'>RUBY_PATCHLEVEL</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
298
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Elliptic curve support: </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_ec_supported?'>ec_supported?</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
299
+ <span class='kw'>end</span></pre>
300
+ </td>
301
+ </tr>
302
+ </table>
303
+ </div>
304
+
305
+ </div>
144
306
 
145
307
  </div>
146
308
 
147
309
  <div id="footer">
148
- Generated on Thu Nov 8 14:19:24 2012 by
310
+ Generated on Tue Apr 16 10:49:55 2013 by
149
311
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
150
- 0.8.2.1 (ruby-1.9.3).
312
+ 0.8.5 (ruby-1.9.3).
151
313
  </div>
152
314
 
153
315
  </body>