jruby-openssl 0.5.2 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.txt +27 -0
  2. data/Manifest.txt +100 -0
  3. data/Rakefile +71 -0
  4. data/lib/jopenssl.jar +0 -0
  5. data/lib/jopenssl/version.rb +1 -1
  6. data/lib/openssl/bn.rb +1 -3
  7. data/lib/openssl/cipher.rb +15 -17
  8. data/lib/openssl/digest.rb +1 -3
  9. data/test/cert_with_ec_pk.cer +27 -0
  10. data/test/fixture/ca_path/72fa7371.0 +19 -0
  11. data/test/fixture/ca_path/verisign.pem +19 -0
  12. data/test/fixture/common.pem +48 -0
  13. data/test/fixture/max.pem +29 -0
  14. data/test/fixture/purpose/b70a5bc1.0 +24 -0
  15. data/test/fixture/purpose/ca/PASSWD_OF_CA_KEY_IS_1234 +0 -0
  16. data/test/fixture/purpose/ca/ca_config.rb +37 -0
  17. data/test/fixture/purpose/ca/cacert.pem +24 -0
  18. data/test/fixture/purpose/ca/newcerts/2_cert.pem +19 -0
  19. data/test/fixture/purpose/ca/newcerts/3_cert.pem +19 -0
  20. data/test/fixture/purpose/ca/private/cakeypair.pem +30 -0
  21. data/test/fixture/purpose/ca/serial +1 -0
  22. data/test/fixture/purpose/cacert.pem +24 -0
  23. data/test/fixture/purpose/scripts/gen_cert.rb +127 -0
  24. data/test/fixture/purpose/scripts/gen_csr.rb +50 -0
  25. data/test/fixture/purpose/scripts/init_ca.rb +66 -0
  26. data/test/fixture/purpose/sslclient.pem +19 -0
  27. data/test/fixture/purpose/sslclient/csr.pem +10 -0
  28. data/test/fixture/purpose/sslclient/keypair.pem +15 -0
  29. data/test/fixture/purpose/sslclient/sslclient.pem +19 -0
  30. data/test/fixture/purpose/sslserver.pem +19 -0
  31. data/test/fixture/purpose/sslserver/csr.pem +10 -0
  32. data/test/fixture/purpose/sslserver/keypair.pem +15 -0
  33. data/test/fixture/purpose/sslserver/sslserver.pem +19 -0
  34. data/test/fixture/verisign.pem +19 -0
  35. data/test/fixture/verisign_c3.pem +14 -0
  36. data/test/openssl/test_cipher.rb +22 -0
  37. data/test/openssl/test_pkcs7.rb +1 -0
  38. data/test/openssl/test_ssl.rb +2 -0
  39. data/test/openssl/test_x509ext.rb +21 -0
  40. data/test/openssl/test_x509name.rb +16 -0
  41. data/test/test_cipher.rb +20 -6
  42. data/test/test_integration.rb +43 -4
  43. data/test/test_parse_certificate.rb +20 -0
  44. data/test/test_x509store.rb +155 -0
  45. metadata +37 -3
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDEDCCAfigAwIBAgIBAzANBgkqhkiG9w0BAQUFADBMMQswCQYDVQQGEwJKUDEa
3
+ MBgGA1UECgwRd3d3LnJ1YnktbGFuZy5vcmcxFDASBgNVBAsMC2RldmVsb3BtZW50
4
+ MQswCQYDVQQDDAJDQTAeFw0wOTExMTkxMDMwMjdaFw0yODExMTQxMDMwMjdaMD0x
5
+ CzAJBgNVBAYTAkpQMRowGAYDVQQKDBF3d3cucnVieS1sYW5nLm9yZzESMBAGA1UE
6
+ AwwJc3NsY2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgemBPByEo
7
+ KbxaYnHXJxslyYsdWWCKf6j2mVIoxzC0b7W4TS5loBzOkZ05rkuapZ7O5flSMjtH
8
+ 5NMJ2h7/zsgK5XBkNRCPFK+8HMXVFdSs+euKY+2qE01P0NIuCrkvKjJgsrXdy3sG
9
+ 2UVUEoYEt5MHDR6aBL0Km+nVKc6T7O+KtQIDAQABo4GPMIGMMAwGA1UdEwEB/wQC
10
+ MAAwMQYJYIZIAYb4QgENBCQWIlJ1YnkvT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlm
11
+ aWNhdGUwHQYDVR0OBBYEFOFnq0r6adftxM/7aApl0DDrLTNWMAsGA1UdDwQEAwIF
12
+ 4DAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcNAQEFBQAD
13
+ ggEBACiRGC9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her < Test::Unit::TestCase
169
169
  }
170
170
  end
171
171
  end
172
+
173
+ # JRUBY-4028
174
+ def test_jruby_4028
175
+ key = "0599E113A7EE32A9"
176
+ data = "1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
177
+ c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
178
+ c1.padding = 0
179
+ c1.encrypt
180
+ c1.key = key
181
+ e = c1.update data
182
+ e << c1.final
183
+
184
+ c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
185
+ c2.padding = 0
186
+ c2.decrypt
187
+ c2.key = key
188
+ d = c2.update e
189
+ d << c2.final
190
+
191
+ assert_equal "]s\345F\251\250\223uO\315\220\255g\031\363c\006\205L\260G7\016`\265\377K5?\375\310\025\026\"\a\246N\270\234]\206\n\r\351\262\257\305\3632p_\205\257\026\226~-7\av#BZx\024\246'\f\216\005\201\r\372\201\316%W\250\210^\340{\371\245\374<~/YnV\277\311\230\250{\336\302W\353\032\321+\200pA\037\274\262\022*u\344\363\304\e\214J\353!\2352\267)s\360c\a", e
192
+ assert_equal data, d
193
+ end
172
194
  end
173
195
 
174
196
  end
@@ -33,6 +33,7 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
33
33
  ["keyUsage","Non Repudiation, Digital Signature, Key Encipherment",true],
34
34
  ["authorityKeyIdentifier","keyid:always",false],
35
35
  ["extendedKeyUsage","clientAuth, emailProtection, codeSigning",false],
36
+ ["nsCertType","client,email",false],
36
37
  ]
37
38
  @ee1_cert = issue_cert(ee1, @rsa1024, 2, Time.now, Time.now+1800, ee_exts,
38
39
  @ca_cert, @rsa2048, OpenSSL::Digest::SHA1.new)
@@ -169,6 +169,8 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
169
169
  ssl.sync_close = true
170
170
  ssl.connect
171
171
 
172
+ assert_raises(ArgumentError) { ssl.sysread(-1) }
173
+
172
174
  # syswrite and sysread
173
175
  ITERATIONS.times{|i|
174
176
  str = "x" * 100 + "\n"
@@ -69,6 +69,27 @@ class OpenSSL::TestX509Extension < Test::Unit::TestCase
69
69
  %r{URI:ldap://ldap.example.com/cn=ca\?certificateRevocationList;binary},
70
70
  cdp.value)
71
71
  end
72
+
73
+ # JRUBY-3888
74
+ # Problems with subjectKeyIdentifier with non 20-bytes sha1 digested keys
75
+ def test_certificate_with_rare_extension
76
+ cert_file = File.join(File.dirname(__FILE__), "..", "fixture", "max.pem")
77
+ cer = OpenSSL::X509::Certificate.new(File.read(cert_file))
78
+ exts = Hash.new
79
+ cer.extensions.each{|ext| exts[ext.oid] = ext.value}
80
+
81
+ assert exts["subjectKeyIdentifier"] == "4C:B9:E1:DC:7A:AC:35:CF"
82
+ end
83
+
84
+ def test_extension_from_20_byte_sha1_digests
85
+ cert_file = File.join(File.dirname(__FILE__), "..", "fixture", "common.pem")
86
+ cer = OpenSSL::X509::Certificate.new(File.read(cert_file))
87
+ exts = Hash.new
88
+ cer.extensions.each{|ext| exts[ext.oid] = ext.value}
89
+
90
+ assert exts["subjectKeyIdentifier"] == "B4:AC:83:5D:21:FB:D6:8A:56:7E:B2:49:6D:69:BB:E4:6F:D8:5A:AC"
91
+ end
92
+
72
93
  end
73
94
 
74
95
  end
@@ -6,6 +6,8 @@ require "test/unit"
6
6
 
7
7
  if defined?(OpenSSL)
8
8
 
9
+ require 'digest/md5'
10
+
9
11
  class OpenSSL::TestX509Name < Test::Unit::TestCase
10
12
  OpenSSL::ASN1::ObjectId.register(
11
13
  "1.2.840.113549.1.9.1", "emailAddress", "emailAddress")
@@ -260,6 +262,20 @@ class OpenSSL::TestX509Name < Test::Unit::TestCase
260
262
  assert_equal(OpenSSL::ASN1::IA5STRING, ary[3][2])
261
263
  assert_equal(OpenSSL::ASN1::PRINTABLESTRING, ary[4][2])
262
264
  end
265
+
266
+ def test_hash
267
+ dn = "/DC=org/DC=ruby-lang/CN=www.ruby-lang.org"
268
+ name = OpenSSL::X509::Name.parse(dn)
269
+ d = Digest::MD5.digest(name.to_der)
270
+ expected = (d[0] & 0xff) | (d[1] & 0xff) << 8 | (d[2] & 0xff) << 16 | (d[3] & 0xff) << 24
271
+ assert_equal(expected, name.hash)
272
+ #
273
+ dn = "/DC=org/DC=ruby-lang/CN=baz.ruby-lang.org"
274
+ name = OpenSSL::X509::Name.parse(dn)
275
+ d = Digest::MD5.digest(name.to_der)
276
+ expected = (d[0] & 0xff) | (d[1] & 0xff) << 8 | (d[2] & 0xff) << 16 | (d[3] & 0xff) << 24
277
+ assert_equal(expected, name.hash)
278
+ end
263
279
  end
264
280
 
265
281
  end
@@ -13,6 +13,13 @@ end
13
13
  require "test/unit"
14
14
 
15
15
  class TestCipher < Test::Unit::TestCase
16
+ def test_keylen
17
+ cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
18
+ # must be 24 but it returns 16 on JRE6 without unlimited jurisdiction
19
+ # policy. it returns 24 on JRE6 with the unlimited policy.
20
+ assert_equal(24, cipher.key_len)
21
+ end
22
+
16
23
  def test_encrypt_takes_parameter
17
24
  enc = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
18
25
  enc.encrypt("123")
@@ -43,6 +50,15 @@ class TestCipher < Test::Unit::TestCase
43
50
  )
44
51
  end
45
52
 
53
+ def test_rc2
54
+ do_repeated_test(
55
+ "RC2",
56
+ "foobarbazboofarf",
57
+ "\x18imZ\x9Ed\x15\xF3\xD6\xE6M\xCDf\xAA\xD3\xFE",
58
+ "\xEF\xF7\x16\x06\x93)-##\xB2~\xAD,\xAD\x82\xF5"
59
+ )
60
+ end
61
+
46
62
  private
47
63
  def do_repeated_test(algo, string, enc1, enc2)
48
64
  do_repeated_encrypt_test(algo, string, enc1, enc2)
@@ -58,10 +74,9 @@ class TestCipher < Test::Unit::TestCase
58
74
  cipher.key = KEY_TEMPLATE[0, cipher.key_len]
59
75
 
60
76
  assert_equal result1, cipher.update(string)
61
- cipher.final
77
+ assert_equal "", cipher.final
62
78
 
63
- assert_equal result2, cipher.update(string)
64
- cipher.final
79
+ assert_equal result2, cipher.update(string) + cipher.final
65
80
  end
66
81
 
67
82
  def do_repeated_decrypt_test(algo, result, string1, string2)
@@ -73,9 +88,8 @@ class TestCipher < Test::Unit::TestCase
73
88
  cipher.key = KEY_TEMPLATE[0, cipher.key_len]
74
89
 
75
90
  assert_equal result, cipher.update(string1)
76
- cipher.final
91
+ assert_equal "", cipher.final
77
92
 
78
- assert_equal result, cipher.update(string2)
79
- cipher.final
93
+ assert_equal result, cipher.update(string2) + cipher.final
80
94
  end
81
95
  end
@@ -29,18 +29,57 @@ class TestIntegration < Test::Unit::TestCase
29
29
  # Warning - this test actually uses the internet connection.
30
30
  # If there is no connection, it will fail.
31
31
  def test_ca_path_name
32
- uri = URI.parse('https://www.paypal.com')
33
-
32
+ uri = URI.parse('https://www.amazon.com')
34
33
  http = Net::HTTP.new(uri.host, uri.port)
35
34
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
36
- http.ca_path = "./"
35
+ http.ca_path = "test/fixture/ca_path/"
37
36
  http.use_ssl = true
37
+ response = http.start do |s|
38
+ assert s.get(uri.request_uri).length > 0
39
+ end
40
+ end
41
+
42
+ # Warning - this test actually uses the internet connection.
43
+ # If there is no connection, it will fail.
44
+ def test_ssl_verify
45
+ uri = URI.parse('https://www.amazon.com/')
46
+ http = Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = true
48
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
49
+ # right trust anchor for www.amazon.com
50
+ http.ca_file = 'test/fixture/verisign.pem'
51
+ response = http.start do |s|
52
+ assert s.get(uri.request_uri).length > 0
53
+ end
54
+ # wrong trust anchor for www.amazon.com
55
+ http.ca_file = 'test/fixture/verisign_c3.pem'
56
+ assert_raises(OpenSSL::SSL::SSLError) do
57
+ # it must cause SSLError for verification failure.
58
+ response = http.start do |s|
59
+ s.get(uri.request_uri)
60
+ end
61
+ end
62
+ # round trip
63
+ http.ca_file = 'test/fixture/verisign.pem'
64
+ response = http.start do |s|
65
+ assert s.get(uri.request_uri).length > 0
66
+ end
67
+ end
38
68
 
69
+ # Warning - this test actually uses the internet connection.
70
+ # If there is no connection, it will fail.
71
+ def test_pathlen_does_not_appear
72
+ uri = URI.parse('https://www.paypal.com/')
73
+ http = Net::HTTP.new(uri.host, uri.port)
74
+ http.use_ssl = true
75
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
76
+ # right trust anchor for www.amazon.com
77
+ http.ca_file = 'test/fixture/verisign_c3.pem'
39
78
  response = http.start do |s|
40
79
  assert s.get(uri.request_uri).length > 0
41
80
  end
42
81
  end
43
-
82
+
44
83
  # JRUBY-2178 and JRUBY-1307
45
84
  # Warning - this test actually uses the internet connection.
46
85
  # If there is no connection, it will fail.
@@ -0,0 +1,20 @@
1
+ require 'openssl'
2
+ require "test/unit"
3
+
4
+ class TestParseCertificate < Test::Unit::TestCase
5
+ CERT = File.dirname(__FILE__) + '/cert_with_ec_pk.cer'
6
+
7
+ def test_certificate_parse_works_with_ec_pk_cert
8
+ cer = OpenSSL::X509::Certificate.new(File.read(CERT))
9
+ assert cer.to_s != nil
10
+ assert cer.issuer.to_s != nil
11
+ assert cer.subject.to_s != nil
12
+ assert cer.extensions.to_s != nil
13
+ end
14
+
15
+ def test_certificate_with_ec_pk_cert_fails_requesting_pk
16
+ cer = OpenSSL::X509::Certificate.new(File.read(CERT))
17
+ assert_raises(OpenSSL::X509::CertificateError) { cer.public_key }
18
+ end
19
+ end
20
+
@@ -0,0 +1,155 @@
1
+ if defined?(JRUBY_VERSION)
2
+ require "java"
3
+ base = File.dirname(__FILE__)
4
+ $CLASSPATH << File.join(base, '..', 'pkg', 'classes')
5
+ $CLASSPATH << File.join(base, '..', 'lib', 'bcprov-jdk14-139.jar')
6
+ end
7
+
8
+ begin
9
+ require "openssl"
10
+ rescue LoadError
11
+ end
12
+
13
+ require "test/unit"
14
+ require "tempfile"
15
+
16
+ class TestX509Store < Test::Unit::TestCase
17
+ def setup
18
+ @store = OpenSSL::X509::Store.new
19
+ end
20
+
21
+ def teardown
22
+ end
23
+
24
+ def test_ns_cert_type
25
+ f = Tempfile.new("globalsign-root.pem")
26
+ f << GLOBALSIGN_ROOT_CA
27
+ f.close
28
+ @store.add_file(f.path)
29
+ f.unlink
30
+
31
+ # CAUTION !
32
+ #
33
+ # sgc is an issuing CA certificate so we should not verify it for the
34
+ # purpose 'PURPOSE_SSL_SERVER'. It's not a SSL server certificate.
35
+ # We're just checking the code for 'PURPOSE_SSL_SERVER'.
36
+ # jruby-openssl/0.5.2 raises the following exception around ASN.1
37
+ # nsCertType handling.
38
+ # Purpose.java:344:in `call': java.lang.ClassCastException: org.bouncycastle.asn1.DEROctetString cannot be cast to org.bouncycastle.asn1.DERBitString
39
+ sgc = OpenSSL::X509::Certificate.new(GLOBALSIGN_ORGANIZATION_VALIDATION_CA)
40
+
41
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
42
+ assert_nothing_raised do
43
+ @store.verify(sgc) # => should be false
44
+ end
45
+ end
46
+
47
+ def test_purpose_ssl_client
48
+ @store.add_file("test/fixture/purpose/cacert.pem")
49
+ cert = OpenSSL::X509::Certificate.new(File.read("test/fixture/purpose/sslclient.pem"))
50
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
51
+ assert_equal(true, @store.verify(cert))
52
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
53
+ assert_equal(false, @store.verify(cert))
54
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
55
+ assert_equal(true, @store.verify(cert))
56
+ end
57
+
58
+ def test_purpose_ssl_server
59
+ @store.add_file("test/fixture/purpose/cacert.pem")
60
+ cert = OpenSSL::X509::Certificate.new(File.read("test/fixture/purpose/sslserver.pem"))
61
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
62
+ assert_equal(true, @store.verify(cert))
63
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
64
+ assert_equal(false, @store.verify(cert))
65
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
66
+ assert_equal(true, @store.verify(cert))
67
+ end
68
+
69
+ def test_add_file_multiple
70
+ f = Tempfile.new("globalsign-root.pem")
71
+ f << GLOBALSIGN_ROOT_CA
72
+ f << "junk junk\n"
73
+ f << "junk junk\n"
74
+ f << "junk junk\n"
75
+ f << File.read("test/fixture/purpose/cacert.pem")
76
+ f.close
77
+ @store.add_file(f.path)
78
+ f.unlink
79
+
80
+ cert = OpenSSL::X509::Certificate.new(File.read("test/fixture/purpose/sslserver.pem"))
81
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
82
+ assert_equal(true, @store.verify(cert))
83
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
84
+ assert_equal(false, @store.verify(cert))
85
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
86
+ assert_equal(true, @store.verify(cert))
87
+ end
88
+
89
+ def test_set_default_paths
90
+ @store.purpose = OpenSSL::X509::PURPOSE_SSL_SERVER
91
+ cert = OpenSSL::X509::Certificate.new(File.read("test/fixture/purpose/sslserver.pem"))
92
+ assert_equal(false, @store.verify(cert))
93
+ begin
94
+ backup = ENV['SSL_CERT_DIR']
95
+ ENV['SSL_CERT_DIR'] = 'test/fixture/purpose/'
96
+ @store.set_default_paths
97
+ assert_equal(true, @store.verify(cert))
98
+ ensure
99
+ ENV['SSL_CERT_DIR'] = backup if backup
100
+ end
101
+ end
102
+
103
+ GLOBALSIGN_ROOT_CA = <<__EOS__
104
+ -----BEGIN CERTIFICATE-----
105
+ MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG
106
+ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
107
+ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05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lXi/EjJKSZp4A==
124
+ -----END CERTIFICATE-----
125
+ __EOS__
126
+
127
+ GLOBALSIGN_ORGANIZATION_VALIDATION_CA = <<__EOS__
128
+ -----BEGIN CERTIFICATE-----
129
+ MIIEZzCCA0+gAwIBAgILBAAAAAABHkSl9SowDQYJKoZIhvcNAQEFBQAwVzELMAkG
130
+ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
131
+ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw0wNzA0MTExMjAw
132
+ MDBaFw0xNzA0MTExMjAwMDBaMGoxIzAhBgNVBAsTGk9yZ2FuaXphdGlvbiBWYWxp
133
+ ZGF0aW9uIENBMRMwEQYDVQQKEwpHbG9iYWxTaWduMS4wLAYDVQQDEyVHbG9iYWxT
134
+ aWduIE9yZ2FuaXphdGlvbiBWYWxpZGF0aW9uIENBMIIBIjANBgkqhkiG9w0BAQEF
135
+ AAOCAQ8AMIIBCgKCAQEAoS/EvM6HA+lnwYnI5ZP8fbStnvZjTmronCxziaIB9I8h
136
+ +P0lnVgWbYb27klXdX516iIRfj37x0JB3PzFDJFVgHvrZDMdm/nKOOmrxiVDUSVA
137
+ 9OR+GFVqqY8QOkAe1leD738vNC8t0vZTwhkNt+3JgfVGLLQjQl6dEwN17Opq/Fd8
138
+ yTaXO5jcExPs7EH6XTTquZPnEBZlzJyS/fXFnT5KuQn85F8eaV9N9FZyRLEdIwPI
139
+ NvZliMi/ORZFjh4mbFEWxSoAOMWkE2mVfasBO6jEFLSA2qwaRCDV/qkGexQnr+Aw
140
+ Id2Q9KnVIxkuHgPmwd+VKeTBlEPdPpCqy0vJvorTOQIDAQABo4IBHzCCARswDgYD
141
+ VR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFH1tKuxm
142
+ q6dRNqsCafFwj8RZC5ofMEsGA1UdIAREMEIwQAYJ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