Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
4.7.0
-
None
-
Windows Vista SP1, OpenSSL 1.0.0a
-
0f16c7ce8dcd6f4905d14875088c55148e41366a
Description
QSslCertificate::serialNumber() returns a QByteArray with "-1" content when the serial number of the certificate is longer than a long. It is because ASN1_INTEGER_get of OpenSSL library returns 0xffffffffL when the integer is too large to fit in a long. ASN1_INTEGERs can be of arbitrary size.
A better method to convert the serial number to QByteArray would be to use a BIO and the i2a_ASN1_INTEGER OpenSSL function.
/*!
Returns the certificate's serial number string in decimal format.
*/
QByteArray QSslCertificate::serialNumber() const
{
if (d->serialNumberString.isEmpty() && d->x509) {
BIO* bio = q_BIO_new(q_BIO_s_mem());
if (!bio)
return QByteArray();
if (i2a_ASN1_INTEGER(bio, d->x509->cert_info->serialNumber) < 0)
{ q_BIO_free(bio); return QByteArray(); } char *data = NULL;
int size = q_BIO_get_mem_data(bio, &data);
if (size < -1 || !data)
d->serialNumberString = QByteArray(data, size)
q_BIO_free(bio);
}
return d->serialNumberString;
}