diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2010-06-01 14:50:55 (GMT) |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 10:06:05 (GMT) |
commit | 0e9b8257e542bb3b6958e90917bad0d1691598e2 (patch) | |
tree | e5844439df1398b1d3d1a6b40992fb448e86dc99 /src/network | |
parent | cf17565d64f2d77af2ea5d576cb3942a5991db6a (diff) | |
download | Qt-0e9b8257e542bb3b6958e90917bad0d1691598e2.zip Qt-0e9b8257e542bb3b6958e90917bad0d1691598e2.tar.gz Qt-0e9b8257e542bb3b6958e90917bad0d1691598e2.tar.bz2 |
QSslCertificate: support large serial numbers
We were calling an OpenSSL function that returned a long for the serial
number; sometimes serial numbers are too big to fit into a long (up to
20 octets). In that case, do not convert the serial number to decimal,
but just output the hexadecimal value.
Reviewed-by: Zeno Albisser
Task-number: QTBUG-9973
(cherry picked from commit 0f16c7ce8dcd6f4905d14875088c55148e41366a)
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/ssl/qsslcertificate.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index c811eae..9e321c9 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -259,13 +259,28 @@ QByteArray QSslCertificate::version() const /*! Returns the certificate's serial number string in decimal 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 { - if (d->serialNumberString.isEmpty() && d->x509) - d->serialNumberString = - QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->serialNumber))); - + if (d->serialNumberString.isEmpty() && d->x509) { + 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; + hexString.reserve(serialNumber->length * 3); + for (int a = 0; a < serialNumber->length; ++a) { + 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))); + } + } return d->serialNumberString; } |