Skip to content

Commit 7955928

Browse files
committed
pgcrypto: Allow tests to pass in OpenSSL FIPS mode
This adds several alternative expected files for when MD5 and 3DES are not available. This is similar to the alternative expected files for when the legacy provider is disabled. In fact, running the pgcrypto tests in FIPS mode makes use of some of these existing alternative expected files as well (e.g., for blowfish). These new expected files currently cover the FIPS mode provided by OpenSSL 3.x as well as the modified OpenSSL 3.x from Red Hat (e.g., Fedora 38), but not the modified OpenSSL 1.x from Red Hat (e.g., Fedora 35). (The latter will have some error message wording differences.) Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/flat/dbbd927f-ef1f-c9a1-4ec6-c759778ac852%40enterprisedb.com
1 parent b1e5c9f commit 7955928

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

contrib/pgcrypto/expected/3des_1.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--
2+
-- 3DES cipher
3+
--
4+
-- test vector from somewhere
5+
SELECT encrypt('\x8000000000000000',
6+
'\x010101010101010101010101010101010101010101010101',
7+
'3des-ecb/pad:none');
8+
ERROR: encrypt error: Cipher cannot be initialized
9+
select encrypt('', 'foo', '3des');
10+
ERROR: encrypt error: Cipher cannot be initialized
11+
-- 10 bytes key
12+
select encrypt('foo', '0123456789', '3des');
13+
ERROR: encrypt error: Cipher cannot be initialized
14+
-- 22 bytes key
15+
select encrypt('foo', '0123456789012345678901', '3des');
16+
ERROR: encrypt error: Cipher cannot be initialized
17+
-- decrypt
18+
select encode(decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'), 'escape');
19+
ERROR: encrypt error: Cipher cannot be initialized
20+
-- iv
21+
select encrypt_iv('foo', '0123456', 'abcd', '3des');
22+
ERROR: encrypt_iv error: Cipher cannot be initialized
23+
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', '3des'), 'escape');
24+
ERROR: decrypt_iv error: Cipher cannot be initialized
25+
-- long message
26+
select encrypt('Lets try a longer message.', '0123456789012345678901', '3des');
27+
ERROR: encrypt error: Cipher cannot be initialized
28+
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des'), 'escape');
29+
ERROR: encrypt error: Cipher cannot be initialized
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--
2+
-- crypt() and gen_salt(): md5
3+
--
4+
SELECT crypt('', '$1$Szzz0yzz');
5+
ERROR: crypt(3) returned NULL
6+
SELECT crypt('foox', '$1$Szzz0yzz');
7+
ERROR: crypt(3) returned NULL
8+
CREATE TABLE ctest (data text, res text, salt text);
9+
INSERT INTO ctest VALUES ('password', '', '');
10+
UPDATE ctest SET salt = gen_salt('md5');
11+
UPDATE ctest SET res = crypt(data, salt);
12+
ERROR: crypt(3) returned NULL
13+
SELECT res = crypt(data, res) AS "worked"
14+
FROM ctest;
15+
ERROR: invalid salt
16+
DROP TABLE ctest;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--
2+
-- HMAC-MD5
3+
--
4+
SELECT hmac(
5+
'Hi There',
6+
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea,
7+
'md5');
8+
ERROR: Cannot use "md5": Cipher cannot be initialized
9+
-- 2
10+
SELECT hmac(
11+
'Jefe',
12+
'what do ya want for nothing?',
13+
'md5');
14+
ERROR: Cannot use "md5": Cipher cannot be initialized
15+
-- 3
16+
SELECT hmac(
17+
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea,
18+
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
19+
'md5');
20+
ERROR: Cannot use "md5": Cipher cannot be initialized
21+
-- 4
22+
SELECT hmac(
23+
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea,
24+
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea,
25+
'md5');
26+
ERROR: Cannot use "md5": Cipher cannot be initialized
27+
-- 5
28+
SELECT hmac(
29+
'Test With Truncation',
30+
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea,
31+
'md5');
32+
ERROR: Cannot use "md5": Cipher cannot be initialized
33+
-- 6
34+
SELECT hmac(
35+
'Test Using Larger Than Block-Size Key - Hash Key First',
36+
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
37+
'md5');
38+
ERROR: Cannot use "md5": Cipher cannot be initialized
39+
-- 7
40+
SELECT hmac(
41+
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
42+
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
43+
'md5');
44+
ERROR: Cannot use "md5": Cipher cannot be initialized

contrib/pgcrypto/expected/md5_1.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--
2+
-- MD5 message digest
3+
--
4+
SELECT digest('', 'md5');
5+
ERROR: Cannot use "md5": Cipher cannot be initialized
6+
SELECT digest('a', 'md5');
7+
ERROR: Cannot use "md5": Cipher cannot be initialized
8+
SELECT digest('abc', 'md5');
9+
ERROR: Cannot use "md5": Cipher cannot be initialized
10+
SELECT digest('message digest', 'md5');
11+
ERROR: Cannot use "md5": Cipher cannot be initialized
12+
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'md5');
13+
ERROR: Cannot use "md5": Cipher cannot be initialized
14+
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5');
15+
ERROR: Cannot use "md5": Cipher cannot be initialized
16+
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5');
17+
ERROR: Cannot use "md5": Cipher cannot be initialized
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--
2+
-- PGP encrypt using MD5
3+
--
4+
select pgp_sym_decrypt(
5+
pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=md5'),
6+
'key', 'expect-s2k-digest-algo=md5');
7+
ERROR: Unsupported digest algorithm

0 commit comments

Comments
 (0)