diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index c921207698228..4d766329c4706 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -2892,7 +2892,6 @@ RSA_R_BAD_PAD_BYTE_COUNT:103:bad pad byte count RSA_R_BAD_SIGNATURE:104:bad signature RSA_R_BLOCK_TYPE_IS_NOT_01:106:block type is not 01 RSA_R_BLOCK_TYPE_IS_NOT_02:107:block type is not 02 -RSA_R_DATA_GREATER_THAN_MOD_LEN:108:data greater than mod len RSA_R_DATA_TOO_LARGE:109:data too large RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE:110:data too large for key size RSA_R_DATA_TOO_LARGE_FOR_MODULUS:132:data too large for modulus @@ -3273,7 +3272,6 @@ SSL_R_VERSION_TOO_LOW:396:version too low SSL_R_WRONG_CERTIFICATE_TYPE:383:wrong certificate type SSL_R_WRONG_CIPHER_RETURNED:261:wrong cipher returned SSL_R_WRONG_CURVE:378:wrong curve -SSL_R_WRONG_SIGNATURE_LENGTH:264:wrong signature length SSL_R_WRONG_SIGNATURE_SIZE:265:wrong signature size SSL_R_WRONG_SIGNATURE_TYPE:370:wrong signature type SSL_R_WRONG_SSL_VERSION:266:wrong ssl version diff --git a/crypto/rsa/rsa_err.c b/crypto/rsa/rsa_err.c index 382b8cb7d10cf..26586b4b93aba 100644 --- a/crypto/rsa/rsa_err.c +++ b/crypto/rsa/rsa_err.c @@ -24,8 +24,6 @@ static const ERR_STRING_DATA RSA_str_reasons[] = { "block type is not 01"}, {ERR_PACK(ERR_LIB_RSA, 0, RSA_R_BLOCK_TYPE_IS_NOT_02), "block type is not 02"}, - {ERR_PACK(ERR_LIB_RSA, 0, RSA_R_DATA_GREATER_THAN_MOD_LEN), - "data greater than mod len"}, {ERR_PACK(ERR_LIB_RSA, 0, RSA_R_DATA_TOO_LARGE), "data too large"}, {ERR_PACK(ERR_LIB_RSA, 0, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE), "data too large for key size"}, diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c index 4b54aa86fe2d5..bd46481fe086d 100644 --- a/crypto/rsa/rsa_ossl.c +++ b/crypto/rsa/rsa_ossl.c @@ -400,13 +400,8 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, goto err; } - /* - * This check was for equality but PGP does evil things and chops off the - * top '0' bytes - */ - if (flen > num) { - RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, - RSA_R_DATA_GREATER_THAN_MOD_LEN); + if (flen != num) { + RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_WRONG_SIGNATURE_LENGTH); goto err; } @@ -556,12 +551,8 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, goto err; } - /* - * This check was for equality but PGP does evil things and chops off the - * top '0' bytes - */ - if (flen > num) { - RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_DATA_GREATER_THAN_MOD_LEN); + if (flen != num) { + RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_WRONG_SIGNATURE_LENGTH); goto err; } diff --git a/crypto/rsa/rsa_saos.c b/crypto/rsa/rsa_saos.c index e7041ca2ae00b..82c73cd9cf9c3 100644 --- a/crypto/rsa/rsa_saos.c +++ b/crypto/rsa/rsa_saos.c @@ -67,12 +67,6 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *p; ASN1_OCTET_STRING *sig = NULL; - if (siglen != (unsigned int)RSA_size(rsa)) { - RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, - RSA_R_WRONG_SIGNATURE_LENGTH); - return 0; - } - s = OPENSSL_malloc((unsigned int)siglen); if (s == NULL) { RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); diff --git a/crypto/rsa/rsa_sign.c b/crypto/rsa/rsa_sign.c index e9c4c553980ef..c2d4cf7b05195 100644 --- a/crypto/rsa/rsa_sign.c +++ b/crypto/rsa/rsa_sign.c @@ -293,11 +293,6 @@ int int_rsa_verify(int type, const unsigned char *m, unsigned int m_len, size_t decrypt_len, encoded_len = 0; unsigned char *decrypt_buf = NULL, *encoded = NULL; - if (siglen != (size_t)RSA_size(rsa)) { - RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH); - return 0; - } - /* Recover the encoded digest. */ decrypt_buf = OPENSSL_malloc(siglen); if (decrypt_buf == NULL) { diff --git a/doc/man3/RSA_public_encrypt.pod b/doc/man3/RSA_public_encrypt.pod index dbd4c555bf842..894f7824d17a8 100644 --- a/doc/man3/RSA_public_encrypt.pod +++ b/doc/man3/RSA_public_encrypt.pod @@ -68,16 +68,13 @@ RSA_size(B) bytes. B and B may overlap. RSA_private_decrypt() decrypts the B bytes at B using the -private key B and stores the plaintext in B. B should -be equal to RSA_size(B) but may be smaller, when leading zero -bytes are in the ciphertext. Those are not important and may be removed, -but RSA_public_encrypt() does not do that. B must point -to a memory section large enough to hold the maximal possible decrypted -data (which is equal to RSA_size(B) for RSA_NO_PADDING, -RSA_size(B) - 11 for the PKCS #1 v1.5 based padding modes and -RSA_size(B) - 42 for RSA_PKCS1_OAEP_PADDING). -B is the padding mode that was used to encrypt the data. -B and B may overlap. +private key B and stores the plaintext in B. B must be +equal to RSA_size(B). B must point to a memory section large +enough to hold the maximal possible decrypted data (which is equal to +RSA_size(B) for RSA_NO_PADDING, RSA_size(B) - 11 for the +PKCS #1 v1.5 based padding modes and RSA_size(B) - 42 for +RSA_PKCS1_OAEP_PADDING). B is the padding mode that was used +to encrypt the data. B and B may overlap. =head1 RETURN VALUES diff --git a/include/openssl/rsaerr.h b/include/openssl/rsaerr.h index ef72bc744ef14..8047de4700687 100644 --- a/include/openssl/rsaerr.h +++ b/include/openssl/rsaerr.h @@ -110,7 +110,6 @@ int ERR_load_RSA_strings(void); # define RSA_R_BAD_SIGNATURE 104 # define RSA_R_BLOCK_TYPE_IS_NOT_01 106 # define RSA_R_BLOCK_TYPE_IS_NOT_02 107 -# define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 # define RSA_R_DATA_TOO_LARGE 109 # define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 # define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132 diff --git a/include/openssl/sslerr.h b/include/openssl/sslerr.h index 25e304ed10b31..0a3678234f49a 100644 --- a/include/openssl/sslerr.h +++ b/include/openssl/sslerr.h @@ -768,7 +768,6 @@ int ERR_load_SSL_strings(void); # define SSL_R_WRONG_CERTIFICATE_TYPE 383 # define SSL_R_WRONG_CIPHER_RETURNED 261 # define SSL_R_WRONG_CURVE 378 -# define SSL_R_WRONG_SIGNATURE_LENGTH 264 # define SSL_R_WRONG_SIGNATURE_SIZE 265 # define SSL_R_WRONG_SIGNATURE_TYPE 370 # define SSL_R_WRONG_SSL_VERSION 266 diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c index 517e90c141112..bd56545993941 100644 --- a/ssl/ssl_err.c +++ b/ssl/ssl_err.c @@ -534,8 +534,6 @@ static const ERR_STRING_DATA SSL_str_reasons[] = { {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_WRONG_CIPHER_RETURNED), "wrong cipher returned"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_WRONG_CURVE), "wrong curve"}, - {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_WRONG_SIGNATURE_LENGTH), - "wrong signature length"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_WRONG_SIGNATURE_SIZE), "wrong signature size"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_WRONG_SIGNATURE_TYPE), diff --git a/test/certs/cert-wrong-sig-len.pem b/test/certs/cert-wrong-sig-len.pem new file mode 100644 index 0000000000000..db2558ef0b180 --- /dev/null +++ b/test/certs/cert-wrong-sig-len.pem @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEHTCCAtKgAwIBAgIUJvpzQbf5lboq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+MD3tkeFbErkrV/l5Kod90n0nra1f/beS86d2w9L47AoBmMyTgrj+k2BXieZWZ8C2 +vefdmfwynCtHtgK+ExeGN9Qnmb5rjWzH/HCwruHSSBnTs9/xZzSoSk5gTenL37ga ++G3KmtJHguCtOo3taWTirOTZ5F3hcX6QKBdk0BrZwNrBTGouRDx+CDkymiBjVM9P +idxIL7tcIDsuHr/83Z95L5J7QjKGeEUjYhXuY2/L3fVfqBe4pQev5K1cbGg1MeSF +vrp46StOJCvdo5qzZNHolAw7uHmh2FCjYDrnxuw9XMoAdI51Hvq2RiQxaDOUAk4O +kA== +-----END CERTIFICATE----- diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t index 219e7e1149a63..0d3ba2425c2b7 100644 --- a/test/recipes/25-test_verify.t +++ b/test/recipes/25-test_verify.t @@ -27,7 +27,7 @@ sub verify { run(app([@args])); } -plan tests => 137; +plan tests => 138; # Canonical success ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]), @@ -364,6 +364,9 @@ ok(verify("some-names2", "sslserver", ["many-constraints"], ["many-constraints"] ok(verify("root-cert-rsa2", "sslserver", ["root-cert-rsa2"], [], "-check_ss_sig"), "Public Key Algorithm rsa instead of rsaEncryption"); +ok(!verify("cert-wrong-sig-len", "sslserver", ["root-cert"], [], ), + "Wrong signature length"); + SKIP: { skip "Ed25519 is not supported by this OpenSSL build", 1 if disabled("ec");