r509 0.8.1 → 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +343 -151
- data/Rakefile +26 -23
- data/bin/r509 +126 -112
- data/bin/r509-parse +24 -24
- data/doc/R509.html +169 -7
- data/doc/R509/ASN1.html +370 -0
- data/doc/R509/ASN1/GeneralName.html +1121 -0
- data/doc/R509/ASN1/GeneralNames.html +843 -0
- data/doc/R509/ASN1/NoticeReference.html +392 -0
- data/doc/R509/ASN1/PolicyInformation.html +387 -0
- data/doc/R509/ASN1/PolicyQualifiers.html +455 -0
- data/doc/R509/ASN1/UserNotice.html +386 -0
- data/doc/R509/{Crl.html → CRL.html} +7 -7
- data/doc/R509/CRL/Administrator.html +1559 -0
- data/doc/R509/{Crl/Parser.html → CRL/SignedList.html} +501 -210
- data/doc/R509/{Csr.html → CSR.html} +444 -314
- data/doc/R509/Cert.html +866 -617
- data/doc/R509/Cert/Extensions.html +52 -41
- data/doc/R509/Cert/Extensions/AuthorityInfoAccess.html +70 -35
- data/doc/R509/Cert/Extensions/AuthorityKeyIdentifier.html +387 -4
- data/doc/R509/Cert/Extensions/BasicConstraints.html +61 -25
- data/doc/R509/Cert/Extensions/CRLDistributionPoints.html +354 -0
- data/doc/R509/Cert/Extensions/CertificatePolicies.html +340 -0
- data/doc/R509/Cert/Extensions/ExtendedKeyUsage.html +440 -49
- data/doc/R509/Cert/Extensions/{CrlDistributionPoints.html → InhibitAnyPolicy.html} +52 -35
- data/doc/R509/Cert/Extensions/KeyUsage.html +247 -121
- data/doc/R509/Cert/Extensions/NameConstraints.html +445 -0
- data/doc/R509/Cert/Extensions/OCSPNoCheck.html +239 -0
- data/doc/R509/Cert/Extensions/PolicyConstraints.html +424 -0
- data/doc/R509/Cert/Extensions/SubjectAlternativeName.html +437 -62
- data/doc/R509/Cert/Extensions/SubjectKeyIdentifier.html +52 -10
- data/doc/R509/CertificateAuthority.html +4 -4
- data/doc/R509/CertificateAuthority/Signer.html +154 -187
- data/doc/R509/Config.html +6 -6
- data/doc/R509/Config/{CaConfig.html → CAConfig.html} +451 -348
- data/doc/R509/Config/{CaConfigPool.html → CAConfigPool.html} +47 -47
- data/doc/R509/Config/CAProfile.html +1015 -0
- data/doc/R509/Config/SubjectItemPolicy.html +86 -86
- data/doc/R509/IOHelpers.html +22 -22
- data/doc/R509/MessageDigest.html +14 -14
- data/doc/R509/NameSanitizer.html +53 -53
- data/doc/R509/{Ocsp.html → OCSP.html} +9 -9
- data/doc/R509/{Ocsp → OCSP}/Request.html +7 -7
- data/doc/R509/{Ocsp → OCSP}/Request/Nonce.html +56 -11
- data/doc/R509/{Ocsp → OCSP}/Response.html +44 -44
- data/doc/R509/{OidMapper.html → OIDMapper.html} +23 -39
- data/doc/R509/PrivateKey.html +415 -168
- data/doc/R509/R509Error.html +3 -3
- data/doc/R509/{Spki.html → SPKI.html} +354 -192
- data/doc/R509/Subject.html +224 -113
- data/doc/R509/Validity.html +27 -5
- data/doc/R509/Validity/Checker.html +13 -13
- data/doc/R509/Validity/DefaultChecker.html +13 -13
- data/doc/R509/Validity/DefaultWriter.html +14 -14
- data/doc/R509/Validity/Status.html +39 -39
- data/doc/R509/Validity/Writer.html +18 -18
- data/doc/_index.html +138 -35
- data/doc/class_list.html +1 -1
- data/doc/css/style.css +10 -0
- data/doc/file.README.html +368 -171
- data/doc/file.r509.html +92 -69
- data/doc/frames.html +1 -1
- data/doc/index.html +368 -171
- data/doc/method_list.html +910 -390
- data/doc/top-level-namespace.html +3 -3
- data/lib/r509.rb +32 -16
- data/lib/r509/asn1.rb +375 -0
- data/lib/r509/cert.rb +381 -364
- data/lib/r509/cert/extensions.rb +443 -76
- data/lib/r509/certificate_authority.rb +407 -0
- data/lib/r509/config.rb +547 -351
- data/lib/r509/crl.rb +336 -366
- data/lib/r509/csr.rb +278 -289
- data/lib/r509/ec-hack.rb +37 -0
- data/lib/r509/exceptions.rb +3 -3
- data/lib/r509/io_helpers.rb +44 -44
- data/lib/r509/message_digest.rb +53 -0
- data/lib/r509/ocsp.rb +80 -70
- data/lib/r509/oid_mapper.rb +32 -0
- data/lib/r509/private_key.rb +228 -0
- data/lib/r509/spki.rb +145 -93
- data/lib/r509/subject.rb +203 -110
- data/lib/r509/validity.rb +70 -68
- data/lib/r509/version.rb +2 -2
- data/r509.yaml +92 -69
- data/spec/asn1_spec.rb +402 -0
- data/spec/cert/extensions_spec.rb +957 -494
- data/spec/cert_spec.rb +382 -307
- data/spec/certificate_authority_spec.rb +668 -250
- data/spec/config_spec.rb +515 -302
- data/spec/crl_spec.rb +197 -198
- data/spec/csr_spec.rb +334 -289
- data/spec/fixtures.rb +247 -171
- data/spec/fixtures/cert1.der +0 -0
- data/spec/fixtures/cert1.pem +0 -0
- data/spec/fixtures/cert1_public_key_modulus.txt +0 -0
- data/spec/fixtures/cert3.p12 +0 -0
- data/spec/fixtures/cert3.pem +0 -0
- data/spec/fixtures/cert3_key.pem +0 -0
- data/spec/fixtures/cert3_key_des3.pem +0 -0
- data/spec/fixtures/cert4.pem +0 -0
- data/spec/fixtures/cert5.pem +0 -0
- data/spec/fixtures/cert6.pem +0 -0
- data/spec/fixtures/cert_expired.pem +0 -0
- data/spec/fixtures/cert_inhibit.pem +24 -0
- data/spec/fixtures/cert_name_constraints.pem +29 -0
- data/spec/fixtures/cert_not_yet_valid.pem +0 -0
- data/spec/fixtures/cert_ocsp_no_check.pem +18 -0
- data/spec/fixtures/cert_policy_constraints.pem +31 -0
- data/spec/fixtures/cert_san.pem +0 -0
- data/spec/fixtures/cert_san2.pem +0 -0
- data/spec/fixtures/cert_unknown_extension.pem +28 -0
- data/spec/fixtures/config_pool_test_minimal.yaml +11 -11
- data/spec/fixtures/config_test.yaml +54 -36
- data/spec/fixtures/config_test_dsa.yaml +35 -0
- data/spec/fixtures/config_test_ec.yaml +35 -0
- data/spec/fixtures/config_test_engine_key.yaml +5 -5
- data/spec/fixtures/config_test_engine_no_key_name.yaml +4 -4
- data/spec/fixtures/config_test_minimal.yaml +4 -4
- data/spec/fixtures/config_test_password.yaml +5 -5
- data/spec/fixtures/config_test_various.yaml +111 -74
- data/spec/fixtures/crl_list_file.txt +0 -0
- data/spec/fixtures/crl_with_reason.pem +0 -0
- data/spec/fixtures/csr1.der +0 -0
- data/spec/fixtures/csr1.pem +0 -0
- data/spec/fixtures/csr1_key.der +0 -0
- data/spec/fixtures/csr1_key.pem +0 -0
- data/spec/fixtures/csr1_key_encrypted_des3.pem +0 -0
- data/spec/fixtures/csr1_newlines.pem +0 -0
- data/spec/fixtures/csr1_no_begin_end.pem +0 -0
- data/spec/fixtures/csr1_public_key_modulus.txt +0 -0
- data/spec/fixtures/csr2.pem +0 -0
- data/spec/fixtures/csr2_key.pem +0 -0
- data/spec/fixtures/csr3.pem +0 -0
- data/spec/fixtures/csr4.pem +0 -0
- data/spec/fixtures/csr_dsa.pem +0 -0
- data/spec/fixtures/csr_invalid_signature.pem +0 -0
- data/spec/fixtures/dsa_key.pem +0 -0
- data/spec/fixtures/dsa_root.cer +28 -0
- data/spec/fixtures/dsa_root.key +20 -0
- data/spec/fixtures/ec_csr2.der +0 -0
- data/spec/fixtures/ec_csr2.pem +8 -0
- data/spec/fixtures/ec_key1.der +0 -0
- data/spec/fixtures/ec_key1.pem +6 -0
- data/spec/fixtures/ec_key1_encrypted.pem +9 -0
- data/spec/fixtures/ec_key2.pem +6 -0
- data/spec/fixtures/hmacsha1.sig +1 -0
- data/spec/fixtures/hmacsha512.sig +1 -0
- data/spec/fixtures/key4.pem +0 -0
- data/spec/fixtures/key4_encrypted_des3.pem +0 -0
- data/spec/fixtures/missing_key_identifier_ca.cer +0 -0
- data/spec/fixtures/missing_key_identifier_ca.key +0 -0
- data/spec/fixtures/ocsptest.r509.local.pem +0 -0
- data/spec/fixtures/ocsptest.r509.local_ocsp_request.der +0 -0
- data/spec/fixtures/ocsptest2.r509.local.pem +0 -0
- data/spec/fixtures/second_ca.cer +0 -0
- data/spec/fixtures/second_ca.key +0 -0
- data/spec/fixtures/spkac.der +0 -0
- data/spec/fixtures/spkac.txt +0 -0
- data/spec/fixtures/spkac_dsa.txt +1 -1
- data/spec/fixtures/spkac_dsa_no_verify.txt +1 -0
- data/spec/fixtures/spkac_ec.txt +1 -0
- data/spec/fixtures/spkac_rsa_newlines.txt +13 -0
- data/spec/fixtures/stca.pem +0 -0
- data/spec/fixtures/stca_ocsp_request.der +0 -0
- data/spec/fixtures/stca_ocsp_response.der +0 -0
- data/spec/fixtures/test1.csr +0 -0
- data/spec/fixtures/test_ca.cer +0 -0
- data/spec/fixtures/test_ca.key +0 -0
- data/spec/fixtures/test_ca.p12 +0 -0
- data/spec/fixtures/test_ca_des3.key +0 -0
- data/spec/fixtures/test_ca_ec.cer +14 -0
- data/spec/fixtures/test_ca_ec.key +6 -0
- data/spec/fixtures/test_ca_ec_ee.cer +22 -0
- data/spec/fixtures/test_ca_ec_ee.key +6 -0
- data/spec/fixtures/test_ca_ocsp.cer +0 -0
- data/spec/fixtures/test_ca_ocsp.key +0 -0
- data/spec/fixtures/test_ca_ocsp.p12 +0 -0
- data/spec/fixtures/test_ca_ocsp_chain.txt +0 -0
- data/spec/fixtures/test_ca_ocsp_response.der +0 -0
- data/spec/fixtures/test_ca_subroot.cer +0 -0
- data/spec/fixtures/test_ca_subroot.key +0 -0
- data/spec/fixtures/test_ca_subroot_ocsp.cer +0 -0
- data/spec/fixtures/test_ca_subroot_ocsp.key +0 -0
- data/spec/fixtures/test_ca_subroot_ocsp_response.der +0 -0
- data/spec/fixtures/unknown_oid.csr +0 -0
- data/spec/message_digest_spec.rb +104 -84
- data/spec/ocsp_spec.rb +105 -105
- data/spec/oid_mapper_spec.rb +21 -21
- data/spec/private_key_spec.rb +275 -0
- data/spec/r509_spec.rb +35 -0
- data/spec/spec_helper.rb +15 -6
- data/spec/spki_spec.rb +221 -142
- data/spec/subject_spec.rb +232 -164
- data/spec/validity_spec.rb +91 -91
- metadata +79 -25
- data/doc/R509/Config/CaProfile.html +0 -651
- data/doc/R509/Crl/Administrator.html +0 -2073
- data/lib/r509/certificateauthority.rb +0 -290
- data/lib/r509/messagedigest.rb +0 -49
- data/lib/r509/oidmapper.rb +0 -32
- data/lib/r509/privatekey.rb +0 -185
- data/spec/privatekey_spec.rb +0 -198
data/spec/r509_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def capture_stdout(&block)
|
4
|
+
original_stdout = $stdout
|
5
|
+
$stdout = fake = StringIO.new
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
$stdout = original_stdout
|
10
|
+
end
|
11
|
+
fake.string
|
12
|
+
end
|
13
|
+
|
14
|
+
describe R509 do
|
15
|
+
it "prints version and feature info with ::print_debug" do
|
16
|
+
output = capture_stdout { R509.print_debug }
|
17
|
+
output.should match /^r509 v/
|
18
|
+
output.should match /^OpenSSL/
|
19
|
+
output.should match /^Ruby/
|
20
|
+
output.should match /^Elliptic/
|
21
|
+
end
|
22
|
+
it "checks if ec is supported", :ec => true do
|
23
|
+
R509.ec_supported?.should == true
|
24
|
+
end
|
25
|
+
it "checks if EC is unsupported" do
|
26
|
+
ec = OpenSSL::PKey.send(:remove_const,:EC) # remove EC support for test!
|
27
|
+
load('r509/ec-hack.rb')
|
28
|
+
R509.ec_supported?.should == false
|
29
|
+
expect { OpenSSL::PKey::EC.new }.to raise_error(R509::R509Error)
|
30
|
+
OpenSSL::PKey.send(:remove_const,:EC) # remove stubbed EC
|
31
|
+
OpenSSL::PKey::EC = ec # add the real one back
|
32
|
+
# this pretty fragile. if the expectation fails then we don't fix the EC class assignment
|
33
|
+
# so any spec called after this will fail improperly.
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
if (RUBY_VERSION.split('.')[1].to_i > 8)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
if (RUBY_VERSION.split('.')[1].to_i > 8 or RUBY_VERSION.split('.')[0].to_i > 1)
|
2
|
+
begin
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
7
|
end
|
8
8
|
|
9
9
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
@@ -12,3 +12,12 @@ require 'rubygems'
|
|
12
12
|
require 'fixtures'
|
13
13
|
require 'rspec'
|
14
14
|
require 'r509'
|
15
|
+
|
16
|
+
# exclude EC specific tests if it's unsupported
|
17
|
+
if not R509.ec_supported?
|
18
|
+
puts "\e[#{31}mWARNING: NOT RUNNING EC TESTS BECAUSE EC IS UNSUPPORTED ON YOUR RUBY INSTALLATION\e[0m"
|
19
|
+
R509.print_debug
|
20
|
+
RSpec.configure do |c|
|
21
|
+
c.filter_run_excluding :ec => true
|
22
|
+
end
|
23
|
+
end
|
data/spec/spki_spec.rb
CHANGED
@@ -2,156 +2,235 @@ require 'spec_helper'
|
|
2
2
|
require 'stringio'
|
3
3
|
require 'r509/spki'
|
4
4
|
|
5
|
+
shared_examples_for "create spki with private key" do
|
6
|
+
it "generates a spki with default digest" do
|
7
|
+
spki = R509::SPKI.new(:key => @key)
|
8
|
+
spki.to_pem.should_not be_nil
|
9
|
+
spki.verify_signature
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@spki = TestFixtures::SPKI.strip
|
11
|
-
@spki_der = TestFixtures::SPKI_DER
|
12
|
+
it "generates a spki from a pem key" do
|
13
|
+
spki = R509::SPKI.new(:key => @key.to_pem)
|
14
|
+
spki.to_pem.should_not be_nil
|
15
|
+
spki.verify_signature
|
12
16
|
end
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
it "generates a spki with custom digest" do
|
19
|
+
spki = R509::SPKI.new(:key => @key, :message_digest => "sha256")
|
20
|
+
spki.to_pem.should_not be_nil
|
21
|
+
spki.verify_signature
|
15
22
|
end
|
16
|
-
|
17
|
-
|
23
|
+
|
24
|
+
it "stores the key" do
|
25
|
+
spki = R509::SPKI.new(:key => @key)
|
26
|
+
spki.key.should == @key
|
18
27
|
end
|
19
|
-
|
20
|
-
|
28
|
+
|
29
|
+
it "verifies signature" do
|
30
|
+
spki = R509::SPKI.new(:key => @key)
|
31
|
+
spki.verify_signature
|
21
32
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_examples_for "spki + private key" do
|
36
|
+
it "verifies they match" do
|
37
|
+
expect { R509::SPKI.new(:key => @key, :spki => @spki) }.to_not raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "errors if they don't match" do
|
41
|
+
expect { R509::SPKI.new(:key => @key, :spki => @spki2) }.to raise_error(R509::R509Error,'Key does not match SPKI.')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe R509::SPKI do
|
46
|
+
before :all do
|
47
|
+
#also known as SPKAC (signed public key and challenge)
|
48
|
+
@spki_dsa = TestFixtures::SPKI_DSA
|
49
|
+
@spki_dsa_no_verify = TestFixtures::SPKI_DSA_NO_VERIFY
|
50
|
+
@spki = TestFixtures::SPKI
|
51
|
+
@spki_rsa_newlines = TestFixtures::SPKI_RSA_NEWLINES
|
52
|
+
@spki_ec = TestFixtures::SPKI_EC
|
53
|
+
@spki_der = TestFixtures::SPKI_DER
|
54
|
+
end
|
55
|
+
it "raises an error if you don't provide a hash" do
|
56
|
+
expect { R509::SPKI.new("junk") }.to raise_error(ArgumentError,'Must provide a hash of options')
|
57
|
+
end
|
58
|
+
it "raises an error if you provide an empty hash" do
|
59
|
+
expect { R509::SPKI.new({}) }.to raise_error(ArgumentError,'Must provide either :spki or :key')
|
60
|
+
end
|
61
|
+
context "rsa" do
|
62
|
+
context "no existing spki" do
|
63
|
+
before :all do
|
64
|
+
@key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 1024)
|
65
|
+
end
|
66
|
+
include_examples "create spki with private key"
|
67
|
+
end
|
68
|
+
context "existing spki + private key" do
|
69
|
+
before :all do
|
70
|
+
@key = R509::PrivateKey.new(:type => :rsa, :bit_strength => 512)
|
71
|
+
@key2 = R509::PrivateKey.new(:type => :rsa, :bit_strength => 512)
|
72
|
+
@spki = R509::SPKI.new(:key => @key).to_pem
|
73
|
+
@spki2 = R509::SPKI.new(:key => @key2).to_pem
|
74
|
+
end
|
75
|
+
include_examples "spki + private key"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context "dsa" do
|
79
|
+
context "no existing spki" do
|
80
|
+
before :all do
|
81
|
+
@key = R509::PrivateKey.new(:type => :dsa, :bit_strength => 1024)
|
82
|
+
end
|
83
|
+
include_examples "create spki with private key"
|
84
|
+
end
|
85
|
+
context "existing spki + private key" do
|
86
|
+
before :all do
|
87
|
+
@key = R509::PrivateKey.new(:type => :dsa, :bit_strength => 512)
|
88
|
+
@key2 = R509::PrivateKey.new(:type => :dsa, :bit_strength => 512)
|
89
|
+
@spki = R509::SPKI.new(:key => @key).to_pem
|
90
|
+
@spki2 = R509::SPKI.new(:key => @key2).to_pem
|
91
|
+
end
|
92
|
+
include_examples "spki + private key"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
context "elliptic curve", :ec => true do
|
96
|
+
context "no existing spki" do
|
97
|
+
before :all do
|
98
|
+
@key = R509::PrivateKey.new(:type => :ec)
|
99
|
+
end
|
100
|
+
include_examples "create spki with private key"
|
101
|
+
end
|
102
|
+
context "existing spki + private key" do
|
103
|
+
before :all do
|
104
|
+
@key = R509::PrivateKey.new(:type => :ec)
|
105
|
+
@key2 = R509::PrivateKey.new(:type => :ec)
|
106
|
+
@spki = R509::SPKI.new(:key => @key).to_pem
|
107
|
+
@spki2 = R509::SPKI.new(:key => @key2).to_pem
|
108
|
+
end
|
109
|
+
include_examples "spki + private key"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
context "with existing spki" do
|
113
|
+
it "loads an RSA spki" do
|
114
|
+
spki = R509::SPKI.new( :spki => @spki )
|
115
|
+
spki.to_pem.should == @spki
|
116
|
+
end
|
117
|
+
it "loads an spkac with newlines" do
|
118
|
+
spki = R509::SPKI.new( :spki => @spki_rsa_newlines )
|
119
|
+
spki.to_pem.should == @spki_rsa_newlines.gsub("\n","")
|
25
120
|
end
|
26
121
|
it "properly strips SPKAC= prefix and loads" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
122
|
+
spki = R509::SPKI.new( :spki => "SPKAC="+@spki )
|
123
|
+
spki.to_pem.should == @spki
|
124
|
+
end
|
125
|
+
end
|
126
|
+
it "returns the public key" do
|
127
|
+
spki = R509::SPKI.new( :spki => @spki )
|
128
|
+
spki.public_key.should_not == nil
|
129
|
+
end
|
130
|
+
it "returns pem" do
|
131
|
+
spki = R509::SPKI.new( :spki => @spki )
|
132
|
+
spki.to_pem.should == @spki
|
133
|
+
end
|
134
|
+
it "returns der" do
|
135
|
+
spki = R509::SPKI.new( :spki => @spki )
|
136
|
+
spki.to_der.should == @spki_der
|
137
|
+
end
|
138
|
+
it "writes to pem" do
|
139
|
+
spki = R509::SPKI.new( :spki => @spki )
|
140
|
+
sio = StringIO.new
|
141
|
+
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
142
|
+
spki.write_pem(sio)
|
143
|
+
sio.string.should == @spki
|
144
|
+
end
|
145
|
+
it "writes to der" do
|
146
|
+
spki = R509::SPKI.new( :spki => @spki )
|
147
|
+
sio = StringIO.new
|
148
|
+
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
149
|
+
spki.write_der(sio)
|
150
|
+
sio.string.should == @spki_der
|
151
|
+
end
|
152
|
+
it "rsa?" do
|
153
|
+
spki = R509::SPKI.new( :spki => @spki )
|
154
|
+
spki.rsa?.should == true
|
155
|
+
spki.dsa?.should == false
|
156
|
+
end
|
157
|
+
it "returns error when asking for curve_name on non-ec" do
|
158
|
+
spki = R509::SPKI.new( :spki => @spki )
|
159
|
+
expect { spki.curve_name }.to raise_error(R509::R509Error,'Curve name is only available with EC SPKIs')
|
160
|
+
end
|
161
|
+
it "returns RSA key algorithm for RSA" do
|
162
|
+
spki = R509::SPKI.new( :spki => @spki )
|
163
|
+
spki.key_algorithm.should == :rsa
|
164
|
+
end
|
165
|
+
it "gets RSA bit strength" do
|
166
|
+
spki = R509::SPKI.new( :spki => @spki )
|
167
|
+
spki.bit_strength.should == 2048
|
168
|
+
end
|
169
|
+
it "loads a DSA spkac" do
|
170
|
+
spki = R509::SPKI.new( :spki => @spki_dsa )
|
171
|
+
spki.to_pem.should == @spki_dsa
|
172
|
+
end
|
173
|
+
it "gets DSA bit strength" do
|
174
|
+
spki = R509::SPKI.new( :spki => @spki_dsa )
|
175
|
+
spki.bit_strength.should == 2048
|
176
|
+
end
|
177
|
+
it "dsa?" do
|
178
|
+
spki = R509::SPKI.new( :spki => @spki_dsa )
|
179
|
+
spki.dsa?.should == true
|
180
|
+
spki.rsa?.should == false
|
181
|
+
end
|
182
|
+
it "returns DSA key algorithm for DSA" do
|
183
|
+
spki = R509::SPKI.new( :spki => @spki_dsa )
|
184
|
+
spki.key_algorithm.should == :dsa
|
185
|
+
end
|
186
|
+
|
187
|
+
context "elliptic curve", :ec => true do
|
188
|
+
it "loads an spkac" do
|
189
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
190
|
+
spki.to_pem.should == @spki_ec
|
191
|
+
end
|
192
|
+
it "returns the curve name" do
|
193
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
194
|
+
spki.curve_name.should == 'secp384r1'
|
195
|
+
end
|
196
|
+
it "raises error on bit strength" do
|
197
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
198
|
+
expect { spki.bit_strength }.to raise_error(R509::R509Error,'Bit strength is not available for EC at this time.')
|
199
|
+
end
|
200
|
+
it "returns the key algorithm" do
|
201
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
202
|
+
spki.key_algorithm.should == :ec
|
32
203
|
end
|
33
204
|
it "returns the public key" do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
it "
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
it "writes to der" do
|
65
|
-
spki = R509::Spki.new(
|
66
|
-
:spki => @spki,
|
67
|
-
:subject => [['CN','spkitest.com']]
|
68
|
-
)
|
69
|
-
sio = StringIO.new
|
70
|
-
sio.set_encoding("BINARY") if sio.respond_to?(:set_encoding)
|
71
|
-
spki.write_der(sio)
|
72
|
-
sio.string.should == @spki_der
|
73
|
-
end
|
74
|
-
it "rsa?" do
|
75
|
-
spki = R509::Spki.new(
|
76
|
-
:spki => @spki,
|
77
|
-
:subject => [['CN','spkitest.com']]
|
78
|
-
)
|
79
|
-
spki.rsa?.should == true
|
80
|
-
spki.dsa?.should == false
|
81
|
-
end
|
82
|
-
it "returns RSA key algorithm for RSA" do
|
83
|
-
spki = R509::Spki.new(
|
84
|
-
:spki => @spki,
|
85
|
-
:subject => [['CN','spkitest.com']]
|
86
|
-
)
|
87
|
-
spki.key_algorithm.should == "RSA"
|
88
|
-
end
|
89
|
-
it "gets RSA bit strength" do
|
90
|
-
spki = R509::Spki.new(
|
91
|
-
:spki => @spki,
|
92
|
-
:subject => [['CN','spkitest.com']]
|
93
|
-
)
|
94
|
-
spki.bit_strength.should == 2048
|
95
|
-
end
|
96
|
-
it "loads a DSA spkac" do
|
97
|
-
spki = R509::Spki.new(
|
98
|
-
:spki => @spki_dsa,
|
99
|
-
:subject => [['CN','spkitest.com']]
|
100
|
-
)
|
101
|
-
spki.to_pem.should == @spki_dsa
|
102
|
-
end
|
103
|
-
it "gets DSA bit strength" do
|
104
|
-
spki = R509::Spki.new(
|
105
|
-
:spki => @spki_dsa,
|
106
|
-
:subject => [['CN','spkitest.com']]
|
107
|
-
)
|
108
|
-
spki.bit_strength.should == 2048
|
109
|
-
end
|
110
|
-
it "dsa?" do
|
111
|
-
spki = R509::Spki.new(
|
112
|
-
:spki => @spki_dsa,
|
113
|
-
:subject => [['CN','spkitest.com']]
|
114
|
-
)
|
115
|
-
spki.dsa?.should == true
|
116
|
-
spki.rsa?.should == false
|
117
|
-
end
|
118
|
-
it "returns DSA key algorithm for DSA" do
|
119
|
-
spki = R509::Spki.new(
|
120
|
-
:spki => @spki_dsa,
|
121
|
-
:subject => [['CN','spkitest.com']]
|
122
|
-
)
|
123
|
-
spki.key_algorithm.should == "DSA"
|
124
|
-
end
|
125
|
-
it "returns expected value for subject" do
|
126
|
-
spki = R509::Spki.new(
|
127
|
-
:spki => @spki,
|
128
|
-
:subject => [['CN','spkitest.com']]
|
129
|
-
)
|
130
|
-
spki.subject.to_s.should == '/CN=spkitest.com'
|
131
|
-
end
|
132
|
-
it "returns expected value for san names" do
|
133
|
-
spki = R509::Spki.new(
|
134
|
-
:spki => @spki,
|
135
|
-
:subject => [['CN','spkitest.com']],
|
136
|
-
:san_names => ['domain1.com','domain2.com']
|
137
|
-
)
|
138
|
-
spki.san_names.should == ['domain1.com','domain2.com']
|
139
|
-
end
|
140
|
-
it "returns empty array when passed no san_names" do
|
141
|
-
spki = R509::Spki.new(
|
142
|
-
:spki => @spki,
|
143
|
-
:subject => [['CN','spkitest.com']]
|
144
|
-
)
|
145
|
-
spki.san_names.empty?.should == true
|
146
|
-
end
|
147
|
-
it "creates a valid hash object with to_hash" do
|
148
|
-
spki = R509::Spki.new(
|
149
|
-
:spki => @spki,
|
150
|
-
:subject => [['CN','spkitest.com']],
|
151
|
-
:san_names => ["test.local"]
|
152
|
-
)
|
153
|
-
spki.to_hash[:subject].kind_of?(R509::Subject).should == true
|
154
|
-
spki.to_hash[:subject].to_s.should == '/CN=spkitest.com'
|
155
|
-
spki.to_hash[:san_names].should == ["test.local"]
|
205
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
206
|
+
spki.public_key.should_not == nil
|
207
|
+
end
|
208
|
+
it "ec?" do
|
209
|
+
spki = R509::SPKI.new( :spki => @spki_ec )
|
210
|
+
spki.ec?.should == true
|
211
|
+
spki.dsa?.should == false
|
212
|
+
spki.rsa?.should == false
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "when elliptic curve support is unavailable" do
|
217
|
+
before :all do
|
218
|
+
@ec = OpenSSL::PKey.send(:remove_const,:EC) # remove EC support for test!
|
219
|
+
load('r509/ec-hack.rb')
|
220
|
+
end
|
221
|
+
after :all do
|
222
|
+
OpenSSL::PKey.send(:remove_const,:EC) # remove stubbed EC
|
223
|
+
OpenSSL::PKey::EC = @ec # add the real one back
|
224
|
+
end
|
225
|
+
it "checks rsa?" do
|
226
|
+
spki = R509::SPKI.new( :spki => @spki )
|
227
|
+
spki.rsa?.should == true
|
228
|
+
spki.ec?.should == false
|
229
|
+
spki.dsa?.should == false
|
230
|
+
end
|
231
|
+
it "returns RSA key algorithm for RSA CSR" do
|
232
|
+
spki = R509::SPKI.new( :spki => @spki )
|
233
|
+
spki.key_algorithm.should == :rsa
|
156
234
|
end
|
235
|
+
end
|
157
236
|
end
|
data/spec/subject_spec.rb
CHANGED
@@ -3,201 +3,269 @@ require 'r509/subject'
|
|
3
3
|
require 'openssl'
|
4
4
|
|
5
5
|
describe R509::Subject do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
before :all do
|
7
|
+
@csr_unknown_oid = TestFixtures::CSR_UNKNOWN_OID
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
10
|
+
it "initializes an empty subject and gets the name" do
|
11
|
+
subject = R509::Subject.new
|
12
|
+
subject.name.to_s.should == ""
|
13
|
+
end
|
14
|
+
it "initializes an empty subject, adds a field, and gets the name" do
|
15
|
+
subject = R509::Subject.new
|
16
|
+
subject["CN"] = "domain.com"
|
17
|
+
subject.name.to_s.should == "/CN=domain.com"
|
18
|
+
end
|
19
|
+
it "initializes with a subject array, and gets the name" do
|
20
|
+
subject = R509::Subject.new([["CN", "domain.com"], ["O", "my org"]])
|
21
|
+
subject.name.to_s.should == "/CN=domain.com/O=my org"
|
22
|
+
end
|
23
|
+
it "initializes with a name, gets the name" do
|
24
|
+
name = OpenSSL::X509::Name.new([["CN", "domain.com"], ["O", "my org"], ["OU", "my unit"]])
|
25
|
+
subject = R509::Subject.new(name)
|
26
|
+
subject.name.to_s.should == "/CN=domain.com/O=my org/OU=my unit"
|
27
|
+
end
|
28
|
+
it "initializes with a subject" do
|
29
|
+
s1 = R509::Subject.new
|
30
|
+
s1["CN"] = "domain.com"
|
31
|
+
s1["O"] = "my org"
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
s2 = R509::Subject.new(s1)
|
34
|
+
s2.name.to_s.should == s1.name.to_s
|
35
|
+
end
|
36
|
+
it "preserves order of a full subject line" do
|
37
|
+
subject = R509::Subject.new([['CN','langui.sh'],['ST','Illinois'],['L','Chicago'],['C','US'],['emailAddress','ca@langui.sh']])
|
38
|
+
subject.name.to_s.should == '/CN=langui.sh/ST=Illinois/L=Chicago/C=US/emailAddress=ca@langui.sh'
|
39
|
+
end
|
40
|
+
it "preserves order of a full subject line and uses to_s directly" do
|
41
|
+
subject = R509::Subject.new([['CN','langui.sh'],['ST','Illinois'],['L','Chicago'],['C','US'],['emailAddress','ca@langui.sh']])
|
42
|
+
subject.to_s.should == '/CN=langui.sh/ST=Illinois/L=Chicago/C=US/emailAddress=ca@langui.sh'
|
43
|
+
end
|
44
|
+
it "preserves order with raw OIDs, and potentially fills in known OID names" do
|
45
|
+
subject = R509::Subject.new([['2.5.4.3','common name'],['2.5.4.15','business category'],['2.5.4.7','locality'],['1.3.6.1.4.1.311.60.2.1.3','jurisdiction oid openssl typically does not know']])
|
46
|
+
subject.to_s.should == "/CN=common name/businessCategory=business category/L=locality/jurisdictionOfIncorporationCountryName=jurisdiction oid openssl typically does not know"
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
it "edits an existing subject entry" do
|
50
|
+
subject = R509::Subject.new([["CN", "domain1.com"], ["O", "my org"]])
|
51
|
+
subject.to_s.should == "/CN=domain1.com/O=my org"
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
subject["CN"] = "domain2.com"
|
54
|
+
subject.to_s.should == "/CN=domain2.com/O=my org"
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
it "deletes an existing subject entry" do
|
58
|
+
subject = R509::Subject.new([["CN", "domain1.com"], ["O", "my org"]])
|
59
|
+
subject.to_s.should == "/CN=domain1.com/O=my org"
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
subject.delete("CN")
|
62
|
+
subject.to_s.should == "/O=my org"
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
it "is empty when initialized" do
|
66
|
+
subject = R509::Subject.new
|
67
|
+
subject.empty?.should == true
|
68
|
+
subject["CN"] = "domain.com"
|
69
|
+
subject.empty?.should == false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "is not empty" do
|
73
|
+
subject = R509::Subject.new([["CN", "domain1.com"]])
|
74
|
+
subject.empty?.should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can get a component out of the subject" do
|
78
|
+
subject = R509::Subject.new([["CN", "domain.com"]])
|
79
|
+
subject["CN"].should == "domain.com"
|
80
|
+
subject["O"].should == nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it "adds an OID" do
|
84
|
+
subject = R509::Subject.new
|
85
|
+
subject['1.3.6.1.4.1.311.60.2.1.3'] = 'jurisdiction oid openssl typically does not know'
|
86
|
+
subject['1.3.6.1.4.1.311.60.2.1.3'].should == 'jurisdiction oid openssl typically does not know'
|
87
|
+
end
|
71
88
|
|
72
|
-
|
73
|
-
|
74
|
-
|
89
|
+
it "deletes an OID" do
|
90
|
+
subject = R509::Subject.new([["CN", "domain.com"], ['1.3.6.1.4.1.38383.60.2.1.0.0', 'random oid']])
|
91
|
+
subject.to_s.should == "/CN=domain.com/1.3.6.1.4.1.38383.60.2.1.0.0=random oid"
|
92
|
+
subject.delete("1.3.6.1.4.1.38383.60.2.1.0.0")
|
93
|
+
subject.to_s.should == "/CN=domain.com"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "fails when you instantiate with an unknown shortname" do
|
97
|
+
expect { R509::Subject.new([["NOTRIGHT", "foo"]]) }.to raise_error(OpenSSL::X509::NameError)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "fails when you add an unknown shortname" do
|
101
|
+
subject = R509::Subject.new
|
102
|
+
expect { subject["WRONG"] = "bar" }.to raise_error(OpenSSL::X509::NameError)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "parses unknown OIDs out of a CSR" do
|
106
|
+
csr = R509::CSR.new(:csr => @csr_unknown_oid)
|
107
|
+
subject = R509::Subject.new(csr.subject)
|
108
|
+
subject["1.2.3.4.5.6.7.8.9.8.7.6.5.4.3.2.1.0.0"].should == "random oid!"
|
109
|
+
subject["1.3.3.543.567.32.43.335.1.1.1"].should == "another random oid!"
|
110
|
+
subject["CN"].should == 'normaldomain.com'
|
111
|
+
end
|
112
|
+
|
113
|
+
context "dynamic getter/setter behaviors" do
|
114
|
+
it "recognizes getters for a standard subject oid" do
|
115
|
+
subject = R509::Subject.new [['CN','testCN']]
|
116
|
+
subject.CN.should == 'testCN'
|
117
|
+
subject.common_name.should == 'testCN'
|
118
|
+
subject.commonName.should == 'testCN'
|
75
119
|
end
|
76
120
|
|
77
|
-
it "
|
78
|
-
|
79
|
-
|
80
|
-
|
121
|
+
it "recognizes setters for a standard subject oid" do
|
122
|
+
subject = R509::Subject.new
|
123
|
+
subject.CN= 'testCN'
|
124
|
+
subject.CN.should == 'testCN'
|
125
|
+
subject.common_name= 'testCN2'
|
126
|
+
subject.common_name.should == 'testCN2'
|
127
|
+
subject.commonName= 'testCN3'
|
128
|
+
subject.commonName.should == 'testCN3'
|
129
|
+
subject.CN.should == 'testCN3'
|
130
|
+
subject.common_name.should == 'testCN3'
|
81
131
|
end
|
82
132
|
|
83
|
-
it "
|
84
|
-
|
85
|
-
|
86
|
-
|
133
|
+
it "returns properly for respond_to? with a standard subject oid" do
|
134
|
+
subject = R509::Subject.new
|
135
|
+
subject.respond_to?("CN").should == true
|
136
|
+
subject.respond_to?("CN=").should == true
|
137
|
+
subject.respond_to?("commonName").should == true
|
138
|
+
subject.respond_to?("commonName=").should == true
|
139
|
+
subject.respond_to?("common_name").should == true
|
140
|
+
subject.respond_to?("common_name=").should == true
|
87
141
|
end
|
88
142
|
|
89
|
-
it "
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
subject.to_s.should == "/CN=domain.com"
|
143
|
+
it "returns properly for respond_to? for an invalid method name" do
|
144
|
+
subject = R509::Subject.new
|
145
|
+
subject.respond_to?("not_a_real_method=").should == false
|
146
|
+
subject.respond_to?("not_a_real_method").should == false
|
94
147
|
end
|
95
148
|
|
96
|
-
it "
|
97
|
-
|
149
|
+
it "errors on invalid method names" do
|
150
|
+
subject = R509::Subject.new
|
151
|
+
expect { subject.random_value="assign" }.to raise_error(NoMethodError)
|
152
|
+
expect { subject.random_value }.to raise_error(NoMethodError)
|
98
153
|
end
|
99
154
|
|
100
|
-
it "
|
101
|
-
|
102
|
-
|
155
|
+
it "works with an arbitrarily defined OID" do
|
156
|
+
R509::OIDMapper.register("1.4.3.2.1.2.3.6.6.6.6", "AOI", "arbitraryName")
|
157
|
+
subject = R509::Subject.new
|
158
|
+
subject.AOI= "test"
|
159
|
+
subject.AOI.should == "test"
|
160
|
+
subject.arbitrary_name = "test2"
|
161
|
+
subject.arbitrary_name.should == "test2"
|
162
|
+
subject.arbitraryName= "test3"
|
163
|
+
subject.arbitraryName.should == "test3"
|
164
|
+
subject.AOI.should == "test3"
|
165
|
+
subject.arbitrary_name.should == "test3"
|
103
166
|
end
|
104
167
|
|
105
|
-
it "
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
168
|
+
it "returns properly for respond_to? with a custom subject oid" do
|
169
|
+
R509::OIDMapper.register("1.4.3.2.1.2.3.7.7.7.7", "IOS", "iOperatingSystem")
|
170
|
+
subject = R509::Subject.new
|
171
|
+
subject.respond_to?("IOS").should == true
|
172
|
+
subject.respond_to?("IOS=").should == true
|
173
|
+
subject.respond_to?("iOperatingSystem").should == true
|
174
|
+
subject.respond_to?("iOperatingSystem=").should == true
|
175
|
+
subject.respond_to?("i_operating_system").should == true
|
176
|
+
subject.respond_to?("i_operating_system=").should == true
|
111
177
|
end
|
112
178
|
|
179
|
+
end
|
180
|
+
|
113
181
|
end
|
114
182
|
|
115
183
|
describe R509::NameSanitizer do
|
116
|
-
|
117
|
-
|
118
|
-
|
184
|
+
before :all do
|
185
|
+
@sanitizer = R509::NameSanitizer.new
|
186
|
+
end
|
119
187
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
188
|
+
it "when it has only known OIDs" do
|
189
|
+
name = OpenSSL::X509::Name.new [["C", "US"], ["ST", "Illinois"]]
|
190
|
+
array = @sanitizer.sanitize(name)
|
191
|
+
array.size.should == 2
|
192
|
+
array[0][0].should == "C"
|
193
|
+
array[0][1].should == "US"
|
194
|
+
array[1][0].should == "ST"
|
195
|
+
array[1][1].should == "Illinois"
|
196
|
+
end
|
129
197
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
198
|
+
it "when it has only unknown OIDs" do
|
199
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "US"], ["1.2.3.5", "Illinois"]]
|
200
|
+
array = @sanitizer.sanitize(name)
|
201
|
+
array.size.should == 2
|
202
|
+
array[0][0].should == "1.2.3.4"
|
203
|
+
array[0][1].should == "US"
|
204
|
+
array[1][0].should == "1.2.3.5"
|
205
|
+
array[1][1].should == "Illinois"
|
206
|
+
end
|
139
207
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
208
|
+
it "when it has an unknown between two knowns" do
|
209
|
+
name = OpenSSL::X509::Name.new [["CN", "domain.com"], ["1.2.3.4", "US"], ["ST", "Illinois"]]
|
210
|
+
array = @sanitizer.sanitize(name)
|
211
|
+
array.size.should == 3
|
212
|
+
array[0][0].should == "CN"
|
213
|
+
array[0][1].should == "domain.com"
|
214
|
+
array[1][0].should == "1.2.3.4"
|
215
|
+
array[1][1].should == "US"
|
216
|
+
array[2][0].should == "ST"
|
217
|
+
array[2][1].should == "Illinois"
|
218
|
+
end
|
151
219
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
220
|
+
it "when it has a known between two unknowns" do
|
221
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "domain.com"], ["C", "US"], ["1.2.3.5", "Illinois"]]
|
222
|
+
array = @sanitizer.sanitize(name)
|
223
|
+
array.size.should == 3
|
224
|
+
array[0][0].should == "1.2.3.4"
|
225
|
+
array[0][1].should == "domain.com"
|
226
|
+
array[1][0].should == "C"
|
227
|
+
array[1][1].should == "US"
|
228
|
+
array[2][0].should == "1.2.3.5"
|
229
|
+
array[2][1].should == "Illinois"
|
230
|
+
end
|
163
231
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
232
|
+
it "when a known has the same value as an unknown defined before it" do
|
233
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "domain.com"], ["CN", "domain.com"]]
|
234
|
+
array = @sanitizer.sanitize(name)
|
235
|
+
array.size.should == 2
|
236
|
+
array[0][0].should == "1.2.3.4"
|
237
|
+
array[0][1].should == "domain.com"
|
238
|
+
array[1][0].should == "CN"
|
239
|
+
array[1][1].should == "domain.com"
|
240
|
+
end
|
173
241
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
242
|
+
it "when two unknowns have the same value" do
|
243
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "domain.com"], ["1.2.3.5", "domain.com"]]
|
244
|
+
array = @sanitizer.sanitize(name)
|
245
|
+
array.size.should == 2
|
246
|
+
array[0][0].should == "1.2.3.4"
|
247
|
+
array[0][1].should == "domain.com"
|
248
|
+
array[1][0].should == "1.2.3.5"
|
249
|
+
array[1][1].should == "domain.com"
|
250
|
+
end
|
183
251
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
252
|
+
it "when two unknowns have the same oid and different values" do
|
253
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "domain.com"], ["1.2.3.4", "other"]]
|
254
|
+
array = @sanitizer.sanitize(name)
|
255
|
+
array.size.should == 2
|
256
|
+
array[0][0].should == "1.2.3.4"
|
257
|
+
array[0][1].should == "domain.com"
|
258
|
+
array[1][0].should == "1.2.3.4"
|
259
|
+
array[1][1].should == "other"
|
260
|
+
end
|
193
261
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
262
|
+
it "when two unknowns have the same oid and the same value" do
|
263
|
+
name = OpenSSL::X509::Name.new [["1.2.3.4", "domain.com"], ["1.2.3.4", "domain.com"]]
|
264
|
+
array = @sanitizer.sanitize(name)
|
265
|
+
array.size.should == 2
|
266
|
+
array[0][0].should == "1.2.3.4"
|
267
|
+
array[0][1].should == "domain.com"
|
268
|
+
array[1][0].should == "1.2.3.4"
|
269
|
+
array[1][1].should == "domain.com"
|
270
|
+
end
|
203
271
|
end
|