Gio.TlsCertificate¶
| Subclasses: | None |
|---|
Methods¶
| Inherited: | GObject.Object (37) |
|---|---|
| Structs: | GObject.ObjectClass (5) |
| class | list_new_from_file (file) |
| class | new_from_file (file) |
| class | new_from_files (cert_file, key_file) |
| class | new_from_pem (data, length) |
get_issuer () |
|
is_same (cert_two) |
|
verify (identity, trusted_ca) |
Properties¶
| Name | Type | Flags | Short Description |
|---|---|---|---|
certificate |
GLib.ByteArray |
r/w/co | The DER representation of the certificate |
certificate-pem |
str |
r/w/co | The PEM representation of the certificate |
issuer |
Gio.TlsCertificate |
r/w/co | The certificate for the issuing entity |
private-key |
GLib.ByteArray |
w/co | The DER representation of the certificate’s private key |
private-key-pem |
str |
w/co | The PEM representation of the certificate’s private key |
Signals¶
| Inherited: | GObject.Object (1) |
|---|
Class Details¶
-
class
Gio.TlsCertificate(**kwargs)¶ Bases: GObject.ObjectAbstract: Yes Structure: Gio.TlsCertificateClassA certificate used for TLS authentication and encryption. This can represent either a certificate only (eg, the certificate received by a client from a server), or the combination of a certificate and a private key (which is needed when acting as a
Gio.TlsServerConnection).New in version 2.28.
-
classmethod
list_new_from_file(file)[source]¶ Parameters: file ( str) – file containing PEM-encoded certificates to importRaises: GLib.ErrorReturns: a GLib.ListcontainingGio.TlsCertificateobjects. You must free the list and its contents when you are done with it.Return type: [ Gio.TlsCertificate]Creates one or more
Gio.TlsCertificatesfrom the PEM-encoded data in file. If file cannot be read or parsed, the function will returnNoneand set error. If file does not contain any PEM-encoded certificates, this will return an empty list and not set error.New in version 2.28.
-
classmethod
new_from_file(file)[source]¶ Parameters: file ( str) – file containing a PEM-encoded certificate to importRaises: GLib.ErrorReturns: the new certificate, or Noneon errorReturn type: Gio.TlsCertificateCreates a
Gio.TlsCertificatefrom the PEM-encoded data in file. The returned certificate will be the first certificate found in file. As of GLib 2.44, if file contains more certificates it will try to load a certificate chain. All certificates will be verified in the order found (top-level certificate should be the last one in the file) and theGio.TlsCertificate:issuerproperty of each certificate will be set accordingly if the verification succeeds. If any certificate in the chain cannot be verified, the first certificate in the file will still be returned.If file cannot be read or parsed, the function will return
Noneand set error. Otherwise, this behaves likeGio.TlsCertificate.new_from_pem().New in version 2.28.
-
classmethod
new_from_files(cert_file, key_file)[source]¶ Parameters: Raises: Returns: the new certificate, or
Noneon errorReturn type: Creates a
Gio.TlsCertificatefrom the PEM-encoded data in cert_file and key_file. The returned certificate will be the first certificate found in cert_file. As of GLib 2.44, if cert_file contains more certificates it will try to load a certificate chain. All certificates will be verified in the order found (top-level certificate should be the last one in the file) and theGio.TlsCertificate:issuerproperty of each certificate will be set accordingly if the verification succeeds. If any certificate in the chain cannot be verified, the first certificate in the file will still be returned.If either file cannot be read or parsed, the function will return
Noneand set error. Otherwise, this behaves likeGio.TlsCertificate.new_from_pem().New in version 2.28.
-
classmethod
new_from_pem(data, length)[source]¶ Parameters: Raises: Returns: the new certificate, or
Noneif data is invalidReturn type: Creates a
Gio.TlsCertificatefrom the PEM-encoded data in data. If data includes both a certificate and a private key, then the returned certificate will include the private key data as well. (See theGio.TlsCertificate:private-key-pemproperty for information about supported formats.)The returned certificate will be the first certificate found in data. As of GLib 2.44, if data contains more certificates it will try to load a certificate chain. All certificates will be verified in the order found (top-level certificate should be the last one in the file) and the
Gio.TlsCertificate:issuerproperty of each certificate will be set accordingly if the verification succeeds. If any certificate in the chain cannot be verified, the first certificate in the file will still be returned.New in version 2.28.
-
get_issuer()[source]¶ Returns: The certificate of self’s issuer, or Noneif self is self-signed or signed with an unknown certificate.Return type: Gio.TlsCertificateGets the
Gio.TlsCertificaterepresenting self’s issuer, if knownNew in version 2.28.
-
is_same(cert_two)[source]¶ Parameters: cert_two ( Gio.TlsCertificate) – second certificate to compareReturns: whether the same or not Return type: boolCheck if two
Gio.TlsCertificateobjects represent the same certificate. The raw DER byte data of the two certificates are checked for equality. This has the effect that two certificates may compare equal even if theirGio.TlsCertificate:issuer,Gio.TlsCertificate:private-key, orGio.TlsCertificate:private-key-pemproperties differ.New in version 2.34.
-
verify(identity, trusted_ca)[source]¶ Parameters: - identity (
Gio.SocketConnectableorNone) – the expected peer identity - trusted_ca (
Gio.TlsCertificateorNone) – the certificate of a trusted authority
Returns: the appropriate
Gio.TlsCertificateFlagsReturn type: This verifies self and returns a set of
Gio.TlsCertificateFlagsindicating any problems found with it. This can be used to verify a certificate outside the context of making a connection, or to check a certificate against a CA that is not part of the system CA database.If identity is not
None, self’s name(s) will be compared against it, andGio.TlsCertificateFlags.BAD_IDENTITYwill be set in the return value if it does not match. If identity isNone, that bit will never be set in the return value.If trusted_ca is not
None, then self (or one of the certificates in its chain) must be signed by it, or elseGio.TlsCertificateFlags.UNKNOWN_CAwill be set in the return value. If trusted_ca isNone, that bit will never be set in the return value.(All other
Gio.TlsCertificateFlagsvalues will always be set or unset as appropriate.)New in version 2.28.
- identity (
-
do_verify(identity, trusted_ca) virtual¶ Parameters: - identity (
Gio.SocketConnectableorNone) – the expected peer identity - trusted_ca (
Gio.TlsCertificateorNone) – the certificate of a trusted authority
Returns: the appropriate
Gio.TlsCertificateFlagsReturn type: This verifies cert and returns a set of
Gio.TlsCertificateFlagsindicating any problems found with it. This can be used to verify a certificate outside the context of making a connection, or to check a certificate against a CA that is not part of the system CA database.If identity is not
None, cert’s name(s) will be compared against it, andGio.TlsCertificateFlags.BAD_IDENTITYwill be set in the return value if it does not match. If identity isNone, that bit will never be set in the return value.If trusted_ca is not
None, then cert (or one of the certificates in its chain) must be signed by it, or elseGio.TlsCertificateFlags.UNKNOWN_CAwill be set in the return value. If trusted_ca isNone, that bit will never be set in the return value.(All other
Gio.TlsCertificateFlagsvalues will always be set or unset as appropriate.)New in version 2.28.
- identity (
-
classmethod
Property Details¶
-
Gio.TlsCertificate.props.certificate¶ Name: certificateType: GLib.ByteArrayDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe DER (binary) encoded representation of the certificate. This property and the
Gio.TlsCertificate:certificate-pemproperty represent the same data, just in different forms.New in version 2.28.
-
Gio.TlsCertificate.props.certificate_pem¶ Name: certificate-pemType: strDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe PEM (ASCII) encoded representation of the certificate. This property and the
Gio.TlsCertificate:certificateproperty represent the same data, just in different forms.New in version 2.28.
-
Gio.TlsCertificate.props.issuer¶ Name: issuerType: Gio.TlsCertificateDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYA
Gio.TlsCertificaterepresenting the entity that issued this certificate. IfNone, this means that the certificate is either self-signed, or else the certificate of the issuer is not available.New in version 2.28.
-
Gio.TlsCertificate.props.private_key¶ Name: private-keyType: GLib.ByteArrayDefault Value: NoneFlags: WRITABLE,CONSTRUCT_ONLYThe DER (binary) encoded representation of the certificate’s private key, in either PKCS#1 format or unencrypted PKCS#8 format. This property (or the
Gio.TlsCertificate:private-key-pemproperty) can be set when constructing a key (eg, from a file), but cannot be read.PKCS#8 format is supported since 2.32; earlier releases only support PKCS#1. You can use the
openssl rsatool to convert PKCS#8 keys to PKCS#1.New in version 2.28.
-
Gio.TlsCertificate.props.private_key_pem¶ Name: private-key-pemType: strDefault Value: NoneFlags: WRITABLE,CONSTRUCT_ONLYThe PEM (ASCII) encoded representation of the certificate’s private key in either PKCS#1 format (”
BEGIN RSA PRIVATE KEY”) or unencrypted PKCS#8 format (”BEGIN PRIVATE KEY”). This property (or theGio.TlsCertificate:private-keyproperty) can be set when constructing a key (eg, from a file), but cannot be read.PKCS#8 format is supported since 2.32; earlier releases only support PKCS#1. You can use the
openssl rsatool to convert PKCS#8 keys to PKCS#1.New in version 2.28.