@@ -8,10 +8,28 @@ class TestNSSPKI < TestCase
88 'r/7iJNroWlSzSMtTiQTEB+ADWHGj9u1xrUrOilq/o2cuQxIfZcNZkYAkWP4DubqW' \
99 'i0//rgBvmco='
1010
11+ def test_build_data
12+ key1 = Fixtures . pkey ( 'rsa1024' )
13+ key2 = Fixtures . pkey ( 'rsa2048' )
14+ spki = OpenSSL ::Netscape ::SPKI . new
15+ spki . challenge = 'RandomChallenge'
16+ spki . public_key = key1
17+ spki . sign ( key1 , OpenSSL ::Digest . new ( 'SHA256' ) )
18+ assert spki . verify ( key1 )
19+ assert !spki . verify ( key2 )
20+ assert_not_nil spki . to_text
21+ assert_not_nil spki . to_der
22+ end
23+
1124 def test_decode_data
1225 spki = OpenSSL ::Netscape ::SPKI . new ( B64 )
1326 assert_equal 'MozillaIsMyFriend' , spki . challenge
1427 assert_instance_of OpenSSL ::PKey ::RSA , spki . public_key
28+
29+ # also accepts DER input
30+ spki = OpenSSL ::Netscape ::SPKI . new ( B64 . unpack1 ( 'm' ) )
31+ assert_equal 'MozillaIsMyFriend' , spki . challenge
32+ assert_instance_of OpenSSL ::PKey ::RSA , spki . public_key
1533 end
1634
1735 def test_to_text
@@ -23,7 +41,20 @@ def test_to_text
2341 assert_match ( /Public Key Algorithm: / , text )
2442 assert_match ( /Challenge String: MozillaIsMyFriend/ , text )
2543 assert_match ( /Signature Algorithm: / , text )
26- # signature hex bytes with : separators
44+ assert_match ( /[0-9a-f]{2}(:[0-9a-f]{2})+/ , text )
45+ end
46+
47+ def test_to_text_after_sign
48+ key = Fixtures . pkey ( 'rsa1024' )
49+ spki = OpenSSL ::Netscape ::SPKI . new
50+ spki . challenge = 'MyChallenge'
51+ spki . public_key = key
52+ spki . sign ( key , OpenSSL ::Digest . new ( 'SHA256' ) )
53+
54+ text = spki . to_text
55+ assert_match ( /\A Netscape SPKI:\n / , text )
56+ assert_match ( /Challenge String: MyChallenge/ , text )
57+ assert_match ( /Signature Algorithm: / , text )
2758 assert_match ( /[0-9a-f]{2}(:[0-9a-f]{2})+/ , text )
2859 end
2960end
0 commit comments