r509 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/CONTRIBUTING.mdown +21 -0
  5. data/LICENSE +13 -0
  6. data/README.mdown +548 -0
  7. data/Rakefile +5 -0
  8. data/bin/r509 +16 -17
  9. data/doc/R509.html +42 -26
  10. data/doc/R509/ASN1.html +22 -16
  11. data/doc/R509/ASN1/GeneralName.html +180 -173
  12. data/doc/R509/ASN1/GeneralNames.html +390 -62
  13. data/doc/R509/CRL.html +9 -7
  14. data/doc/R509/CRL/Administrator.html +208 -623
  15. data/doc/R509/CRL/FileReaderWriter.html +856 -0
  16. data/doc/R509/CRL/ReaderWriter.html +524 -0
  17. data/doc/R509/CRL/SignedList.html +29 -42
  18. data/doc/R509/CSR.html +248 -333
  19. data/doc/R509/Cert.html +364 -491
  20. data/doc/R509/Cert/Extensions.html +134 -43
  21. data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +335 -65
  22. data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +201 -102
  23. data/doc/R509/Cert/Extensions/BasicConstraints.html +297 -68
  24. data/doc/R509/Cert/Extensions/CRLDistributionPoints.html +690 -77
  25. data/doc/R509/Cert/Extensions/CertificatePolicies.html +293 -43
  26. data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +321 -173
  27. data/doc/R509/Cert/Extensions/GeneralNamesMixin.html +656 -0
  28. data/doc/R509/Cert/Extensions/InhibitAnyPolicy.html +270 -42
  29. data/doc/R509/Cert/Extensions/KeyUsage.html +334 -184
  30. data/doc/R509/Cert/Extensions/NameConstraints.html +363 -93
  31. data/doc/R509/{ASN1 → Cert/Extensions}/NoticeReference.html +209 -48
  32. data/doc/R509/Cert/Extensions/OCSPNoCheck.html +244 -17
  33. data/doc/R509/Cert/Extensions/PolicyConstraints.html +322 -71
  34. data/doc/R509/{ASN1 → Cert/Extensions}/PolicyInformation.html +204 -43
  35. data/doc/R509/{ASN1 → Cert/Extensions}/PolicyQualifiers.html +205 -48
  36. data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +348 -143
  37. data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +165 -13
  38. data/doc/R509/{ASN1 → Cert/Extensions}/UserNotice.html +204 -43
  39. data/doc/R509/Cert/Extensions/ValidationMixin.html +120 -0
  40. data/doc/R509/CertificateAuthority.html +9 -7
  41. data/doc/R509/CertificateAuthority/OptionsBuilder.html +475 -0
  42. data/doc/R509/CertificateAuthority/Signer.html +149 -198
  43. data/doc/R509/Config.html +10 -8
  44. data/doc/R509/Config/CAConfig.html +708 -625
  45. data/doc/R509/Config/CAConfigPool.html +179 -31
  46. data/doc/R509/Config/CertProfile.html +1544 -0
  47. data/doc/R509/Config/SubjectItemPolicy.html +437 -99
  48. data/doc/R509/Engine.html +14 -28
  49. data/doc/R509/Helpers.html +1014 -0
  50. data/doc/R509/MessageDigest.html +73 -25
  51. data/doc/R509/NameSanitizer.html +39 -39
  52. data/doc/R509/OCSP.html +5 -5
  53. data/doc/R509/OCSP/Request.html +5 -5
  54. data/doc/R509/OCSP/Request/Nonce.html +5 -5
  55. data/doc/R509/OCSP/Response.html +7 -7
  56. data/doc/R509/OIDMapper.html +121 -6
  57. data/doc/R509/PrivateKey.html +226 -227
  58. data/doc/R509/R509Error.html +5 -5
  59. data/doc/R509/SPKI.html +244 -342
  60. data/doc/R509/Subject.html +241 -70
  61. data/doc/R509/Validity.html +5 -5
  62. data/doc/R509/Validity/Checker.html +5 -5
  63. data/doc/R509/Validity/DefaultChecker.html +5 -9
  64. data/doc/R509/Validity/DefaultWriter.html +5 -9
  65. data/doc/R509/Validity/Status.html +5 -5
  66. data/doc/R509/Validity/Writer.html +5 -5
  67. data/doc/_index.html +92 -30
  68. data/doc/class_list.html +2 -2
  69. data/doc/file.CONTRIBUTING.html +96 -0
  70. data/doc/file.LICENSE.html +87 -0
  71. data/doc/file.README.html +279 -389
  72. data/doc/file.YAML.html +243 -0
  73. data/doc/file.r509.html +298 -105
  74. data/doc/file_list.html +11 -2
  75. data/doc/frames.html +1 -1
  76. data/doc/index.html +279 -389
  77. data/doc/js/full_list.js +6 -1
  78. data/doc/method_list.html +869 -1139
  79. data/doc/top-level-namespace.html +103 -5
  80. data/lib/r509.rb +7 -2
  81. data/lib/r509/asn1.rb +97 -135
  82. data/lib/r509/cert.rb +17 -106
  83. data/lib/r509/cert/extensions.rb +13 -676
  84. data/lib/r509/cert/extensions/authority_info_access.rb +128 -0
  85. data/lib/r509/cert/extensions/authority_key_identifier.rb +100 -0
  86. data/lib/r509/cert/extensions/base.rb +142 -0
  87. data/lib/r509/cert/extensions/basic_constraints.rb +119 -0
  88. data/lib/r509/cert/extensions/certificate_policies.rb +262 -0
  89. data/lib/r509/cert/extensions/crl_distribution_points.rb +98 -0
  90. data/lib/r509/cert/extensions/extended_key_usage.rb +189 -0
  91. data/lib/r509/cert/extensions/inhibit_any_policy.rb +70 -0
  92. data/lib/r509/cert/extensions/key_usage.rb +209 -0
  93. data/lib/r509/cert/extensions/name_constraints.rb +179 -0
  94. data/lib/r509/cert/extensions/ocsp_no_check.rb +56 -0
  95. data/lib/r509/cert/extensions/policy_constraints.rb +122 -0
  96. data/lib/r509/cert/extensions/subject_alternative_name.rb +88 -0
  97. data/lib/r509/cert/extensions/subject_key_identifier.rb +56 -0
  98. data/lib/r509/cert/extensions/validation_mixin.rb +42 -0
  99. data/lib/r509/certificate_authority/options_builder.rb +142 -0
  100. data/lib/r509/certificate_authority/signer.rb +189 -0
  101. data/lib/r509/config.rb +3 -600
  102. data/lib/r509/config/ca_config.rb +414 -0
  103. data/lib/r509/config/cert_profile.rb +110 -0
  104. data/lib/r509/config/subject_item_policy.rb +118 -0
  105. data/lib/r509/crl/administrator.rb +169 -0
  106. data/lib/r509/crl/reader_writer.rb +109 -0
  107. data/lib/r509/crl/signed_list.rb +135 -0
  108. data/lib/r509/csr.rb +35 -116
  109. data/lib/r509/engine.rb +21 -11
  110. data/lib/r509/helpers.rb +110 -0
  111. data/lib/r509/io_helpers.rb +18 -13
  112. data/lib/r509/message_digest.rb +13 -3
  113. data/lib/r509/oid_mapper.rb +14 -0
  114. data/lib/r509/private_key.rb +74 -50
  115. data/lib/r509/spki.rb +50 -113
  116. data/lib/r509/subject.rb +24 -2
  117. data/lib/r509/trollop.rb +788 -0
  118. data/lib/r509/version.rb +1 -1
  119. data/r509.yaml +289 -96
  120. data/spec/asn1_spec.rb +171 -98
  121. data/spec/cert/extensions/authority_info_access_spec.rb +247 -0
  122. data/spec/cert/extensions/authority_key_identifier_spec.rb +85 -0
  123. data/spec/cert/extensions/base_spec.rb +172 -0
  124. data/spec/cert/extensions/basic_constraints_spec.rb +185 -0
  125. data/spec/cert/extensions/certificate_policies_spec.rb +288 -0
  126. data/spec/cert/extensions/crl_distribution_points_spec.rb +149 -0
  127. data/spec/cert/extensions/extended_key_usage_spec.rb +174 -0
  128. data/spec/cert/extensions/inhibit_any_policy_spec.rb +92 -0
  129. data/spec/cert/extensions/key_usage_spec.rb +172 -0
  130. data/spec/cert/extensions/name_constraints_spec.rb +335 -0
  131. data/spec/cert/extensions/ocsp_no_check_spec.rb +76 -0
  132. data/spec/cert/extensions/policy_constraints_spec.rb +155 -0
  133. data/spec/cert/extensions/subject_alternative_name_spec.rb +354 -0
  134. data/spec/cert/extensions/subject_key_identifier_spec.rb +64 -0
  135. data/spec/cert_spec.rb +11 -9
  136. data/spec/certificate_authority/options_builder_spec.rb +307 -0
  137. data/spec/certificate_authority/signer_spec.rb +278 -0
  138. data/spec/config/ca_config_spec.rb +405 -0
  139. data/spec/config/cert_profile_spec.rb +88 -0
  140. data/spec/config/subject_item_policy_spec.rb +81 -0
  141. data/spec/crl/administrator_spec.rb +199 -0
  142. data/spec/crl/reader_writer_spec.rb +97 -0
  143. data/spec/crl/signed_list_spec.rb +84 -0
  144. data/spec/csr_spec.rb +43 -36
  145. data/spec/engine_spec.rb +51 -0
  146. data/spec/fixtures.rb +40 -40
  147. data/spec/fixtures/cert1.pem +1 -1
  148. data/spec/fixtures/config_pool_test_minimal.yaml +11 -15
  149. data/spec/fixtures/config_test.yaml +96 -59
  150. data/spec/fixtures/config_test_dsa.yaml +29 -35
  151. data/spec/fixtures/config_test_ec.yaml +29 -35
  152. data/spec/fixtures/config_test_engine_key.yaml +7 -7
  153. data/spec/fixtures/config_test_engine_no_key_name.yaml +6 -6
  154. data/spec/fixtures/config_test_minimal.yaml +3 -5
  155. data/spec/fixtures/config_test_password.yaml +4 -6
  156. data/spec/fixtures/config_test_various.yaml +147 -137
  157. data/spec/fixtures/crl_list_file.txt +1 -1
  158. data/spec/fixtures/test_ca_crl.cer +20 -0
  159. data/spec/fixtures/test_ca_crl.key +28 -0
  160. data/spec/fixtures/test_ca_crl.p12 +0 -0
  161. data/spec/message_digest_spec.rb +6 -0
  162. data/spec/oid_mapper_spec.rb +11 -0
  163. data/spec/private_key_spec.rb +19 -18
  164. data/spec/spec_helper.rb +10 -6
  165. data/spec/spki_spec.rb +38 -19
  166. data/spec/subject_spec.rb +16 -0
  167. metadata +108 -59
  168. metadata.gz.sig +0 -0
  169. data/README.md +0 -638
  170. data/doc/R509/Config/CAProfile.html +0 -1015
  171. data/doc/R509/IOHelpers.html +0 -564
  172. data/lib/r509/certificate_authority.rb +0 -407
  173. data/lib/r509/crl.rb +0 -351
  174. data/spec/cert/extensions_spec.rb +0 -1095
  175. data/spec/certificate_authority_spec.rb +0 -681
  176. data/spec/config_spec.rb +0 -562
  177. data/spec/crl_spec.rb +0 -226
@@ -1,681 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe R509::CertificateAuthority::Signer do
4
- before :each do
5
- @csr = TestFixtures::CSR
6
- @csr_invalid_signature = TestFixtures::CSR_INVALID_SIGNATURE
7
- @csr3 = TestFixtures::CSR3
8
- @test_ca_config = TestFixtures.test_ca_config
9
- @ca = R509::CertificateAuthority::Signer.new(@test_ca_config)
10
- @ca_no_profile = R509::CertificateAuthority::Signer.new(TestFixtures.test_ca_no_profile_config)
11
- @spki = TestFixtures::SPKI
12
- end
13
-
14
- it "raises an error if you don't pass csr or spki" do
15
- expect { @ca.sign({ :profile_name => 'server' }) }.to raise_error(ArgumentError, "You must supply either :csr or :spki")
16
- end
17
- it "raises an error if you pass a config that has no private key for ca_cert" do
18
- config = R509::Config::CAConfig.new( :ca_cert => R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT) )
19
- profile = R509::Config::CAProfile.new
20
- config.set_profile("some_profile",profile)
21
- expect { R509::CertificateAuthority::Signer.new(config) }.to raise_error(R509::R509Error, "You must have a private key associated with your CA certificate to issue")
22
- end
23
- it "raises an error if you pass both csr and spki" do
24
- csr = R509::CSR.new(:csr => @csr)
25
- spki = R509::SPKI.new(:spki => @spki, :subject=>[['CN','test']])
26
- expect { @ca.sign({ :spki => spki, :csr => csr, :profile_name => 'server' }) }.to raise_error(ArgumentError, "You can't pass both :csr and :spki")
27
- end
28
- it "raise an error if you don't pass an R509::SPKI in :spki" do
29
- spki = OpenSSL::Netscape::SPKI.new(@spki)
30
- expect { @ca.sign({ :spki => spki, :profile_name => 'server' }) }.to raise_error(ArgumentError, 'You must pass an R509::SPKI object for :spki')
31
- end
32
- it "raise an error if you pass :spki without :subject" do
33
- spki = R509::SPKI.new(:spki => @spki)
34
- expect { @ca.sign({ :spki => spki, :profile_name => 'server' }) }.to raise_error(ArgumentError, 'You must supply :subject when passing :spki')
35
- end
36
- it "raise an error if you don't pass an R509::CSR in :csr" do
37
- csr = OpenSSL::X509::Request.new(@csr)
38
- expect { @ca.sign({ :csr => csr, :profile_name => 'server' }) }.to raise_error(ArgumentError, 'You must pass an R509::CSR object for :csr')
39
- end
40
- it "raises an error if you have no CAProfile with your CAConfig when attempting to issue a cert" do
41
- config = R509::Config::CAConfig.new(
42
- :ca_cert => TestFixtures.test_ca_cert
43
- )
44
- ca = R509::CertificateAuthority::Signer.new(config)
45
- expect { ca.sign(:csr => @csr) }.to raise_error(R509::R509Error, 'You must have at least one CAProfile on your CAConfig to issue')
46
- end
47
- it "properly issues a cert with the default CAProfile configuration" do
48
- csr = R509::CSR.new(:subject => [["CN","testy.mctest"]], :bit_strength => 1024)
49
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
50
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
51
- profile = R509::Config::CAProfile.new
52
- config.set_profile("default",profile)
53
- ca = R509::CertificateAuthority::Signer.new(config)
54
- expect { ca.sign( :csr => csr, :profile_name => 'default') }.to_not raise_error
55
- end
56
- it "properly issues server cert using spki" do
57
- spki = R509::SPKI.new(:spki => @spki)
58
- cert = @ca.sign({ :spki => spki, :profile_name => 'server', :subject=>[['CN','test.local']]})
59
- cert.to_pem.should match(/BEGIN CERTIFICATE/)
60
- cert.subject.to_s.should == '/CN=test.local'
61
- cert.extended_key_usage.web_server_authentication?.should == true
62
- end
63
- it "properly issues server cert" do
64
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
65
- cert = @ca.sign({ :csr => csr, :profile_name => 'server' })
66
- cert.to_pem.should match(/BEGIN CERTIFICATE/)
67
- cert.subject.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Paul Kehrer/CN=langui.sh'
68
- cert.extended_key_usage.web_server_authentication?.should == true
69
- end
70
- it "properly issues cert with all EKUs" do
71
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
72
- config = R509::Config::CAConfig.from_yaml("all_eku_ca", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_various.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
73
- ca = R509::CertificateAuthority::Signer.new(config)
74
- cert = ca.sign({ :csr => csr, :profile_name => 'smorgasbord' })
75
- cert.extended_key_usage.web_server_authentication?.should == true
76
- cert.extended_key_usage.web_client_authentication?.should == true
77
- cert.extended_key_usage.code_signing?.should == true
78
- cert.extended_key_usage.email_protection?.should == true
79
- cert.extended_key_usage.ocsp_signing?.should == true
80
- cert.extended_key_usage.time_stamping?.should == true
81
- end
82
- it "properly issues cert with OCSP noCheck in profile" do
83
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
84
- config = R509::Config::CAConfig.from_yaml("ocsp_no_check_ca", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_various.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
85
- ca = R509::CertificateAuthority::Signer.new(config)
86
- cert = ca.sign({ :csr => csr, :profile_name => 'ocsp_no_check_delegate' })
87
- cert.ocsp_no_check?.should == true
88
- cert.extended_key_usage.ocsp_signing?.should == true
89
- end
90
- it "does not encode noCheck if not specified by the profile" do
91
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
92
- cert = @ca.sign({ :csr => csr, :profile_name => 'server' })
93
- cert.ocsp_no_check?.should == false
94
- end
95
- it "when supplied, uses subject_item_policy to determine allowed subject" do
96
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
97
- cert = @ca.sign({ :csr => csr, :profile_name => 'server_with_subject_item_policy' })
98
- #profile requires C, ST, CN. O and OU are optional
99
- cert.subject.to_s.should == '/C=US/ST=Illinois/O=Paul Kehrer/CN=langui.sh'
100
- end
101
- it "raises error when issuing cert with csr that does not match subject_item_policy" do
102
- csr = R509::CSR.new(:csr => @csr)
103
- expect { @ca.sign({ :csr => csr, :profile_name => 'server_with_subject_item_policy' }) }.to raise_error(R509::R509Error, /This profile requires you supply/)
104
- end
105
- it "issues with specified (dnsName) san domains in array" do
106
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
107
- san_names = ['langui.sh','domain2.com']
108
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :subject => csr.subject, :san_names => san_names )
109
- cert.san.dns_names.should == ['langui.sh','domain2.com']
110
- end
111
- it "issues with empty san_names array" do
112
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
113
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :subject => csr.subject, :san_names => [] )
114
- cert.san.should be_nil
115
- end
116
- it "issues with specified (directoryName and dnsName) san domains in array" do
117
- name = [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']]
118
- csr = R509::CSR.new(:subject => name, :bit_strength => 1024)
119
- san_names = ['langui.sh','domain2.com',name]
120
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :subject => csr.subject, :san_names => san_names )
121
- cert.san.dns_names.should == ['langui.sh','domain2.com']
122
- cert.san.directory_names.size.should == 1
123
- cert.san.directory_names[0].to_s.should == "/C=US/ST=Illinois/L=Chicago/O=Paul Kehrer/CN=langui.sh"
124
- end
125
- it "issues with specified san domains in R509::ASN1::GeneralNames object" do
126
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :bit_strength => 1024)
127
- san_names = R509::ASN1.general_name_parser(['langui.sh','domain2.com'])
128
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :subject => csr.subject, :san_names => san_names )
129
- cert.san.dns_names.should == ['langui.sh','domain2.com']
130
- end
131
- it "issues with san domains from csr" do
132
- csr = R509::CSR.new(:csr => @csr)
133
- cert = @ca.sign(:csr => csr, :profile_name => 'server')
134
- cert.san.dns_names.should == ['test.local','additionaldomains.com','saniam.com']
135
- end
136
- it "issues a csr made via array" do
137
- csr = R509::CSR.new(:subject => [['CN','langui.sh']], :bit_strength => 1024)
138
- cert = @ca.sign(:csr => csr, :profile_name => 'server')
139
- cert.subject.to_s.should == '/CN=langui.sh'
140
- end
141
- it "overrides a CSR's subject with :subject" do
142
- csr = R509::CSR.new(:csr => @csr)
143
- subject = csr.subject
144
- subject.CN = "someotherdomain.com"
145
- subject.delete("O")
146
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :subject => subject )
147
- cert.subject.to_s.should == '/CN=someotherdomain.com'
148
- end
149
- it "tests that policy identifiers are properly encoded" do
150
- csr = R509::CSR.new(:csr => @csr)
151
- cert = @ca.sign(:csr => csr, :profile_name => 'server')
152
- cert.certificate_policies.should_not be_nil
153
- cert.certificate_policies.policies.count.should == 1
154
- cert.certificate_policies.policies[0].policy_identifier.should == "2.16.840.1.12345.1.2.3.4.1"
155
- cert.certificate_policies.policies[0].policy_qualifiers.cps_uris.should == ["http://example.com/cps", "http://other.com/cps"]
156
- cert.certificate_policies.policies[0].policy_qualifiers.user_notices.count.should == 1
157
- un = cert.certificate_policies.policies[0].policy_qualifiers.user_notices[0]
158
- un.notice_reference.notice_numbers.should == [1,2,3,4]
159
- un.notice_reference.organization.should == 'my org'
160
- un.explicit_text.should == "thing"
161
- end
162
- it "multiple policy identifiers are properly encoded" do
163
- csr = R509::CSR.new(:csr => @csr)
164
- config = R509::Config::CAConfig.from_yaml("multi_policy_ca", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_various.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
165
- ca = R509::CertificateAuthority::Signer.new(config)
166
- cert = ca.sign(:csr => csr, :profile_name => 'server')
167
- cert.certificate_policies.should_not be_nil
168
- cert.certificate_policies.policies.count.should == 3
169
- p0 = cert.certificate_policies.policies[0]
170
- p0.policy_identifier.should == "2.16.840.1.99999.21.234"
171
- p0.policy_qualifiers.cps_uris.should == ["http://example.com/cps", "http://haha.com"]
172
- p0.policy_qualifiers.user_notices.count.should == 1
173
- un0 = p0.policy_qualifiers.user_notices[0]
174
- un0.notice_reference.notice_numbers.should == [1,2,3]
175
- un0.notice_reference.organization.should == "my org"
176
- un0.explicit_text.should == "this is a great thing"
177
- p1 = cert.certificate_policies.policies[1]
178
- p1.policy_identifier.should == "2.16.840.1.99999.21.235"
179
- p1.policy_qualifiers.cps_uris.should == ["http://example.com/cps2"]
180
- p1.policy_qualifiers.user_notices.count.should == 2
181
- un1 = p1.policy_qualifiers.user_notices[0]
182
- un1.notice_reference.notice_numbers.should == [3,2,1]
183
- un1.notice_reference.organization.should == "another org"
184
- un1.explicit_text.should == 'this is a bad thing'
185
- un2 = p1.policy_qualifiers.user_notices[1]
186
- un2.notice_reference.should be_nil
187
- un2.explicit_text.should == "another user notice"
188
- p2 = cert.certificate_policies.policies[2]
189
- p2.policy_identifier.should == "2.16.840.1.99999.0"
190
- p2.policy_qualifiers.should be_nil
191
- end
192
- it "issues a certificate with an authority key identifier" do
193
- csr = R509::CSR.new(:csr => @csr)
194
- cert = @ca.sign(:csr => csr, :profile_name => 'server')
195
- cert.authority_key_identifier.should_not be_nil
196
- end
197
- context "inhibitAnyPolicy" do
198
- it "issues without inhibit any policy when not present" do
199
- csr = R509::CSR.new(:csr => @csr)
200
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
201
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
202
- profile = R509::Config::CAProfile.new
203
- config.set_profile("default",profile)
204
- ca = R509::CertificateAuthority::Signer.new(config)
205
- cert = ca.sign(:csr => csr, :profile_name => 'default')
206
- cert.inhibit_any_policy.should == nil
207
- end
208
- it "issues with inhibit any policy when present" do
209
- csr = R509::CSR.new(:csr => @csr)
210
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
211
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
212
- profile = R509::Config::CAProfile.new(:inhibit_any_policy => 1)
213
- config.set_profile("default",profile)
214
- ca = R509::CertificateAuthority::Signer.new(config)
215
- cert = ca.sign(:csr => csr, :profile_name => 'default')
216
- cert.inhibit_any_policy.skip_certs.should == 1
217
- end
218
- end
219
- context "policyConstraints" do
220
- it "issues without policy constraints when not present" do
221
- csr = R509::CSR.new(:csr => @csr)
222
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
223
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
224
- profile = R509::Config::CAProfile.new
225
- config.set_profile("default",profile)
226
- ca = R509::CertificateAuthority::Signer.new(config)
227
- cert = ca.sign(:csr => csr, :profile_name => 'default')
228
- cert.policy_constraints.should == nil
229
- end
230
- it "issues with require_explicit_policy" do
231
- csr = R509::CSR.new(:csr => @csr)
232
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
233
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
234
- profile = R509::Config::CAProfile.new(:policy_constraints => {"require_explicit_policy" => 3})
235
- config.set_profile("default",profile)
236
- ca = R509::CertificateAuthority::Signer.new(config)
237
- cert = ca.sign(:csr => csr, :profile_name => 'default')
238
- cert.policy_constraints.require_explicit_policy.should == 3
239
- cert.policy_constraints.inhibit_policy_mapping.should == nil
240
- end
241
- it "issues with inhibit_policy_mapping" do
242
- csr = R509::CSR.new(:csr => @csr)
243
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
244
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
245
- profile = R509::Config::CAProfile.new(:policy_constraints => {"inhibit_policy_mapping" => 3})
246
- config.set_profile("default",profile)
247
- ca = R509::CertificateAuthority::Signer.new(config)
248
- cert = ca.sign(:csr => csr, :profile_name => 'default')
249
- cert.policy_constraints.require_explicit_policy.should == nil
250
- cert.policy_constraints.inhibit_policy_mapping.should == 3
251
- end
252
- it "issues with both require and inhibit" do
253
- csr = R509::CSR.new(:csr => @csr)
254
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
255
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
256
- profile = R509::Config::CAProfile.new(:policy_constraints => {"require_explicit_policy" => 3, "inhibit_policy_mapping" => 2})
257
- config.set_profile("default",profile)
258
- ca = R509::CertificateAuthority::Signer.new(config)
259
- cert = ca.sign(:csr => csr, :profile_name => 'default')
260
- cert.policy_constraints.require_explicit_policy.should == 3
261
- cert.policy_constraints.inhibit_policy_mapping.should == 2
262
- end
263
- end
264
- context "nameConstraints" do
265
- it "issues with no constraints if not present in profile" do
266
- csr = R509::CSR.new(:csr => @csr)
267
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
268
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
269
- profile = R509::Config::CAProfile.new
270
- config.set_profile("default",profile)
271
- ca = R509::CertificateAuthority::Signer.new(config)
272
- cert = ca.sign(:csr => csr, :profile_name => 'default')
273
- cert.name_constraints.should be_nil
274
- end
275
- it "issues with permitted constraints" do
276
- csr = R509::CSR.new(:csr => @csr)
277
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
278
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
279
- profile = R509::Config::CAProfile.new(:name_constraints => { "permitted" => [ { "type" => "DNS", "value" => "domain.com" } , { "type" => "IP", "value" => "ff::/ff:ff:ff:ff:ff:ff:ff:ff" } ] } )
280
- config.set_profile("default",profile)
281
- ca = R509::CertificateAuthority::Signer.new(config)
282
- cert = ca.sign(:csr => csr, :profile_name => 'default')
283
- cert.name_constraints.permitted_names[0].type.should == :dNSName
284
- cert.name_constraints.permitted_names[0].value.should == 'domain.com'
285
- cert.name_constraints.permitted_names[1].type.should == :iPAddress
286
- cert.name_constraints.permitted_names[1].value.should == 'ff::/ff:ff:ff:ff:ff:ff:ff:ff'
287
- end
288
- it "issues with excluded constraints" do
289
- csr = R509::CSR.new(:csr => @csr)
290
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
291
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
292
- profile = R509::Config::CAProfile.new(:name_constraints => { "excluded" => [ { "type" => "dirName", "value" => [["CN","domain.com"]] }, { "type" => "URI", "value" => ".domain.com" } ] } )
293
- config.set_profile("default",profile)
294
- ca = R509::CertificateAuthority::Signer.new(config)
295
- cert = ca.sign(:csr => csr, :profile_name => 'default')
296
- cert.name_constraints.excluded_names[0].type.should == :directoryName
297
- cert.name_constraints.excluded_names[0].value.to_s.should == '/CN=domain.com'
298
- cert.name_constraints.excluded_names[1].type.should == :uniformResourceIdentifier
299
- cert.name_constraints.excluded_names[1].value.to_s.should == '.domain.com'
300
- end
301
- it "issues with both constraints" do
302
- csr = R509::CSR.new(:csr => @csr)
303
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
304
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
305
- profile = R509::Config::CAProfile.new(:name_constraints => { "permitted" => [ { "type" => "DNS", "value" => "domain.com" } ], "excluded" => [ { "type" => "dirName", "value" => [["CN","domain.com"]] } ] } )
306
- config.set_profile("default",profile)
307
- ca = R509::CertificateAuthority::Signer.new(config)
308
- cert = ca.sign(:csr => csr, :profile_name => 'default')
309
- cert.name_constraints.permitted_names[0].type.should == :dNSName
310
- cert.name_constraints.permitted_names[0].value.should == 'domain.com'
311
- cert.name_constraints.excluded_names[0].type.should == :directoryName
312
- cert.name_constraints.excluded_names[0].value.to_s.should == '/CN=domain.com'
313
- end
314
- end
315
- context "authorityInfoAccess" do
316
- it "issues a certificate with a ca_issuers_location and ocsp_location" do
317
- csr = R509::CSR.new(:csr => @csr)
318
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
319
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
320
- config.ca_issuers_location = ['http://domain.com/ca.html']
321
- config.ocsp_location = ['http://ocsp.domain.com','http://ocsp.other.com']
322
- profile = R509::Config::CAProfile.new
323
- config.set_profile("default",profile)
324
- ca = R509::CertificateAuthority::Signer.new(config)
325
- cert = ca.sign(:csr => csr, :profile_name => 'default')
326
- cert.authority_info_access.ca_issuers.uris.should == ["http://domain.com/ca.html"]
327
- cert.authority_info_access.ocsp.uris.should == ["http://ocsp.domain.com","http://ocsp.other.com"]
328
- end
329
- it "issues a certificate with a ca_issuers_location and ocsp_location (dirName,URI,DNS)" do
330
- csr = R509::CSR.new(:csr => @csr)
331
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
332
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
333
- config.ca_issuers_location = ['http://domain.com/ca.html','domain.com',R509::Subject.new([['CN','myDir'],['C','US']])]
334
- config.ocsp_location = ['http://ocsp.domain.com/','ocsp.domain.com',R509::Subject.new([['CN','ocsp'],['L','Locality']])]
335
- profile = R509::Config::CAProfile.new
336
- config.set_profile("default",profile)
337
- ca = R509::CertificateAuthority::Signer.new(config)
338
- cert = ca.sign(:csr => csr, :profile_name => 'default')
339
- cert.authority_info_access.ca_issuers.uris.should == ["http://domain.com/ca.html"]
340
- cert.authority_info_access.ca_issuers.dns_names.should == ['domain.com']
341
- cert.authority_info_access.ca_issuers.directory_names[0].to_s.should == '/CN=myDir/C=US'
342
- cert.authority_info_access.ocsp.uris.should == ["http://ocsp.domain.com/"]
343
- cert.authority_info_access.ocsp.dns_names.should == ["ocsp.domain.com"]
344
- cert.authority_info_access.ocsp.directory_names[0].to_s.should == '/CN=ocsp/L=Locality'
345
- end
346
- it "issues a certificate with a ca_issuers_location and no ocsp_location" do
347
- csr = R509::CSR.new(:csr => @csr)
348
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
349
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
350
- config.ca_issuers_location = ['http://domain.com/ca.html']
351
- profile = R509::Config::CAProfile.new
352
- config.set_profile("default",profile)
353
- ca = R509::CertificateAuthority::Signer.new(config)
354
- cert = ca.sign(:csr => csr, :profile_name => 'default')
355
- cert.authority_info_access.ca_issuers.uris.should == ["http://domain.com/ca.html"]
356
- cert.authority_info_access.ocsp.uris.should == []
357
- end
358
- it "issues a certificate with multiple ca_issuer_locations" do
359
- csr = R509::CSR.new(:csr => @csr)
360
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
361
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
362
- config.ca_issuers_location = ["http://somelocation.com/c.html","http://other.com/d.html"]
363
- profile = R509::Config::CAProfile.new
364
- config.set_profile("default",profile)
365
- ca = R509::CertificateAuthority::Signer.new(config)
366
- cert = ca.sign( :csr => csr, :profile_name => 'default')
367
- cert.authority_info_access.ocsp.uris.should == []
368
- cert.authority_info_access.ca_issuers.uris.should == ["http://somelocation.com/c.html","http://other.com/d.html"]
369
- end
370
- it "issues a certificate with ocsp_location" do
371
- csr = R509::CSR.new(:csr => @csr)
372
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
373
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
374
- config.ocsp_location = ["http://myocsp.jb.net"]
375
- profile = R509::Config::CAProfile.new
376
- config.set_profile("default",profile)
377
- ca = R509::CertificateAuthority::Signer.new(config)
378
- cert = ca.sign( :csr => csr, :profile_name => 'default')
379
- cert.authority_info_access.ca_issuers.uris.should == []
380
- cert.authority_info_access.ocsp.uris.should == ["http://myocsp.jb.net"]
381
- end
382
- it "issues a certificate with an empty array for ocsp_location" do
383
- csr = R509::CSR.new(:csr => @csr)
384
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
385
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
386
- config.ocsp_location = []
387
- profile = R509::Config::CAProfile.new
388
- config.set_profile("default",profile)
389
- ca = R509::CertificateAuthority::Signer.new(config)
390
- cert = ca.sign( :csr => csr, :profile_name => 'default')
391
- cert.authority_info_access.should be_nil
392
- end
393
- it "issues a certificate with an empty array for ca_issuers_location" do
394
- csr = R509::CSR.new(:csr => @csr)
395
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
396
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
397
- config.ca_issuers_location = []
398
- profile = R509::Config::CAProfile.new
399
- config.set_profile("default",profile)
400
- ca = R509::CertificateAuthority::Signer.new(config)
401
- cert = ca.sign( :csr => csr, :profile_name => 'default')
402
- cert.authority_info_access.should be_nil
403
- end
404
- end
405
- it "issues a certificate with no CDP" do
406
- csr = R509::CSR.new(:csr => @csr)
407
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
408
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
409
- profile = R509::Config::CAProfile.new
410
- config.set_profile("default",profile)
411
- ca = R509::CertificateAuthority::Signer.new(config)
412
- cert = ca.sign( :csr => csr, :profile_name => 'default')
413
- cert.crl_distribution_points.should == nil
414
- end
415
- it "issues a certificate with an empty array for CDP" do
416
- csr = R509::CSR.new(:csr => @csr)
417
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
418
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
419
- config.cdp_location = []
420
- profile = R509::Config::CAProfile.new
421
- config.set_profile("default",profile)
422
- ca = R509::CertificateAuthority::Signer.new(config)
423
- cert = ca.sign( :csr => csr, :profile_name => 'default')
424
- cert.crl_distribution_points.should be_nil
425
- end
426
- it "issues a certificate with a single CDP" do
427
- csr = R509::CSR.new(:csr => @csr)
428
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
429
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
430
- config.cdp_location = ["http://mycdp.com/x.crl"]
431
- profile = R509::Config::CAProfile.new
432
- config.set_profile("default",profile)
433
- ca = R509::CertificateAuthority::Signer.new(config)
434
- cert = ca.sign( :csr => csr, :profile_name => 'default')
435
- cert.crl_distribution_points.crl.uris.should == ["http://mycdp.com/x.crl"]
436
- end
437
- it "issues a certificate with multiple CDPs" do
438
- csr = R509::CSR.new(:csr => @csr)
439
- ca_cert = R509::Cert.new( :cert => TestFixtures::TEST_CA_CERT, :key => TestFixtures::TEST_CA_KEY )
440
- config = R509::Config::CAConfig.new(:ca_cert => ca_cert)
441
- config.cdp_location = ["http://mycdp.com/x.crl","http://anothercrl.com/x.crl"]
442
- profile = R509::Config::CAProfile.new
443
- config.set_profile("default",profile)
444
- ca = R509::CertificateAuthority::Signer.new(config)
445
- cert = ca.sign( :csr => csr, :profile_name => 'default')
446
- cert.crl_distribution_points.crl.uris.should == ["http://mycdp.com/x.crl","http://anothercrl.com/x.crl"]
447
- end
448
- it "tests basic constraints CA:TRUE and pathlen:0 on a subroot" do
449
- csr = R509::CSR.new(:csr => @csr)
450
- cert = @ca.sign(:csr => csr, :profile_name => 'subroot')
451
- cert.basic_constraints.is_ca?.should == true
452
- cert.basic_constraints.path_length.should == 0
453
- end
454
- it "issues with md5" do
455
- csr = R509::CSR.new(:csr => @csr3)
456
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'md5')
457
- cert.cert.signature_algorithm.should == 'md5WithRSAEncryption'
458
- end
459
- it "issues with sha1" do
460
- csr = R509::CSR.new(:csr => @csr3)
461
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'sha1')
462
- cert.cert.signature_algorithm.should == 'sha1WithRSAEncryption'
463
- end
464
- it "issues with sha224" do
465
- csr = R509::CSR.new(:csr => @csr3)
466
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'sha224')
467
- cert.cert.signature_algorithm.should == 'sha224WithRSAEncryption'
468
- end
469
- it "issues with sha256" do
470
- csr = R509::CSR.new(:csr => @csr3)
471
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'sha256')
472
- cert.cert.signature_algorithm.should == 'sha256WithRSAEncryption'
473
- end
474
- it "issues with sha384" do
475
- csr = R509::CSR.new(:csr => @csr3)
476
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'sha384')
477
- cert.cert.signature_algorithm.should == 'sha384WithRSAEncryption'
478
- end
479
- it "issues with sha512" do
480
- csr = R509::CSR.new(:csr => @csr3)
481
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'sha512')
482
- cert.cert.signature_algorithm.should == 'sha512WithRSAEncryption'
483
- end
484
- it "issues with invalid hash (sha1 fallback)" do
485
- csr = R509::CSR.new(:csr => @csr3)
486
- cert = @ca.sign(:csr => csr, :profile_name => 'server', :message_digest => 'invalid')
487
- cert.cert.signature_algorithm.should == 'sha1WithRSAEncryption'
488
- end
489
- it "generates random serial when serial is not specified and uses microtime as part of the serial to prevent collision" do
490
- now = Time.now
491
- Time.stub!(:now).and_return(now)
492
- time = now.to_i.to_s
493
- csr = R509::CSR.new(:csr => @csr3)
494
- cert = @ca.sign(:csr => csr, :profile_name => "server")
495
- cert.serial.to_s.size.should >= 45
496
- cert.serial.to_s.index(time).should_not be_nil
497
- end
498
- it "accepts specified serial number" do
499
- csr = R509::CSR.new(:csr => @csr3)
500
- cert = @ca.sign(:csr => csr, :profile_name => "server", :serial => 12345)
501
- cert.serial.should == 12345
502
- end
503
- it "has default notBefore/notAfter dates" do
504
- not_before = (Time.now - (6 * 60 * 60)).utc
505
- not_after = (Time.now - (6 * 60 * 60) + (365 * 24 * 60 * 60)).utc
506
- csr = R509::CSR.new(:csr => @csr3)
507
- cert = @ca.sign(:csr => csr, :profile_name => "server")
508
- cert.cert.not_before.year.should == not_before.year
509
- cert.cert.not_before.month.should == not_before.month
510
- cert.cert.not_before.day.should == not_before.day
511
- cert.cert.not_before.hour.should == not_before.hour
512
- cert.cert.not_before.min.should == not_before.min
513
- cert.cert.not_after.year.should == not_after.year
514
- cert.cert.not_after.month.should == not_after.month
515
- cert.cert.not_after.day.should == not_after.day
516
- cert.cert.not_after.hour.should == not_after.hour
517
- cert.cert.not_after.min.should == not_after.min
518
- end
519
- it "allows you to specify notBefore/notAfter dates" do
520
- not_before = Time.now - 5 * 60 * 60
521
- not_after = Time.now + 5 * 60 * 60
522
- csr = R509::CSR.new(:csr => @csr3)
523
- cert = @ca.sign(:csr => csr, :profile_name => "server", :not_before => not_before, :not_after => not_after)
524
- cert.cert.not_before.ctime.should == not_before.utc.ctime
525
- cert.cert.not_after.ctime.should == not_after.utc.ctime
526
- end
527
- it "issues a certificate from a root that does not have a subjectKeyIdentifier" do
528
- config = R509::Config::CAConfig.from_yaml("missing_key_identifier_ca", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_various.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
529
- ca = R509::CertificateAuthority::Signer.new(config)
530
- csr = R509::CSR.new(:csr => @csr3)
531
- cert = ca.sign(:csr => csr, :profile_name => "server")
532
- cert.authority_key_identifier.should == nil
533
- cert.extended_key_usage.web_server_authentication?.should == true
534
- end
535
- it "raises error unless you provide a proper config (or nil)" do
536
- expect { R509::CertificateAuthority::Signer.new('invalid') }.to raise_error(R509::R509Error, 'config must be a kind of R509::Config::CAConfig or nil (for self-sign only)')
537
- end
538
- it "raises error when providing invalid ca profile" do
539
- csr = R509::CSR.new(:csr => @csr)
540
- expect { @ca.sign(:csr => csr, :profile_name => 'invalid') }.to raise_error(R509::R509Error, "unknown profile 'invalid'")
541
- end
542
- it "raises error when attempting to issue CSR with invalid signature" do
543
- csr = R509::CSR.new(:csr => @csr_invalid_signature)
544
- expect { @ca.sign(:csr => csr, :profile_name => 'server') }.to raise_error(R509::R509Error, 'Certificate request signature is invalid.')
545
- end
546
- it "raises error when passing non-hash to selfsign method" do
547
- expect { @ca.selfsign(@csr) }.to raise_error(ArgumentError, "You must pass a hash of options consisting of at minimum :csr")
548
- end
549
- it "raises error when passing invalid data for san_names" do
550
- csr = R509::CSR.new(
551
- :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']],
552
- :bit_strength => 1024
553
- )
554
- san_names = "invalid"
555
- expect { @ca.selfsign(:csr => csr, :san_names => san_names) }.to raise_error(ArgumentError,'When passing SAN names it must be provided as either an array of strings or an R509::ASN1::GeneralNames object')
556
- end
557
- it "issues a self-signed certificate with custom fields" do
558
- not_before = Time.now.to_i
559
- not_after = Time.now.to_i+3600*24*7300
560
- csr = R509::CSR.new(
561
- :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']],
562
- :bit_strength => 1024
563
- )
564
- san_names = R509::ASN1.general_name_parser(['sanname1','sanname2'])
565
- cert = @ca.selfsign(
566
- :csr => csr,
567
- :serial => 3,
568
- :not_before => not_before,
569
- :not_after => not_after,
570
- :message_digest => 'sha256',
571
- :san_names => san_names
572
- )
573
- cert.public_key.to_s.should == csr.public_key.to_s
574
- cert.signature_algorithm.should == 'sha256WithRSAEncryption'
575
- cert.serial.should == 3
576
- cert.not_before.to_i.should == not_before
577
- cert.not_after.to_i.should == not_after
578
- cert.subject.to_s.should == '/C=US/O=r509 LLC/CN=r509 Self-Signed CA Test'
579
- cert.issuer.to_s.should == '/C=US/O=r509 LLC/CN=r509 Self-Signed CA Test'
580
- cert.basic_constraints.is_ca?.should == true
581
- cert.san.dns_names.should include('sanname1','sanname2')
582
- end
583
- it "issues a self-signed certificate with san names provided as an array" do
584
- not_before = Time.now.to_i
585
- not_after = Time.now.to_i+3600*24*7300
586
- csr = R509::CSR.new(
587
- :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']],
588
- :bit_strength => 1024
589
- )
590
- san_names = ['sanname1','sanname2']
591
- cert = @ca.selfsign(
592
- :csr => csr,
593
- :not_before => not_before,
594
- :not_after => not_after,
595
- :message_digest => 'sha256',
596
- :san_names => san_names
597
- )
598
- cert.san.dns_names.should include('sanname1','sanname2')
599
- end
600
- it "issues self-signed certificate with SAN in CSR" do
601
- csr = R509::CSR.new(
602
- :subject => [['CN','My Self Sign']],
603
- :san_names => ['sanname1','sanname2'],
604
- :bit_strength => 1024
605
- )
606
- cert = @ca.selfsign(
607
- :csr => csr
608
- )
609
- cert.san.dns_names.should include('sanname1','sanname2')
610
- cert.subject.to_s.should == '/CN=My Self Sign'
611
- cert.issuer.to_s.should == '/CN=My Self Sign'
612
- cert.public_key.to_s.should == csr.public_key.to_s
613
- end
614
- it "issues a self-signed certificate with defaults" do
615
- csr = R509::CSR.new(
616
- :subject => [['C','US'],['O','r509 LLC'],['CN','r509 Self-Signed CA Test']],
617
- :bit_strength => 1024
618
- )
619
- cert = @ca.selfsign(
620
- :csr => csr
621
- )
622
- cert.public_key.to_s.should == csr.public_key.to_s
623
- cert.signature_algorithm.should == 'sha1WithRSAEncryption'
624
- (cert.not_after.to_i-cert.not_before.to_i).should == 31536000
625
- cert.subject.to_s.should == '/C=US/O=r509 LLC/CN=r509 Self-Signed CA Test'
626
- cert.issuer.to_s.should == '/C=US/O=r509 LLC/CN=r509 Self-Signed CA Test'
627
- cert.basic_constraints.is_ca?.should == true
628
- end
629
- it "raises an error if attempting to self-sign without a key" do
630
- csr = R509::CSR.new(:csr => @csr3)
631
- expect { @ca.selfsign( :csr => csr ) }.to raise_error(ArgumentError, "CSR must also have a private key to self sign")
632
- end
633
- it "raises an error if you call sign without passing a config to the object" do
634
- ca_signer = R509::CertificateAuthority::Signer.new
635
- csr = R509::CSR.new(:csr => @csr3)
636
- expect { ca_signer.sign(:csr => csr, :profile_name => "server") }.to raise_error(R509::R509Error, "When instantiating the signer without a config you can only call #selfsign")
637
- end
638
-
639
- context "issuing off an elliptic curve CA", :ec => true do
640
- before :all do
641
- @test_ca_ec = R509::Config::CAConfig.from_yaml("test_ca_ec", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_ec.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
642
- @ca_ec = R509::CertificateAuthority::Signer.new(@test_ca_ec)
643
- end
644
-
645
- it "properly issues server cert" do
646
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :type => :ec)
647
- cert = @ca_ec.sign( :csr => csr, :profile_name => 'server' )
648
- cert.to_pem.should match(/BEGIN CERTIFICATE/)
649
- cert.subject.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Paul Kehrer/CN=langui.sh'
650
- cert.signature_algorithm.should == 'ecdsa-with-SHA384'
651
- cert.key_algorithm.should == :ec
652
- cert.extended_key_usage.web_server_authentication?.should == true
653
- end
654
- it "properly issues server cert using spki" do
655
- spki = R509::SPKI.new(:spki => @spki)
656
- cert = @ca_ec.sign( :spki => spki, :profile_name => 'server', :subject=>[['CN','test.local']] )
657
- cert.to_pem.should match(/BEGIN CERTIFICATE/)
658
- cert.subject.to_s.should == '/CN=test.local'
659
- cert.signature_algorithm.should == 'ecdsa-with-SHA384'
660
- cert.key_algorithm.should == :rsa #weird right?! it's because the spki is RSA even though the signature is from an EC root
661
- cert.extended_key_usage.web_server_authentication?.should == true
662
- end
663
- end
664
-
665
- context "issuing off a DSA CA" do
666
- before :all do
667
- @test_ca_dsa = R509::Config::CAConfig.from_yaml("test_ca_dsa", File.read("#{File.dirname(__FILE__)}/fixtures/config_test_dsa.yaml"), {:ca_root_path => "#{File.dirname(__FILE__)}/fixtures"})
668
- @ca_dsa = R509::CertificateAuthority::Signer.new(@test_ca_dsa)
669
- end
670
-
671
- it "properly issues server cert" do
672
- csr = R509::CSR.new(:subject => [['C','US'],['ST','Illinois'],['L','Chicago'],['O','Paul Kehrer'],['CN','langui.sh']], :type => :dsa, :bit_strength => 1024)
673
- cert = @ca_dsa.sign( :csr => csr, :profile_name => 'server' )
674
- cert.to_pem.should match(/BEGIN CERTIFICATE/)
675
- cert.subject.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Paul Kehrer/CN=langui.sh'
676
- cert.signature_algorithm.should == 'dsaWithSHA1'
677
- cert.key_algorithm.should == :dsa
678
- cert.extended_key_usage.web_server_authentication?.should == true
679
- end
680
- end
681
- end