Always use the hex format for certificate serial numbers.

In Qt 4.x the serial number is reported by a mixture of the hex value
and the number, The hex is what is used by other tools, and we should do
the same.

Change-Id: Ia0361d43fb5b920d053c95e932e0c8a012436e5e
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
This commit is contained in:
Richard Moore 2011-11-10 22:37:16 +00:00 committed by Qt by Nokia
parent 6f4bdf3b64
commit 6f115edd74
3 changed files with 13 additions and 17 deletions

4
dist/changes-5.0.0 vendored
View File

@ -99,6 +99,10 @@ QtNetwork
* QHostAddress::isLoopback() API added. Returns true if the address is * QHostAddress::isLoopback() API added. Returns true if the address is
one of the IP loopback addresses. one of the IP loopback addresses.
* QSslCertificate::serialNumber() now always returns the serial number in
hexadecimal format.
QtOpenGL QtOpenGL
-------- --------

View File

@ -271,17 +271,12 @@ QByteArray QSslCertificate::version() const
} }
/*! /*!
Returns the certificate's serial number string in decimal format. Returns the certificate's serial number string in hexadecimal format.
In case the serial number cannot be converted to decimal format
(i.e. if it is bigger than 4294967295, which means it does not fit into 4 bytes),
its hexadecimal version is returned.
*/ */
QByteArray QSslCertificate::serialNumber() const QByteArray QSslCertificate::serialNumber() const
{ {
if (d->serialNumberString.isEmpty() && d->x509) { if (d->serialNumberString.isEmpty() && d->x509) {
ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber; ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;
// if we cannot convert to a long, just output the hexadecimal number
if (serialNumber->length > 4) {
QByteArray hexString; QByteArray hexString;
hexString.reserve(serialNumber->length * 3); hexString.reserve(serialNumber->length * 3);
for (int a = 0; a < serialNumber->length; ++a) { for (int a = 0; a < serialNumber->length; ++a) {
@ -290,9 +285,6 @@ QByteArray QSslCertificate::serialNumber() const
} }
hexString.chop(1); hexString.chop(1);
d->serialNumberString = hexString; d->serialNumberString = hexString;
} else {
d->serialNumberString = QByteArray::number(qlonglong(q_ASN1_INTEGER_get(serialNumber)));
}
} }
return d->serialNumberString; return d->serialNumberString;
} }

View File

@ -711,7 +711,7 @@ void tst_QSslCertificate::certInfo()
QCOMPARE(cert.subjectInfo("ST"), QStringList()); QCOMPARE(cert.subjectInfo("ST"), QStringList());
QCOMPARE(cert.version(), QByteArray::number(1)); QCOMPARE(cert.version(), QByteArray::number(1));
QCOMPARE(cert.serialNumber(), QByteArray::number(17)); QCOMPARE(cert.serialNumber(), QByteArray("11"));
QCOMPARE(cert.toPem().constData(), (const char*)pem); QCOMPARE(cert.toPem().constData(), (const char*)pem);
QCOMPARE(cert.toDer(), QByteArray::fromHex(der)); QCOMPARE(cert.toDer(), QByteArray::fromHex(der));