Skip to content

Commit

Permalink
remove pending test cases, clean up debug statments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcr committed Dec 24, 2018
1 parent 539b953 commit 0366ce3
Showing 1 changed file with 26 additions and 192 deletions.
218 changes: 26 additions & 192 deletions test/test_cms.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: false
require_relative 'utils'
require 'byebug'

if defined?(OpenSSL)
if defined?(OpenSSL::CMS)

class OpenSSL::TestCMS < OpenSSL::TestCase
def setup
Expand Down Expand Up @@ -35,7 +36,6 @@ def test_signed

data = "aaaaa\r\nbbbbb\r\nccccc\r\n"
tmp = OpenSSL::CMS.sign(@ee1_cert, @rsa1024, data, ca_certs)
byebug
cms = OpenSSL::CMS::ContentInfo.new(tmp.to_der)
certs = cms.certificates
signers = cms.signers
Expand Down Expand Up @@ -67,197 +67,31 @@ def test_signed
assert_equal(@ee1_cert.serial, signers[0].serial)
assert_equal(@ee1_cert.issuer.to_s, signers[0].issuer.to_s)

# A signed-data which have multiple signatures can be created
# through the following steps.
# 1. create two signed-data
# 2. copy signerInfo and certificate from one to another

tmp1 = OpenSSL::CMS.sign(@ee1_cert, @rsa1024, data, [], flag)
tmp2 = OpenSSL::CMS.sign(@ee2_cert, @rsa1024, data, [], flag)
tmp1.add_signer(tmp2.signers[0])
tmp1.add_certificate(@ee2_cert)

cms = OpenSSL::CMS.ContentInfo.new(tmp1.to_der)
certs = cms.certificates
signers = cms.signers
assert(cms.verify([], store))
assert_equal(data, cms.data)
assert_equal(2, certs.size)
assert_equal(2, signers.size)
assert_equal(@ee1_cert.serial, signers[0].serial)
assert_equal(@ee1_cert.issuer.to_s, signers[0].issuer.to_s)
assert_equal(@ee2_cert.serial, signers[1].serial)
assert_equal(@ee2_cert.issuer.to_s, signers[1].issuer.to_s)
end

def test_detached_sign
pend "not yet"
store = OpenSSL::X509::Store.new
store.add_cert(@ca_cert)
ca_certs = [@ca_cert]

data = "aaaaa\nbbbbb\nccccc\n"
flag = OpenSSL::PKCS7::BINARY|OpenSSL::PKCS7::DETACHED
tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs, flag)
p7 = OpenSSL::PKCS7.new(tmp.to_der)
assert_nothing_raised do
OpenSSL::ASN1.decode(p7)
end

certs = p7.certificates
signers = p7.signers
assert(!p7.verify([], store))
assert(p7.verify([], store, data))
assert_equal(data, p7.data)
assert_equal(2, certs.size)
assert_equal(@ee1_cert.subject.to_s, certs[0].subject.to_s)
assert_equal(@ca_cert.subject.to_s, certs[1].subject.to_s)
assert_equal(1, signers.size)
assert_equal(@ee1_cert.serial, signers[0].serial)
assert_equal(@ee1_cert.issuer.to_s, signers[0].issuer.to_s)
end

def test_enveloped
pend "not yet"
certs = [@ee1_cert, @ee2_cert]
cipher = OpenSSL::Cipher::AES.new("128-CBC")
data = "aaaaa\nbbbbb\nccccc\n"

tmp = OpenSSL::PKCS7.encrypt(certs, data, cipher, OpenSSL::PKCS7::BINARY)
p7 = OpenSSL::PKCS7.new(tmp.to_der)
recip = p7.recipients
assert_equal(:enveloped, p7.type)
assert_equal(2, recip.size)

assert_equal(@ca_cert.subject.to_s, recip[0].issuer.to_s)
assert_equal(2, recip[0].serial)
assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))

assert_equal(@ca_cert.subject.to_s, recip[1].issuer.to_s)
assert_equal(3, recip[1].serial)
assert_equal(data, p7.decrypt(@rsa1024, @ee2_cert))

assert_equal(data, p7.decrypt(@rsa1024))
end

def test_graceful_parsing_failure #[ruby-core:43250]
pend "not yet"
contents = File.read(__FILE__)
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(contents) }
end

def test_degenerate_cms
pend "not yet"
ca_cert_pem = <<END
-----BEGIN CERTIFICATE-----
MIID4DCCAsigAwIBAgIJAL1oVI72wmQwMA0GCSqGSIb3DQEBBQUAMFMxCzAJBgNV
BAYTAkFVMQ4wDAYDVQQIEwVTdGF0ZTENMAsGA1UEBxMEQ2l0eTEQMA4GA1UECh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wDM16UunMAK26lNG9J6q02o4d/oU2a7x0fD80yF
64kNA1wDAwaVCYiUH541qKp+b4iDqer8nf8HqzYDFlpje18xYZMEd1hj8dVOharM
pISJ+D52hV/BGEYF8r5k3hpC5d76gSP2oCcaY0XvLBf97qik
-----END CERTIFICATE-----
END
cms = OpenSSL::CMS.new
cms.type = "signed"
ca_cert = OpenSSL::X509::Certificate.new(ca_cert_pem)
cms.add_certificate ca_cert
cms.add_data ""

assert_nothing_raised do
cms.to_pem
if false
# multiple signers not yet supported.
# A signed-data which have multiple signatures can be created
# through the following steps.
# 1. create two signed-data
# 2. copy signerInfo and certificate from one to another

tmp1 = OpenSSL::CMS.sign(@ee1_cert, @rsa1024, data, [], flag)
tmp2 = OpenSSL::CMS.sign(@ee2_cert, @rsa1024, data, [], flag)
tmp1.add_signer(tmp2.signers[0])
tmp1.add_certificate(@ee2_cert)

cms = OpenSSL::CMS.ContentInfo.new(tmp1.to_der)
certs = cms.certificates
signers = cms.signers
assert(cms.verify([], store))
assert_equal(data, cms.data)
assert_equal(2, certs.size)
assert_equal(2, signers.size)
assert_equal(@ee1_cert.serial, signers[0].serial)
assert_equal(@ee1_cert.issuer.to_s, signers[0].issuer.to_s)
assert_equal(@ee2_cert.serial, signers[1].serial)
assert_equal(@ee2_cert.issuer.to_s, signers[1].issuer.to_s)
end
end

def test_split_content
pend "not yet"
pki_message_pem = <<END
-----BEGIN PKCS7-----
MIIHSwYJKoZIhvcNAQcCoIIHPDCCBzgCAQExCzAJBgUrDgMCGgUAMIIDiAYJKoZI
hvcNAQcBoIIDeQSCA3UwgAYJKoZIhvcNAQcDoIAwgAIBADGCARAwggEMAgEAMHUw
cDEQMA4GA1UECgwHZXhhbXBsZTEXMBUGA1UEAwwOVEFSTUFDIFJPT1QgQ0ExIjAg
BgkqhkiG9w0BCQEWE3NvbWVvbmVAZXhhbXBsZS5vcmcxCzAJBgNVBAYTAlVTMRIw
EAYDVQQHDAlUb3duIEhhbGwCAWYwDQYJKoZIhv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
TDgnvtSW8RvVHqKrwgkxxEsRHg7u8UdzZ0jg+O5+3F8B6/NWMyts0OaFqT9wvI8y
O7VIy3dUtGdz7Hde6Ggp/iTn1LbgdJ3N8Hzxf1j6NMWUKHVsadvwpRJbUeqq9c3+
QuxsJi8wWemxxQCE+tPyc1dP+ej5/M7bERbSOHMGgX03758IvP7A/fy2DjGPv2+l
AwlEke0Uze1367QKgxM0nc3SZDlptY7zPIJC5saWXb8Rt2bw2JxEBOTavrp+ZwJ8
tcH961onq8Tme2ICaCzk
-----END PKCS7-----
END
pki_msg = OpenSSL::CMS.new(pki_message_pem)
store = OpenSSL::X509::Store.new
pki_msg.verify(nil, store, nil, OpenSSL::CMS::NOVERIFY)
cmsenc = OpenSSL::CMS.new(pki_msg.data)
assert_equal(pki_message_content_pem, cmsenc.to_pem)
end
end

end
end # if(OpenSSL)

0 comments on commit 0366ce3

Please sign in to comment.