r509 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -0
- data/CONTRIBUTING.mdown +21 -0
- data/LICENSE +13 -0
- data/README.mdown +548 -0
- data/Rakefile +5 -0
- data/bin/r509 +16 -17
- data/doc/R509.html +42 -26
- data/doc/R509/ASN1.html +22 -16
- data/doc/R509/ASN1/GeneralName.html +180 -173
- data/doc/R509/ASN1/GeneralNames.html +390 -62
- data/doc/R509/CRL.html +9 -7
- data/doc/R509/CRL/Administrator.html +208 -623
- data/doc/R509/CRL/FileReaderWriter.html +856 -0
- data/doc/R509/CRL/ReaderWriter.html +524 -0
- data/doc/R509/CRL/SignedList.html +29 -42
- data/doc/R509/CSR.html +248 -333
- data/doc/R509/Cert.html +364 -491
- data/doc/R509/Cert/Extensions.html +134 -43
- data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +335 -65
- data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +201 -102
- data/doc/R509/Cert/Extensions/BasicConstraints.html +297 -68
- data/doc/R509/Cert/Extensions/CRLDistributionPoints.html +690 -77
- data/doc/R509/Cert/Extensions/CertificatePolicies.html +293 -43
- data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +321 -173
- data/doc/R509/Cert/Extensions/GeneralNamesMixin.html +656 -0
- data/doc/R509/Cert/Extensions/InhibitAnyPolicy.html +270 -42
- data/doc/R509/Cert/Extensions/KeyUsage.html +334 -184
- data/doc/R509/Cert/Extensions/NameConstraints.html +363 -93
- data/doc/R509/{ASN1 → Cert/Extensions}/NoticeReference.html +209 -48
- data/doc/R509/Cert/Extensions/OCSPNoCheck.html +244 -17
- data/doc/R509/Cert/Extensions/PolicyConstraints.html +322 -71
- data/doc/R509/{ASN1 → Cert/Extensions}/PolicyInformation.html +204 -43
- data/doc/R509/{ASN1 → Cert/Extensions}/PolicyQualifiers.html +205 -48
- data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +348 -143
- data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +165 -13
- data/doc/R509/{ASN1 → Cert/Extensions}/UserNotice.html +204 -43
- data/doc/R509/Cert/Extensions/ValidationMixin.html +120 -0
- data/doc/R509/CertificateAuthority.html +9 -7
- data/doc/R509/CertificateAuthority/OptionsBuilder.html +475 -0
- data/doc/R509/CertificateAuthority/Signer.html +149 -198
- data/doc/R509/Config.html +10 -8
- data/doc/R509/Config/CAConfig.html +708 -625
- data/doc/R509/Config/CAConfigPool.html +179 -31
- data/doc/R509/Config/CertProfile.html +1544 -0
- data/doc/R509/Config/SubjectItemPolicy.html +437 -99
- data/doc/R509/Engine.html +14 -28
- data/doc/R509/Helpers.html +1014 -0
- data/doc/R509/MessageDigest.html +73 -25
- data/doc/R509/NameSanitizer.html +39 -39
- data/doc/R509/OCSP.html +5 -5
- data/doc/R509/OCSP/Request.html +5 -5
- data/doc/R509/OCSP/Request/Nonce.html +5 -5
- data/doc/R509/OCSP/Response.html +7 -7
- data/doc/R509/OIDMapper.html +121 -6
- data/doc/R509/PrivateKey.html +226 -227
- data/doc/R509/R509Error.html +5 -5
- data/doc/R509/SPKI.html +244 -342
- data/doc/R509/Subject.html +241 -70
- data/doc/R509/Validity.html +5 -5
- data/doc/R509/Validity/Checker.html +5 -5
- data/doc/R509/Validity/DefaultChecker.html +5 -9
- data/doc/R509/Validity/DefaultWriter.html +5 -9
- data/doc/R509/Validity/Status.html +5 -5
- data/doc/R509/Validity/Writer.html +5 -5
- data/doc/_index.html +92 -30
- data/doc/class_list.html +2 -2
- data/doc/file.CONTRIBUTING.html +96 -0
- data/doc/file.LICENSE.html +87 -0
- data/doc/file.README.html +279 -389
- data/doc/file.YAML.html +243 -0
- data/doc/file.r509.html +298 -105
- data/doc/file_list.html +11 -2
- data/doc/frames.html +1 -1
- data/doc/index.html +279 -389
- data/doc/js/full_list.js +6 -1
- data/doc/method_list.html +869 -1139
- data/doc/top-level-namespace.html +103 -5
- data/lib/r509.rb +7 -2
- data/lib/r509/asn1.rb +97 -135
- data/lib/r509/cert.rb +17 -106
- data/lib/r509/cert/extensions.rb +13 -676
- data/lib/r509/cert/extensions/authority_info_access.rb +128 -0
- data/lib/r509/cert/extensions/authority_key_identifier.rb +100 -0
- data/lib/r509/cert/extensions/base.rb +142 -0
- data/lib/r509/cert/extensions/basic_constraints.rb +119 -0
- data/lib/r509/cert/extensions/certificate_policies.rb +262 -0
- data/lib/r509/cert/extensions/crl_distribution_points.rb +98 -0
- data/lib/r509/cert/extensions/extended_key_usage.rb +189 -0
- data/lib/r509/cert/extensions/inhibit_any_policy.rb +70 -0
- data/lib/r509/cert/extensions/key_usage.rb +209 -0
- data/lib/r509/cert/extensions/name_constraints.rb +179 -0
- data/lib/r509/cert/extensions/ocsp_no_check.rb +56 -0
- data/lib/r509/cert/extensions/policy_constraints.rb +122 -0
- data/lib/r509/cert/extensions/subject_alternative_name.rb +88 -0
- data/lib/r509/cert/extensions/subject_key_identifier.rb +56 -0
- data/lib/r509/cert/extensions/validation_mixin.rb +42 -0
- data/lib/r509/certificate_authority/options_builder.rb +142 -0
- data/lib/r509/certificate_authority/signer.rb +189 -0
- data/lib/r509/config.rb +3 -600
- data/lib/r509/config/ca_config.rb +414 -0
- data/lib/r509/config/cert_profile.rb +110 -0
- data/lib/r509/config/subject_item_policy.rb +118 -0
- data/lib/r509/crl/administrator.rb +169 -0
- data/lib/r509/crl/reader_writer.rb +109 -0
- data/lib/r509/crl/signed_list.rb +135 -0
- data/lib/r509/csr.rb +35 -116
- data/lib/r509/engine.rb +21 -11
- data/lib/r509/helpers.rb +110 -0
- data/lib/r509/io_helpers.rb +18 -13
- data/lib/r509/message_digest.rb +13 -3
- data/lib/r509/oid_mapper.rb +14 -0
- data/lib/r509/private_key.rb +74 -50
- data/lib/r509/spki.rb +50 -113
- data/lib/r509/subject.rb +24 -2
- data/lib/r509/trollop.rb +788 -0
- data/lib/r509/version.rb +1 -1
- data/r509.yaml +289 -96
- data/spec/asn1_spec.rb +171 -98
- data/spec/cert/extensions/authority_info_access_spec.rb +247 -0
- data/spec/cert/extensions/authority_key_identifier_spec.rb +85 -0
- data/spec/cert/extensions/base_spec.rb +172 -0
- data/spec/cert/extensions/basic_constraints_spec.rb +185 -0
- data/spec/cert/extensions/certificate_policies_spec.rb +288 -0
- data/spec/cert/extensions/crl_distribution_points_spec.rb +149 -0
- data/spec/cert/extensions/extended_key_usage_spec.rb +174 -0
- data/spec/cert/extensions/inhibit_any_policy_spec.rb +92 -0
- data/spec/cert/extensions/key_usage_spec.rb +172 -0
- data/spec/cert/extensions/name_constraints_spec.rb +335 -0
- data/spec/cert/extensions/ocsp_no_check_spec.rb +76 -0
- data/spec/cert/extensions/policy_constraints_spec.rb +155 -0
- data/spec/cert/extensions/subject_alternative_name_spec.rb +354 -0
- data/spec/cert/extensions/subject_key_identifier_spec.rb +64 -0
- data/spec/cert_spec.rb +11 -9
- data/spec/certificate_authority/options_builder_spec.rb +307 -0
- data/spec/certificate_authority/signer_spec.rb +278 -0
- data/spec/config/ca_config_spec.rb +405 -0
- data/spec/config/cert_profile_spec.rb +88 -0
- data/spec/config/subject_item_policy_spec.rb +81 -0
- data/spec/crl/administrator_spec.rb +199 -0
- data/spec/crl/reader_writer_spec.rb +97 -0
- data/spec/crl/signed_list_spec.rb +84 -0
- data/spec/csr_spec.rb +43 -36
- data/spec/engine_spec.rb +51 -0
- data/spec/fixtures.rb +40 -40
- data/spec/fixtures/cert1.pem +1 -1
- data/spec/fixtures/config_pool_test_minimal.yaml +11 -15
- data/spec/fixtures/config_test.yaml +96 -59
- data/spec/fixtures/config_test_dsa.yaml +29 -35
- data/spec/fixtures/config_test_ec.yaml +29 -35
- data/spec/fixtures/config_test_engine_key.yaml +7 -7
- data/spec/fixtures/config_test_engine_no_key_name.yaml +6 -6
- data/spec/fixtures/config_test_minimal.yaml +3 -5
- data/spec/fixtures/config_test_password.yaml +4 -6
- data/spec/fixtures/config_test_various.yaml +147 -137
- data/spec/fixtures/crl_list_file.txt +1 -1
- data/spec/fixtures/test_ca_crl.cer +20 -0
- data/spec/fixtures/test_ca_crl.key +28 -0
- data/spec/fixtures/test_ca_crl.p12 +0 -0
- data/spec/message_digest_spec.rb +6 -0
- data/spec/oid_mapper_spec.rb +11 -0
- data/spec/private_key_spec.rb +19 -18
- data/spec/spec_helper.rb +10 -6
- data/spec/spki_spec.rb +38 -19
- data/spec/subject_spec.rb +16 -0
- metadata +108 -59
- metadata.gz.sig +0 -0
- data/README.md +0 -638
- data/doc/R509/Config/CAProfile.html +0 -1015
- data/doc/R509/IOHelpers.html +0 -564
- data/lib/r509/certificate_authority.rb +0 -407
- data/lib/r509/crl.rb +0 -351
- data/spec/cert/extensions_spec.rb +0 -1095
- data/spec/certificate_authority_spec.rb +0 -681
- data/spec/config_spec.rb +0 -562
- data/spec/crl_spec.rb +0 -226
data/spec/crl_spec.rb
DELETED
@@ -1,226 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'stringio'
|
3
|
-
|
4
|
-
describe R509::CRL::SignedList do
|
5
|
-
before :each do
|
6
|
-
@crl_reason = TestFixtures::CRL_REASON
|
7
|
-
@crl = R509::CRL::SignedList.new(@crl_reason)
|
8
|
-
@test_ca_cert = TestFixtures::TEST_CA_CERT
|
9
|
-
end
|
10
|
-
|
11
|
-
it "loads a crl with load_from_file" do
|
12
|
-
path = File.dirname(__FILE__) + '/fixtures/crl_with_reason.pem'
|
13
|
-
crl = R509::CRL::SignedList.load_from_file path
|
14
|
-
crl.revoked[12345].should_not be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns issuer" do
|
18
|
-
@crl.issuer.to_s.should == "/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns last_update" do
|
22
|
-
@crl.last_update.should == Time.at(1327446093)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns next_update" do
|
26
|
-
@crl.next_update.should == Time.at(1328054493)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns signature_algorithm" do
|
30
|
-
@crl.signature_algorithm.should == "sha1WithRSAEncryption"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "verifies the CRL signature" do
|
34
|
-
cert = R509::Cert.new(:cert => @test_ca_cert)
|
35
|
-
@crl.verify(cert.public_key).should == true
|
36
|
-
end
|
37
|
-
|
38
|
-
it "checks if a serial is revoked?" do
|
39
|
-
@crl.revoked?(111111).should == false
|
40
|
-
@crl.revoked?(12345).should == true
|
41
|
-
end
|
42
|
-
|
43
|
-
it "returns a hash of all revoked certs" do
|
44
|
-
@crl.revoked[12345][:time].should == Time.at(1327449693)
|
45
|
-
@crl.revoked[12345][:reason].should == "Key Compromise"
|
46
|
-
@crl.revoked[123456][:time].should == Time.at(1327449693)
|
47
|
-
@crl.revoked[123456][:reason].should == "Unspecified"
|
48
|
-
@crl.revoked[1234567][:time].should == Time.at(1327449693)
|
49
|
-
@crl.revoked[1234567][:reason].should == "Unspecified"
|
50
|
-
@crl.revoked[12345678].should == nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns revocation information for a serial" do
|
54
|
-
@crl.revoked_cert(11111).should == nil
|
55
|
-
revoked_info = @crl.revoked_cert(12345)
|
56
|
-
revoked_info[:time].should == Time.at(1327449693)
|
57
|
-
revoked_info[:reason].should == "Key Compromise"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "returns der" do
|
61
|
-
@crl.to_der.should_not be_nil
|
62
|
-
end
|
63
|
-
it "returns pem" do
|
64
|
-
@crl.to_pem.should_not be_nil
|
65
|
-
end
|
66
|
-
it "writes to pem" do
|
67
|
-
sio = StringIO.new
|
68
|
-
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
69
|
-
@crl.write_pem(sio)
|
70
|
-
parsed_crl = R509::CRL::SignedList.new(sio.string)
|
71
|
-
parsed_crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA'
|
72
|
-
parsed_crl.issuer.CN.should == 'Test CA'
|
73
|
-
end
|
74
|
-
it "writes to der" do
|
75
|
-
sio = StringIO.new
|
76
|
-
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
77
|
-
@crl.write_der(sio)
|
78
|
-
parsed_crl = R509::CRL::SignedList.new(sio.string)
|
79
|
-
parsed_crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA'
|
80
|
-
parsed_crl.issuer.CN.should == 'Test CA'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe R509::CRL::Administrator do
|
85
|
-
before :each do
|
86
|
-
@cert = TestFixtures::CERT
|
87
|
-
@csr = TestFixtures::CSR
|
88
|
-
@csr3 = TestFixtures::CSR3
|
89
|
-
@test_ca_config = TestFixtures.test_ca_no_profile_config
|
90
|
-
@test_ca_dsa_config = TestFixtures.test_ca_dsa_no_profile_config
|
91
|
-
end
|
92
|
-
it "generates CRL with no entries in revocation list (RSA key)" do
|
93
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
94
|
-
crl_admin.generate_crl
|
95
|
-
crl_admin.crl.to_pem.should match(/BEGIN X509 CRL/)
|
96
|
-
crl_admin.crl.signature_algorithm.should == 'sha1WithRSAEncryption'
|
97
|
-
end
|
98
|
-
it "generates CRL with no entries in revocation list (DSA key)" do
|
99
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_dsa_config)
|
100
|
-
crl_admin.generate_crl
|
101
|
-
crl_admin.crl.to_pem.should match(/BEGIN X509 CRL/)
|
102
|
-
crl_admin.crl.signature_algorithm.should == 'dsaWithSHA1'
|
103
|
-
end
|
104
|
-
context "elliptic curve", :ec => true do
|
105
|
-
before :all do
|
106
|
-
@test_ca_ec_config = TestFixtures.test_ca_ec_no_profile_config
|
107
|
-
end
|
108
|
-
it "generates CRL with no entries in revocation list (EC key)" do
|
109
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_ec_config)
|
110
|
-
crl_admin.generate_crl
|
111
|
-
crl_admin.crl.to_pem.should match(/BEGIN X509 CRL/)
|
112
|
-
crl_admin.crl.signature_algorithm.should == 'ecdsa-with-SHA1'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
it "raises exception when no R509::Config::CAConfig object is passed to the constructor" do
|
116
|
-
expect { R509::CRL::Administrator.new(['random']) }.to raise_error(R509::R509Error)
|
117
|
-
end
|
118
|
-
it "can write the crl_number_file" do
|
119
|
-
crl = R509::CRL::Administrator.new(@test_ca_config)
|
120
|
-
crl.crl_number_file.string.should == "1"
|
121
|
-
crl.crl_number_file.reopen("")
|
122
|
-
crl.save_crl_number
|
123
|
-
crl.crl_number_file.string.should == "1"
|
124
|
-
end
|
125
|
-
it "adds a cert to the revocation list" do
|
126
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
127
|
-
crl_admin.revoked?(383834832).should == false
|
128
|
-
crl_admin.revoke_cert(383834832)
|
129
|
-
crl_admin.revoked?(383834832).should == true
|
130
|
-
crl_admin.crl.revoked[383834832].should_not be_nil
|
131
|
-
crl_admin.crl.crl.revoked[0].serial.should == 383834832
|
132
|
-
end
|
133
|
-
it "can revoke (with reason)" do
|
134
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
135
|
-
crl_admin.revoked?(12345).should == false
|
136
|
-
crl_admin.revoke_cert(12345, 1)
|
137
|
-
crl_admin.revoked?(12345).should == true
|
138
|
-
crl_admin.revoked_cert(12345)[:reason].should == 1
|
139
|
-
|
140
|
-
crl_admin.crl.crl.revoked[0].serial.should == 12345
|
141
|
-
crl_admin.crl.crl.revoked[0].extensions[0].oid.should == "CRLReason"
|
142
|
-
crl_admin.crl.crl.revoked[0].extensions[0].value.should == "Key Compromise"
|
143
|
-
end
|
144
|
-
it "can revoke (without reason)" do
|
145
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
146
|
-
crl_admin.revoked?(12345).should == false
|
147
|
-
crl_admin.revoke_cert(12345)
|
148
|
-
crl_admin.revoked?(12345).should == true
|
149
|
-
crl_admin.revoked_cert(12345)[:reason].should be_nil
|
150
|
-
|
151
|
-
crl_admin.crl.crl.revoked[0].serial.should == 12345
|
152
|
-
crl_admin.crl.crl.revoked[0].extensions.size.should == 0
|
153
|
-
puts crl_admin.crl_list_file.string
|
154
|
-
end
|
155
|
-
it "cannot revoke the same serial twice" do
|
156
|
-
crl = R509::CRL::Administrator.new(@test_ca_config)
|
157
|
-
crl.revoked?(12345).should == false
|
158
|
-
crl.revoke_cert(12345, 1)
|
159
|
-
crl.revoked?(12345).should == true
|
160
|
-
crl.revoked_cert(12345)[:reason].should == 1
|
161
|
-
expect { crl.revoke_cert(12345, 1) }.to raise_error(R509::R509Error, "Cannot revoke a previously revoked certificate")
|
162
|
-
crl.revoked?(12345).should == true
|
163
|
-
end
|
164
|
-
it "adds a cert to the revocation list with an invalid reason code" do
|
165
|
-
crl = R509::CRL::Administrator.new(@test_ca_config)
|
166
|
-
crl.revoke_cert(383834832,15)
|
167
|
-
crl.generate_crl.should match(/BEGIN X509 CRL/)
|
168
|
-
crl.revoked?(383834832).should == true
|
169
|
-
crl.revoked_cert(383834832)[:reason].should == 0
|
170
|
-
end
|
171
|
-
it "removes a cert from the revocation list" do
|
172
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
173
|
-
crl_admin.revoke_cert(383834832)
|
174
|
-
crl_admin.revoked?(383834832).should == true
|
175
|
-
crl_admin.crl.crl.revoked[0].serial.should == 383834832
|
176
|
-
crl_admin.unrevoke_cert(383834832)
|
177
|
-
crl_admin.revoked?(383834832).should == false
|
178
|
-
crl_admin.crl.crl.revoked.empty?.should == true
|
179
|
-
end
|
180
|
-
it "loads an existing revocation list file" do
|
181
|
-
config = R509::Config::CAConfig.new(
|
182
|
-
:ca_cert => TestFixtures.test_ca_cert,
|
183
|
-
:crl_list_file => TestFixtures::CRL_LIST_FILE
|
184
|
-
)
|
185
|
-
crl = R509::CRL::Administrator.new(config)
|
186
|
-
crl.revoked?(12345).should == true
|
187
|
-
crl.revoked_cert(12345)[:revoke_time].should == 1323983885
|
188
|
-
crl.revoked_cert(12345)[:reason].should == 0
|
189
|
-
crl.revoked?(12346).should == true
|
190
|
-
crl.revoked_cert(12346)[:revoke_time].should == 1323983885
|
191
|
-
crl.revoked_cert(12346)[:reason].should == nil
|
192
|
-
end
|
193
|
-
it "when nil crl_list_file still call generate_crl" do
|
194
|
-
config = R509::Config::CAConfig.new(
|
195
|
-
:ca_cert => TestFixtures.test_ca_cert,
|
196
|
-
:crl_list_file => nil
|
197
|
-
)
|
198
|
-
crl_admin = R509::CRL::Administrator.new(config)
|
199
|
-
crl_admin.crl.to_pem.should match(/BEGIN X509 CRL/)
|
200
|
-
end
|
201
|
-
it "sets validity via yaml" do
|
202
|
-
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
203
|
-
now = Time.at Time.now.to_i
|
204
|
-
crl_admin.generate_crl
|
205
|
-
crl_admin.crl.next_update.should == (now+168*3600) #default 168 hours (7 days)
|
206
|
-
end
|
207
|
-
it "writes crl list" do
|
208
|
-
crl = R509::CRL::Administrator.new(@test_ca_config)
|
209
|
-
crl.revoke_cert(12345)
|
210
|
-
crl.crl_list_file.string.should match(/[0-9]+,[0-9]+,/)
|
211
|
-
end
|
212
|
-
it "doesn't write the crl_number_file when it is nil" do
|
213
|
-
config = R509::Config::CAConfig.new(
|
214
|
-
:ca_cert => TestFixtures.test_ca_cert
|
215
|
-
)
|
216
|
-
crl = R509::CRL::Administrator.new(config)
|
217
|
-
expect { crl.save_crl_number }.to_not raise_error(StandardError)
|
218
|
-
end
|
219
|
-
it "doesn't write the crl_list_file when it is nil" do
|
220
|
-
config = R509::Config::CAConfig.new(
|
221
|
-
:ca_cert => TestFixtures.test_ca_cert
|
222
|
-
)
|
223
|
-
crl = R509::CRL::Administrator.new(config)
|
224
|
-
expect { crl.save_crl_list }.to_not raise_error(StandardError)
|
225
|
-
end
|
226
|
-
end
|