Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- Gcr.fingerprint_from_attributes(attrs, checksum_type)[source]¶
- Parameters:
attrs (
Gck.Attributes
) – attributes for key or certificatechecksum_type (
GLib.ChecksumType
) – the type of fingerprint to create
- Returns:
the fingerprint or
None
if the input was invalid.- Return type:
Create a key fingerprint for a certificate, public key or private key. Note that this is not a fingerprint of certificate data, which you would use
Gcr.Certificate.get_fingerprint
() for.
- Gcr.fingerprint_from_subject_public_key_info(key_info, checksum_type)[source]¶
- Parameters:
key_info (
bytes
) – DER encoded subjectPublicKeyInfo structurechecksum_type (
GLib.ChecksumType
) – the type of fingerprint to create
- Returns:
the fingerprint or
None
if the input was invalid.- Return type:
Create a key fingerprint for a DER encoded subjectPublicKeyInfo. The fingerprint is created so that it will be identical for a key and its corresponding certificate.
Note that in the case of certificates this is not a fingerprint of the actual certificate data, but rather of the public key contained in a certificate.
- Gcr.importer_create_for_parsed(parsed)[source]¶
- Parameters:
parsed (
Gcr.Parsed
) – a parser with a parsed item to import- Returns:
a list of importers which can import the parsed item, which should be freed with
GObject.Object.unref
(), orNone
if no types of importers can be created- Return type:
Create a set of importers which can import this parsed item. The parsed item is represented by the state of the
Gcr.Parser
at the time of calling this method.
- Gcr.importer_queue_and_filter_for_parsed(importers, parsed)[source]¶
- Parameters:
importers ([
Gcr.Importer
]) – a set of importersparsed (
Gcr.Parsed
) – a parsed item
- Returns:
a new set of importers that queued the item.
- Return type:
Queues an additional item to be imported in all compattible importers in the set. The parsed item is represented by the state of the
Gcr.Parser
at the time of calling this method.If the parsed item is incompatible with an importer, then that the item will not be queued on that importer.
- Gcr.importer_register(importer_type, attrs)[source]¶
- Parameters:
importer_type (
GObject.GType
) – theGObject.GType
of the importer being registeredattrs (
Gck.Attributes
) – the attributes that this importer is compatible with
Register an importer to handle parsed items that match the given attributes.
- Gcr.mock_prompter_expect_close()[source]¶
Queue an expected response on the mock prompter.
Expects any prompt, and closes the prompt when it gets it.
- Gcr.mock_prompter_expect_confirm_cancel()[source]¶
Queue an expected response on the mock prompter.
Expects a confirmation prompt, and then cancels that prompt.
- Gcr.mock_prompter_expect_password_cancel()[source]¶
Queue an expected response on the mock prompter.
Expects a password prompt, and then cancels that prompt.
- Gcr.mock_prompter_get_delay_msec()[source]¶
- Returns:
the delay
- Return type:
Get the delay in milliseconds before the mock prompter completes an expected prompt.
- Gcr.mock_prompter_is_expecting()[source]¶
- Returns:
whether expecting a prompt
- Return type:
Check if the mock prompter is expecting a response. This will be
True
when one of thegcr_mock_prompter_expect_xxx()
functions have been used to queue an expected prompt, but that prompt response has not be ‘used’ yet.
- Gcr.mock_prompter_is_prompting()[source]¶
- Returns:
whether prompting
- Return type:
Check if the mock prompter is showing any prompts.
- Gcr.mock_prompter_set_delay_msec(delay_msec)[source]¶
- Parameters:
delay_msec (
int
) – prompt response delay in milliseconds
Set the delay in milliseconds before the mock prompter completes an expected prompt.
- Gcr.mock_prompter_start()[source]¶
- Returns:
the bus name that the mock prompter is listening on
- Return type:
Start the mock prompter. This is often used from the
setup()
function of tests.Starts the mock prompter in an additional thread. Use the returned DBus bus name with
Gcr.SystemPrompt.open_for_prompter
() to connect to this prompter.
- Gcr.mock_prompter_stop()[source]¶
Stop the mock prompter. This is often used from the
teardown()
function of tests.
- Gcr.parsed_unref(parsed)[source]¶
-
Unreferences a parsed item which was referenced with
Gcr.Parsed.ref
()
- Gcr.pkcs11_add_module(module)[source]¶
- Parameters:
module (
Gck.Module
) – aGck.Module
Add a
Gck.Module
to the list of PKCS#11 modules that are used by the GCR library.It is not normally necessary to call this function. The available PKCS#11 modules installed on the system are automatically loaded by the GCR library.
- Gcr.pkcs11_add_module_from_file(module_path, unused)[source]¶
- Parameters:
- Raises:
- Returns:
whether the module was sucessfully added.
- Return type:
Initialize a PKCS#11 module and add it to the modules that are used by the GCR library. Note that is an error to initialize the same PKCS#11 module twice.
It is not normally necessary to call this function. The available PKCS#11 modules installed on the system are automatically loaded by the GCR library.
- Gcr.pkcs11_get_modules()[source]¶
- Returns:
a newly allocated list of
Gck.Module
objects- Return type:
List all the PKCS#11 modules that are used by the GCR library. Each module is a [class`Gck`.Module] object.
An empty list of modules will be returned if [func`pkcs11_set_modules`], or [func`pkcs11_initialize`] has not yet run.
- Gcr.pkcs11_get_trust_lookup_slots()[source]¶
- Returns:
a list of
Gck.Slot
objects to use for lookup of trust, or the empty list if not initialized or no appropriate trust stores could be found.- Return type:
[
Gck.Slot
]
List all the PKCS#11 slots that are used by the GCR library for lookup of trust assertions. Each slot is a [class`Gck`.Slot] object.
This will return an empty list if the [func`pkcs11_initialize`] function has not yet been called.
- Gcr.pkcs11_get_trust_lookup_uris()[source]¶
-
Get the PKCS#11 URIs that are used to identify which slots to use for lookup trust assertions.
- Gcr.pkcs11_get_trust_store_slot()[source]¶
- Returns:
the
Gck.Slot
to use for trust assertions, or null if not initialized or no appropriate trust store could be found.- Return type:
Selects an appropriate PKCS#11 slot to store trust assertions. The slot to use is normally configured automatically by the system.
This will only return a valid result after the [func`pkcs11_initialize`] method has been called.
When done with the
Gck.Slot
, useGObject.Object.unref
() to release it.
- Gcr.pkcs11_get_trust_store_uri()[source]¶
-
Get the PKCS#11 URI that is used to identify which slot to use for storing trust storage.
- Gcr.pkcs11_initialize(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optional cancellable used to cancel the operation- Raises:
- Returns:
whether the operation was successful or not.
- Return type:
Asynchronously initialize the registered PKCS#11 modules.
- Gcr.pkcs11_initialize_async(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optional cancellable used to cancel the operationcallback (
Gio.AsyncReadyCallback
orNone
) – callback which will be called when the operation completes
Asynchronously initialize the registered PKCS#11 modules.
- Gcr.pkcs11_initialize_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – the asynchronous result- Raises:
- Returns:
whether the operation was successful or not.
- Return type:
Complete the asynchronous operation to initialize the registered PKCS#11 modules.
- Gcr.pkcs11_set_modules(modules)[source]¶
- Parameters:
modules ([
Gck.Module
]) – a list of PKCS#11 modules
Set the list of PKCS#11 modules that are used by the GCR library. Each module in the list is a [class`Gck`.Module] object.
It is not normally necessary to call this function. The available PKCS#11 modules installed on the system are automatically loaded by the GCR library.
- Gcr.pkcs11_set_trust_lookup_uris(pkcs11_uris)[source]¶
-
Set the PKCS#11 URIs that are used to identify which slots to use for lookup of trust assertions.
It is not normally necessary to call this function. The relevant PKCS#11 slots are automatically configured by the GCR library.
- Gcr.pkcs11_set_trust_store_uri(pkcs11_uri)[source]¶
-
Set the PKCS#11 URI that is used to identify which slot to use for storing trust assertions.
It is not normally necessary to call this function. The relevant PKCS#11 slot is automatically configured by the GCR library.
- Gcr.trust_add_pinned_certificate(certificate, purpose, peer, cancellable)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
purpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinned certificatecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
True
if the pinned certificate is recorded successfully- Return type:
Add a pinned certificate for connections to peer for purpose. A pinned certificate overrides all other certificate verification and should be used with care.
If the same pinned certificate already exists, then this operation does not add another, and succeeds without error.
This call may block, see
Gcr.trust_add_pinned_certificate_async
() for the non-blocking version.
- Gcr.trust_add_pinned_certificate_async(certificate, purpose, peer, cancellable, callback, *user_data)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
purpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinned certificatecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation completesuser_data (
object
orNone
) – the data to pass to callback function
Add a pinned certificate for communication with peer for purpose. A pinned certificate overrides all other certificate verification and should be used with care.
If the same pinned certificate already exists, then this operation does not add another, and succeeds without error.
When the operation is finished, callback will be called. You can then call [func`Gcr`.trust_add_pinned_certificate_finish] to get the result of the operation.
- Gcr.trust_add_pinned_certificate_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to the callback- Raises:
- Returns:
True
if the pinned certificate is recorded successfully- Return type:
Finishes an asynchronous operation started by
Gcr.trust_add_pinned_certificate_async
().
- Gcr.trust_is_certificate_anchored(certificate, purpose, cancellable)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
to checkpurpose (
str
) – the purpose stringcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
True
if the certificate is a trust anchor- Return type:
Check if the certificate is a trust anchor for the given purpose. A trust anchor is used to verify the signatures on other certificates when verifying a certificate chain. Also known as a trusted certificate authority.
This call may block, see [func`Gcr`.trust_is_certificate_anchored_async] for the non-blocking version.
In the case of an error,
False
is also returned. Check error to detect if an error occurred.
- Gcr.trust_is_certificate_anchored_async(certificate, purpose, cancellable, callback, *user_data)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
to checkpurpose (
str
) – the purpose stringcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation completesuser_data (
object
orNone
) – the data to pass to callback function
Check if the certificate is a trust anchor for the given purpose. A trust anchor is used to verify the signatures on other certificates when verifying a certificate chain. Also known as a trusted certificate authority.
When the operation is finished, callback will be called. You can then call
Gcr.trust_is_certificate_anchored_finish
() to get the result of the operation.
- Gcr.trust_is_certificate_anchored_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to the callback- Raises:
- Returns:
True
if the certificate is a trust anchor- Return type:
Finishes an asynchronous operation started by
Gcr.trust_is_certificate_anchored_async
().In the case of an error,
False
is also returned. Check error to detect if an error occurred.
- Gcr.trust_is_certificate_distrusted(serial_nr, issuer, cancellable)[source]¶
- Parameters:
serial_nr (
bytes
) – The serial number of the certificateissuer (
bytes
) – The raw issuercancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
True
if the certificate is marked as distrusted- Return type:
Checks whether the certificate that can be uniquely identified with the given serial_nr and issuer is marked as distrusted (for example by the user, or because it’s part of a CRL).
Since we can’t directly use [iface`Certificate`] to fetch these values, you need to call these with the raw serial number and issuer as provided by the PKCS#11 fields
CKA_SERIAL_NR
andCKA_ISSUER
.
- Gcr.trust_is_certificate_distrusted_async(serial_nr, issuer, cancellable, callback, *user_data)[source]¶
- Parameters:
serial_nr (
bytes
) – The serial number of the certificateissuer (
bytes
) – The raw issuercancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation completesuser_data (
object
orNone
) – the data to pass to callback function
Asynchronously checks whether the certificate that can be uniquely identified with the given serial_nr and issuer is marked as distrusted (for example by the user, or because it’s part of a CRL).
Since we can’t directly use [iface`Certificate`] to fetch these values, you need to call these with the raw serial number and issuer as provided by the PKCS#11 fields
CKA_SERIAL_NR
andCKA_ISSUER
.When the operation is finished, callback will be called. You can then call [func`trust_is_certificate_distrusted_finish`] to get the result of the operation.
- Gcr.trust_is_certificate_distrusted_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to the callback- Raises:
- Returns:
True
if the certificate is a trust anchor- Return type:
Finishes an asynchronous operation started by [func`trust_is_certificate_distrusted_async`].
In the case of an error,
False
is also returned. Check error to detect if an error occurred.
- Gcr.trust_is_certificate_pinned(certificate, purpose, peer, cancellable)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
to checkpurpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinnedcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
True
if the certificate is pinned for the host and purpose- Return type:
Check if certificate is pinned for purpose to communicate with peer. A pinned certificate overrides all other certificate verification.
This call may block, see
Gcr.trust_is_certificate_pinned_async
() for the non-blocking version.In the case of an error,
False
is also returned. Check error to detect if an error occurred.
- Gcr.trust_is_certificate_pinned_async(certificate, purpose, peer, cancellable, callback, *user_data)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
to checkpurpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinnedcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation completesuser_data (
object
orNone
) – the data to pass to callback function
Check if certificate is pinned for purpose to communicate with peer. A pinned certificate overrides all other certificate verification.
When the operation is finished, callback will be called. You can then call [func`Gcr`.trust_is_certificate_pinned_finish] to get the result of the operation.
- Gcr.trust_is_certificate_pinned_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to the callback- Raises:
- Returns:
True
if the certificate is pinned.- Return type:
Finishes an asynchronous operation started by
Gcr.trust_is_certificate_pinned_async
().In the case of an error,
False
is also returned. Check error to detect if an error occurred.
- Gcr.trust_remove_pinned_certificate(certificate, purpose, peer, cancellable)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
purpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinned certificatecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
True
if the pinned certificate no longer exists- Return type:
Remove a pinned certificate for communication with peer for purpose.
If the same pinned certificate does not exist, or was already removed, then this operation succeeds without error.
This call may block, see
Gcr.trust_remove_pinned_certificate_async
() for the non-blocking version.
- Gcr.trust_remove_pinned_certificate_async(certificate, purpose, peer, cancellable, callback, *user_data)[source]¶
- Parameters:
certificate (
Gcr.Certificate
) – aGcr.Certificate
purpose (
str
) – the purpose stringpeer (
str
) – the peer for this pinned certificatecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation completesuser_data (
object
orNone
) – the data to pass to callback function
Remove a pinned certificate for communication with peer for purpose.
If the same pinned certificate does not exist, or was already removed, then this operation succeeds without error.
When the operation is finished, callback will be called. You can then call
Gcr.trust_remove_pinned_certificate_finish
() to get the result of the operation.
- Gcr.trust_remove_pinned_certificate_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to the callback- Raises:
- Returns:
True
if the pinned certificate no longer exists- Return type:
Finishes an asynchronous operation started by
Gcr.trust_remove_pinned_certificate_async
().