Qt 4.8
Public Functions | Static Public Functions | Public Variables | Friends | List of all members
QSslCertificatePrivate Class Reference

#include <qsslcertificate_p.h>

Public Functions

void init (const QByteArray &data, QSsl::EncodingFormat format)
 
 QSslCertificatePrivate ()
 
 ~QSslCertificatePrivate ()
 

Static Public Functions

static QList< QSslCertificatecertificatesFromDer (const QByteArray &der, int count=-1)
 
static QList< QSslCertificatecertificatesFromPem (const QByteArray &pem, int count=-1)
 
static bool isBlacklisted (const QSslCertificate &certificate)
 
static QByteArray QByteArray_from_X509 (X509 *x509, QSsl::EncodingFormat format)
 
static QSslCertificate QSslCertificate_from_X509 (X509 *x509)
 

Public Variables

QMap< QString, QStringissuerInfo
 
QDateTime notValidAfter
 
QDateTime notValidBefore
 
bool null
 
QAtomicInt ref
 
QByteArray serialNumberString
 
QMap< QString, QStringsubjectInfo
 
QByteArray versionString
 
X509x509
 

Friends

class QSslSocketBackendPrivate
 

Detailed Description

Definition at line 67 of file qsslcertificate_p.h.

Constructors and Destructors

◆ QSslCertificatePrivate()

QSslCertificatePrivate::QSslCertificatePrivate ( )
inline

Definition at line 70 of file qsslcertificate_p.h.

71  : null(true), x509(0)
72  {
74  }
static void ensureInitialized()
Declared static in QSslSocketPrivate, makes sure the SSL libraries have been initialized.

◆ ~QSslCertificatePrivate()

QSslCertificatePrivate::~QSslCertificatePrivate ( )
inline

Definition at line 76 of file qsslcertificate_p.h.

77  {
78  if (x509)
80  }
void q_X509_free(X509 *a)

Functions

◆ certificatesFromDer()

QList< QSslCertificate > QSslCertificatePrivate::certificatesFromDer ( const QByteArray der,
int  count = -1 
)
static

Definition at line 780 of file qsslcertificate.cpp.

Referenced by QSslCertificate::fromData().

781 {
782  QList<QSslCertificate> certificates;
784 
785 
786 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
787  const unsigned char *data = (const unsigned char *)der.data();
788 #else
789  unsigned char *data = (unsigned char *)der.data();
790 #endif
791  int size = der.size();
792 
793  while (count == -1 || certificates.size() < count) {
794  if (X509 *x509 = q_d2i_X509(0, &data, size)) {
795  certificates << QSslCertificate_from_X509(x509);
796  q_X509_free(x509);
797  } else {
798  break;
799  }
800  size -= ((char *)data - der.data());
801  }
802 
803  return certificates;
804 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
struct x509_st X509
static QSslCertificate QSslCertificate_from_X509(X509 *x509)
static const char * data(const QByteArray &arr)
void q_X509_free(X509 *a)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static void ensureInitialized()
Declared static in QSslSocketPrivate, makes sure the SSL libraries have been initialized.
X509 * q_d2i_X509(X509 **a, unsigned char **b, long c)

◆ certificatesFromPem()

QList< QSslCertificate > QSslCertificatePrivate::certificatesFromPem ( const QByteArray pem,
int  count = -1 
)
static

Definition at line 741 of file qsslcertificate.cpp.

Referenced by QSslCertificate::fromData().

742 {
743  QList<QSslCertificate> certificates;
745 
746  int offset = 0;
747  while (count == -1 || certificates.size() < count) {
748  int startPos = pem.indexOf(BEGINCERTSTRING, offset);
749  if (startPos == -1)
750  break;
751  startPos += sizeof(BEGINCERTSTRING) - 1;
752  if (!matchLineFeed(pem, &startPos))
753  break;
754 
755  int endPos = pem.indexOf(ENDCERTSTRING, startPos);
756  if (endPos == -1)
757  break;
758 
759  offset = endPos + sizeof(ENDCERTSTRING) - 1;
760  if (offset < pem.size() && !matchLineFeed(pem, &offset))
761  break;
762 
764  QByteArray::fromRawData(pem.data() + startPos, endPos - startPos));
765 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
766  const unsigned char *data = (const unsigned char *)decoded.data();
767 #else
768  unsigned char *data = (unsigned char *)decoded.data();
769 #endif
770 
771  if (X509 *x509 = q_d2i_X509(0, &data, decoded.size())) {
772  certificates << QSslCertificate_from_X509(x509);
773  q_X509_free(x509);
774  }
775  }
776 
777  return certificates;
778 }
#define BEGINCERTSTRING
#define ENDCERTSTRING
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
struct x509_st X509
static bool matchLineFeed(const QByteArray &pem, int *offset)
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
static QSslCertificate QSslCertificate_from_X509(X509 *x509)
static const char * data(const QByteArray &arr)
void q_X509_free(X509 *a)
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
static QByteArray fromBase64(const QByteArray &base64)
Returns a decoded copy of the Base64 array base64.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static void ensureInitialized()
Declared static in QSslSocketPrivate, makes sure the SSL libraries have been initialized.
X509 * q_d2i_X509(X509 **a, unsigned char **b, long c)

◆ init()

void QSslCertificatePrivate::init ( const QByteArray data,
QSsl::EncodingFormat  format 
)

Definition at line 639 of file qsslcertificate.cpp.

Referenced by QSslCertificate::QSslCertificate().

640 {
641  if (!data.isEmpty()) {
643  ? certificatesFromPem(data, 1)
644  : certificatesFromDer(data, 1);
645  if (!certs.isEmpty()) {
646  *this = *certs.first().d;
647  if (x509)
648  x509 = q_X509_dup(x509);
649  }
650  }
651 }
X509 * q_X509_dup(X509 *a)
static QList< QSslCertificate > certificatesFromDer(const QByteArray &der, int count=-1)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QExplicitlySharedDataPointer< QSslCertificatePrivate > d
Definition: qssl.h:62
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static QList< QSslCertificate > certificatesFromPem(const QByteArray &pem, int count=-1)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ isBlacklisted()

bool QSslCertificatePrivate::isBlacklisted ( const QSslCertificate certificate)
static

Definition at line 853 of file qsslcertificate.cpp.

Referenced by QSslCertificate::isValid(), and QSslSocketBackendPrivate::startHandshake().

854 {
855  for (int a = 0; certificate_blacklist[a] != 0; a++) {
856  QString blacklistedCommonName = QString::fromUtf8(certificate_blacklist[(a+1)]);
857  if (certificate.serialNumber() == certificate_blacklist[a++] &&
858  (certificate.subjectInfo(QSslCertificate::CommonName) == blacklistedCommonName ||
859  certificate.issuerInfo(QSslCertificate::CommonName) == blacklistedCommonName))
860  return true;
861  }
862  return false;
863 }
QByteArray serialNumber() const
Returns the certificate&#39;s serial number string in decimal format.
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static const char * certificate_blacklist[]
QString subjectInfo(SubjectInfo info) const
Returns the information for the subject, or an empty string if there is no information for subject in...
QString issuerInfo(SubjectInfo info) const
Returns the issuer information for the subject from the certificate, or an empty string if there is n...

◆ QByteArray_from_X509()

QByteArray QSslCertificatePrivate::QByteArray_from_X509 ( X509 x509,
QSsl::EncodingFormat  format 
)
static

Definition at line 657 of file qsslcertificate.cpp.

Referenced by QSslCertificate::toDer(), and QSslCertificate::toPem().

658 {
659  if (!x509) {
660  qWarning("QSslSocketBackendPrivate::X509_to_QByteArray: null X509");
661  return QByteArray();
662  }
663 
664  // Use i2d_X509 to convert the X509 to an array.
665  int length = q_i2d_X509(x509, 0);
666  QByteArray array;
667  array.resize(length);
668  char *data = array.data();
669  char **dataP = &data;
670  unsigned char **dataPu = (unsigned char **)dataP;
671  if (q_i2d_X509(x509, dataPu) < 0)
672  return QByteArray();
673 
674  if (format == QSsl::Der)
675  return array;
676 
677  // Convert to Base64 - wrap at 64 characters.
678  array = array.toBase64();
679  QByteArray tmp;
680  for (int i = 0; i <= array.size() - 64; i += 64) {
681  tmp += QByteArray::fromRawData(array.data() + i, 64);
682  tmp += '\n';
683  }
684  if (int remainder = array.size() % 64) {
685  tmp += QByteArray::fromRawData(array.data() + array.size() - remainder, remainder);
686  tmp += '\n';
687  }
688 
689  return BEGINCERTSTRING "\n" + tmp + ENDCERTSTRING "\n";
690 }
#define BEGINCERTSTRING
#define ENDCERTSTRING
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
int q_i2d_X509(X509 *a, unsigned char **b)
void resize(int size)
Sets the size of the byte array to size bytes.
QByteArray toBase64() const
Returns a copy of the byte array, encoded as Base64.
Definition: qssl.h:63
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ QSslCertificate_from_X509()

QSslCertificate QSslCertificatePrivate::QSslCertificate_from_X509 ( X509 x509)
static

Definition at line 706 of file qsslcertificate.cpp.

Referenced by QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(), and QSslSocketBackendPrivate::startHandshake().

707 {
708  QSslCertificate certificate;
709  if (!x509 || !QSslSocket::supportsSsl())
710  return certificate;
711 
712  ASN1_TIME *nbef = q_X509_get_notBefore(x509);
713  ASN1_TIME *naft = q_X509_get_notAfter(x509);
714  certificate.d->notValidBefore = q_getTimeFromASN1(nbef);
715  certificate.d->notValidAfter = q_getTimeFromASN1(naft);
716  certificate.d->null = false;
717  certificate.d->x509 = q_X509_dup(x509);
718 
719  return certificate;
720 }
X509 * q_X509_dup(X509 *a)
#define q_X509_get_notBefore(x)
static bool supportsSsl()
Returns true if this platform supports SSL; otherwise, returns false.
QExplicitlySharedDataPointer< QSslCertificatePrivate > d
QDateTime q_getTimeFromASN1(const ASN1_TIME *aTime)
The QSslCertificate class provides a convenient API for an X509 certificate.
#define q_X509_get_notAfter(x)

Friends and Related Functions

◆ QSslSocketBackendPrivate

Definition at line 101 of file qsslcertificate_p.h.

Properties

◆ issuerInfo

QMap<QString, QString> QSslCertificatePrivate::issuerInfo

Definition at line 86 of file qsslcertificate_p.h.

Referenced by QSslCertificate::issuerInfo().

◆ notValidAfter

QDateTime QSslCertificatePrivate::notValidAfter

◆ notValidBefore

QDateTime QSslCertificatePrivate::notValidBefore

◆ null

bool QSslCertificatePrivate::null

◆ ref

QAtomicInt QSslCertificatePrivate::ref

Definition at line 103 of file qsslcertificate_p.h.

◆ serialNumberString

QByteArray QSslCertificatePrivate::serialNumberString

Definition at line 84 of file qsslcertificate_p.h.

Referenced by QSslCertificate::serialNumber().

◆ subjectInfo

QMap<QString, QString> QSslCertificatePrivate::subjectInfo

Definition at line 87 of file qsslcertificate_p.h.

Referenced by QSslCertificate::subjectInfo().

◆ versionString

QByteArray QSslCertificatePrivate::versionString

Definition at line 83 of file qsslcertificate_p.h.

Referenced by QSslCertificate::version().

◆ x509

X509* QSslCertificatePrivate::x509

The documentation for this class was generated from the following files: