PySide6.QtNetwork.QSslCertificate¶
- class QSslCertificate¶
- The - QSslCertificateclass provides a convenient API for an X509 certificate.- Details- QSslCertificatestores an X509 certificate, and is commonly used to verify the identity and store information about the local host, a remotely connected peer, or a trusted third party Certificate Authority.- There are many ways to construct a - QSslCertificate. The most common way is to call- peerCertificate(), which returns a- QSslCertificateobject, or- peerCertificateChain(), which returns a list of them. You can also load certificates from a DER (binary) or PEM (Base64) encoded bundle, typically stored as one or more local files, or in a Qt Resource.- You can call - isNull()to check if your certificate is null. By default,- QSslCertificateconstructs a null certificate. A null certificate is invalid, but an invalid certificate is not necessarily null. If you want to reset all contents in a certificate, call- clear().- After loading a certificate, you can find information about the certificate, its subject, and its issuer, by calling one of the many accessor functions, including - version(),- serialNumber(),- issuerInfo()and- subjectInfo(). You can call- effectiveDate()and- expiryDate()to check when the certificate starts being effective and when it expires. The- publicKey()function returns the certificate subject’s public key as a- QSslKey. You can call- issuerInfo()or- subjectInfo()to get detailed information about the certificate issuer and its subject.- Internally, - QSslCertificateis stored as an X509 structure. You can access this handle by calling- handle(), but the results are likely to not be portable.- See also - Synopsis¶- Methods¶- def - __init__()
- def - clear()
- def - digest()
- def - effectiveDate()
- def - expiryDate()
- def - extensions()
- def - handle()
- def - isBlacklisted()
- def - isNull()
- def - isSelfSigned()
- def - issuerInfo()
- def - __ne__()
- def - __eq__()
- def - publicKey()
- def - serialNumber()
- def - subjectInfo()
- def - swap()
- def - toDer()
- def - toPem()
- def - toText()
- def - version()
 - Static functions¶- def - fromData()
- def - fromDevice()
- def - fromFile()
- def - fromPath()
- def - importPkcs12()
- def - verify()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - class SubjectInfo¶
- Describes keys that you can pass to - issuerInfo()or- subjectInfo()to get information about the certificate issuer or subject.- Constant - Description - QSslCertificate.SubjectInfo.Organization - “O” The name of the organization. - QSslCertificate.SubjectInfo.CommonName - “CN” The common name; most often this is used to store the host name. - QSslCertificate.SubjectInfo.LocalityName - “L” The locality. - QSslCertificate.SubjectInfo.OrganizationalUnitName - “OU” The organizational unit name. - QSslCertificate.SubjectInfo.CountryName - “C” The country. - QSslCertificate.SubjectInfo.StateOrProvinceName - “ST” The state or province. - QSslCertificate.SubjectInfo.DistinguishedNameQualifier - The distinguished name qualifier - QSslCertificate.SubjectInfo.SerialNumber - The certificate’s serial number - QSslCertificate.SubjectInfo.EmailAddress - The email address associated with the certificate 
 - class PatternSyntax¶
- The syntax used to interpret the meaning of the pattern. - Constant - Description - QSslCertificate.PatternSyntax.PatternSyntax.RegularExpression - A rich Perl-like pattern matching syntax. - QSslCertificate.PatternSyntax.PatternSyntax.Wildcard - This provides a simple pattern matching syntax similar to that used by shells (command interpreters) for “file globbing”. See QRegularExpression::fromWildcard(). - QSslCertificate.PatternSyntax.PatternSyntax.FixedString - The pattern is a fixed string. This is equivalent to using the RegularExpression pattern on a string in which all metacharacters are escaped using escape(). This is the default. 
 - __init__(other)¶
- Parameters:
- other – - QSslCertificate
 
 - Constructs an identical copy of - other.- __init__(device[, format=QSsl.Pem])
- Parameters:
- device – - QIODevice
- format – - EncodingFormat
 
 
 - Constructs a - QSslCertificateby reading- formatencoded data from- deviceand using the first certificate found. You can later call- isNull()to see if- devicecontained a certificate, and if this certificate was loaded successfully.- __init__([data=QByteArray()[, format=QSsl.Pem]])
- Parameters:
- data – - QByteArray
- format – - EncodingFormat
 
 
 - Constructs a - QSslCertificateby parsing the- formatencoded- dataand using the first available certificate found. You can later call- isNull()to see if- datacontained a certificate, and if this certificate was loaded successfully.- clear()¶
 - Clears the contents of this certificate, making it a null certificate. - See also - Returns a cryptographic digest of this certificate. By default, an MD5 digest will be generated, but you can also specify a custom - algorithm.- Returns the date-time that the certificate becomes valid, or an empty QDateTime if this is a null certificate. - See also - Returns the date-time that the certificate expires, or an empty QDateTime if this is a null certificate. - See also - extensions()¶
- Return type:
- .list of QSslCertificateExtension 
 
 - Returns a list containing the X509 extensions of this certificate. - static fromData(data[, format=QSsl.Pem])¶
- Parameters:
- data – - QByteArray
- format – - EncodingFormat
 
- Return type:
- .list of QSslCertificate 
 
 - Searches for and parses all certificates in - datathat are encoded in the specified- formatand returns them in a list of certificates.- See also - static fromDevice(device[, format=QSsl.Pem])¶
- Parameters:
- device – - QIODevice
- format – - EncodingFormat
 
- Return type:
- .list of QSslCertificate 
 
 - Searches for and parses all certificates in - devicethat are encoded in the specified- formatand returns them in a list of certificates.- See also - static fromFile(filePath[, format=QSsl.Pem])¶
- Parameters:
- filePath – str 
- format – - EncodingFormat
 
- Return type:
- .list of QSslCertificate 
 
 - Reads the data from the file - filePathand parses all certificates that are encoded in the specified- formatand returns a list of- QSslCertificateobjects.- If - filePathisn’t a regular file, this method will return an empty list.- See also - static fromPath(path[, format=QSsl.Pem[, syntax=QSslCertificate.PatternSyntax.FixedString]])¶
- Parameters:
- path – str 
- format – - EncodingFormat
- syntax – - PatternSyntax
 
- Return type:
- .list of QSslCertificate 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Searches all files in the - pathfor certificates encoded in the specified- formatand returns them in a list.- pathmust be a file or a pattern matching one or more files, as specified by- syntax.- Example: - certs = QSslCertificate.fromPath("C:/ssl/certificate.*.pem",() QSsl.Pem, QSslCertificate.Wildcard) for cert in certs: print(cert.issuerInfo(QSslCertificate.Organization)) - See also - handle()¶
- Return type:
- Qt::HANDLE
 
 - Returns a pointer to the native certificate handle, if there is one, else - None.- You can use this handle, together with the native API, to access extended information about the certificate. - Warning - Use of this function has a high probability of being non-portable, and its return value may vary from platform to platform or change from minor release to minor release. - static importPkcs12(device, key, cert[, caCertificates=None[, passPhrase=QByteArray()]])¶
- Parameters:
- device – - QIODevice
- key – - QSslKey
- cert – - QSslCertificate
- caCertificates – - QList
- passPhrase – - QByteArray
 
- Return type:
- bool 
 
 - Imports a PKCS#12 (pfx) file from the specified - device. A PKCS#12 file is a bundle that can contain a number of certificates and keys. This method reads a single- key, its- certificateand any associated- caCertificatesfrom the bundle. If a- passPhraseis specified then this will be used to decrypt the bundle. Returns- trueif the PKCS#12 file was successfully loaded.- Note - The - devicemust be open and ready to be read from.- isBlacklisted()¶
- Return type:
- bool 
 
 - Returns - trueif this certificate is blacklisted; otherwise returns- false.- See also - isNull()¶
- Return type:
- bool 
 
 - Returns - trueif this is a null certificate (i.e., a certificate with no contents); otherwise returns- false.- By default, - QSslCertificateconstructs a null certificate.- See also - isSelfSigned()¶
- Return type:
- bool 
 
 - Returns - trueif this certificate is self signed; otherwise returns- false.- A certificate is considered self-signed its issuer and subject are identical. - issuerDisplayName()¶
- Return type:
- str 
 
 - Returns a name that describes the issuer. It returns the - CommonNameif available, otherwise falls back to the first- Organizationor the first- OrganizationalUnitName.- See also - issuerInfo(info)¶
- Parameters:
- info – - SubjectInfo
- Return type:
- list of strings 
 
 - Returns the issuer information for the - subjectfrom the certificate, or an empty list if there is no information for- subjectin the certificate. There can be more than one entry of each type.- See also - issuerInfo(attribute)
- Parameters:
- attribute – - QByteArray
- Return type:
- list of strings 
 
 - Returns the issuer information for - attributefrom the certificate, or an empty list if there is no information for- attributein the certificate. There can be more than one entry for an attribute.- See also - issuerInfoAttributes()¶
- Return type:
- .list of QByteArray 
 
 - Returns a list of the attributes that have values in the issuer information of this certificate. The information associated with a given attribute can be accessed using the - issuerInfo()method. Note that this list may include the OIDs for any elements that are not known by the SSL backend.- See also - __ne__(other)¶
- Parameters:
- other – - QSslCertificate
- Return type:
- bool 
 
 - Returns - trueif this certificate is not the same as- other; otherwise returns- false.- __eq__(other)¶
- Parameters:
- other – - QSslCertificate
- Return type:
- bool 
 
 - Returns - trueif this certificate is the same as- other; otherwise returns- false.- Returns the certificate subject’s public key. - serialNumber()¶
- Return type:
 
 - Returns the certificate’s serial number string in hexadecimal format. - subjectAlternativeNames()¶
- Return type:
- .QMultiMapQSsl.AlternativeNameEntryType,QString 
 
 - Returns the list of alternative subject names for this certificate. The alternative names typically contain host names, optionally with wildcards, that are valid for this certificate. - These names are tested against the connected peer’s host name, if either the subject information for - CommonNamedoesn’t define a valid host name, or the subject info name doesn’t match the peer’s host name.- See also - subjectDisplayName()¶
- Return type:
- str 
 
 - Returns a name that describes the subject. It returns the - CommonNameif available, otherwise falls back to the first- Organizationor the first- OrganizationalUnitName.- See also - subjectInfo(info)¶
- Parameters:
- info – - SubjectInfo
- Return type:
- list of strings 
 
 - Returns the information for the - subject, or an empty list if there is no information for- subjectin the certificate. There can be more than one entry of each type.- See also - subjectInfo(attribute)
- Parameters:
- attribute – - QByteArray
- Return type:
- list of strings 
 
 - Returns the subject information for - attribute, or an empty list if there is no information for- attributein the certificate. There can be more than one entry for an attribute.- See also - subjectInfoAttributes()¶
- Return type:
- .list of QByteArray 
 
 - Returns a list of the attributes that have values in the subject information of this certificate. The information associated with a given attribute can be accessed using the - subjectInfo()method. Note that this list may include the OIDs for any elements that are not known by the SSL backend.- See also - swap(other)¶
- Parameters:
- other – - QSslCertificate
 
 - Swaps this certificate instance with - other. This operation is very fast and never fails.- toDer()¶
- Return type:
 
 - Returns this certificate converted to a DER (binary) encoded representation. - toPem()¶
- Return type:
 
 - Returns this certificate converted to a PEM (Base64) encoded representation. - toText()¶
- Return type:
- str 
 
 - Returns this certificate converted to a human-readable text representation. - static verify(certificateChain[, hostName=""])¶
- Parameters:
- certificateChain – .list of QSslCertificate 
- hostName – str 
 
- Return type:
- .list of QSslError 
 
 - Verifies a certificate chain. The chain to be verified is passed in the - certificateChainparameter. The first certificate in the list should be the leaf certificate of the chain to be verified. If- hostNameis specified then the certificate is also checked to see if it is valid for the specified host name.- Note that the root (CA) certificate should not be included in the list to be verified, this will be looked up automatically using the CA list specified in the default - QSslConfiguration, and, in addition, if possible, CA certificates loaded on demand on Unix and Windows.- version()¶
- Return type:
 
 - Returns the certificate’s version string.