Next: X.509 certificate functions, Up: Function reference
The prototypes for the following functions lie in gnutls/gnutls.h.
alert: is an alert number
gnutls_session_tstructure.This function will return a string that describes the given alert number, or
NULL. Seegnutls_alert_get().Returns: string corresponding to
gnutls_alert_description_tvalue.
session: is a
gnutls_session_tstructure.This function will return the last alert number received. This function should be called if
GNUTLS_E_WARNING_ALERT_RECEIVEDorGNUTLS_E_FATAL_ALERT_RECEIVEDhas been returned by a gnutls function. The peer may send alerts if he thinks some things were not right. Check gnutls.h for the available alert descriptions.If no alert has been received the returned value is undefined.
Returns: returns the last alert received, a
gnutls_alert_description_tvalue.
session: is a
gnutls_session_tstructure.err: is an integer
Sends an alert to the peer depending on the error code returned by a gnutls function. This function will call
gnutls_error_to_alert()to determine the appropriate alert to send.This function may also return
GNUTLS_E_AGAIN, orGNUTLS_E_INTERRUPTED.If the return value is
GNUTLS_E_INVALID_REQUEST, then no alert has been sent to the peer.Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
session: is a
gnutls_session_tstructure.level: is the level of the alert
desc: is the alert description
This function will send an alert to the peer in order to inform him of something important (eg. his Certificate could not be verified). If the alert level is Fatal then the peer is expected to close the connection, otherwise he may ignore the alert and continue.
The error code of the underlying record send function will be returned, so you may also receive
GNUTLS_E_INTERRUPTEDorGNUTLS_E_AGAINas well.Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
sc: is a pointer to an
gnutls_anon_client_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
sc: is a pointer to an
gnutls_anon_server_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
sc: is an
gnutls_anon_client_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.
sc: is an
gnutls_anon_server_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.
res: is a gnutls_anon_server_credentials_t structure
func: is the function to be called
This function will set a callback in order for the server to get the diffie hellman or RSA parameters for anonymous authentication. The callback should return zero on success.
res: is a gnutls_anon_server_credentials_t structure
dh_params: is a structure that holds diffie hellman parameters.
This function will set the diffie hellman parameters for an anonymous server to use. These parameters will be used in Anonymous Diffie Hellman cipher suites.
res: is a gnutls_certificate_credentials_t structure
func: is the function to be called
This function will set a callback in order for the server to get the diffie hellman parameters for anonymous authentication. The callback should return zero on success.
session: is a
gnutls_session_tstructure.Returns the type of credentials that were used for client authentication. The returned information is to be used to distinguish the function used to access authentication data.
Returns: The type of credentials for the client authentication schema, an
gnutls_credentials_type_ttype.
session: is a
gnutls_session_tstructure.Returns type of credentials for the current authentication schema. The returned information is to be used to distinguish the function used to access authentication data.
Eg. for CERTIFICATE ciphersuites (key exchange algorithms: KX_RSA, KX_DHE_RSA), the same function are to be used to access the authentication data.
Returns: The type of credentials for the current authentication schema, an
gnutls_credentials_type_ttype.
session: is a
gnutls_session_tstructure.Returns the type of credentials that were used for server authentication. The returned information is to be used to distinguish the function used to access authentication data.
Returns: The type of credentials for the server authentication schema, an
gnutls_credentials_type_ttype.
session: is a
gnutls_session_tstructure.how: is an integer
Terminates the current TLS/SSL connection. The connection should have been initiated using
gnutls_handshake().howshould be one ofGNUTLS_SHUT_RDWR,GNUTLS_SHUT_WR.In case of
GNUTLS_SHUT_RDWRthen the TLS connection gets terminated and further receives and sends will be disallowed. If the return value is zero you may continue using the connection.GNUTLS_SHUT_RDWRactually sends an alert containing a close request and waits for the peer to reply with the same message.In case of
GNUTLS_SHUT_WRthen the TLS connection gets terminated and further sends will be disallowed. In order to reuse the connection you should wait for an EOF from the peer.GNUTLS_SHUT_WRsends an alert containing a close request.Note that not all implementations will properly terminate a TLS connection. Some of them, usually for performance reasons, will terminate only the underlying transport layer, thus causing a transmission error to the peer. This error cannot be distinguished from a malicious party prematurely terminating the session, thus this behavior is not recommended.
This function may also return
GNUTLS_E_AGAINorGNUTLS_E_INTERRUPTED; cf.gnutls_record_get_direction().Returns:
GNUTLS_E_SUCCESSon success, or an error code, see function documentation for entire semantics.
session: is a gnutls session
This function will return the peer's certificate activation time. This is the creation time for openpgp keys.
Returns: (time_t)-1 on error.
res: is a pointer to an
gnutls_certificate_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
session: is a gnutls session
Get whether client certificate is requested or not.
Returns: 0 if the peer (server) did not request client authentication or 1 otherwise, or a negative value in case of error.
cred: is a
gnutls_certificate_credentials_tstructure.func: is the callback function
This function sets a callback to be called in order to retrieve the certificate to be used in the handshake. The callback's function prototype is: int (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int nreqs, const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length, gnutls_retr_st* st);
req_ca_certis only used in X.509 certificates. Contains a list with the CA names that the server considers trusted. Normally we should send a certificate that is signed by one of these CAs. These names are DER encoded. To get a more meaningful value use the functiongnutls_x509_rdn_get().
pk_algoscontains a list with server's acceptable signature algorithms. The certificate returned should support the server's given algorithms.
stshould contain the certificates and private keys.If the callback function is provided then gnutls will call it, in the handshake, after the certificate request message has been received.
The callback function should set the certificate list to be sent, and return 0 on success. If no certificate was selected then the number of certificates should be set to zero. The value (-1) indicates error and the handshake will be terminated.
session: is a gnutls session
This function will return the peer's certificate expiration time.
Returns: (time_t)-1 on error.
sc: is an
gnutls_certificate_credentials_tstructure.This function will delete all the CA name in the given credentials. Clients may call this to save some memory since in client side the CA names are not used.
CA names are used by servers to advertize the CAs they support to clients.
sc: is an
gnutls_certificate_credentials_tstructure.This function will delete all the CAs associated with the given credentials. Servers that do not use
gnutls_certificate_verify_peers2()may call this to save some memory.
sc: is an
gnutls_certificate_credentials_tstructure.This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.
This function does not free any temporary parameters associated with this structure (ie RSA and DH parameters are not freed by this function).
sc: is an
gnutls_certificate_credentials_tstructure.This function will delete all the CRLs associated with the given credentials.
sc: is an
gnutls_certificate_credentials_tstructure.This function will delete all the keys and the certificates associated with the given credentials. This function must not be called when a TLS negotiation that uses the credentials is in progress.
sc: is an
gnutls_certificate_credentials_tstructure.This function will export the OpenPGP keyring associated with the given credentials.
Since: 2.4.0
session: is a gnutls session
Get the certificate as sent to the peer, in the last handshake. These certificates are in raw format. In X.509 this is a certificate list. In OpenPGP this is a single certificate.
Returns: return a pointer to a
gnutls_datum_tcontaining our certificates, orNULLin case of an error or if no certificate was used.
session: is a gnutls session
list_size: is the length of the certificate list
Get the peer's raw certificate (chain) as sent by the peer. These certificates are in raw format (DER encoded for X.509). In case of a X.509 then a certificate list may be present. The first certificate in the list is the peer's certificate, following the issuer's certificate, then the issuer's issuer etc.
In case of OpenPGP keys a single key will be returned in raw format.
Returns: return a pointer to a
gnutls_datum_tcontaining our certificates, orNULLin case of an error or if no certificate was used.
sc: is an
gnutls_certificate_credentials_tstructure.x509_ca_list: will point to the CA list. Should be treated as constant
ncas: the number of CAs
This function will export all the CAs associated with the given credentials.
Since: 2.4.0
sc: is an
gnutls_certificate_credentials_tstructure.x509_crl_list: the exported CRL list. Should be treated as constant
ncrls: the number of exported CRLs
This function will export all the CRLs associated with the given credentials.
Since: 2.4.0
session: is a pointer to a
gnutls_session_tstructure.status: is 0 or 1
If status is non zero, this function will order gnutls not to send the rdnSequence in the certificate request message. That is the server will not advertize it's trusted CAs to the peer. If status is zero then the default behaviour will take effect, which is to advertize the server's trusted CAs.
This function has no effect in clients, and in authentication methods other than certificate with X.509 certificates.
session: is an
gnutls_session_tstructure.req: is one of GNUTLS_CERT_REQUEST, GNUTLS_CERT_REQUIRE
This function specifies if we (in case of a server) are going to send a certificate request message to the client. If
reqis GNUTLS_CERT_REQUIRE then the server will return an error if the peer does not provide a certificate. If you do not call this function then the client will not be asked to send a certificate.
cred: is a
gnutls_certificate_credentials_tstructure.func: is the callback function
This function sets a callback to be called in order to retrieve the certificate to be used in the handshake. The callback's function prototype is: int (*callback)(gnutls_session_t, gnutls_retr_st* st);
stshould contain the certificates and private keys.If the callback function is provided then gnutls will call it, in the handshake, after the certificate request message has been received.
The callback function should set the certificate list to be sent, and return 0 on success. The value (-1) indicates error and the handshake will be terminated.
res: is a gnutls_certificate_credentials_t structure
dh_params: is a structure that holds diffie hellman parameters.
This function will set the diffie hellman parameters for a certificate server to use. These parameters will be used in Ephemeral Diffie Hellman cipher suites. Note that only a pointer to the parameters are stored in the certificate handle, so if you deallocate the parameters before the certificate is deallocated, you must change the parameters stored in the certificate first.
res: is a gnutls_certificate_credentials_t structure
func: is the function to be called
This function will set a callback in order for the server to get the diffie hellman or RSA parameters for certificate authentication. The callback should return zero on success.
res: is a gnutls_certificate_credentials_t structure
rsa_params: is a structure that holds temporary RSA parameters.
This function will set the temporary RSA parameters for a certificate server to use. These parameters will be used in RSA-EXPORT cipher suites.
res: is a gnutls_certificate_credentials_t structure
flags: are the flags
This function will set the flags to be used at verification of the certificates. Flags must be OR of the
gnutls_certificate_verify_flagsenumerations.
res: is a gnutls_certificate_credentials structure
max_bits: is the number of bits of an acceptable certificate (default 8200)
max_depth: is maximum depth of the verification of a certificate chain (default 5)
This function will set some upper limits for the default verification function,
gnutls_certificate_verify_peers2(), to avoid denial of service attacks. You can set them to zero to disable limits.
res: is an
gnutls_certificate_credentials_tstructure.crlfile: is a file containing the list of verified CRLs (DER or PEM list)
type: is PEM or DER
This function adds the trusted CRLs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.Returns: number of CRLs processed or a negative value on error.
res: is an
gnutls_certificate_credentials_tstructure.CRL: is a list of trusted CRLs. They should have been verified before.
type: is DER or PEM
This function adds the trusted CRLs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.Returns: number of CRLs processed, or a negative value on error.
res: is an
gnutls_certificate_credentials_tstructure.crl_list: is a list of trusted CRLs. They should have been verified before.
crl_list_size: holds the size of the crl_list
This function adds the trusted CRLs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.Returns:
GNUTLS_E_SUCCESSon success, or an error code.Since: 2.4.0
res: is an
gnutls_certificate_credentials_tstructure.CERTFILE: is a file that containing the certificate list (path) for the specified private key, in PKCS7 format, or a list of certificates
KEYFILE: is a file that contains the private key
type: is PEM or DER
This function sets a certificate/private key pair in the gnutls_certificate_credentials_t structure. This function may be called more than once (in case multiple keys/certificates exist for the server).
Currently only PKCS-1 encoded RSA and DSA private keys are accepted by this function.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
res: is an
gnutls_certificate_credentials_tstructure.cert: contains a certificate list (path) for the specified private key
key: is the private key, or
NULLtype: is PEM or DER
This function sets a certificate/private key pair in the gnutls_certificate_credentials_t structure. This function may be called more than once (in case multiple keys/certificates exist for the server).
Currently are supported: RSA PKCS-1 encoded private keys, DSA private keys.
DSA private keys are encoded the OpenSSL way, which is an ASN.1 DER sequence of 6 INTEGERs - version, p, q, g, pub, priv.
Note that the keyUsage (2.5.29.15) PKIX extension in X.509 certificates is supported. This means that certificates intended for signing cannot be used for ciphersuites that require encryption.
If the certificate and the private key are given in PEM encoding then the strings that hold their values must be null terminated.
The
keymay beNULLif you are using a sign callback, seegnutls_sign_callback_set().Returns:
GNUTLS_E_SUCCESSon success, or an error code.
res: is an
gnutls_certificate_credentials_tstructure.cert_list: contains a certificate list (path) for the specified private key
cert_list_size: holds the size of the certificate list
key: is a gnutls_x509_privkey_t key
This function sets a certificate/private key pair in the gnutls_certificate_credentials_t structure. This function may be called more than once (in case multiple keys/certificates exist for the server).
Returns:
GNUTLS_E_SUCCESSon success, or an error code.Since: 2.4.0
res: is an
gnutls_certificate_credentials_tstructure.pkcs12file: filename of file containing PKCS
12blob.type: is PEM or DER of the
pkcs12file.password: optional password used to decrypt PKCS
12file, bags and keys.This function sets a certificate/private key pair and/or a CRL in the gnutls_certificate_credentials_t structure. This function may be called more than once (in case multiple keys/certificates exist for the server).
MAC: ed PKCS
12files are supported. Encrypted PKCS12bags are supported. Encrypted PKCS8private keys are supported. However, only password based security, and the same password for all operations, are supported.The private keys may be RSA PKCS
1or DSA private keys encoded in the OpenSSL way.PKCS
12file may contain many keys and/or certificates, and there is no way to identify which key/certificate pair you want. You should make sure the PKCS12file only contain one key/certificate pair and/or one CRL.It is believed that the limitations of this function is acceptable for most usage, and that any more flexibility would introduce complexity that would make it harder to use this functionality at all.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
res: is an
gnutls_certificate_credentials_tstructure.cafile: is a file containing the list of trusted CAs (DER or PEM list)
type: is PEM or DER
This function adds the trusted CAs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.In case of a server the names of the CAs set here will be sent to the client if a certificate request is sent. This can be disabled using
gnutls_certificate_send_x509_rdn_sequence().Returns: number of certificates processed, or a negative value on error.
res: is an
gnutls_certificate_credentials_tstructure.ca: is a list of trusted CAs or a DER certificate
type: is DER or PEM
This function adds the trusted CAs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.In case of a server the CAs set here will be sent to the client if a certificate request is sent. This can be disabled using
gnutls_certificate_send_x509_rdn_sequence().Returns: the number of certificates processed or a negative value on error.
res: is an
gnutls_certificate_credentials_tstructure.ca_list: is a list of trusted CAs
ca_list_size: holds the size of the CA list
This function adds the trusted CAs in order to verify client or server certificates. In case of a client this is not required to be called if the certificates are not verified using
gnutls_certificate_verify_peers2(). This function may be called multiple times.In case of a server the CAs set here will be sent to the client if a certificate request is sent. This can be disabled using
gnutls_certificate_send_x509_rdn_sequence().Returns:
GNUTLS_E_SUCCESSon success, or an error code.Since: 2.4.0
name: is a certificate type name
The names are compared in a case insensitive way.
Returns: an id of the specified in a string certificate type, or
GNUTLS_CRT_UNKNOWNon error.
type: is a certificate type
Convert a
gnutls_certificate_type_ttype to a string.Returns: a string that contains the name of the specified certificate type, or
NULLin case of unknown types.
session: is a
gnutls_session_tstructure.The certificate type is by default X.509, unless it is negotiated as a TLS extension.
Returns: the currently used
gnutls_certificate_type_tcertificate type.
Get a list of certificate types. Note that to be able to use OpenPGP certificates, you must link to libgnutls-extra and call
gnutls_global_init_extra().Returns: a zero-terminated list of
gnutls_certificate_type_tintegers indicating the available certificate types.
session: is a
gnutls_session_tstructure.list: is a 0 terminated list of gnutls_certificate_type_t elements.
Sets the priority on the certificate types supported by gnutls. Priority is higher for elements specified before others. After specifying the types you want, you must append a 0. Note that the certificate type priority is set on the client. The server does not use the cert type priority except for disabling types that were not specified.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
session: is a gnutls session
status: is the output of the verification
This function will try to verify the peer's certificate and return its status (trusted, invalid etc.). The value of
statusshould be one or more of the gnutls_certificate_status_t enumerated elements bitwise or'd. To avoid denial of service attacks some default upper limits regarding the certificate key size and chain size are set. To override them usegnutls_certificate_set_verify_limits().Note that you must also check the peer's name in order to check if the verified certificate belongs to the actual peer.
This is the same as
gnutls_x509_crt_list_verify()and uses the loaded CAs in the credentials as trusted CAs.Note that some commonly used X.509 Certificate Authorities are still using Version 1 certificates. If you want to accept them, you need to call
gnutls_certificate_set_verify_flags()with, e.g.,GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRTparameter.Returns: a negative error code on error and zero on success.
session: is a gnutls session
This function will try to verify the peer's certificate and return its status (trusted, invalid etc.). However you must also check the peer's name in order to check if the verified certificate belongs to the actual peer.
The return value should be one or more of the gnutls_certificate_status_t enumerated elements bitwise or'd, or a negative value on error.
This is the same as
gnutls_x509_crt_list_verify().Deprecated: Use
gnutls_certificate_verify_peers2()instead.
req_version: the version to check
Check that the version of the library is at minimum the requested one and return the version string; return NULL if the condition is not satisfied. If a NULL is passed to this function, no check is done, but the version string is simply returned.
See
LIBGNUTLS_VERSIONfor a suitablereq_versionstring.Return value: Version string of run-time library, or NULL if the run-time library does not meet the required version number. If
NULLis passed to this function no check is done and only the version string is returned.
The names are compared in a case insensitive way.
Returns: return a
gnutls_cipher_algorithm_tvalue corresponding to the specified cipher, orGNUTLS_CIPHER_UNKNOWNon error.
algorithm: is an encryption algorithm
Get key size for cipher.
Returns: length (in bytes) of the given cipher's key size, or 0 if the given cipher is invalid.
algorithm: is an encryption algorithm
Convert a
gnutls_cipher_algorithm_ttype to a string.Returns: a pointer to a string that contains the name of the specified cipher, or
NULL.
session: is a
gnutls_session_tstructure.Get currently used cipher.
Returns: the currently used cipher, an
gnutls_cipher_algorithm_ttype.
Get a list of supported cipher algorithms. Note that not necessarily all ciphers are supported as TLS cipher suites. For example, DES is not supported as a cipher suite, but is supported for other purposes (e.g., PKCS
8or similar).Returns: a zero-terminated list of
gnutls_cipher_algorithm_tintegers indicating the available ciphers.
session: is a
gnutls_session_tstructure.list: is a 0 terminated list of gnutls_cipher_algorithm_t elements.
Sets the priority on the ciphers supported by gnutls. Priority is higher for elements specified before others. After specifying the ciphers you want, you must append a 0. Note that the priority is set on the client. The server does not use the algorithm's priority except for disabling algorithms that were not specified.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
kx_algorithm: is a Key exchange algorithm
cipher_algorithm: is a cipher algorithm
mac_algorithm: is a MAC algorithm
Note that the full cipher suite name must be prepended by TLS or SSL depending of the protocol in use.
Returns: a string that contains the name of a TLS cipher suite, specified by the given algorithms, or
NULL.
idx: index of cipher suite to get information about, starts on 0.
cs_id: output buffer with room for 2 bytes, indicating cipher suite value
kx: output variable indicating key exchange algorithm, or
NULL.cipher: output variable indicating cipher, or
NULL.mac: output variable indicating MAC algorithm, or
NULL.version: output variable indicating TLS protocol version, or
NULL.Get information about supported cipher suites. Use the function iteratively to get information about all supported cipher suites. Call with idx=0 to get information about first cipher suite, then idx=1 and so on until the function returns NULL.
Returns: the name of
idxcipher suite, and set the information about the cipher suite in the output variables. Ifidxis out of bounds,NULLis returned.
The names are compared in a case insensitive way.
Returns: an id of the specified in a string compression method, or
GNUTLS_COMP_UNKNOWNon error.
algorithm: is a Compression algorithm
Convert a
gnutls_compression_method_tvalue to a string.Returns: a pointer to a string that contains the name of the specified compression algorithm, or
NULL.
session: is a
gnutls_session_tstructure.Get currently used compression algorithm.
Returns: the currently used compression method, a
gnutls_compression_method_tvalue.
Get a list of compression methods. Note that to be able to use LZO compression, you must link to libgnutls-extra and call
gnutls_global_init_extra().Returns: a zero-terminated list of
gnutls_compression_method_tintegers indicating the available compression methods.
session: is a
gnutls_session_tstructure.list: is a 0 terminated list of gnutls_compression_method_t elements.
Sets the priority on the compression algorithms supported by gnutls. Priority is higher for elements specified before others. After specifying the algorithms you want, you must append a 0. Note that the priority is set on the client. The server does not use the algorithm's priority except for disabling algorithms that were not specified.
TLS 1.0 does not define any compression algorithms except NULL. Other compression algorithms are to be considered as gnutls extensions.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
session: is a
gnutls_session_tstructure.Clears all the credentials previously set in this session.
session: is a
gnutls_session_tstructure.type: is the type of the credentials
cred: is a pointer to a structure.
Sets the needed credentials for the specified type. Eg username, password - or public and private keys etc. The (void* cred) parameter is a structure that depends on the specified type and on the current session (client or server). [ In order to minimize memory usage, and share credentials between several threads gnutls keeps a pointer to cred, and not the whole cred structure. Thus you will have to keep the structure allocated until you call
gnutls_deinit(). ]For GNUTLS_CRD_ANON cred should be gnutls_anon_client_credentials_t in case of a client. In case of a server it should be gnutls_anon_server_credentials_t.
For GNUTLS_CRD_SRP cred should be gnutls_srp_client_credentials_t in case of a client, and gnutls_srp_server_credentials_t, in case of a server.
For GNUTLS_CRD_CERTIFICATE cred should be gnutls_certificate_credentials_t.
priority: is the priority of the interface
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new interface's data
This function will register an interface for gnutls to operate on big integers. Any interface registered will override the included interface. The interface with the lowest priority will be used by gnutls.
Note that the bigint interface must interoperate with the public key interface. Thus if this interface is updated the
gnutls_crypto_pk_register()should also be used.This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_bigint_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
priority: is the priority of the cipher interface
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new interface's data
This function will register a cipher interface to be used by gnutls. Any interface registered will override the included engine and by convention kernel implemented interfaces should have priority of 90. The interface with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_cipher_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
priority: is the priority of the digest interface
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new interface's data
This function will register a digest interface to be used by gnutls. Any interface registered will override the included engine and by convention kernel implemented interfaces should have priority of 90. The interface with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_digest_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
priority: is the priority of the mac interface
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new interface's data
This function will register a mac interface to be used by gnutls. Any interface registered will override the included engine and by convention kernel implemented interfaces should have priority of 90. The interface with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_mac_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
priority: is the priority of the interface
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new interface's data
This function will register an interface for gnutls to operate on public key operations. Any interface registered will override the included interface. The interface with the lowest priority will be used by gnutls.
Note that the bigint interface must interoperate with the bigint interface. Thus if this interface is updated the
gnutls_crypto_bigint_register()should also be used.This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_pk_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
priority: is the priority of the generator
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new generator's data
This function will register a random generator to be used by gnutls. Any generator registered will override the included generator and by convention kernel implemented generators have priority of 90. The generator with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_rnd_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
algorithm: is the gnutls algorithm identifier
priority: is the priority of the algorithm
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new cipher's data
This function will register a cipher algorithm to be used by gnutls. Any algorithm registered will override the included algorithms and by convention kernel implemented algorithms have priority of 90. The algorithm with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_single_cipher_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
algorithm: is the gnutls algorithm identifier
priority: is the priority of the algorithm
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new algorithms's data
This function will register a digest (hash) algorithm to be used by gnutls. Any algorithm registered will override the included algorithms and by convention kernel implemented algorithms have priority of 90. The algorithm with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_single_digest_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
algorithm: is the gnutls algorithm identifier
priority: is the priority of the algorithm
version: should be set to
GNUTLS_CRYPTO_API_VERSIONs: is a structure holding new algorithms's data
This function will register a MAC algorithm to be used by gnutls. Any algorithm registered will override the included algorithms and by convention kernel implemented algorithms have priority of 90. The algorithm with the lowest priority will be used by gnutls.
This function should be called before
gnutls_global_init().For simplicity you can use the convenience
gnutls_crypto_single_mac_register()macro.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
session: is a
gnutls_session_tstructure.session_entry: is the session data (not key)
Check if database entry has expired. This function is to be used when you want to clear unnesessary session which occupy space in your backend.
Returns: Returns
GNUTLS_E_EXPIRED, if the database entry has expired or 0 otherwise.
session: is a
gnutls_session_tstructure.Get db function pointer.
Returns: the pointer that will be sent to db store, retrieve and delete functions, as the first argument.
session: is a
gnutls_session_tstructure.This function will remove the current session data from the session database. This will prevent future handshakes reusing these session data. This function should be called if a session was terminated abnormally, and before
gnutls_deinit()is called.Normally
gnutls_deinit()will remove abnormally terminated sessions.
session: is a
gnutls_session_tstructure.seconds: is the number of seconds.
Set the expiration time for resumed sessions. The default is 3600 (one hour) at the time writing this.
session: is a
gnutls_session_tstructure.ptr: is the pointer
Sets the pointer that will be provided to db store, retrieve and delete functions, as the first argument.
session: is a
gnutls_session_tstructure.rem_func: is the function.
Sets the function that will be used to remove data from the resumed sessions database. This function must return 0 on success.
The first argument to
rem_func()will be null unlessgnutls_db_set_ptr()has been called.
session: is a
gnutls_session_tstructure.retr_func: is the function.
Sets the function that will be used to retrieve data from the resumed sessions database. This function must return a gnutls_datum_t containing the data on success, or a gnutls_datum_t containing null and 0 on failure.
The datum's data must be allocated using the function
gnutls_malloc().The first argument to
retr_func()will be null unlessgnutls_db_set_ptr()has been called.
session: is a
gnutls_session_tstructure.store_func: is the function
Sets the function that will be used to store data from the resumed sessions database. This function must remove 0 on success.
The first argument to
store_func()will be null unlessgnutls_db_set_ptr()has been called.
session: is a
gnutls_session_tstructure.This function clears all buffers associated with the
session. This function will also remove session data from the session database if the session was terminated abnormally.
session: is a gnutls session
raw_gen: will hold the generator.
raw_prime: will hold the prime.
This function will return the group parameters used in the last Diffie Hellman authentication with the peer. These are the prime and the generator used. This function should be used for both anonymous and ephemeral diffie Hellman. The output parameters must be freed with
gnutls_free().Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
session: is a gnutls session
Get the Diffie-Hellman public key bit size. Can be used for both anonymous and ephemeral diffie Hellman.
Returns: the public key bit size used in the last Diffie Hellman authentication with the peer, or a negative value in case of error.
session: is a gnutls session
This function will return the bits of the prime used in the last Diffie Hellman authentication with the peer. Should be used for both anonymous and ephemeral diffie Hellman.
Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
session: is a gnutls session
raw_key: will hold the public key.
This function will return the peer's public key used in the last Diffie Hellman authentication. This function should be used for both anonymous and ephemeral diffie Hellman. The output parameters must be freed with
gnutls_free().Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
session: is a gnutls session
This function will return the bits used in the last Diffie Hellman authentication with the peer. Should be used for both anonymous and ephemeral diffie Hellman.
Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
dst: Is the destination structure, which should be initialized.
src: Is the source structure
This function will copy the DH parameters structure from source to destination.
dh_params: Is a structure that holds the prime numbers
This function will deinitialize the DH parameters structure.
params: Holds the DH parameters
format: the format of output params. One of PEM or DER.
params_data: will contain a PKCS3 DHParams structure PEM or DER encoded
params_data_size: holds the size of params_data (and will be replaced by the actual size of parameters)
This function will export the given dh parameters to a PKCS3 DHParams structure. This is the format generated by "openssl dhparam" tool. If the buffer provided is not long enough to hold the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
If the structure is PEM encoded, it will have a header of "BEGIN DH PARAMETERS".
In case of failure a negative value will be returned, and 0 on success.
params: Holds the DH parameters
prime: will hold the new prime
generator: will hold the new generator
bits: if non null will hold is the prime's number of bits
This function will export the pair of prime and generator for use in the Diffie-Hellman key exchange. The new parameters will be allocated using
gnutls_malloc()and will be stored in the appropriate datum.
params: Is the structure that the DH parameters will be stored
bits: is the prime's number of bits
This function will generate a new pair of prime and generator for use in the Diffie-Hellman key exchange. The new parameters will be allocated using
gnutls_malloc()and will be stored in the appropriate datum. This function is normally slow.Note that the bits value should be one of 768, 1024, 2048, 3072 or 4096. Also note that the DH parameters are only useful to servers. Since clients use the parameters sent by the server, it's of no use to call this in client side.
params: A structure where the parameters will be copied to
pkcs3_params: should contain a PKCS3 DHParams structure PEM or DER encoded
format: the format of params. PEM or DER.
This function will extract the DHParams found in a PKCS3 formatted structure. This is the format generated by "openssl dhparam" tool.
If the structure is PEM encoded, it should have a header of "BEGIN DH PARAMETERS".
In case of failure a negative value will be returned, and 0 on success.
dh_params: Is a structure that will hold the prime numbers
prime: holds the new prime
generator: holds the new generator
This function will replace the pair of prime and generator for use in the Diffie-Hellman key exchange. The new parameters should be stored in the appropriate gnutls_datum.
dh_params: Is a structure that will hold the prime numbers
This function will initialize the DH parameters structure.
session: is a
gnutls_session_tstructure.bits: is the number of bits
This function sets the number of bits, for use in an Diffie Hellman key exchange. This is used both in DH ephemeral and DH anonymous cipher suites. This will set the minimum size of the prime that will be used for the handshake.
In the client side it sets the minimum accepted number of bits. If a server sends a prime with less bits than that
GNUTLS_E_DH_PRIME_UNACCEPTABLEwill be returned by the handshake.
error: is an error returned by a gnutls function. Error should be a negative value.
If a function returns a negative value you may feed that value to this function to see if it is fatal. Returns 1 for a fatal error 0 otherwise. However you may want to check the error code manually, since some non-fatal errors to the protocol may be fatal for you (your program).
This is only useful if you are dealing with errors from the record layer or the handshake layer.
For positive
errorvalues, 0 is returned.
err: is a negative integer
level: the alert level will be stored there
Get an alert depending on the error code returned by a gnutls function. All alerts sent by this function should be considered fatal. The only exception is when
errisGNUTLS_E_REHANDSHAKE, where a warning alert should be sent to the peer indicating that no renegotiation will be performed.If there is no mapping to a valid alert the alert to indicate internal error is returned.
Returns: the alert code to use for a particular error code.
type: the 16-bit integer referring to the extension type
name: human printable name of the extension used for debugging
parse_type: either
GNUTLS_EXT_TLSorGNUTLS_EXT_APPLICATION.recv_func: a function to receive extension data
send_func: a function to send extension data
This function is used to register a new TLS extension handler.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
algo: is a digest algorithm
data: is the data
result: is the place where the result will be copied (may be null).
result_size: should hold the size of the result. The actual size of the returned result will also be copied there.
This function will calculate a fingerprint (actually a hash), of the given data. The result is not printable data. You should convert it to hex, or to something else printable.
This is the usual way to calculate a fingerprint of an X.509 DER encoded certificate. Note however that the fingerprint of an OpenPGP is not just a hash and cannot be calculated with this function.
Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
This function will free data pointed by ptr.
The deallocation function used is the one set by
gnutls_global_set_mem_functions().
This function deinitializes the global data, that were initialized using
gnutls_global_init().Note! This function is not thread safe. See the discussion for
gnutls_global_init()for more information.
This function initializes the global data to defaults. Every gnutls application has a global data which holds common parameters shared by gnutls session structures. You should call
gnutls_global_deinit()when gnutls usage is no longer neededNote that this function will also initialize libgcrypt, if it has not been initialized before. Thus if you want to manually initialize libgcrypt you must do it before calling this function. This is useful in cases you want to disable libgcrypt's internal lockings etc.
This function increment a global counter, so that
gnutls_global_deinit()only releases resources when it has been called as many times asgnutls_global_init(). This is useful when GnuTLS is used by more than one library in an application. This function can be called many times, but will only do something the first time.Note! This function is not thread safe. If two threads call this function simultaneously, they can cause a race between checking the global counter and incrementing it, causing both threads to execute the library initialization code. That would lead to a memory leak. To handle this, your application could invoke this function after aquiring a thread mutex. To ignore the potential memory leak is also an option.
Returns: On success,
GNUTLS_E_SUCCESS(zero) is returned, otherwise an error code is returned.
log_func: it's a log function
This is the function where you set the logging function gnutls is going to use. This function only accepts a character array. Normally you may not use this function since it is only used for debugging purposes.
gnutls_log_func is of the form, void (*gnutls_log_func)( int level, const char*);
level: it's an integer from 0 to 9.
This is the function that allows you to set the log level. The level is an integer between 0 and 9. Higher values mean more verbosity. The default value is 0. Larger values should only be used with care, since they may reveal sensitive information.
Use a log level over 10 to enable all debugging options.
alloc_func: it's the default memory allocation function. Like
malloc().secure_alloc_func: This is the memory allocation function that will be used for sensitive data.
is_secure_func: a function that returns 0 if the memory given is not secure. May be NULL.
realloc_func: A realloc function
free_func: The function that frees allocated data. Must accept a NULL pointer.
This is the function were you set the memory allocation functions gnutls is going to use. By default the libc's allocation functions (
malloc(),free()), are used by gnutls, to allocate both sensitive and not sensitive data. This function is provided to set the memory allocation functions to something other than the defaults (ie the gcrypt allocation functions).This function must be called before
gnutls_global_init()is called.
session: is a
gnutls_session_tstructure.This function is only useful to check where the last performed handshake failed. If the previous handshake succeed or was not performed at all then no meaningful value will be returned.
Check
gnutls_handshake_description_tin gnutls.h for the available handshake descriptions.Returns: the last handshake message type received, a
gnutls_handshake_description_t.
session: is a
gnutls_session_tstructure.This function is only useful to check where the last performed handshake failed. If the previous handshake succeed or was not performed at all then no meaningful value will be returned.
Check
gnutls_handshake_description_tin gnutls.h for the available handshake descriptions.Returns: the last handshake message type sent, a
gnutls_handshake_description_t.
session: is a
gnutls_session_tstructure.max: is the maximum number.
This function will set the maximum size of all handshake messages. Handshakes over this size are rejected with
GNUTLS_E_HANDSHAKE_TOO_LARGEerror code. The default value is 48kb which is typically large enough. Set this to 0 if you do not want to set an upper limit.The reason for restricting the handshake message sizes are to limit Denial of Service attacks.
func: is the function to be called
This function will set a callback to be called after the client hello has been received (callback valid in server side only). This allows the server to adjust settings based on received extensions.
Those settings could be ciphersuites, requesting certificate, or anything else except for version negotiation (this is done before the hello message is parsed).
This callback must return 0 on success or a gnutls error code to terminate the handshake.
Warning: You should not use this function to terminate the handshake based on client input unless you know what you are doing. Before the handshake is finished there is no way to know if there is a man-in-the-middle attack being performed.
session: is a
gnutls_session_tstructure.allow: is an integer (0 or 1)
This function will enable or disable the use of private cipher suites (the ones that start with 0xFF). By default or if
allowis 0 then these cipher suites will not be advertized nor used.Unless this function is called with the option to allow (1), then no compression algorithms, like LZO. That is because these algorithms are not yet defined in any RFC or even internet draft.
Enabling the private ciphersuites when talking to other than gnutls servers and clients may cause interoperability problems.
session: is a
gnutls_session_tstructure.This function does the handshake of the TLS/SSL protocol, and initializes the TLS connection.
This function will fail if any problem is encountered, and will return a negative error code. In case of a client, if the client has asked to resume a session, but the server couldn't, then a full handshake will be performed.
The non-fatal errors such as
GNUTLS_E_AGAINandGNUTLS_E_INTERRUPTEDinterrupt the handshake procedure, which should be later be resumed. Call this function again, until it returns 0; cf.gnutls_record_get_direction()andgnutls_error_is_fatal().If this function is called by a server after a rehandshake request then
GNUTLS_E_GOT_APPLICATION_DATAorGNUTLS_E_WARNING_ALERT_RECEIVEDmay be returned. Note that these are non fatal errors, only in the specific case of a rehandshake. Their meaning is that the client rejected the rehandshake request.Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.
hex_data: string with data in hex format
hex_size: size of hex data
bin_data: output array with binary data
bin_size: when calling *
bin_sizeshould hold size ofbin_data, on return will hold actual size ofbin_data.Convert a buffer with hex data to binary data.
Returns:
GNUTLS_E_SUCCESSon success, otherwise an error.Since: 2.4.0
hex_data: contain the encoded data
result: the place where decoded data will be copied
result_size: holds the size of the result
This function will decode the given encoded data, using the hex encoding used by PSK password files.
Note that hex_data should be null terminated.
Returns:
GNUTLS_E_SHORT_MEMORY_BUFFERif the buffer given is not long enough, or 0 on success.
data: contain the raw data
result: the place where hex data will be copied
result_size: holds the size of the result
This function will convert the given data to printable data, using the hex encoding, as used in the PSK password files.
Returns:
GNUTLS_E_SHORT_MEMORY_BUFFERif the buffer given is not long enough, or 0 on success.
session: is a pointer to a
gnutls_session_tstructure.con_end: indicate if this session is to be used for server or client.
This function initializes the current session to null. Every session must be initialized before use, so internal structures can be allocated. This function allocates structures which can only be free'd by calling
gnutls_deinit(). Returns zero on success.
con_endcan be one ofGNUTLS_CLIENTandGNUTLS_SERVER.Returns:
GNUTLS_E_SUCCESSon success, or an error code.
Convert a string to a
gnutls_kx_algorithm_tvalue. The names are compared in a case insensitive way.Returns: an id of the specified KX algorithm, or
GNUTLS_KX_UNKNOWNon error.
algorithm: is a key exchange algorithm
Convert a
gnutls_kx_algorithm_tvalue to a string.Returns: a pointer to a string that contains the name of the specified key exchange algorithm, or
NULL.
session: is a
gnutls_session_tstructure.Get currently used key exchange algorithm.
Returns: the key exchange algorithm used in the last handshake, a
gnutls_kx_algorithm_tvalue.
Get a list of supported key exchange algorithms.
Returns: a zero-terminated list of
gnutls_kx_algorithm_tintegers indicating the available key exchange algorithms.
session: is a
gnutls_session_tstructure.list: is a 0 terminated list of gnutls_kx_algorithm_t elements.
Sets the priority on the key exchange algorithms supported by gnutls. Priority is higher for elements specified before others. After specifying the algorithms you want, you must append a 0. Note that the priority is set on the client. The server does not use the algorithm's priority except for disabling algorithms that were not specified.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
Convert a string to a
gnutls_mac_algorithm_tvalue. The names are compared in a case insensitive way.Returns: an
gnutls_mac_algorithm_tidof the specified in a string MAC algorithm, orGNUTLS_MAC_UNKNOWNon failures.
algorithm: is an encryption algorithm
Get size of MAC key.
Returns: length (in bytes) of the given MAC key size, or 0 if the given MAC algorithm is invalid.
algorithm: is a MAC algorithm
Convert a
gnutls_mac_algorithm_tvalue to a string.Returns: a string that contains the name of the specified MAC algorithm, or
NULL.
session: is a
gnutls_session_tstructure.Get currently used MAC algorithm.
Returns: the currently used mac algorithm, a
gnutls_mac_algorithm_tvalue.
Get a list of hash algorithms for use as MACs. Note that not necessarily all MACs are supported in TLS cipher suites. For example, MD2 is not supported as a cipher suite, but is supported for other purposes (e.g., X.509 signature verification or similar).
Returns: Return a zero-terminated list of
gnutls_mac_algorithm_tintegers indicating the available MACs.
session: is a
gnutls_session_tstructure.list: is a 0 terminated list of gnutls_mac_algorithm_t elements.
Sets the priority on the mac algorithms supported by gnutls. Priority is higher for elements specified before others. After specifying the algorithms you want, you must append a 0. Note that the priority is set on the client. The server does not use the algorithm's priority except for disabling algorithms that were not specified.
Returns:
GNUTLS_E_SUCCESSon success, or an error code.
This function will allocate 's' bytes data, and return a pointer to memory. This function is supposed to be used by callbacks.
The allocation function used is the one set by
gnutls_global_set_mem_functions().
session: is a pointer to a
gnutls_session_tstructure.status: is one of GNUTLS_OPENPGP_CERT, or GNUTLS_OPENPGP_CERT_FINGERPRINT
This function will order gnutls to send the key fingerprint instead of the key in the initial handshake procedure. This should be used with care and only when there is indication or knowledge that the server can obtain the client's key.
session: is a
gnutls_session_tstructure.len: length of Opaque PRF data to use in client.
data: Opaque PRF data to use in client.
Request that the client should attempt to negotiate the Opaque PRF Input TLS extension, using the given data as the client's Opaque PRF input.
The data is copied into the session context after this call, so you may de-allocate it immediately after calling this function.
session: is a
gnutls_session_tstructure.cb: function pointer to Opaque PRF extension server callback.
userdata: hook passed to callback function for passing application state.
Request that the server should attempt to accept the Opaque PRF Input TLS extension. If the client requests the extension, the provided callback
cbwill be invoked. The callback must have the following prototype:int callback (gnutls_session_t session, void *userdata, size_t oprfi_len, const unsigned char *in_oprfi, unsigned char *out_oprfi);
The callback can inspect the client-provided data in the input parameters, and specify its own opaque prf input data in the output variable. The function must return 0 on success, otherwise the handshake will be aborted.
header: The PEM header (eg. CERTIFICATE)
b64_data: contains the encoded data
result: the place where decoded data lie
This function will decode the given encoded data. The decoded data will be allocated, and stored into result. If the header given is non null this function will search for "——BEGIN header" and decode only this part. Otherwise it will decode the first PEM packet found.
You should use
gnutls_free()to free the returned data.Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
header: A null terminated string with the PEM header (eg. CERTIFICATE)
b64_data: contain the encoded data
result: the place where decoded data will be copied
result_size: holds the size of the result
This function will decode the given encoded data. If the header given is non null this function will search for "——BEGIN header" and decode only this part. Otherwise it will decode the first PEM packet found.
Returns: On success
GNUTLS_E_SUCCESS(0) is returned,GNUTLS_E_SHORT_MEMORY_BUFFERis returned if the buffer given is not long enough, or 0 on success.
msg: is a message to be put in the encoded header
data: contains the raw data
result: will hold the newly allocated encoded data
This function will convert the given data to printable data, using the base64 encoding. This is the encoding used in PEM messages. This function will allocate the required memory to hold the encoded data.
You should use
gnutls_free()to free the returned data.Returns: On success,
GNUTLS_E_SUCCESS(0) is returned, otherwise an error code is returned.
msg: is a message to be put in the header
data: contain the raw data
result: the place where base64 data will be copied
result_size: holds the size of the result
This function will convert the given data to printable data, using the base64 encoding. This is the encoding used in PEM messages.
The output string will be null terminated, although the size will not include the terminating null.
Returns: On success
GNUTLS_E_SUCCESS(0) is returned,GNUTLS_E_SHORT_MEMORY_BUFFERis returned if the buffer given is not long enough, or 0 on success.
error: is an error returned by a gnutls function. Error is always a negative value.
This function is like
perror(). The only difference is that it accepts an error number returned by a gnutls function.
algorithm: is a pk algorithm
Convert a
gnutls_pk_algorithm_tvalue to a string.Returns: a string that contains the name of the specified public key algorithm, or
NULL.