QSslCertificate¶
The QSslCertificate
class provides a convenient API for an X509 certificate. More…

Synopsis¶
Functions¶
def
__eq__
(other)def
__ne__
(other)def
clear
()def
digest
([algorithm=QCryptographicHash.Md5])def
effectiveDate
()def
expiryDate
()def
extensions
()def
handle
()def
isBlacklisted
()def
isNull
()def
isSelfSigned
()def
issuerDisplayName
()def
issuerInfo
(attribute)def
issuerInfo
(info)def
issuerInfoAttributes
()def
publicKey
()def
serialNumber
()def
subjectAlternativeNames
()def
subjectDisplayName
()def
subjectInfo
(attribute)def
subjectInfo
(info)def
subjectInfoAttributes
()def
swap
(other)def
toDer
()def
toPem
()def
toText
()def
version
()
Static functions¶
def
fromData
(data[, format=QSsl.Pem])def
fromDevice
(device[, format=QSsl.Pem])def
fromPath
(path[, format=QSsl.Pem[, syntax=PatternSyntax.FixedString]])def
importPkcs12
(device, key, cert[, caCertificates=None[, passPhrase=QByteArray()]])def
verify
(certificateChain[, hostName=””])
Detailed Description¶
QSslCertificate
stores 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 QSslCertificate
object, 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 to check if your certificate is null. By default, QSslCertificate
constructs 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 , , and . You can call and to check when the certificate starts being effective and when it expires. The function returns the certificate subject’s public key as a QSslKey
. You can call or to get detailed information about the certificate issuer and its subject.
Internally, QSslCertificate
is stored as an X509 structure. You can access this handle by calling , but the results are likely to not be portable.
See also
-
class
PySide6.QtNetwork.
QSslCertificate
(device[, format=QSsl.Pem])¶ PySide6.QtNetwork.QSslCertificate([data=QByteArray()[, format=QSsl.Pem]])
PySide6.QtNetwork.QSslCertificate(other)
- Parameters
data –
PySide6.QtCore.QByteArray
device –
PySide6.QtCore.QIODevice
format –
EncodingFormat
Constructs a QSslCertificate
by reading format
encoded data from device
and using the first certificate found. You can later call to see if device
contained a certificate, and if this certificate was loaded successfully.
Constructs an identical copy of other
.
-
PySide6.QtNetwork.QSslCertificate.
SubjectInfo
¶
Describes keys that you can pass to or to get information about the certificate issuer or subject.
Constant
Description
QSslCertificate.Organization
“O” The name of the organization.
QSslCertificate.CommonName
“CN” The common name; most often this is used to store the host name.
QSslCertificate.LocalityName
“L” The locality.
QSslCertificate.OrganizationalUnitName
“OU” The organizational unit name.
QSslCertificate.CountryName
“C” The country.
QSslCertificate.StateOrProvinceName
“ST” The state or province.
QSslCertificate.DistinguishedNameQualifier
The distinguished name qualifier
QSslCertificate.SerialNumber
The certificate’s serial number
QSslCertificate.EmailAddress
The email address associated with the certificate
-
PySide6.QtNetwork.QSslCertificate.
PatternSyntax
¶
The syntax used to interpret the meaning of the pattern.
Constant
Description
QSslCertificate.PatternSyntax.RegularExpression
A rich Perl-like pattern matching syntax.
QSslCertificate.PatternSyntax.Wildcard
This provides a simple pattern matching syntax similar to that used by shells (command interpreters) for “file globbing”. See QRegularExpression Wildcard Matching .
QSslCertificate.PatternSyntax.FixedString
The pattern is a fixed string. This is equivalent to using the pattern on a string in which all metacharacters are escaped using escape(). This is the default.
New in version 5.15.
-
PySide6.QtNetwork.QSslCertificate.
clear
()¶
Clears the contents of this certificate, making it a null certificate.
See also
-
PySide6.QtNetwork.QSslCertificate.
digest
([algorithm=QCryptographicHash.Md5])¶ - Parameters
algorithm –
Algorithm
- Return type
Returns a cryptographic digest of this certificate. By default, an MD5 digest will be generated, but you can also specify a custom algorithm
.
-
PySide6.QtNetwork.QSslCertificate.
effectiveDate
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
expiryDate
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
extensions
()¶ - Return type
-
static
PySide6.QtNetwork.QSslCertificate.
fromData
(data[, format=QSsl.Pem])¶ - Parameters
data –
PySide6.QtCore.QByteArray
format –
EncodingFormat
- Return type
Searches for and parses all certificates in data
that are encoded in the specified format
and returns them in a list of certificates.
See also
-
static
PySide6.QtNetwork.QSslCertificate.
fromDevice
(device[, format=QSsl.Pem])¶ - Parameters
device –
PySide6.QtCore.QIODevice
format –
EncodingFormat
- Return type
Searches for and parses all certificates in device
that are encoded in the specified format
and returns them in a list of certificates.
See also
-
static
PySide6.QtNetwork.QSslCertificate.
fromPath
(path[, format=QSsl.Pem[, syntax=PatternSyntax.FixedString]])¶ - Parameters
path – str
format –
EncodingFormat
syntax –
PatternSyntax
- Return type
Searches all files in the path
for certificates encoded in the specified format
and returns them in a list. path
must be a file or a pattern matching one or more files, as specified by syntax
.
Example:
const auto certs = QSslCertificate::fromPath("C:/ssl/certificate.*.pem", QSsl::Pem, QSslCertificate::Wildcard); for (const QSslCertificate &cert : certs) { qDebug() << cert.issuerInfo(QSslCertificate::Organization); }See also
-
PySide6.QtNetwork.QSslCertificate.
handle
()¶ - Return type
Qt::HANDLE
-
static
PySide6.QtNetwork.QSslCertificate.
importPkcs12
(device, key, cert[, caCertificates=None[, passPhrase=QByteArray()]])¶ - Parameters
device –
PySide6.QtCore.QIODevice
caCertificates –
QList
passPhrase –
PySide6.QtCore.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 certificate
and any associated caCertificates
from the bundle. If a passPhrase
is specified then this will be used to decrypt the bundle. Returns true
if the PKCS#12 file was successfully loaded.
Note
The device
must be open and ready to be read from.
-
PySide6.QtNetwork.QSslCertificate.
isBlacklisted
()¶ - Return type
bool
Returns true
if this certificate is blacklisted; otherwise returns false
.
See also
-
PySide6.QtNetwork.QSslCertificate.
isNull
()¶ - Return type
bool
-
PySide6.QtNetwork.QSslCertificate.
isSelfSigned
()¶ - Return type
bool
-
PySide6.QtNetwork.QSslCertificate.
issuerDisplayName
()¶ - Return type
str
Returns a name that describes the issuer. It returns the CommonName
if available, otherwise falls back to the first Organization
or the first OrganizationalUnitName
.
See also
-
PySide6.QtNetwork.QSslCertificate.
issuerInfo
(attribute)¶ - Parameters
attribute –
PySide6.QtCore.QByteArray
- Return type
list of strings
-
PySide6.QtNetwork.QSslCertificate.
issuerInfo
(info) - Parameters
info –
SubjectInfo
- Return type
list of strings
-
PySide6.QtNetwork.QSslCertificate.
issuerInfoAttributes
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
__ne__
(other)¶ - Parameters
- Return type
bool
-
PySide6.QtNetwork.QSslCertificate.
__eq__
(other)¶ - Parameters
- Return type
bool
-
PySide6.QtNetwork.QSslCertificate.
publicKey
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
serialNumber
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
subjectAlternativeNames
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
subjectDisplayName
()¶ - Return type
str
Returns a name that describes the subject. It returns the CommonName
if available, otherwise falls back to the first Organization
or the first OrganizationalUnitName
.
See also
-
PySide6.QtNetwork.QSslCertificate.
subjectInfo
(info)¶ - Parameters
info –
SubjectInfo
- Return type
list of strings
-
PySide6.QtNetwork.QSslCertificate.
subjectInfo
(attribute) - Parameters
attribute –
PySide6.QtCore.QByteArray
- Return type
list of strings
-
PySide6.QtNetwork.QSslCertificate.
subjectInfoAttributes
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
swap
(other)¶ - Parameters
-
PySide6.QtNetwork.QSslCertificate.
toDer
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
toPem
()¶ - Return type
-
PySide6.QtNetwork.QSslCertificate.
toText
()¶ - Return type
str
-
static
PySide6.QtNetwork.QSslCertificate.
verify
(certificateChain[, hostName=""])¶ - Parameters
certificateChain –
hostName – str
- Return type
Verifies a certificate chain. The chain to be verified is passed in the certificateChain
parameter. The first certificate in the list should be the leaf certificate of the chain to be verified. If hostName
is 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.
-
PySide6.QtNetwork.QSslCertificate.
version
()¶ - Return type
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.