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:
parent
6f4bdf3b64
commit
6f115edd74
4
dist/changes-5.0.0
vendored
4
dist/changes-5.0.0
vendored
@ -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
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -271,28 +271,20 @@ 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
|
QByteArray hexString;
|
||||||
if (serialNumber->length > 4) {
|
hexString.reserve(serialNumber->length * 3);
|
||||||
QByteArray hexString;
|
for (int a = 0; a < serialNumber->length; ++a) {
|
||||||
hexString.reserve(serialNumber->length * 3);
|
hexString += QByteArray::number(serialNumber->data[a], 16).rightJustified(2, '0');
|
||||||
for (int a = 0; a < serialNumber->length; ++a) {
|
hexString += ':';
|
||||||
hexString += QByteArray::number(serialNumber->data[a], 16).rightJustified(2, '0');
|
|
||||||
hexString += ':';
|
|
||||||
}
|
|
||||||
hexString.chop(1);
|
|
||||||
d->serialNumberString = hexString;
|
|
||||||
} else {
|
|
||||||
d->serialNumberString = QByteArray::number(qlonglong(q_ASN1_INTEGER_get(serialNumber)));
|
|
||||||
}
|
}
|
||||||
|
hexString.chop(1);
|
||||||
|
d->serialNumberString = hexString;
|
||||||
}
|
}
|
||||||
return d->serialNumberString;
|
return d->serialNumberString;
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user