Skip to content

Commit f9429bd

Browse files
authored
Merge pull request #997 from junaruga/wip/fips-test-pkcs12
Fix test_pkcs12.rb in FIPS.
2 parents b814041 + d86270d commit f9429bd

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Rakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Rake::TestTask.new(:test_fips_internal) do |t|
2828
t.test_files = FileList['test/**/test_*.rb'] - FileList[
2929
'test/openssl/test_hmac.rb',
3030
'test/openssl/test_kdf.rb',
31-
'test/openssl/test_pkcs12.rb',
3231
'test/openssl/test_ts.rb',
3332
]
3433
t.warning = true

test/openssl/test_pkcs12.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33

44
if defined?(OpenSSL)
55

6+
# OpenSSL::PKCS12.create calling the PKCS12_create() has the argument mac_iter
7+
# which uses a MAC key using PKCS12KDF which is not FIPS-approved.
8+
# OpenSSL::PKCS12.new with base64-encoded example calling PKCS12_parse()
9+
# verifies the MAC key using PKCS12KDF which is not FIPS-approved.
10+
#
11+
# PBE-SHA1-3DES uses PKCS12KDF which is not FIPS-approved according to the RFC
12+
# 7292 PKCS#12.
13+
# https://datatracker.ietf.org/doc/html/rfc7292#appendix-C
14+
# > The PBES1 encryption scheme defined in PKCS #5 provides a number of
15+
# > algorithm identifiers for deriving keys and IVs; here, we specify a
16+
# > few more, all of which use the procedure detailed in Appendices B.2
17+
# > and B.3 to construct keys (and IVs, where needed). As is implied by
18+
# > their names, all of the object identifiers below use the hash
19+
# > function SHA-1.
20+
# > ...
21+
# > pbeWithSHAAnd3-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 3}
22+
#
23+
# Note that the pbeWithSHAAnd3-KeyTripleDES-CBC (pkcs12-pbeids 3) in the RFC
24+
# 7292 PKCS#12 means PBE-SHA1-3DES in OpenSSL. PKCS12KDF is used in PKCS#12.
25+
# https://oidref.com/1.2.840.113549.1.12.1.3
26+
# https://github.com/openssl/openssl/blob/ed57d1e06dca28689190e00d9893e0fd7ecc67c1/crypto/objects/objects.txt#L385
27+
return if OpenSSL.fips_mode
28+
629
module OpenSSL
730
class TestPKCS12 < OpenSSL::TestCase
831
DEFAULT_PBE_PKEYS = "PBE-SHA1-3DES"
@@ -210,8 +233,13 @@ def test_create_with_keytype
210233
end
211234

212235
def test_new_with_no_keys
213-
# generated with:
214-
# openssl pkcs12 -certpbe PBE-SHA1-3DES -in <@mycert> -nokeys -export
236+
# Generated with the following steps:
237+
# Print the value of the @mycert such as by `puts @mycert.to_s` and
238+
# save the value as the file `mycert.pem`.
239+
# Run the following commands:
240+
# openssl pkcs12 -certpbe PBE-SHA1-3DES -in <(cat mycert.pem) \
241+
# -nokeys -export -passout pass:abc123 -out /tmp/p12.out
242+
# base64 -w 60 /tmp/p12.out
215243
str = <<~EOF.unpack1("m")
216244
MIIGJAIBAzCCBeoGCSqGSIb3DQEHAaCCBdsEggXXMIIF0zCCBc8GCSqGSIb3
217245
DQEHBqCCBcAwggW8AgEAMIIFtQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQMw
@@ -259,8 +287,10 @@ def test_new_with_no_keys
259287
end
260288

261289
def test_new_with_no_certs
262-
# generated with:
263-
# openssl pkcs12 -inkey fixtures/openssl/pkey/rsa-1.pem -nocerts -export
290+
# Generated with the folowing steps:
291+
# openssl pkcs12 -inkey test/openssl/fixtures/pkey/rsa-1.pem \
292+
# -nocerts -export -passout pass:abc123 -out /tmp/p12.out
293+
# base64 -w 60 /tmp/p12.out
264294
str = <<~EOF.unpack1("m")
265295
MIIJ7wIBAzCCCbUGCSqGSIb3DQEHAaCCCaYEggmiMIIJnjCCCZoGCSqGSIb3
266296
DQEHAaCCCYsEggmHMIIJgzCCCX8GCyqGSIb3DQEMCgECoIIJbjCCCWowHAYK

0 commit comments

Comments
 (0)