diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2010-06-01 14:50:55 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2010-06-02 09:46:44 (GMT) |
commit | 0f16c7ce8dcd6f4905d14875088c55148e41366a (patch) | |
tree | d0b6a19e3fe57b55711ff7a7b6c48e9a15f457e4 /src/network/ssl | |
parent | cd50f97a9f09eece645c9d7d01cb14c04521a915 (diff) | |
download | Qt-0f16c7ce8dcd6f4905d14875088c55148e41366a.zip Qt-0f16c7ce8dcd6f4905d14875088c55148e41366a.tar.gz Qt-0f16c7ce8dcd6f4905d14875088c55148e41366a.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
Diffstat (limited to 'src/network/ssl')
-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 fd647e2..31c5ed1 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; } |