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
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'r509/config/subject_item_policy'
|
3
|
+
require 'r509/exceptions'
|
4
|
+
|
5
|
+
describe R509::Config::SubjectItemPolicy do
|
6
|
+
it "raises an error if you supply a non-hash" do
|
7
|
+
expect { R509::Config::SubjectItemPolicy.new('string') }.to raise_error(ArgumentError, "Must supply a hash in form 'shortname'=>hash_with_policy_info")
|
8
|
+
end
|
9
|
+
it "raises an error if you supply values that are not hashes as well" do
|
10
|
+
expect { R509::Config::SubjectItemPolicy.new("CN" => "what what") }.to raise_error(ArgumentError, "Each value must be a hash with a :policy key")
|
11
|
+
end
|
12
|
+
it "raises an error if a required element is missing" do
|
13
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" }, "O" => { :policy => "required" }, "OU" => { :policy => "optional" }, "L" => { :policy => "required" })
|
14
|
+
subject = R509::Subject.new [["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
15
|
+
expect { subject_item_policy.validate_subject(subject) }.to raise_error(R509::R509Error, /This profile requires you supply/)
|
16
|
+
end
|
17
|
+
it "raises an error if your hash values are anything other than required or optional" do
|
18
|
+
expect { R509::Config::SubjectItemPolicy.new("CN" => { :policy => "somethirdoption" }) }.to raise_error(ArgumentError, "Unknown subject item policy value. Allowed values are required, optional, or match")
|
19
|
+
end
|
20
|
+
it "raises an error if a subject item does not match the value supplied" do
|
21
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "match", :value => "some-cn-goes-here" })
|
22
|
+
subject = R509::Subject.new [["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
23
|
+
expect { subject_item_policy.validate_subject(subject) }.to raise_error(R509::R509Error, 'This profile requires that CN have value: some-cn-goes-here')
|
24
|
+
end
|
25
|
+
it "errors if you get case of subject_item_policy element wrong" do
|
26
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("cn" => { :policy => "required" })
|
27
|
+
subject = R509::Subject.new [["CN","langui.sh"]]
|
28
|
+
expect { subject_item_policy.validate_subject(subject) }.to raise_error(R509::R509Error, 'This profile requires you supply cn')
|
29
|
+
end
|
30
|
+
it "validates a subject with the same fields as the policy" do
|
31
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" }, "O" => { :policy => "required" }, "OU" => { :policy => "optional" })
|
32
|
+
subject = R509::Subject.new [["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
33
|
+
validated_subject = subject_item_policy.validate_subject(subject)
|
34
|
+
validated_subject.to_s.should == subject.to_s
|
35
|
+
end
|
36
|
+
it "allows matched fields" do
|
37
|
+
sip = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "match", :value => "langui.sh" }, "O" => { :policy => "match", :value => "ooooor"})
|
38
|
+
subject = R509::Subject.new [['CN','langui.sh'],['O','ooooor']]
|
39
|
+
validated_subject = sip.validate_subject(subject)
|
40
|
+
validated_subject.to_s.should == subject.to_s
|
41
|
+
end
|
42
|
+
it "builds hash" do
|
43
|
+
args = { "CN" => { :policy => "match", :value => "langui.sh" }, "O" => { :policy => "match", :value => "ooooor"} }
|
44
|
+
sip = R509::Config::SubjectItemPolicy.new(args)
|
45
|
+
# this equality check works because ruby does not compare hash order (which exists in 1.9+)
|
46
|
+
# when doing comparison
|
47
|
+
sip.to_h.should == args
|
48
|
+
end
|
49
|
+
it "builds yaml" do
|
50
|
+
args = { "CN" => { :policy => "match", :value => "langui.sh" }, "O" => { :policy => "match", :value => "ooooor"} }
|
51
|
+
sip = R509::Config::SubjectItemPolicy.new(args)
|
52
|
+
# this equality check works because ruby does not compare hash order (which exists in 1.9+)
|
53
|
+
# when doing comparison
|
54
|
+
YAML.load(sip.to_yaml).should == args
|
55
|
+
end
|
56
|
+
it "preserves subject order when applying policies" do
|
57
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" }, "O" => { :policy => "required" }, "OU" => { :policy => "optional" }, "L" => { :policy => "required" }, "C" => { :policy => "required" })
|
58
|
+
subject = R509::Subject.new [["C","US"],["L","Chicago"],["ST","Illinois"],["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
59
|
+
validated_subject = subject_item_policy.validate_subject(subject)
|
60
|
+
validated_subject.to_s.should == "/C=US/L=Chicago/CN=langui.sh/OU=Org Unit/O=Org"
|
61
|
+
end
|
62
|
+
it "removes subject items that are not in the policy" do
|
63
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" })
|
64
|
+
subject = R509::Subject.new [["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
65
|
+
validated_subject = subject_item_policy.validate_subject(subject)
|
66
|
+
validated_subject.to_s.should == "/CN=langui.sh"
|
67
|
+
end
|
68
|
+
it "does not reorder subject items as it validates" do
|
69
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" }, "O" => { :policy => "required" }, "OU" => { :policy => "optional" }, "L" => { :policy => "match", :value => "Chicago" })
|
70
|
+
subject = R509::Subject.new [["L","Chicago"],["CN","langui.sh"],["OU","Org Unit"],["O","Org"]]
|
71
|
+
validated_subject = subject_item_policy.validate_subject(subject)
|
72
|
+
validated_subject.to_s.should == subject.to_s
|
73
|
+
end
|
74
|
+
it "loads all the required, optional, and match elements" do
|
75
|
+
subject_item_policy = R509::Config::SubjectItemPolicy.new("CN" => { :policy => "required" }, "O" => { :policy => "required" }, "OU" => { :policy => "optional" }, "L" => { :policy => "required" }, "emailAddress" => { :policy => "match", :value => "some@emailaddress.com" })
|
76
|
+
subject_item_policy.optional.should include("OU")
|
77
|
+
subject_item_policy.match.should include("emailAddress")
|
78
|
+
subject_item_policy.match_values["emailAddress"].should == "some@emailaddress.com"
|
79
|
+
subject_item_policy.required.should include("CN","O","L")
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe R509::CRL::Administrator do
|
4
|
+
before :each do
|
5
|
+
@cert = TestFixtures::CERT
|
6
|
+
@csr = TestFixtures::CSR
|
7
|
+
@csr3 = TestFixtures::CSR3
|
8
|
+
@test_ca_config = TestFixtures.test_ca_no_profile_config
|
9
|
+
@test_ca_dsa_config = TestFixtures.test_ca_dsa_no_profile_config
|
10
|
+
end
|
11
|
+
|
12
|
+
it "signs CRL with no delegate certificate" do
|
13
|
+
config = R509::Config::CAConfig.new(
|
14
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
15
|
+
)
|
16
|
+
crl_admin = R509::CRL::Administrator.new(config)
|
17
|
+
crl = crl_admin.generate_crl
|
18
|
+
crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "signs CRL with delegate certificate" do
|
22
|
+
config = R509::Config::CAConfig.new(
|
23
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
24
|
+
:crl_cert => TestFixtures.test_ca_crl_delegate,
|
25
|
+
)
|
26
|
+
crl_admin = R509::CRL::Administrator.new(config)
|
27
|
+
crl = crl_admin.generate_crl
|
28
|
+
crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=r509 LLC/CN=r509 CRL Delegate'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "signs CRL with non-default message digest" do
|
32
|
+
config = R509::Config::CAConfig.new(
|
33
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
34
|
+
:crl_md => 'sha256'
|
35
|
+
)
|
36
|
+
crl_admin = R509::CRL::Administrator.new(config)
|
37
|
+
crl = crl_admin.generate_crl
|
38
|
+
crl.signature_algorithm.should == 'sha256WithRSAEncryption'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "signs CRL with default message digest" do
|
42
|
+
config = R509::Config::CAConfig.new(
|
43
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
44
|
+
)
|
45
|
+
crl_admin = R509::CRL::Administrator.new(config)
|
46
|
+
crl = crl_admin.generate_crl
|
47
|
+
crl.signature_algorithm.should == 'sha1WithRSAEncryption'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "generates CRL with no entries in revocation list (RSA key)" do
|
51
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
52
|
+
crl = crl_admin.generate_crl
|
53
|
+
crl.to_pem.should match(/BEGIN X509 CRL/)
|
54
|
+
crl.signature_algorithm.should == 'sha1WithRSAEncryption'
|
55
|
+
end
|
56
|
+
it "generates CRL with no entries in revocation list (DSA key)" do
|
57
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_dsa_config)
|
58
|
+
crl = crl_admin.generate_crl
|
59
|
+
crl.to_pem.should match(/BEGIN X509 CRL/)
|
60
|
+
crl.signature_algorithm.should == 'dsaWithSHA1'
|
61
|
+
end
|
62
|
+
context "elliptic curve", :ec => true do
|
63
|
+
before :all do
|
64
|
+
@test_ca_ec_config = TestFixtures.test_ca_ec_no_profile_config
|
65
|
+
end
|
66
|
+
it "generates CRL with no entries in revocation list (EC key)" do
|
67
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_ec_config)
|
68
|
+
crl = crl_admin.generate_crl
|
69
|
+
crl.to_pem.should match(/BEGIN X509 CRL/)
|
70
|
+
crl.signature_algorithm.should == 'ecdsa-with-SHA1'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it "raises exception when no R509::Config::CAConfig object is passed to the constructor" do
|
74
|
+
expect { R509::CRL::Administrator.new(['random']) }.to raise_error(R509::R509Error)
|
75
|
+
end
|
76
|
+
it "raises exception when reader/writer is passed that is not a subclass of ReaderWriter)" do
|
77
|
+
expect { R509::CRL::Administrator.new(@test_ca_config,{}) }.to raise_error(ArgumentError,'argument reader_writer must be a subclass of R509::CRL::ReaderWriter')
|
78
|
+
end
|
79
|
+
it "adds a cert to the revocation list" do
|
80
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
81
|
+
crl_admin.revoked?(383834832).should == false
|
82
|
+
crl_admin.revoke_cert(383834832)
|
83
|
+
crl_admin.revoked?(383834832).should == true
|
84
|
+
crl_admin.revoked?('383834832').should == true
|
85
|
+
crl = crl_admin.generate_crl
|
86
|
+
crl.revoked[383834832].should_not be_nil
|
87
|
+
crl.crl.revoked[0].serial.should == 383834832
|
88
|
+
end
|
89
|
+
it "can revoke (with reason)" do
|
90
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
91
|
+
crl_admin.revoked?(12345).should == false
|
92
|
+
crl_admin.revoke_cert(12345, 1)
|
93
|
+
crl_admin.revoked?(12345).should == true
|
94
|
+
crl_admin.revoked_cert(12345)[:reason].should == 1
|
95
|
+
crl = crl_admin.generate_crl
|
96
|
+
|
97
|
+
crl.crl.revoked[0].serial.should == 12345
|
98
|
+
crl.crl.revoked[0].extensions[0].oid.should == "CRLReason"
|
99
|
+
crl.crl.revoked[0].extensions[0].value.should == "Key Compromise"
|
100
|
+
end
|
101
|
+
it "can revoke (without reason)" do
|
102
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
103
|
+
crl_admin.revoked?(12345).should == false
|
104
|
+
crl_admin.revoke_cert(12345)
|
105
|
+
crl_admin.revoked?(12345).should == true
|
106
|
+
crl_admin.revoked_cert(12345)[:reason].should be_nil
|
107
|
+
crl = crl_admin.generate_crl
|
108
|
+
|
109
|
+
crl.crl.revoked[0].serial.should == 12345
|
110
|
+
crl.crl.revoked[0].extensions.size.should == 0
|
111
|
+
end
|
112
|
+
it "cannot revoke the same serial twice" do
|
113
|
+
crl = R509::CRL::Administrator.new(@test_ca_config)
|
114
|
+
crl.revoked?(12345).should == false
|
115
|
+
crl.revoke_cert(12345, 1)
|
116
|
+
crl.revoked?(12345).should == true
|
117
|
+
crl.revoked_cert(12345)[:reason].should == 1
|
118
|
+
expect { crl.revoke_cert(12345, 1) }.to raise_error(R509::R509Error, "Cannot revoke a previously revoked certificate")
|
119
|
+
crl.revoked?(12345).should == true
|
120
|
+
end
|
121
|
+
it "adds a cert to the revocation list with an invalid reason code" do
|
122
|
+
crl = R509::CRL::Administrator.new(@test_ca_config)
|
123
|
+
expect { crl.revoke_cert(383834832,15) }.to raise_error(ArgumentError, 'Revocation reason must be integer 0-10 (excluding 7) or nil')
|
124
|
+
expect { crl.revoke_cert(383834832,7) }.to raise_error(ArgumentError, 'Revocation reason must be integer 0-10 (excluding 7) or nil')
|
125
|
+
expect { crl.revoke_cert(383834832,'string') }.to raise_error(ArgumentError, 'Revocation reason must be integer 0-10 (excluding 7) or nil')
|
126
|
+
end
|
127
|
+
it "removes a cert from the revocation list" do
|
128
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
129
|
+
crl_admin.revoke_cert(383834832)
|
130
|
+
crl_admin.revoked?(383834832).should == true
|
131
|
+
crl = crl_admin.generate_crl
|
132
|
+
crl.crl.revoked[0].serial.should == 383834832
|
133
|
+
crl_admin.unrevoke_cert(383834832)
|
134
|
+
crl = crl_admin.generate_crl
|
135
|
+
crl_admin.revoked?(383834832).should == false
|
136
|
+
crl.crl.revoked.empty?.should == true
|
137
|
+
end
|
138
|
+
it "loads an existing revocation list file" do
|
139
|
+
config = R509::Config::CAConfig.new(
|
140
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
141
|
+
:crl_list_file => TestFixtures::CRL_LIST_FILE
|
142
|
+
)
|
143
|
+
crl = R509::CRL::Administrator.new(config)
|
144
|
+
crl.revoked?(12345).should == true
|
145
|
+
crl.revoked_cert(12345)[:revoke_time].should == 1323983885
|
146
|
+
crl.revoked_cert(12345)[:reason].should == 0
|
147
|
+
crl.revoked?(12346).should == true
|
148
|
+
crl.revoked_cert(12346)[:revoke_time].should == 1323983885
|
149
|
+
crl.revoked_cert(12346)[:reason].should == nil
|
150
|
+
end
|
151
|
+
it "load when nil crl_list_file" do
|
152
|
+
config = R509::Config::CAConfig.new(
|
153
|
+
:ca_cert => TestFixtures.test_ca_cert,
|
154
|
+
:crl_list_file => nil
|
155
|
+
)
|
156
|
+
expect { R509::CRL::Administrator.new(config) }.to_not raise_error
|
157
|
+
end
|
158
|
+
it "sets validity via yaml" do
|
159
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
160
|
+
t = Time.at Time.now.to_i
|
161
|
+
Time.should_receive(:now).twice.and_return(t)
|
162
|
+
crl = crl_admin.generate_crl
|
163
|
+
crl.next_update.should == (t.utc+168*3600) #default 168 hours (7 days)
|
164
|
+
end
|
165
|
+
it "has proper defaults for last_update and next_update" do
|
166
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
167
|
+
now = Time.at Time.now.to_i
|
168
|
+
crl = crl_admin.generate_crl
|
169
|
+
crl.last_update.should == now-@test_ca_config.crl_start_skew_seconds
|
170
|
+
crl.next_update.should == now+@test_ca_config.crl_validity_hours*3600
|
171
|
+
end
|
172
|
+
it "takes custom last_update and next_update" do
|
173
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config)
|
174
|
+
last = Time.at Time.now.to_i - 86400
|
175
|
+
nex = Time.at Time.now.to_i + 5
|
176
|
+
crl = crl_admin.generate_crl(last,nex)
|
177
|
+
crl.last_update.should == last
|
178
|
+
crl.next_update.should == nex
|
179
|
+
end
|
180
|
+
it "calls write_list_entry when revoking" do
|
181
|
+
rw = double("rw")
|
182
|
+
rw.should_receive(:kind_of?).and_return(true)
|
183
|
+
rw.should_receive(:write_list_entry)
|
184
|
+
rw.should_receive(:read_number).and_return(0)
|
185
|
+
rw.should_receive(:read_list).and_return(nil)
|
186
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config,rw)
|
187
|
+
crl_admin.revoked?(383834832).should == false
|
188
|
+
crl_admin.revoke_cert(383834832)
|
189
|
+
end
|
190
|
+
it "calls write_number when incrementing crl_number" do
|
191
|
+
rw = double("rw")
|
192
|
+
rw.should_receive(:kind_of?).and_return(true)
|
193
|
+
rw.should_receive(:read_number).and_return(0)
|
194
|
+
rw.should_receive(:read_list).and_return(nil)
|
195
|
+
rw.should_receive(:write_number).with(1)
|
196
|
+
crl_admin = R509::CRL::Administrator.new(@test_ca_config,rw)
|
197
|
+
crl_admin.generate_crl
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe R509::CRL::ReaderWriter do
|
5
|
+
before :all do
|
6
|
+
@rw = R509::CRL::ReaderWriter.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "abstract base class raises error for write_list_entry" do
|
10
|
+
expect { @rw.write_list_entry }.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "abstract base class raises error for remove_list_entry" do
|
14
|
+
expect { @rw.remove_list_entry }.to raise_error(NotImplementedError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "abstract base class raises error for write_number" do
|
18
|
+
expect { @rw.write_number }.to raise_error(NotImplementedError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "abstract base class raises error for read_list" do
|
22
|
+
expect { @rw.read_list }.to raise_error(NotImplementedError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "abstract base class raises error for read_number" do
|
26
|
+
expect { @rw.read_number }.to raise_error(NotImplementedError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe R509::CRL::FileReaderWriter do
|
31
|
+
before :each do
|
32
|
+
@rw = R509::CRL::FileReaderWriter.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it "handles nil crl_list_file in read_list" do
|
36
|
+
@rw.crl_list_file = nil
|
37
|
+
@rw.read_list(nil).should == nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "handles nil crl_list_file in write_list_entry" do
|
41
|
+
@rw.crl_list_file = nil
|
42
|
+
@rw.write_list_entry(1,1,nil).should == nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "handles nil crl_number_file in read_number" do
|
46
|
+
@rw.crl_number_file = nil
|
47
|
+
@rw.read_number.should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it "handles nil crl_number_file in write_number" do
|
51
|
+
@rw.crl_number_file = nil
|
52
|
+
@rw.write_number(0).should == nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it "reads a crl list" do
|
56
|
+
@rw.crl_list_file = TestFixtures::CRL_LIST_FILE
|
57
|
+
admin = double("admin")
|
58
|
+
admin.should_receive(:revoke_cert).with(12345, 0, 1323983885, false)
|
59
|
+
admin.should_receive(:revoke_cert).with(12346, nil, 1323983885, false)
|
60
|
+
@rw.read_list(admin)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "writes a crl list entry" do
|
64
|
+
sio = StringIO.new
|
65
|
+
@rw.crl_list_file = sio
|
66
|
+
@rw.write_list_entry(1,1,nil)
|
67
|
+
sio.string.should == "1,1,\n"
|
68
|
+
@rw.write_list_entry(2,2,1)
|
69
|
+
sio.string.should == "1,1,\n2,2,1\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "removes a crl list entry" do
|
73
|
+
sio = StringIO.new
|
74
|
+
@rw.crl_list_file = sio
|
75
|
+
@rw.write_list_entry(1,1,nil)
|
76
|
+
sio.string.should == "1,1,\n"
|
77
|
+
@rw.write_list_entry(2,2,1)
|
78
|
+
sio.string.should == "1,1,\n2,2,1\n"
|
79
|
+
@rw.remove_list_entry(2)
|
80
|
+
sio.string.should == "1,1,\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "reads a number" do
|
84
|
+
sio = StringIO.new
|
85
|
+
sio.write("500")
|
86
|
+
sio.rewind # rewind the pointer to the beginning so the next read catche the 500
|
87
|
+
@rw.crl_number_file = sio
|
88
|
+
@rw.read_number.should == 500
|
89
|
+
end
|
90
|
+
|
91
|
+
it "writes a crl number" do
|
92
|
+
sio = StringIO.new
|
93
|
+
@rw.crl_number_file = sio
|
94
|
+
@rw.write_number(30)
|
95
|
+
@rw.crl_number_file.string.should == "30"
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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?('111111').should == false
|
41
|
+
@crl.revoked?(12345).should == true
|
42
|
+
@crl.revoked?('12345').should == true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns a hash of all revoked certs" do
|
46
|
+
@crl.revoked[12345][:time].should == Time.at(1327449693)
|
47
|
+
@crl.revoked[12345][:reason].should == "Key Compromise"
|
48
|
+
@crl.revoked[123456][:time].should == Time.at(1327449693)
|
49
|
+
@crl.revoked[123456][:reason].should == "Unspecified"
|
50
|
+
@crl.revoked[1234567][:time].should == Time.at(1327449693)
|
51
|
+
@crl.revoked[1234567][:reason].should == "Unspecified"
|
52
|
+
@crl.revoked[12345678].should == nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns revocation information for a serial" do
|
56
|
+
@crl.revoked_cert(11111).should == nil
|
57
|
+
revoked_info = @crl.revoked_cert(12345)
|
58
|
+
revoked_info[:time].should == Time.at(1327449693)
|
59
|
+
revoked_info[:reason].should == "Key Compromise"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns der" do
|
63
|
+
@crl.to_der.should_not be_nil
|
64
|
+
end
|
65
|
+
it "returns pem" do
|
66
|
+
@crl.to_pem.should_not be_nil
|
67
|
+
end
|
68
|
+
it "writes to pem" do
|
69
|
+
sio = StringIO.new
|
70
|
+
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
71
|
+
@crl.write_pem(sio)
|
72
|
+
parsed_crl = R509::CRL::SignedList.new(sio.string)
|
73
|
+
parsed_crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA'
|
74
|
+
parsed_crl.issuer.CN.should == 'Test CA'
|
75
|
+
end
|
76
|
+
it "writes to der" do
|
77
|
+
sio = StringIO.new
|
78
|
+
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
79
|
+
@crl.write_der(sio)
|
80
|
+
parsed_crl = R509::CRL::SignedList.new(sio.string)
|
81
|
+
parsed_crl.issuer.to_s.should == '/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA'
|
82
|
+
parsed_crl.issuer.CN.should == 'Test CA'
|
83
|
+
end
|
84
|
+
end
|