From: Jonathan M. Wilbur Date: Thu, 12 Sep 2024 11:07:04 +0000 (+0000) Subject: feat: use ossl_serial_number_print in X509_print_ex X-Git-Tag: openssl-3.5.0-alpha1~1108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c90451d89d55ba42f2be01065361030f26f3e852;p=thirdparty%2Fopenssl.git feat: use ossl_serial_number_print in X509_print_ex Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/25428) --- diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 4befbe25daf..71f9e33c217 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -88,37 +88,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, if (BIO_write(bp, " Serial Number:", 22) <= 0) goto err; - - if (bs->length <= (int)sizeof(long)) { - ERR_set_mark(); - l = ASN1_INTEGER_get(bs); - ERR_pop_to_mark(); - } else { - l = -1; - } - if (l != -1) { - unsigned long ul; - if (bs->type == V_ASN1_NEG_INTEGER) { - ul = 0 - (unsigned long)l; - neg = "-"; - } else { - ul = l; - neg = ""; - } - if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", neg, ul, neg, ul) <= 0) - goto err; - } else { - neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : ""; - if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0) - goto err; - - for (i = 0; i < bs->length; i++) { - if (BIO_printf(bp, "%02x%c", bs->data[i], - ((i + 1 == bs->length) ? '\n' : ':')) <= 0) - goto err; - } - } - + if (ossl_serial_number_print(bp, bs, 12) != 0) + goto err; + if (BIO_puts(bp, "\n") <= 0) + goto err; } if (!(cflag & X509_FLAG_NO_SIGNAME)) { diff --git a/test/recipes/25-test_rusext_data/grfc.msb b/test/recipes/25-test_rusext_data/grfc.msb index 5184e4ff7a8..bb40ae1aa77 100644 --- a/test/recipes/25-test_rusext_data/grfc.msb +++ b/test/recipes/25-test_rusext_data/grfc.msb @@ -1,7 +1,7 @@ Certificate: Data: Version: 3 (0x2) - Serial Number: + Serial Number: 0c:8c:40:93:bb:e6:93:bd:43:0b:f5:18:26:03:1d:05 Signature Algorithm: GOST R 34.11-94 with GOST R 34.10-2001 Issuer: OGRN=1027739334479, INN=007706228218, street=\U0414\U0435\U0440\U0431\U0435\U043D\U0435\U0432\U0441\U043A\U0430\U044F \U043D\U0430\U0431. \U0434. 7 \U0441\U0442\U0440. 15, emailAddress=pki-grfc@grfc.ru, C=RU, ST=77 \U0433. \U041C\U043E\U0441\U043A\U0432\U0430, L=\U041C\U043E\U0441\U043A\U0432\U0430, O=\U0424\U0413\U0423\U041F "\U0413\U0420\U0427\U0426", CN=\U0423\U0426 \U0424\U0413\U0423\U041F "\U0413\U0420\U0427\U0426" diff --git a/test/recipes/25-test_rusext_data/grfc.utf8 b/test/recipes/25-test_rusext_data/grfc.utf8 index a709dcf67cd..ea9ec395fe8 100644 --- a/test/recipes/25-test_rusext_data/grfc.utf8 +++ b/test/recipes/25-test_rusext_data/grfc.utf8 @@ -1,7 +1,7 @@ Certificate: Data: Version: 3 (0x2) - Serial Number: + Serial Number: 0c:8c:40:93:bb:e6:93:bd:43:0b:f5:18:26:03:1d:05 Signature Algorithm: GOST R 34.11-94 with GOST R 34.10-2001 Issuer: OGRN=1027739334479, INN=007706228218, street=Дербеневская наб. д. 7 стр. 15, emailAddress=pki-grfc@grfc.ru, C=RU, ST=77 г. Москва, L=Москва, O=ФГУП "ГРЧЦ", CN=УЦ ФГУП "ГРЧЦ"