Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12523

QSslCertificate::serialNumber() returns "-1" on long serial number

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 4.7.0
    • 4.7.0
    • Network: SSL
    • 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)

      { q_BIO_free(bio); return QByteArray(); }

      d->serialNumberString = QByteArray(data, size)
      q_BIO_free(bio);
      }

      return d->serialNumberString;
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            phartman Peter Hartmann (closed Nokia identity) (Inactive)
            egergo Gergő Ertli
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes