Merge pull request #1455 from xjtian/long_serials

Fix get_x509_serial for long serial numbers
This commit is contained in:
Tatsuhiro Tsujikawa 2020-03-31 18:47:53 +09:00 committed by GitHub
commit 600fcdf52d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 13 deletions

View File

@ -2030,17 +2030,6 @@ StringRef get_x509_issuer_name(BlockAllocator &balloc, X509 *x) {
#endif /* !WORDS_BIGENDIAN */ #endif /* !WORDS_BIGENDIAN */
StringRef get_x509_serial(BlockAllocator &balloc, X509 *x) { StringRef get_x509_serial(BlockAllocator &balloc, X509 *x) {
#if OPENSSL_1_1_API && !defined(OPENSSL_IS_BORINGSSL)
auto sn = X509_get0_serialNumber(x);
uint64_t r;
if (ASN1_INTEGER_get_uint64(&r, sn) != 1) {
return StringRef{};
}
r = bswap64(r);
return util::format_hex(
balloc, StringRef{reinterpret_cast<uint8_t *>(&r), sizeof(r)});
#else // !OPENSSL_1_1_API || OPENSSL_IS_BORINGSSL
auto sn = X509_get_serialNumber(x); auto sn = X509_get_serialNumber(x);
auto bn = BN_new(); auto bn = BN_new();
auto bn_d = defer(BN_free, bn); auto bn_d = defer(BN_free, bn);
@ -2052,8 +2041,7 @@ StringRef get_x509_serial(BlockAllocator &balloc, X509 *x) {
auto n = BN_bn2bin(bn, b.data()); auto n = BN_bn2bin(bn, b.data());
assert(n <= 20); assert(n <= 20);
return util::format_hex(balloc, StringRef{std::begin(b), std::end(b)}); return util::format_hex(balloc, StringRef{b.data(), static_cast<size_t>(n)});
#endif // !OPENSSL_1_1_API
} }
namespace { namespace {