class Gio::TlsCertificate
- Gio::TlsCertificate
- GObject::Object
- Reference
- Object
Overview
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).
Defined in:
lib/gi-crystal/src/auto/gio-2.0/tls_certificate.crConstructors
-
.new
Initialize a new
TlsCertificate
. - .new(*, certificate : Enumerable(UInt8)? = nil, certificate_pem : String? = nil, dns_names : Enumerable(Pointer(Void))? = nil, ip_addresses : Enumerable(Pointer(Void))? = nil, issuer : Gio::TlsCertificate? = nil, issuer_name : String? = nil, not_valid_after : GLib::DateTime? = nil, not_valid_before : GLib::DateTime? = nil, password : String? = nil, pkcs11_uri : String? = nil, pkcs12_data : Enumerable(UInt8)? = nil, private_key : Enumerable(UInt8)? = nil, private_key_pem : String? = nil, private_key_pkcs11_uri : String? = nil, subject_name : String? = nil)
-
.new_from_file(file : String) : self
Creates a #GTlsCertificate from the data in @file.
-
.new_from_file_with_password(file : String, password : String) : self
Creates a #GTlsCertificate from the data in @file.
-
.new_from_files(cert_file : String, key_file : String) : self
Creates a #GTlsCertificate from the PEM-encoded data in @cert_file and @key_file.
-
.new_from_pem(data : String, length : Int64) : self
Creates a #GTlsCertificate from the PEM-encoded data in @data.
-
.new_from_pkcs11_uris(pkcs11_uri : String, private_key_pkcs11_uri : String?) : self
Creates a #GTlsCertificate from a PKCS #11 URI.
-
.new_from_pkcs12(data : Enumerable(UInt8), password : String?) : self
Creates a #GTlsCertificate from the data in @data.
Class Method Summary
-
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
- #certificate : Enumerable(UInt8)
- #certificate=(value : Enumerable(UInt8)) : Enumerable(UInt8)
- #certificate_pem : String
- #certificate_pem=(value : String) : String
-
#dns_names : Enumerable(GLib::Bytes)?
Gets the value of #GTlsCertificate:dns-names.
-
#ip_addresses : Enumerable(Gio::InetAddress)?
Gets the value of #GTlsCertificate:ip-addresses.
-
#is_same(cert_two : Gio::TlsCertificate) : Bool
Check if two #GTlsCertificate objects represent the same certificate.
-
#issuer : Gio::TlsCertificate?
Gets the #GTlsCertificate representing @cert's issuer, if known
- #issuer=(value : Gio::TlsCertificate?) : Gio::TlsCertificate?
-
#issuer_name : String?
Returns the issuer name from the certificate.
- #list_new_from_file(file : String) : GLib::List
-
#not_valid_after : GLib::DateTime?
Returns the time at which the certificate became or will become invalid.
-
#not_valid_before : GLib::DateTime?
Returns the time at which the certificate became or will become valid.
- #password=(value : String) : String
- #pkcs11_uri : String
- #pkcs11_uri=(value : String) : String
- #pkcs12_data=(value : Enumerable(UInt8)) : Enumerable(UInt8)
- #private_key : Enumerable(UInt8)
- #private_key=(value : Enumerable(UInt8)) : Enumerable(UInt8)
- #private_key_pem : String
- #private_key_pem=(value : String) : String
- #private_key_pkcs11_uri : String
- #private_key_pkcs11_uri=(value : String) : String
-
#subject_name : String?
Returns the subject name from the certificate.
-
#verify(identity : Gio::SocketConnectable?, trusted_ca : Gio::TlsCertificate?) : Gio::TlsCertificateFlags
This verifies @cert and returns a set of #GTlsCertificateFlags indicating any problems found with it.
Instance methods inherited from class GObject::Object
bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding
bind_property,
bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding
bind_property_full,
data(key : String) : Pointer(Void)?
data,
finalize
finalize,
freeze_notify : Nil
freeze_notify,
getv(names : Enumerable(String), values : Enumerable(_)) : Nil
getv,
notify(property_name : String) : Nil
notify,
notify_by_pspec(pspec : GObject::ParamSpec) : Nil
notify_by_pspec,
notify_signal
notify_signal,
property(property_name : String, value : _) : Nil
property,
qdata(quark : UInt32) : Pointer(Void)?
qdata,
ref_count : UInt32
ref_count,
run_dispose : Nil
run_dispose,
set_data(key : String, data : Pointer(Void)?) : Nil
set_data,
set_property(property_name : String, value : _) : Nil
set_property,
steal_data(key : String) : Pointer(Void)?
steal_data,
steal_qdata(quark : UInt32) : Pointer(Void)?
steal_qdata,
thaw_notify : Nil
thaw_notify,
to_unsafe : Pointer(Void)
to_unsafe,
watch_closure(closure : GObject::Closure) : Nil
watch_closure
Constructor methods inherited from class GObject::Object
cast(obj : GObject::Object) : self
cast,
cast?(obj : GObject::Object) : self?
cast?,
new(pointer : Pointer(Void), transfer : GICrystal::Transfer)new new, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv
Class methods inherited from class GObject::Object
compat_control(what : UInt64, data : Pointer(Void)?) : UInt64
compat_control,
g_type : UInt64
g_type,
interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec
interface_find_property,
interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec)
interface_list_properties
Constructor Detail
Creates a #GTlsCertificate from the data in @file.
As of 2.72, if the filename ends in .p12
or .pfx
the data is loaded by
g_tls_certificate_new_from_pkcs12() otherwise it is loaded by
g_tls_certificate_new_from_pem(). See those functions for
exact details.
If @file cannot be read or parsed, the function will return nil
and
set @error.
Creates a #GTlsCertificate from the data in @file.
If @file cannot be read or parsed, the function will return nil
and
set @error.
Any unknown file types will error with %G_IO_ERROR_NOT_SUPPORTED.
Currently only .p12
and .pfx
files are supported.
See g_tls_certificate_new_from_pkcs12() for more details.
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 #GTlsCertificate: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
nil
and set @error. Otherwise, this behaves like
g_tls_certificate_new_from_pem().
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 #GTlsCertificate: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 #GTlsCertificate: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.
Creates a #GTlsCertificate from a PKCS #11 URI.
An example @pkcs11_uri would be pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My%20Client%20Certificate;id=%01
Where the token’s layout is:
|[ Object 0: URL: pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My%20Client%20Certificate;id=%01;object=private%20key;type=private Type: Private key (RSA-2048) ID: 01
Object 1: URL: pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My%20Client%20Certificate;id=%01;object=Certificate%20for%20Authentication;type=cert Type: X.509 Certificate (RSA-2048) ID: 01 ]|
In this case the certificate and private key would both be detected and used as expected. @pkcs_uri may also just reference an X.509 certificate object and then optionally @private_key_pkcs11_uri allows using a private key exposed under a different URI.
Note that the private key is not accessed until usage and may fail or require a PIN later.
Creates a #GTlsCertificate from the data in @data. It must contain a certificate and matching private key.
If extra certificates are included they will be verified as a chain and the #GTlsCertificate:issuer property will be set. All other data will be ignored.
You can pass as single password for all of the data which will be used both for the PKCS #12 container as well as encrypted private keys. If decryption fails it will error with %G_TLS_ERROR_BAD_CERTIFICATE_PASSWORD.
This constructor requires support in the current #GTlsBackend. If support is missing it will error with %G_IO_ERROR_NOT_SUPPORTED.
Other parsing failures will error with %G_TLS_ERROR_BAD_CERTIFICATE.
Class Method Detail
Instance Method Detail
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 #GTlsCertificate:issuer, #GTlsCertificate:private-key, or #GTlsCertificate:private-key-pem properties differ.
Returns the time at which the certificate became or will become invalid.
Returns the time at which the certificate became or will become valid.
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 @cert is valid, %G_TLS_CERTIFICATE_NO_FLAGS is returned.
If @identity is not nil
, @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 nil
, that bit will
never be set in the return value.
If @trusted_ca is not nil
, 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 nil
, that bit will never be set in the return
value.
GLib guarantees that if certificate verification fails, at least one error will be set in the return value, but it does not guarantee that all possible errors will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask %G_TLS_CERTIFICATE_EXPIRED if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate.
Because TLS session context is not used, #GTlsCertificate may not perform as many checks on the certificates as #GTlsConnection would. For example, certificate constraints may not be honored, and revocation checks may not be performed. The best way to verify TLS certificates used by a TLS connection is to let #GTlsConnection handle the verification.