Top |
Functions
Properties
GByteArray * | certificate | Read / Write / Construct Only |
gchar * | certificate-pem | Read / Write / Construct Only |
GTlsCertificate * | issuer | Read / Write / Construct Only |
GByteArray * | private-key | Write / Construct Only |
gchar * | private-key-pem | Write / Construct Only |
Description
A 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 GTlsServerConnection).
Functions
g_tls_certificate_new_from_pem ()
GTlsCertificate * g_tls_certificate_new_from_pem (const gchar *data
,gssize length
,GError **error
);
Creates a GTlsCertificate from 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
the “private-key-pem” property 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 “issuer” property 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.
Since 2.28
g_tls_certificate_new_from_file ()
GTlsCertificate * g_tls_certificate_new_from_file (const gchar *file
,GError **error
);
Creates a GTlsCertificate from 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
the “issuer” property 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 NULL
and
set error
. Otherwise, this behaves like
g_tls_certificate_new_from_pem()
.
Since 2.28
g_tls_certificate_new_from_files ()
GTlsCertificate * g_tls_certificate_new_from_files (const gchar *cert_file
,const gchar *key_file
,GError **error
);
Creates a GTlsCertificate from 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 the
“issuer” property 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
NULL
and set error
. Otherwise, this behaves like
g_tls_certificate_new_from_pem()
.
Since 2.28
g_tls_certificate_list_new_from_file ()
GList * g_tls_certificate_list_new_from_file (const gchar *file
,GError **error
);
Creates one or more GTlsCertificates from the PEM-encoded
data in file
. If file
cannot be read or parsed, the function will
return NULL
and set error
. If file
does not contain any
PEM-encoded certificates, this will return an empty list and not
set error
.
Returns
a GList containing GTlsCertificate objects. You must free the list and its contents when you are done with it.
[element-type Gio.TlsCertificate][transfer full]
Since 2.28
g_tls_certificate_get_issuer ()
GTlsCertificate *
g_tls_certificate_get_issuer (GTlsCertificate *cert
);
Gets the GTlsCertificate representing cert
's issuer, if known
Returns
The certificate of cert
's issuer,
or NULL
if cert
is self-signed or signed with an unknown
certificate.
[transfer none]
Since 2.28
g_tls_certificate_verify ()
GTlsCertificateFlags g_tls_certificate_verify (GTlsCertificate *cert
,GSocketConnectable *identity
,GTlsCertificate *trusted_ca
);
This verifies cert
and returns a set of GTlsCertificateFlags
indicating 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 NULL
, cert
's name(s) will be compared against
it, and G_TLS_CERTIFICATE_BAD_IDENTITY
will be set in the return
value if it does not match. If identity
is NULL
, that bit will
never be set in the return value.
If trusted_ca
is not NULL
, then cert
(or one of the certificates
in its chain) must be signed by it, or else
G_TLS_CERTIFICATE_UNKNOWN_CA
will be set in the return value. If
trusted_ca
is NULL
, that bit will never be set in the return
value.
(All other GTlsCertificateFlags values will always be set or unset as appropriate.)
Parameters
cert |
||
identity |
the expected peer identity. |
[allow-none] |
trusted_ca |
the certificate of a trusted authority. |
[allow-none] |
Since 2.28
g_tls_certificate_is_same ()
gboolean g_tls_certificate_is_same (GTlsCertificate *cert_one
,GTlsCertificate *cert_two
);
Check if two GTlsCertificate objects 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 their “issuer”, “private-key”, or “private-key-pem” properties differ.
Since 2.34
Property Details
The “certificate”
property
“certificate” GByteArray *
The DER (binary) encoded representation of the certificate. This property and the “certificate-pem” property represent the same data, just in different forms.
Flags: Read / Write / Construct Only
Since 2.28
The “certificate-pem”
property
“certificate-pem” gchar *
The PEM (ASCII) encoded representation of the certificate. This property and the “certificate” property represent the same data, just in different forms.
Flags: Read / Write / Construct Only
Default value: NULL
Since 2.28
The “issuer”
property
“issuer” GTlsCertificate *
A GTlsCertificate representing the entity that issued this
certificate. If NULL
, this means that the certificate is either
self-signed, or else the certificate of the issuer is not
available.
Flags: Read / Write / Construct Only
Since 2.28
The “private-key”
property
“private-key” GByteArray *
The DER (binary) encoded representation of the certificate's private key, in either PKCS#1 format or unencrypted PKCS#8 format. This property (or the “private-key-pem” property) 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 rsa
tool to convert PKCS#8 keys to PKCS#1.
Flags: Write / Construct Only
Since 2.28
The “private-key-pem”
property
“private-key-pem” gchar *
The 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 the
“private-key” property) 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 rsa
tool to convert PKCS#8 keys to PKCS#1.
Flags: Write / Construct Only
Default value: NULL
Since 2.28