TlsInteraction

Added in version 2.30.

class TlsInteraction(**properties: Any)

Superclasses: Object

GTlsInteraction provides a mechanism for the TLS connection and database code to interact with the user. It can be used to ask the user for passwords.

To use a GTlsInteraction with a TLS connection use set_interaction.

Callers should instantiate a derived class that implements the various interaction methods to show the required dialogs.

Callers should use the ‘invoke’ functions like invoke_ask_password to run interaction methods. These functions make sure that the interaction is invoked in the main loop and not in the current thread, if the current thread is not running the main loop.

Derived classes can choose to implement whichever interactions methods they’d like to support by overriding those virtual methods in their class initialization function. Any interactions not implemented will return G_TLS_INTERACTION_UNHANDLED. If a derived class implements an async method, it must also implement the corresponding finish method.

Methods

class TlsInteraction
ask_password(password: TlsPassword, cancellable: Cancellable | None = None) TlsInteractionResult

Run synchronous interaction to ask the user for a password. In general, invoke_ask_password() should be used instead of this function.

Derived subclasses usually implement a password prompt, although they may also choose to provide a password from elsewhere. The password value will be filled in and then callback will be called. Alternatively the user may abort this password request, which will usually abort the TLS connection.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.30.

Parameters:
ask_password_async(password: TlsPassword, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Run asynchronous interaction to ask the user for a password. In general, invoke_ask_password() should be used instead of this function.

Derived subclasses usually implement a password prompt, although they may also choose to provide a password from elsewhere. The password value will be filled in and then callback will be called. Alternatively the user may abort this password request, which will usually abort the TLS connection.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Certain implementations may not support immediate cancellation.

Added in version 2.30.

Parameters:
  • password – a TlsPassword object

  • cancellable – an optional Cancellable cancellation object

  • callback – will be called when the interaction completes

  • user_data – data to pass to the callback

ask_password_finish(result: AsyncResult) TlsInteractionResult

Complete an ask password user interaction request. This should be once the ask_password_async() completion callback is called.

If HANDLED is returned, then the TlsPassword passed to ask_password() will have its password filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code.

Added in version 2.30.

Parameters:

result – the result passed to the callback

invoke_ask_password(password: TlsPassword, cancellable: Cancellable | None = None) TlsInteractionResult

Invoke the interaction to ask the user for a password. It invokes this interaction in the main loop, specifically the MainContext returned by get_thread_default() when the interaction is created. This is called by called by TlsConnection or TlsDatabase to ask the user for a password.

Derived subclasses usually implement a password prompt, although they may also choose to provide a password from elsewhere. The password value will be filled in and then callback will be called. Alternatively the user may abort this password request, which will usually abort the TLS connection.

The implementation can either be a synchronous (eg: modal dialog) or an asynchronous one (eg: modeless dialog). This function will take care of calling which ever one correctly.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.30.

Parameters:
invoke_request_certificate(connection: TlsConnection, flags: TlsCertificateRequestFlags, cancellable: Cancellable | None = None) TlsInteractionResult

Invoke the interaction to ask the user to choose a certificate to use with the connection. It invokes this interaction in the main loop, specifically the MainContext returned by get_thread_default() when the interaction is created. This is called by called by TlsConnection when the peer requests a certificate during the handshake.

Derived subclasses usually implement a certificate selector, although they may also choose to provide a certificate from elsewhere. Alternatively the user may abort this certificate request, which may or may not abort the TLS connection.

The implementation can either be a synchronous (eg: modal dialog) or an asynchronous one (eg: modeless dialog). This function will take care of calling which ever one correctly.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.40.

Parameters:
  • connection – a TlsConnection object

  • flags – flags providing more information about the request

  • cancellable – an optional Cancellable cancellation object

request_certificate(connection: TlsConnection, flags: TlsCertificateRequestFlags, cancellable: Cancellable | None = None) TlsInteractionResult

Run synchronous interaction to ask the user to choose a certificate to use with the connection. In general, invoke_request_certificate() should be used instead of this function.

Derived subclasses usually implement a certificate selector, although they may also choose to provide a certificate from elsewhere. Alternatively the user may abort this certificate request, which will usually abort the TLS connection.

If HANDLED is returned, then the TlsConnection passed to request_certificate() will have had its TlsConnection:certificate filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.40.

Parameters:
  • connection – a TlsConnection object

  • flags – flags providing more information about the request

  • cancellable – an optional Cancellable cancellation object

request_certificate_async(connection: TlsConnection, flags: TlsCertificateRequestFlags, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Run asynchronous interaction to ask the user for a certificate to use with the connection. In general, invoke_request_certificate() should be used instead of this function.

Derived subclasses usually implement a certificate selector, although they may also choose to provide a certificate from elsewhere. callback will be called when the operation completes. Alternatively the user may abort this certificate request, which will usually abort the TLS connection.

Added in version 2.40.

Parameters:
  • connection – a TlsConnection object

  • flags – flags providing more information about the request

  • cancellable – an optional Cancellable cancellation object

  • callback – will be called when the interaction completes

  • user_data – data to pass to the callback

request_certificate_finish(result: AsyncResult) TlsInteractionResult

Complete a request certificate user interaction request. This should be once the request_certificate_async() completion callback is called.

If HANDLED is returned, then the TlsConnection passed to request_certificate_async() will have had its TlsConnection:certificate filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code.

Added in version 2.40.

Parameters:

result – the result passed to the callback

Virtual Methods

class TlsInteraction
do_ask_password(password: TlsPassword, cancellable: Cancellable | None = None) TlsInteractionResult

Run synchronous interaction to ask the user for a password. In general, invoke_ask_password() should be used instead of this function.

Derived subclasses usually implement a password prompt, although they may also choose to provide a password from elsewhere. The password value will be filled in and then callback will be called. Alternatively the user may abort this password request, which will usually abort the TLS connection.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.30.

Parameters:
do_ask_password_async(password: TlsPassword, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Run asynchronous interaction to ask the user for a password. In general, invoke_ask_password() should be used instead of this function.

Derived subclasses usually implement a password prompt, although they may also choose to provide a password from elsewhere. The password value will be filled in and then callback will be called. Alternatively the user may abort this password request, which will usually abort the TLS connection.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Certain implementations may not support immediate cancellation.

Added in version 2.30.

Parameters:
  • password – a TlsPassword object

  • cancellable – an optional Cancellable cancellation object

  • callback – will be called when the interaction completes

  • user_data – data to pass to the callback

do_ask_password_finish(result: AsyncResult) TlsInteractionResult

Complete an ask password user interaction request. This should be once the ask_password_async() completion callback is called.

If HANDLED is returned, then the TlsPassword passed to ask_password() will have its password filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code.

Added in version 2.30.

Parameters:

result – the result passed to the callback

do_request_certificate(connection: TlsConnection, flags: TlsCertificateRequestFlags, cancellable: Cancellable | None = None) TlsInteractionResult

Run synchronous interaction to ask the user to choose a certificate to use with the connection. In general, invoke_request_certificate() should be used instead of this function.

Derived subclasses usually implement a certificate selector, although they may also choose to provide a certificate from elsewhere. Alternatively the user may abort this certificate request, which will usually abort the TLS connection.

If HANDLED is returned, then the TlsConnection passed to request_certificate() will have had its TlsConnection:certificate filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code. Certain implementations may not support immediate cancellation.

Added in version 2.40.

Parameters:
  • connection – a TlsConnection object

  • flags – flags providing more information about the request

  • cancellable – an optional Cancellable cancellation object

do_request_certificate_async(connection: TlsConnection, flags: TlsCertificateRequestFlags, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Run asynchronous interaction to ask the user for a certificate to use with the connection. In general, invoke_request_certificate() should be used instead of this function.

Derived subclasses usually implement a certificate selector, although they may also choose to provide a certificate from elsewhere. callback will be called when the operation completes. Alternatively the user may abort this certificate request, which will usually abort the TLS connection.

Added in version 2.40.

Parameters:
  • connection – a TlsConnection object

  • flags – flags providing more information about the request

  • cancellable – an optional Cancellable cancellation object

  • callback – will be called when the interaction completes

  • user_data – data to pass to the callback

do_request_certificate_finish(result: AsyncResult) TlsInteractionResult

Complete a request certificate user interaction request. This should be once the request_certificate_async() completion callback is called.

If HANDLED is returned, then the TlsConnection passed to request_certificate_async() will have had its TlsConnection:certificate filled in.

If the interaction is cancelled by the cancellation object, or by the user then FAILED will be returned with an error that contains a CANCELLED error code.

Added in version 2.40.

Parameters:

result – the result passed to the callback

Fields

class TlsInteraction
parent_instance
priv