Infinity.XmppConnection¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/c |
The certificate credentials for GnuTLS |
||
r/w/co |
The hostname of the local host |
||
r/w/co |
The hostname of the remote host |
||
r/w/c |
The SASL context used for authentication |
||
r/w/c |
Whitespace separated list of SASL mechanisms to accept/offer |
||
r/w/co |
How to choose whether to use (or offer, as a server) TLS |
||
r/w/co |
Site of the connection (client or server) |
||
r/w/co |
Underlaying TCP connection |
||
r |
Whether TLS is enabled for the connection or not |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class Infinity.XmppConnection(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Infinity.XmppConnection
is an opaque data type. You should only access it via the public API functions.- classmethod error_quark()¶
- Return type:
Error domain for generic connection errors. Errors in this domain will be from the
Infinity.XmppConnectionError
enumeration. SeeGLib.Error
for information on error domains.
- classmethod new(tcp, site, local_hostname, remote_hostname, security_policy, creds, sasl_context, sasl_mechanisms)¶
- Parameters:
tcp (
Infinity.TcpConnection
) – The underlaying TCP connection to use.site (
Infinity.XmppConnectionSite
) – Whether this is a XMPP client or server.local_hostname (
str
orNone
) – The hostname of the local host, orNone
.remote_hostname (
str
) – The hostname of the remote host.security_policy (
Infinity.XmppConnectionSecurityPolicy
) – Whether to use (or offer, as a server) TLS. SeeInfinity.XmppConnectionSecurityPolicy
for the meaning of this parameter.creds (
Infinity.CertificateCredentials
orNone
) – Certificate credentials used to secure the communication.sasl_context (
Infinity.SaslContext
orNone
) – A SASL context used for authentication.sasl_mechanisms (
str
orNone
) – A whitespace-separated list of SASL mechanisms to accept/offer, orNone
.
- Returns:
A new
Infinity.XmppConnection
.- Return type:
Creates a new
Infinity.XmppConnection
with tcp as communication channel. No attempt is being made to open tcp, if it is not already open. However, communication is initiated as soon as tcp gets intoInfinity.TcpConnectionStatus.CONNECTED
state, so you might still open it lateron yourself.local_hostname specifies the hostname of the local host, and remote_hostname specifies the hostname of the remote host, as known to the caller. These can be a string representation of the IP address of tcp, or a DNS name such as “example.com”. local_hostname can be
None
in which case the host name as reported byGLib.get_host_name
() is used.creds may be
None
in which case the connection creates the credentials as soon as they are required. However, this only works if site isInfinity.XmppConnectionSite.CLIENT
or security_policy isInfinity.XmppConnectionSecurityPolicy.ONLY_UNSECURED
(or both, of course). For server connections creds must contain a valid server certificate in case security_policy is notInfinity.XmppConnectionSecurityPolicy.ONLY_UNSECURED
. creds can contain a certificate for the client site and, if so, is used for client authentication.If sasl_context is
None
,Infinity.XmppConnection
uses a built-in context that only supports ANONYMOUS authentication. In sasl_context's callback function, theInfinity.XmppConnection
for which the authentication shall be performed can be accessed via the session_data parameter ofInfinity.SaslContextCallbackFunc
.If sasl_context is not
None
, then the sasl_mechanisms parameter defines what SASL mechanisms are used. On the server side, these are the mechanisms offered to the client, and on the client side, these are the accepted mechanisms (meaning that if a server does not offer any of these, the connection will be closed). If sasl_context isNone
, then this parameter is ignored. sasl_mechanisms can beNone
in which case all available mechanisms are accepted or offered, respectively.
- certificate_verify_cancel(error)¶
- Parameters:
error (
GLib.Error
) – Reason why the certificate is not trusted, orNone
.
Call this function when your callback set in inf_xmpp_connection_set_certificate_callback() was called and you do not trust the peer’s certificate. The connection will then be closed with a corresponding error.
If error is non-
None
, then it should contain a reason why the certificate was not trusted. If you verified the peer’s certificate with gnutls_certificate_verify_peers2(), or gnutls_x509_crt_list_verify(), then a corresponding error can be generated with the verification result withInfinity.gnutls_certificate_verification_set_error
(). The reason is then shown to the local user.
- certificate_verify_continue()¶
Call this function when your callback set in inf_xmpp_connection_set_certificate_callback() was called and you do trust the peer’s certificate. The connection process will then continue.
- get_dh_prime_bits()¶
- Returns:
The number of Diffie-Hellman prime bits.
- Return type:
Returns the number of prime bits used for the Diffie-Hellman group if a key exchange algorithm based on Diffie-Hellman is used. Otherwise, 0 is returned. This function can only be used if
Infinity.XmppConnection.get_tls_enabled
() returns true.
- get_own_certificate()¶
- Returns:
The certificate of the local host. The returned value should not be freed, it is owned by the
Infinity.XmppConnection
.- Return type:
Returns the local host’s certificate that was used to authenticate with the remote host, or
None
if no certificate was used. This function can only be used after the TLS handshake has completed, seeInfinity.XmppConnection.get_tls_enabled
().
- get_peer_certificate()¶
- Returns:
The certificate chain of the remote host. The returned value should not be freed, it is owned by the
Infinity.XmppConnection
.- Return type:
Returns the certificate chain that the remote host authenticated itself with. This function can only be used after the TLS handshake has completed, see
Infinity.XmppConnection.get_tls_enabled
().
- get_sasl_error()¶
- Returns:
A pointer to a
GLib.Error
object owned by self.- Return type:
Gets the SASL error of self. See
Infinity.XmppConnection.set_sasl_error
().
- get_tls_enabled()¶
-
Returns whether TLS encryption is enabled for self. This returns
True
as soon as the TLS handshake is completed but before the server certificate was verified (see inf_xmpp_connection_set_certificate_callback()).
- reset_sasl_authentication(new_context, new_mechanisms)¶
- Parameters:
Sets a new SASL context and mechanisms to use for authentication. This does not have any effect if authentication has already been performed. This can be useful if a server decides to use a stricter authentication policy and gets away with its previous SASL context. If new_context is
None
, then a built-in SASL context is used which only accepts anonymous authentication.If the authentication is currently in progress then it is aborted. The server sends an
Infinity.XmppConnectionAuthError.TEMPORARY_AUTH_FAILURE
error to the client withInfinity.AuthenticationDetailError.TRY_AGAIN
detail (seeInfinity.XmppConnection.get_sasl_error
()).On the client side, if authentication is in progress, a request to abort the authentication is sent to the server. The server will then reply with an
Infinity.XmppConnectionAuthError.ABORTED
error. In the signal handler of theInfinity.XmlConnection
::error
signal you should reinitiate the authentication withInfinity.XmppConnection.retry_sasl_authentication
() or the connection will be closed. It is also possible that the final authentication request has already been sent, and the server replies with successful authentication instead. In that case calling this function will have no effect apart from closing and reopening the connection will use the new context and mechanisms.
- retry_sasl_authentication()¶
- Raises:
- Returns:
- Return type:
When SASL authentication failed then the
Infinity.XmlConnection
::error
signal is emitted with an error from the INF_XMPP_CONNECTION_AUTH_ERROR domain. If the signal handler wants to retry authentication then it should call this function, possibly modifying theInfinity.XmppConnection
:sasl-mechanisms
property before. If this function is not called then the connection will terminate.The function can fail if the server does not support any of the available mechanisms given in
Infinity.XmppConnection
:sasl-mechanisms
. If so, the function returnsFalse
and error is set.
- set_sasl_error(error)¶
- Parameters:
error (
GLib.Error
) – The SASL error to set.
Sets the SASL error of self. The SASL error is an additional hint of what went wrong during authentication. It should be set on the server side in the gsasl callback checking the user authentication. If on the client side
Infinity.XmlConnection
::error
is emitted with an error from the INF_XMPP_CONNECTION_AUTH_ERROR domain thenInfinity.XmppConnection.get_sasl_error
() can be used to obtain more detailed error information.
Property Details¶
- Infinity.XmppConnection.props.credentials¶
- Name:
credentials
- Type:
- Default Value:
- Flags:
The certificate credentials for GnuTLS
- Infinity.XmppConnection.props.local_hostname¶
- Name:
local-hostname
- Type:
- Default Value:
- Flags:
The hostname of the local host
- Infinity.XmppConnection.props.remote_hostname¶
- Name:
remote-hostname
- Type:
- Default Value:
- Flags:
The hostname of the remote host
- Infinity.XmppConnection.props.sasl_context¶
- Name:
sasl-context
- Type:
- Default Value:
- Flags:
The SASL context used for authentication
- Infinity.XmppConnection.props.sasl_mechanisms¶
-
Whitespace separated list of SASL mechanisms to accept/offer
- Infinity.XmppConnection.props.security_policy¶
- Name:
security-policy
- Type:
- Default Value:
- Flags:
How to choose whether to use (or offer, as a server) TLS
- Infinity.XmppConnection.props.site¶
- Name:
site
- Type:
- Default Value:
- Flags:
Site of the connection (client or server)
- Infinity.XmppConnection.props.tcp_connection¶
- Name:
tcp-connection
- Type:
- Default Value:
- Flags:
Underlaying TCP connection