Skip to content

Commit adb42b5

Browse files
committed
pkcs7: add a test case for the data content type
While it is not useful alone, it is still a valid content type. Some methods on OpenSSL::PKCS7 are only meant to work with the signed-data or enveloped-data content type. Add some assertions for their behavior with unsupported content types. The next patches will update the relevant code.
1 parent 697d449 commit adb42b5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/openssl/test_pkcs7.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@ def test_enveloped
160160
}
161161
end
162162

163+
def test_data
164+
asn1 = OpenSSL::ASN1::Sequence([
165+
OpenSSL::ASN1::ObjectId("pkcs7-data"),
166+
OpenSSL::ASN1::OctetString("content", 0, :EXPLICIT),
167+
])
168+
p7 = OpenSSL::PKCS7.new
169+
p7.type = :data
170+
p7.data = "content"
171+
assert_raise(OpenSSL::PKCS7::PKCS7Error) { p7.add_certificate(@ee1_cert) }
172+
assert_raise(OpenSSL::PKCS7::PKCS7Error) { p7.certificates = [@ee1_cert] }
173+
assert_raise(OpenSSL::PKCS7::PKCS7Error) { p7.cipher = "aes-128-cbc" }
174+
assert_equal(asn1.to_der, p7.to_der)
175+
176+
p7 = OpenSSL::PKCS7.new(asn1)
177+
assert_equal(:data, p7.type)
178+
assert_equal(false, p7.detached?)
179+
# Not applicable
180+
assert_nil(p7.certificates)
181+
assert_nil(p7.crls)
182+
# Not applicable. Should they return nil or raise an exception instead?
183+
assert_equal([], p7.signers)
184+
assert_equal([], p7.recipients)
185+
# PKCS7#verify can't distinguish verification failure and other errors
186+
store = OpenSSL::X509::Store.new
187+
assert_equal(false, p7.verify([@ee1_cert], store))
188+
assert_raise(OpenSSL::PKCS7::PKCS7Error) { p7.decrypt(@rsa1024) }
189+
end
190+
163191
def test_empty_signed_data_ruby_bug_19974
164192
data = "-----BEGIN PKCS7-----\nMAsGCSqGSIb3DQEHAg==\n-----END PKCS7-----\n"
165193
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(data) }

0 commit comments

Comments
 (0)