[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9. Function Reference


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.1 Core Functions

The prototypes for the following functions lie in `gnutls/gnutls.h'.

gnutls_alert_get_name

Function: const char * gnutls_alert_get_name (gnutls_alert_description_t alert)

alert: is an alert number gnutls_session_t structure.

This function will return a string that describes the given alert number, or NULL. See gnutls_alert_get().

Returns: string corresponding to gnutls_alert_description_t value.

gnutls_alert_get

Function: gnutls_alert_description_t gnutls_alert_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function will return the last alert number received. This function should be called if GNUTLS_E_WARNING_ALERT_RECEIVED or GNUTLS_E_FATAL_ALERT_RECEIVED has 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_t value.

gnutls_alert_send_appropriate

Function: int gnutls_alert_send_appropriate (gnutls_session_t session, int err)

session: is a gnutls_session_t structure.

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, or GNUTLS_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.

gnutls_alert_send

Function: int gnutls_alert_send (gnutls_session_t session, gnutls_alert_level_t level, gnutls_alert_description_t desc)

session: is a gnutls_session_t structure.

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_INTERRUPTED or GNUTLS_E_AGAIN as well.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_anon_allocate_client_credentials

Function: int gnutls_anon_allocate_client_credentials (gnutls_anon_client_credentials_t * sc)

sc: is a pointer to an gnutls_anon_client_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_anon_allocate_server_credentials

Function: int gnutls_anon_allocate_server_credentials (gnutls_anon_server_credentials_t * sc)

sc: is a pointer to an gnutls_anon_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_anon_free_client_credentials

Function: void gnutls_anon_free_client_credentials (gnutls_anon_client_credentials_t sc)

sc: is an gnutls_anon_client_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_anon_free_server_credentials

Function: void gnutls_anon_free_server_credentials (gnutls_anon_server_credentials_t sc)

sc: is an gnutls_anon_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_anon_set_params_function

Function: void gnutls_anon_set_params_function (gnutls_anon_server_credentials_t res, gnutls_params_function * func)

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.

gnutls_anon_set_server_dh_params

Function: void gnutls_anon_set_server_dh_params (gnutls_anon_server_credentials_t res, gnutls_dh_params_t dh_params)

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.

gnutls_anon_set_server_params_function

Function: void gnutls_anon_set_server_params_function (gnutls_anon_server_credentials_t res, gnutls_params_function * func)

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.

gnutls_auth_client_get_type

Function: gnutls_credentials_type_t gnutls_auth_client_get_type (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_t type.

gnutls_auth_get_type

Function: gnutls_credentials_type_t gnutls_auth_get_type (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_t type.

gnutls_auth_server_get_type

Function: gnutls_credentials_type_t gnutls_auth_server_get_type (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_t type.

gnutls_bye

Function: int gnutls_bye (gnutls_session_t session, gnutls_close_request_t how)

session: is a gnutls_session_t structure.

how: is an integer

Terminates the current TLS/SSL connection. The connection should have been initiated using gnutls_handshake(). how should be one of GNUTLS_SHUT_RDWR, GNUTLS_SHUT_WR.

In case of GNUTLS_SHUT_RDWR then 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_RDWR actually sends an alert containing a close request and waits for the peer to reply with the same message.

In case of GNUTLS_SHUT_WR then 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_WR sends 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_AGAIN or GNUTLS_E_INTERRUPTED; cf. gnutls_record_get_direction().

Returns: GNUTLS_E_SUCCESS on success, or an error code, see function documentation for entire semantics.

gnutls_certificate_activation_time_peers

Function: time_t gnutls_certificate_activation_time_peers (gnutls_session_t session)

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.

Deprecated: gnutls_certificate_verify_peers2() now verifies activation times.

gnutls_certificate_allocate_credentials

Function: int gnutls_certificate_allocate_credentials (gnutls_certificate_credentials_t * res)

res: is a pointer to an gnutls_certificate_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_certificate_client_get_request_status

Function: int gnutls_certificate_client_get_request_status (gnutls_session_t session)

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.

gnutls_certificate_client_set_retrieve_function

Function: void gnutls_certificate_client_set_retrieve_function (gnutls_certificate_credentials_t cred, gnutls_certificate_client_retrieve_function * func)

cred: is a gnutls_certificate_credentials_t structure.

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_cert is 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 function gnutls_x509_rdn_get().

pk_algos contains a list with server's acceptable signature algorithms. The certificate returned should support the server's given algorithms.

st should 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.

gnutls_certificate_expiration_time_peers

Function: time_t gnutls_certificate_expiration_time_peers (gnutls_session_t session)

session: is a gnutls session

This function will return the peer's certificate expiration time.

Returns: (time_t)-1 on error.

Deprecated: gnutls_certificate_verify_peers2() now verifies expiration times.

gnutls_certificate_free_ca_names

Function: void gnutls_certificate_free_ca_names (gnutls_certificate_credentials_t sc)

sc: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_free_cas

Function: void gnutls_certificate_free_cas (gnutls_certificate_credentials_t sc)

sc: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_free_credentials

Function: void gnutls_certificate_free_credentials (gnutls_certificate_credentials_t sc)

sc: is an gnutls_certificate_credentials_t structure.

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).

gnutls_certificate_free_crls

Function: void gnutls_certificate_free_crls (gnutls_certificate_credentials_t sc)

sc: is an gnutls_certificate_credentials_t structure.

This function will delete all the CRLs associated with the given credentials.

gnutls_certificate_free_keys

Function: void gnutls_certificate_free_keys (gnutls_certificate_credentials_t sc)

sc: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_get_openpgp_keyring

Function: void gnutls_certificate_get_openpgp_keyring (gnutls_certificate_credentials_t sc, gnutls_openpgp_keyring_t * keyring)

sc: is an gnutls_certificate_credentials_t structure.

This function will export the OpenPGP keyring associated with the given credentials.

Since: 2.4.0

gnutls_certificate_get_ours

Function: const gnutls_datum_t * gnutls_certificate_get_ours (gnutls_session_t session)

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_t containing our certificates, or NULL in case of an error or if no certificate was used.

gnutls_certificate_get_peers

Function: const gnutls_datum_t * gnutls_certificate_get_peers (gnutls_session_t session, unsigned int * list_size)

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_t containing our certificates, or NULL in case of an error or if no certificate was used.

gnutls_certificate_get_x509_cas

Function: void gnutls_certificate_get_x509_cas (gnutls_certificate_credentials_t sc, gnutls_x509_crt_t ** x509_ca_list, unsigned int * ncas)

sc: is an gnutls_certificate_credentials_t structure.

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

gnutls_certificate_get_x509_crls

Function: void gnutls_certificate_get_x509_crls (gnutls_certificate_credentials_t sc, gnutls_x509_crl_t ** x509_crl_list, unsigned int * ncrls)

sc: is an gnutls_certificate_credentials_t structure.

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

gnutls_certificate_send_x509_rdn_sequence

Function: void gnutls_certificate_send_x509_rdn_sequence (gnutls_session_t session, int status)

session: is a pointer to a gnutls_session_t structure.

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.

gnutls_certificate_server_set_request

Function: void gnutls_certificate_server_set_request (gnutls_session_t session, gnutls_certificate_request_t req)

session: is an gnutls_session_t structure.

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 req is 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.

gnutls_certificate_server_set_retrieve_function

Function: void gnutls_certificate_server_set_retrieve_function (gnutls_certificate_credentials_t cred, gnutls_certificate_server_retrieve_function * func)

cred: is a gnutls_certificate_credentials_t structure.

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);

st should 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.

gnutls_certificate_set_dh_params

Function: void gnutls_certificate_set_dh_params (gnutls_certificate_credentials_t res, gnutls_dh_params_t dh_params)

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.

gnutls_certificate_set_params_function

Function: void gnutls_certificate_set_params_function (gnutls_certificate_credentials_t res, gnutls_params_function * func)

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.

gnutls_certificate_set_rsa_export_params

Function: void gnutls_certificate_set_rsa_export_params (gnutls_certificate_credentials_t res, gnutls_rsa_params_t rsa_params)

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.

gnutls_certificate_set_verify_flags

Function: void gnutls_certificate_set_verify_flags (gnutls_certificate_credentials_t res, unsigned int flags)

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_flags enumerations.

gnutls_certificate_set_verify_limits

Function: void gnutls_certificate_set_verify_limits (gnutls_certificate_credentials_t res, unsigned int max_bits, unsigned int max_depth)

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.

gnutls_certificate_set_x509_crl_file

Function: int gnutls_certificate_set_x509_crl_file (gnutls_certificate_credentials_t res, const char * crlfile, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_set_x509_crl_mem

Function: int gnutls_certificate_set_x509_crl_mem (gnutls_certificate_credentials_t res, const gnutls_datum_t * CRL, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_set_x509_crl

Function: int gnutls_certificate_set_x509_crl (gnutls_certificate_credentials_t res, gnutls_x509_crl_t * crl_list, int crl_list_size)

res: is an gnutls_certificate_credentials_t structure.

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_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_certificate_set_x509_key_file

Function: int gnutls_certificate_set_x509_key_file (gnutls_certificate_credentials_t res, const char * CERTFILE, const char * KEYFILE, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

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_SUCCESS on success, or an error code.

gnutls_certificate_set_x509_key_mem

Function: int gnutls_certificate_set_x509_key_mem (gnutls_certificate_credentials_t res, const gnutls_datum_t * cert, const gnutls_datum_t * key, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

cert: contains a certificate list (path) for the specified private key

key: is the private key, or NULL

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 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 key may be NULL if you are using a sign callback, see gnutls_sign_callback_set().

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_certificate_set_x509_key

Function: int gnutls_certificate_set_x509_key (gnutls_certificate_credentials_t res, gnutls_x509_crt_t * cert_list, int cert_list_size, gnutls_x509_privkey_t key)

res: is an gnutls_certificate_credentials_t structure.

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_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_certificate_set_x509_simple_pkcs12_file

Function: int gnutls_certificate_set_x509_simple_pkcs12_file (gnutls_certificate_credentials_t res, const char * pkcs12file, gnutls_x509_crt_fmt_t type, const char * password)

res: is an gnutls_certificate_credentials_t structure.

pkcs12file: filename of file containing PKCS12 blob.

type: is PEM or DER of the pkcs12file.

password: optional password used to decrypt PKCS12 file, 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 PKCS12 files are supported. Encrypted PKCS12 bags are supported. Encrypted PKCS8 private keys are supported. However, only password based security, and the same password for all operations, are supported.

The private keys may be RSA PKCS1 or DSA private keys encoded in the OpenSSL way.

PKCS12 file 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 PKCS12 file 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_SUCCESS on success, or an error code.

gnutls_certificate_set_x509_trust_file

Function: int gnutls_certificate_set_x509_trust_file (gnutls_certificate_credentials_t res, const char * cafile, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_set_x509_trust_mem

Function: int gnutls_certificate_set_x509_trust_mem (gnutls_certificate_credentials_t res, const gnutls_datum_t * ca, gnutls_x509_crt_fmt_t type)

res: is an gnutls_certificate_credentials_t structure.

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.

gnutls_certificate_set_x509_trust

Function: int gnutls_certificate_set_x509_trust (gnutls_certificate_credentials_t res, gnutls_x509_crt_t * ca_list, int ca_list_size)

res: is an gnutls_certificate_credentials_t structure.

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_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_certificate_type_get_id

Function: gnutls_certificate_type_t gnutls_certificate_type_get_id (const char * name)

name: is a certificate type name

The names are compared in a case insensitive way.

Returns: an gnutls_certificate_type_t for the specified in a string certificate type, or GNUTLS_CRT_UNKNOWN on error.

gnutls_certificate_type_get_name

Function: const char * gnutls_certificate_type_get_name (gnutls_certificate_type_t type)

type: is a certificate type

Convert a gnutls_certificate_type_t type to a string.

Returns: a string that contains the name of the specified certificate type, or NULL in case of unknown types.

gnutls_certificate_type_get

Function: gnutls_certificate_type_t gnutls_certificate_type_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

The certificate type is by default X.509, unless it is negotiated as a TLS extension.

Returns: the currently used gnutls_certificate_type_t certificate type.

gnutls_certificate_type_list

Function: const gnutls_certificate_type_t * gnutls_certificate_type_list ( void)

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_t integers indicating the available certificate types.

gnutls_certificate_type_set_priority

Function: int gnutls_certificate_type_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

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_SUCCESS on success, or an error code.

gnutls_certificate_verify_peers2

Function: int gnutls_certificate_verify_peers2 (gnutls_session_t session, unsigned int * status)

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 status should 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 use gnutls_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_CRT parameter.

Returns: a negative error code on error and zero on success.

gnutls_certificate_verify_peers

Function: int gnutls_certificate_verify_peers (gnutls_session_t session)

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.

gnutls_check_version

Function: const char * gnutls_check_version (const char * req_version)

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_VERSION for a suitable req_version string.

Return value: Version string of run-time library, or NULL if the run-time library does not meet the required version number. If NULL is passed to this function no check is done and only the version string is returned.

gnutls_cipher_get_id

Function: gnutls_cipher_algorithm_t gnutls_cipher_get_id (const char * name)

name: is a MAC algorithm name

The names are compared in a case insensitive way.

Returns: return a gnutls_cipher_algorithm_t value corresponding to the specified cipher, or GNUTLS_CIPHER_UNKNOWN on error.

gnutls_cipher_get_key_size

Function: size_t gnutls_cipher_get_key_size (gnutls_cipher_algorithm_t algorithm)

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.

gnutls_cipher_get_name

Function: const char * gnutls_cipher_get_name (gnutls_cipher_algorithm_t algorithm)

algorithm: is an encryption algorithm

Convert a gnutls_cipher_algorithm_t type to a string.

Returns: a pointer to a string that contains the name of the specified cipher, or NULL.

gnutls_cipher_get

Function: gnutls_cipher_algorithm_t gnutls_cipher_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get currently used cipher.

Returns: the currently used cipher, an gnutls_cipher_algorithm_t type.

gnutls_cipher_list

Function: const gnutls_cipher_algorithm_t * gnutls_cipher_list ( void)

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., PKCS8 or similar).

Returns: a zero-terminated list of gnutls_cipher_algorithm_t integers indicating the available ciphers.

gnutls_cipher_set_priority

Function: int gnutls_cipher_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

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_SUCCESS on success, or an error code.

gnutls_cipher_suite_get_name

Function: const char * gnutls_cipher_suite_get_name (gnutls_kx_algorithm_t kx_algorithm, gnutls_cipher_algorithm_t cipher_algorithm, gnutls_mac_algorithm_t mac_algorithm)

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.

gnutls_cipher_suite_info

Function: const char * gnutls_cipher_suite_info (size_t idx, char * cs_id, gnutls_kx_algorithm_t * kx, gnutls_cipher_algorithm_t * cipher, gnutls_mac_algorithm_t * mac, gnutls_protocol_t * version)

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 idx cipher suite, and set the information about the cipher suite in the output variables. If idx is out of bounds, NULL is returned.

gnutls_compression_get_id

Function: gnutls_compression_method_t gnutls_compression_get_id (const char * name)

name: is a compression method name

The names are compared in a case insensitive way.

Returns: an id of the specified in a string compression method, or GNUTLS_COMP_UNKNOWN on error.

gnutls_compression_get_name

Function: const char * gnutls_compression_get_name (gnutls_compression_method_t algorithm)

algorithm: is a Compression algorithm

Convert a gnutls_compression_method_t value to a string.

Returns: a pointer to a string that contains the name of the specified compression algorithm, or NULL.

gnutls_compression_get

Function: gnutls_compression_method_t gnutls_compression_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get currently used compression algorithm.

Returns: the currently used compression method, a gnutls_compression_method_t value.

gnutls_compression_list

Function: const gnutls_compression_method_t * gnutls_compression_list ( void)

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_t integers indicating the available compression methods.

gnutls_compression_set_priority

Function: int gnutls_compression_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

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_SUCCESS on success, or an error code.

gnutls_credentials_clear

Function: void gnutls_credentials_clear (gnutls_session_t session)

session: is a gnutls_session_t structure.

Clears all the credentials previously set in this session.

gnutls_credentials_set

Function: int gnutls_credentials_set (gnutls_session_t session, gnutls_credentials_type_t type, void * cred)

session: is a gnutls_session_t structure.

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.

gnutls_crypto_bigint_register2

Function: int gnutls_crypto_bigint_register2 (int priority, int version, gnutls_crypto_bigint_st * s)

priority: is the priority of the interface

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_cipher_register2

Function: int gnutls_crypto_cipher_register2 (int priority, int version, gnutls_crypto_cipher_st * s)

priority: is the priority of the cipher interface

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_digest_register2

Function: int gnutls_crypto_digest_register2 (int priority, int version, gnutls_crypto_digest_st * s)

priority: is the priority of the digest interface

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_mac_register2

Function: int gnutls_crypto_mac_register2 (int priority, int version, gnutls_crypto_mac_st * s)

priority: is the priority of the mac interface

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_pk_register2

Function: int gnutls_crypto_pk_register2 (int priority, int version, gnutls_crypto_pk_st * s)

priority: is the priority of the interface

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_rnd_register2

Function: int gnutls_crypto_rnd_register2 (int priority, int version, gnutls_crypto_rnd_st * s)

priority: is the priority of the generator

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_single_cipher_register2

Function: int gnutls_crypto_single_cipher_register2 (gnutls_cipher_algorithm_t algorithm, int priority, int version, gnutls_crypto_single_cipher_st * s)

algorithm: is the gnutls algorithm identifier

priority: is the priority of the algorithm

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_single_digest_register2

Function: int gnutls_crypto_single_digest_register2 (gnutls_digest_algorithm_t algorithm, int priority, int version, gnutls_crypto_single_digest_st * s)

algorithm: is the gnutls algorithm identifier

priority: is the priority of the algorithm

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_crypto_single_mac_register2

Function: int gnutls_crypto_single_mac_register2 (gnutls_mac_algorithm_t algorithm, int priority, int version, gnutls_crypto_single_mac_st * s)

algorithm: is the gnutls algorithm identifier

priority: is the priority of the algorithm

version: should be set to GNUTLS_CRYPTO_API_VERSION

s: 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_SUCCESS on success, otherwise an error.

Since: 2.6.0

gnutls_db_check_entry

Function: int gnutls_db_check_entry (gnutls_session_t session, gnutls_datum_t session_entry)

session: is a gnutls_session_t structure.

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.

gnutls_db_get_ptr

Function: void * gnutls_db_get_ptr (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get db function pointer.

Returns: the pointer that will be sent to db store, retrieve and delete functions, as the first argument.

gnutls_db_remove_session

Function: void gnutls_db_remove_session (gnutls_session_t session)

session: is a gnutls_session_t structure.

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.

gnutls_db_set_cache_expiration

Function: void gnutls_db_set_cache_expiration (gnutls_session_t session, int seconds)

session: is a gnutls_session_t structure.

seconds: is the number of seconds.

Set the expiration time for resumed sessions. The default is 3600 (one hour) at the time writing this.

gnutls_db_set_ptr

Function: void gnutls_db_set_ptr (gnutls_session_t session, void * ptr)

session: is a gnutls_session_t structure.

ptr: is the pointer

Sets the pointer that will be provided to db store, retrieve and delete functions, as the first argument.

gnutls_db_set_remove_function

Function: void gnutls_db_set_remove_function (gnutls_session_t session, gnutls_db_remove_func rem_func)

session: is a gnutls_session_t structure.

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 unless gnutls_db_set_ptr() has been called.

gnutls_db_set_retrieve_function

Function: void gnutls_db_set_retrieve_function (gnutls_session_t session, gnutls_db_retr_func retr_func)

session: is a gnutls_session_t structure.

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 unless gnutls_db_set_ptr() has been called.

gnutls_db_set_store_function

Function: void gnutls_db_set_store_function (gnutls_session_t session, gnutls_db_store_func store_func)

session: is a gnutls_session_t structure.

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 unless gnutls_db_set_ptr() has been called.

gnutls_deinit

Function: void gnutls_deinit (gnutls_session_t session)

session: is a gnutls_session_t structure.

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.

gnutls_dh_get_group

Function: int gnutls_dh_get_group (gnutls_session_t session, gnutls_datum_t * raw_gen, gnutls_datum_t * raw_prime)

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.

gnutls_dh_get_peers_public_bits

Function: int gnutls_dh_get_peers_public_bits (gnutls_session_t session)

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.

gnutls_dh_get_prime_bits

Function: int gnutls_dh_get_prime_bits (gnutls_session_t session)

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.

gnutls_dh_get_pubkey

Function: int gnutls_dh_get_pubkey (gnutls_session_t session, gnutls_datum_t * raw_key)

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.

gnutls_dh_get_secret_bits

Function: int gnutls_dh_get_secret_bits (gnutls_session_t session)

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.

gnutls_dh_params_cpy

Function: int gnutls_dh_params_cpy (gnutls_dh_params_t dst, gnutls_dh_params_t src)

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.

gnutls_dh_params_deinit

Function: void gnutls_dh_params_deinit (gnutls_dh_params_t dh_params)

dh_params: Is a structure that holds the prime numbers

This function will deinitialize the DH parameters structure.

gnutls_dh_params_export_pkcs3

Function: int gnutls_dh_params_export_pkcs3 (gnutls_dh_params_t params, gnutls_x509_crt_fmt_t format, unsigned char * params_data, size_t * params_data_size)

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.

gnutls_dh_params_export_raw

Function: int gnutls_dh_params_export_raw (gnutls_dh_params_t params, gnutls_datum_t * prime, gnutls_datum_t * generator, unsigned int * bits)

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.

gnutls_dh_params_generate2

Function: int gnutls_dh_params_generate2 (gnutls_dh_params_t params, unsigned int bits)

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.

gnutls_dh_params_import_pkcs3

Function: int gnutls_dh_params_import_pkcs3 (gnutls_dh_params_t params, const gnutls_datum_t * pkcs3_params, gnutls_x509_crt_fmt_t format)

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.

gnutls_dh_params_import_raw

Function: int gnutls_dh_params_import_raw (gnutls_dh_params_t dh_params, const gnutls_datum_t * prime, const gnutls_datum_t * generator)

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.

gnutls_dh_params_init

Function: int gnutls_dh_params_init (gnutls_dh_params_t * dh_params)

dh_params: Is a structure that will hold the prime numbers

This function will initialize the DH parameters structure.

gnutls_dh_set_prime_bits

Function: void gnutls_dh_set_prime_bits (gnutls_session_t session, unsigned int bits)

session: is a gnutls_session_t structure.

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_UNACCEPTABLE will be returned by the handshake.

gnutls_error_is_fatal

Function: int gnutls_error_is_fatal (int error)

error: is a GnuTLS error code, a negative value

If a GnuTLS function returns a negative value you may feed that value to this function to see if the error condition is fatal.

Note that you may want to check the error code manually, since some non-fatal errors to the protocol may be fatal for you program.

This function is only useful if you are dealing with errors from the record layer or the handshake layer.

Returns: 1 if the error code is fatal, for positive error values, 0 is returned. For unknown error values, -1 is returned.

gnutls_error_to_alert

Function: int gnutls_error_to_alert (int err, int * level)

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 err is GNUTLS_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.

gnutls_ext_register

Function: int gnutls_ext_register (int type, const char * name, gnutls_ext_parse_type_t parse_type, gnutls_ext_recv_func recv_func, gnutls_ext_send_func send_func)

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_TLS or GNUTLS_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_SUCCESS on success, or an error code.

Since: 2.6.0

gnutls_fingerprint

Function: int gnutls_fingerprint (gnutls_digest_algorithm_t algo, const gnutls_datum_t * data, void * result, size_t * result_size)

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.

gnutls_free

Function: void gnutls_free (void * ptr)

This function will free data pointed by ptr.

The deallocation function used is the one set by gnutls_global_set_mem_functions().

gnutls_global_deinit

Function: void gnutls_global_deinit ( void)

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.

gnutls_global_init

Function: int gnutls_global_init ( void)

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 needed

Note 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 as gnutls_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.

gnutls_global_set_log_function

Function: void gnutls_global_set_log_function (gnutls_log_func log_func)

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*);

gnutls_global_set_log_level

Function: void gnutls_global_set_log_level (int level)

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.

gnutls_global_set_mem_functions

Function: void gnutls_global_set_mem_functions (gnutls_alloc_function alloc_func, gnutls_alloc_function secure_alloc_func, gnutls_is_secure_function is_secure_func, gnutls_realloc_function realloc_func, gnutls_free_function free_func)

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.

gnutls_handshake_get_last_in

Function: gnutls_handshake_description_t gnutls_handshake_get_last_in (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_t in gnutls.h for the available handshake descriptions.

Returns: the last handshake message type received, a gnutls_handshake_description_t.

gnutls_handshake_get_last_out

Function: gnutls_handshake_description_t gnutls_handshake_get_last_out (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_t in gnutls.h for the available handshake descriptions.

Returns: the last handshake message type sent, a gnutls_handshake_description_t.

gnutls_handshake_set_max_packet_length

Function: void gnutls_handshake_set_max_packet_length (gnutls_session_t session, size_t max)

session: is a gnutls_session_t structure.

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_LARGE error 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.

gnutls_handshake_set_post_client_hello_function

Function: void gnutls_handshake_set_post_client_hello_function (gnutls_session_t session, gnutls_handshake_post_client_hello_func func)

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.

gnutls_handshake_set_private_extensions

Function: void gnutls_handshake_set_private_extensions (gnutls_session_t session, int allow)

session: is a gnutls_session_t structure.

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 allow is 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.

gnutls_handshake

Function: int gnutls_handshake (gnutls_session_t session)

session: is a gnutls_session_t structure.

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_AGAIN and GNUTLS_E_INTERRUPTED interrupt the handshake procedure, which should be later be resumed. Call this function again, until it returns 0; cf. gnutls_record_get_direction() and gnutls_error_is_fatal().

If this function is called by a server after a rehandshake request then GNUTLS_E_GOT_APPLICATION_DATA or GNUTLS_E_WARNING_ALERT_RECEIVED may 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_SUCCESS on success, otherwise an error.

gnutls_hex2bin

Function: int gnutls_hex2bin (const char * hex_data, size_t hex_size, char * bin_data, size_t * bin_size)

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_size should hold size of bin_data, on return will hold actual size of bin_data.

Convert a buffer with hex data to binary data.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_hex_decode

Function: int gnutls_hex_decode (const gnutls_datum_t * hex_data, char * result, size_t * result_size)

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_BUFFER if the buffer given is not long enough, or 0 on success.

gnutls_hex_encode

Function: int gnutls_hex_encode (const gnutls_datum_t * data, char * result, size_t * result_size)

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_BUFFER if the buffer given is not long enough, or 0 on success.

gnutls_init

Function: int gnutls_init (gnutls_session_t * session, gnutls_connection_end_t con_end)

session: is a pointer to a gnutls_session_t structure.

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_end can be one of GNUTLS_CLIENT and GNUTLS_SERVER.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_kx_get_id

Function: gnutls_kx_algorithm_t gnutls_kx_get_id (const char * name)

name: is a KX name

Convert a string to a gnutls_kx_algorithm_t value. The names are compared in a case insensitive way.

Returns: an id of the specified KX algorithm, or GNUTLS_KX_UNKNOWN on error.

gnutls_kx_get_name

Function: const char * gnutls_kx_get_name (gnutls_kx_algorithm_t algorithm)

algorithm: is a key exchange algorithm

Convert a gnutls_kx_algorithm_t value to a string.

Returns: a pointer to a string that contains the name of the specified key exchange algorithm, or NULL.

gnutls_kx_get

Function: gnutls_kx_algorithm_t gnutls_kx_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get currently used key exchange algorithm.

Returns: the key exchange algorithm used in the last handshake, a gnutls_kx_algorithm_t value.

gnutls_kx_list

Function: const gnutls_kx_algorithm_t * gnutls_kx_list ( void)

Get a list of supported key exchange algorithms.

Returns: a zero-terminated list of gnutls_kx_algorithm_t integers indicating the available key exchange algorithms.

gnutls_kx_set_priority

Function: int gnutls_kx_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

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_SUCCESS on success, or an error code.

gnutls_mac_get_id

Function: gnutls_mac_algorithm_t gnutls_mac_get_id (const char * name)

name: is a MAC algorithm name

Convert a string to a gnutls_mac_algorithm_t value. The names are compared in a case insensitive way.

Returns: an gnutls_mac_algorithm_tid of the specified in a string MAC algorithm, or GNUTLS_MAC_UNKNOWN on failures.

gnutls_mac_get_key_size

Function: size_t gnutls_mac_get_key_size (gnutls_mac_algorithm_t algorithm)

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.

gnutls_mac_get_name

Function: const char * gnutls_mac_get_name (gnutls_mac_algorithm_t algorithm)

algorithm: is a MAC algorithm

Convert a gnutls_mac_algorithm_t value to a string.

Returns: a string that contains the name of the specified MAC algorithm, or NULL.

gnutls_mac_get

Function: gnutls_mac_algorithm_t gnutls_mac_get (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get currently used MAC algorithm.

Returns: the currently used mac algorithm, a gnutls_mac_algorithm_t value.

gnutls_mac_list

Function: const gnutls_mac_algorithm_t * gnutls_mac_list ( void)

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_t integers indicating the available MACs.

gnutls_mac_set_priority

Function: int gnutls_mac_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

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_SUCCESS on success, or an error code.

gnutls_malloc

Function: void * gnutls_malloc (size_t s)

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().

gnutls_openpgp_send_cert

Function: void gnutls_openpgp_send_cert (gnutls_session_t session, gnutls_openpgp_crt_status_t status)

session: is a pointer to a gnutls_session_t structure.

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.

gnutls_oprfi_enable_client

Function: void gnutls_oprfi_enable_client (gnutls_session_t session, size_t len, unsigned char * data)

session: is a gnutls_session_t structure.

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.

gnutls_oprfi_enable_server

Function: void gnutls_oprfi_enable_server (gnutls_session_t session, gnutls_oprfi_callback_func cb, void * userdata)

session: is a gnutls_session_t structure.

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 cb will 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.

gnutls_pem_base64_decode_alloc

Function: int gnutls_pem_base64_decode_alloc (const char * header, const gnutls_datum_t * b64_data, gnutls_datum_t * result)

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.

gnutls_pem_base64_decode

Function: int gnutls_pem_base64_decode (const char * header, const gnutls_datum_t * b64_data, unsigned char * result, size_t * result_size)

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_BUFFER is returned if the buffer given is not long enough, or 0 on success.

gnutls_pem_base64_encode_alloc

Function: int gnutls_pem_base64_encode_alloc (const char * msg, const gnutls_datum_t * data, gnutls_datum_t * result)

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.

gnutls_pem_base64_encode

Function: int gnutls_pem_base64_encode (const char * msg, const gnutls_datum_t * data, char * result, size_t * result_size)

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_BUFFER is returned if the buffer given is not long enough, or 0 on success.

gnutls_perror

Function: void gnutls_perror (int error)

error: is a GnuTLS error code, a negative value

This function is like perror(). The only difference is that it accepts an error number returned by a gnutls function.

gnutls_pk_algorithm_get_name

Function: const char * gnutls_pk_algorithm_get_name (gnutls_pk_algorithm_t algorithm)

algorithm: is a pk algorithm

Convert a gnutls_pk_algorithm_t value to a string.

Returns: a string that contains the name of the specified public key algorithm, or NULL.

gnutls_pk_get_id

Function: gnutls_pk_algorithm_t gnutls_pk_get_id (const char * name)

name: is a string containing a public key algorithm name.

Convert a string to a gnutls_pk_algorithm_t value. The names are compared in a case insensitive way. For example, gnutls_pk_get_id("RSA") will return GNUTLS_PK_RSA.

Returns: an gnutls_pk_algorithm_tid of the specified in a string public key algorithm, or GNUTLS_PK_UNKNOWN on failures.

Since: 2.6.0

gnutls_pk_get_name

Function: const char * gnutls_pk_get_name (gnutls_pk_algorithm_t algorithm)

algorithm: is a public key algorithm

Convert a gnutls_pk_algorithm_t value to a string.

Returns: a pointer to a string that contains the name of the specified public key algorithm, or NULL.

Since: 2.6.0

gnutls_pk_list

Function: const gnutls_pk_algorithm_t * gnutls_pk_list ( void)

Get a list of supported public key algorithms.

Returns: a zero-terminated list of gnutls_pk_algorithm_t integers indicating the available ciphers.

Since: 2.6.0

gnutls_prf_raw

Function: int gnutls_prf_raw (gnutls_session_t session, size_t label_size, const char * label, size_t seed_size, const char * seed, size_t outsize, char * out)

session: is a gnutls_session_t structure.

label_size: length of the label variable.

label: label used in PRF computation, typically a short string.

seed_size: length of the seed variable.

seed: optional extra data to seed the PRF with.

outsize: size of pre-allocated output buffer to hold the output.

out: pre-allocate buffer to hold the generated data.

Apply the TLS Pseudo-Random-Function (PRF) using the master secret on some data.

The label variable usually contain a string denoting the purpose for the generated data. The seed usually contain data such as the client and server random, perhaps together with some additional data that is added to guarantee uniqueness of the output for a particular purpose.

Because the output is not guaranteed to be unique for a particular session unless seed include the client random and server random fields (the PRF would output the same data on another connection resumed from the first one), it is not recommended to use this function directly. The gnutls_prf() function seed the PRF with the client and server random fields directly, and is recommended if you want to generate pseudo random data unique for each session.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_prf

Function: int gnutls_prf (gnutls_session_t session, size_t label_size, const char * label, int server_random_first, size_t extra_size, const char * extra, size_t outsize, char * out)

session: is a gnutls_session_t structure.

label_size: length of the label variable.

label: label used in PRF computation, typically a short string.

server_random_first: non-0 if server random field should be first in seed

extra_size: length of the extra variable.

extra: optional extra data to seed the PRF with.

outsize: size of pre-allocated output buffer to hold the output.

out: pre-allocate buffer to hold the generated data.

Apply the TLS Pseudo-Random-Function (PRF) using the master secret on some data, seeded with the client and server random fields.

The label variable usually contain a string denoting the purpose for the generated data. The server_random_first indicate whether the client random field or the server random field should be first in the seed. Non-0 indicate that the server random field is first, 0 that the client random field is first.

The extra variable can be used to add more data to the seed, after the random variables. It can be used to tie make sure the generated output is strongly connected to some additional data (e.g., a string used in user authentication).

The output is placed in *OUT, which must be pre-allocated.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_priority_deinit

Function: void gnutls_priority_deinit (gnutls_priority_t priority_cache)

priority_cache: is a gnutls_prioritity_t structure.

Deinitializes the priority cache.

gnutls_priority_init

Function: int gnutls_priority_init (gnutls_priority_t * priority_cache, const char * priorities, const char ** err_pos)

priority_cache: is a gnutls_prioritity_t structure.

priorities: is a string describing priorities

err_pos: In case of an error this will have the position in the string the error occured

Sets priorities for the ciphers, key exchange methods, macs and compression methods. This is to avoid using the gnutls_*_priority() functions.

The priorities option allows you to specify a semi-colon separated list of the cipher priorities to enable.

Unless the first keyword is "NONE" the defaults are:

Protocols: TLS1.1, TLS1.0, and SSL3.0.

Compression: NULL.

Certificate types: X.509, OpenPGP.

You can also use predefined sets of ciphersuites: "PERFORMANCE" all the "secure" ciphersuites are enabled, limited to 128 bit ciphers and sorted by terms of speed performance.

"NORMAL" option enables all "secure" ciphersuites. The 256-bit ciphers are included as a fallback only. The ciphers are sorted by security margin.

"SECURE128" flag enables all "secure" ciphersuites with ciphers up to 128 bits, sorted by security margin.

"SECURE256" flag enables all "secure" ciphersuites including the 256 bit ciphers, sorted by security margin.

"EXPORT" all the ciphersuites are enabled, including the low-security 40 bit ciphers.

"NONE" nothing is enabled. This disables even protocols and compression methods.

Special keywords: "!" or "-" appended with an algorithm will remove this algorithm. "+" appended with an algorithm will add this algorithm. "COMPAT" will enable compatibility features for a server. "SSL3_RECORD_VERSION" will use SSL3.0 record version in client hello.

To avoid collisions in order to specify a compression algorithm in this string you have to prefix it with "COMP-", protocol versions with "VERS-" and certificate types with "CTYPE-". All other algorithms don't need a prefix.

For key exchange algorithms when in NORMAL or SECURE levels the perfect forward secrecy algorithms take precendence of the other protocols. In all cases all the supported key exchange algorithms are enabled (except for the RSA-EXPORT which is only enabled in EXPORT level).

Note that although one can select very long key sizes (such as 256 bits) for symmetric algorithms, to actually increase security the public key algorithms have to use longer key sizes as well.

Examples: "NORMAL:!AES-128-CBC", "EXPORT:!VERS-TLS1.0:+COMP-DEFLATE:+CTYPE-OPENPGP", "NONE:+VERS-TLS1.0:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL", "NORMAL", "NORMAL:COMPAT".

For all the current available algorithms and protocols use "gnutls-cli -l" to get a listing.

Returns: On syntax error GNUTLS_E_INVALID_REQUEST is returned, GNUTLS_E_SUCCESS on success, or an error code.

gnutls_priority_set_direct

Function: int gnutls_priority_set_direct (gnutls_session_t session, const char * priorities, const char ** err_pos)

session: is a gnutls_session_t structure.

priorities: is a string describing priorities

err_pos: In case of an error this will have the position in the string the error occured

Sets the priorities to use on the ciphers, key exchange methods, macs and compression methods. This function avoids keeping a priority cache and is used to directly set string priorities to a TLS session. For documentation check the gnutls_priority_init().

Returns: On syntax error GNUTLS_E_INVALID_REQUEST is returned, GNUTLS_E_SUCCESS on success, or an error code.

gnutls_priority_set

Function: int gnutls_priority_set (gnutls_session_t session, gnutls_priority_t priority)

session: is a gnutls_session_t structure.

priority: is a gnutls_priority_t structure.

Sets the priorities to use on the ciphers, key exchange methods, macs and compression methods.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_protocol_get_id

Function: gnutls_protocol_t gnutls_protocol_get_id (const char * name)

name: is a protocol name

The names are compared in a case insensitive way.

Returns: an id of the specified protocol, or GNUTLS_VERSION_UNKNOWN on error.

gnutls_protocol_get_name

Function: const char * gnutls_protocol_get_name (gnutls_protocol_t version)

version: is a (gnutls) version number

Convert a gnutls_protocol_t value to a string.

Returns: a string that contains the name of the specified TLS version (e.g., "TLS1.0"), or NULL.

gnutls_protocol_get_version

Function: gnutls_protocol_t gnutls_protocol_get_version (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get TLS version, a gnutls_protocol_t value.

Returns: the version of the currently used protocol.

gnutls_protocol_list

Function: const gnutls_protocol_t * gnutls_protocol_list ( void)

Get a list of supported protocols, e.g. SSL 3.0, TLS 1.0 etc.

Returns: a zero-terminated list of gnutls_protocol_t integers indicating the available protocols.

gnutls_protocol_set_priority

Function: int gnutls_protocol_set_priority (gnutls_session_t session, const int * list)

session: is a gnutls_session_t structure.

list: is a 0 terminated list of gnutls_protocol_t elements.

Sets the priority on the protocol versions supported by gnutls. This function actually enables or disables protocols. Newer protocol versions always have highest priority.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_psk_allocate_client_credentials

Function: int gnutls_psk_allocate_client_credentials (gnutls_psk_client_credentials_t * sc)

sc: is a pointer to an gnutls_psk_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_psk_allocate_server_credentials

Function: int gnutls_psk_allocate_server_credentials (gnutls_psk_server_credentials_t * sc)

sc: is a pointer to an gnutls_psk_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_psk_client_get_hint

Function: const char * gnutls_psk_client_get_hint (gnutls_session_t session)

session: is a gnutls session

The PSK identity hint may give the client help in deciding which username to use. This should only be called in case of PSK authentication and in case of a client.

Returns: the identity hint of the peer, or NULL in case of an error.

Since: 2.4.0

gnutls_psk_free_client_credentials

Function: void gnutls_psk_free_client_credentials (gnutls_psk_client_credentials_t sc)

sc: is an gnutls_psk_client_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_psk_free_server_credentials

Function: void gnutls_psk_free_server_credentials (gnutls_psk_server_credentials_t sc)

sc: is an gnutls_psk_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_psk_netconf_derive_key

Function: int gnutls_psk_netconf_derive_key (const char * password, const char * psk_identity, const char * psk_identity_hint, gnutls_datum_t * output_key)

password: zero terminated string containing password.

psk_identity: zero terminated string with PSK identity.

psk_identity_hint: zero terminated string with PSK identity hint.

output_key: output variable, contains newly allocated *data pointer.

This function will derive a PSK key from a password, for use with the Netconf protocol.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_psk_server_get_username

Function: const char * gnutls_psk_server_get_username (gnutls_session_t session)

session: is a gnutls session

This should only be called in case of PSK authentication and in case of a server.

Returns: the username of the peer, or NULL in case of an error.

gnutls_psk_set_client_credentials_function

Function: void gnutls_psk_set_client_credentials_function (gnutls_psk_client_credentials_t cred, gnutls_psk_client_credentials_function * func)

cred: is a gnutls_psk_server_credentials_t structure.

func: is the callback function

This function can be used to set a callback to retrieve the username and password for client PSK authentication. The callback's function form is: int (*callback)(gnutls_session_t, char** username, gnutls_datum_t* key);

The username and key->data must be allocated using gnutls_malloc(). username should be ASCII strings or UTF-8 strings prepared using the "SASLprep" profile of "stringprep".

The callback function will be called once per handshake.

The callback function should return 0 on success. -1 indicates an error.

gnutls_psk_set_client_credentials

Function: int gnutls_psk_set_client_credentials (gnutls_psk_client_credentials_t res, const char * username, const gnutls_datum_t * key, gnutls_psk_key_flags flags)

res: is an gnutls_psk_client_credentials_t structure.

username: is the user's zero-terminated userid

key: is the user's key

This function sets the username and password, in a gnutls_psk_client_credentials_t structure. Those will be used in PSK authentication. username should be an ASCII string or UTF-8 strings prepared using the "SASLprep" profile of "stringprep". The key can be either in raw byte format or in Hex (not with the '0x' prefix).

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_psk_set_params_function

Function: void gnutls_psk_set_params_function (gnutls_psk_server_credentials_t res, gnutls_params_function * func)

res: is a gnutls_psk_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 psk authentication. The callback should return zero on success.

gnutls_psk_set_server_credentials_file

Function: int gnutls_psk_set_server_credentials_file (gnutls_psk_server_credentials_t res, const char * password_file)

res: is an gnutls_psk_server_credentials_t structure.

password_file: is the PSK password file (passwd.psk)

This function sets the password file, in a gnutls_psk_server_credentials_t structure. This password file holds usernames and keys and will be used for PSK authentication.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_psk_set_server_credentials_function

Function: void gnutls_psk_set_server_credentials_function (gnutls_psk_server_credentials_t cred, gnutls_psk_server_credentials_function * func)

cred: is a gnutls_psk_server_credentials_t structure.

func: is the callback function

This function can be used to set a callback to retrieve the user's PSK credentials. The callback's function form is: int (*callback)(gnutls_session_t, const char* username, gnutls_datum_t* key);

username contains the actual username. The key must be filled in using the gnutls_malloc().

In case the callback returned a negative number then gnutls will assume that the username does not exist.

The callback function will only be called once per handshake. The callback function should return 0 on success, while -1 indicates an error.

gnutls_psk_set_server_credentials_hint

Function: int gnutls_psk_set_server_credentials_hint (gnutls_psk_server_credentials_t res, const char * hint)

res: is an gnutls_psk_server_credentials_t structure.

hint: is the PSK identity hint string

This function sets the identity hint, in a gnutls_psk_server_credentials_t structure. This hint is sent to the client to help it chose a good PSK credential (i.e., username and password).

Returns: GNUTLS_E_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_psk_set_server_dh_params

Function: void gnutls_psk_set_server_dh_params (gnutls_psk_server_credentials_t res, gnutls_dh_params_t dh_params)

res: is a gnutls_psk_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 Diffie Hellman with PSK cipher suites.

gnutls_psk_set_server_params_function

Function: void gnutls_psk_set_server_params_function (gnutls_psk_server_credentials_t res, gnutls_params_function * func)

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 PSK authentication. The callback should return zero on success.

gnutls_record_check_pending

Function: size_t gnutls_record_check_pending (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function checks if there are any data to receive in the gnutls buffers. Returns the size of that data or 0. Notice that you may also use select() to check for data in a TCP connection, instead of this function. (gnutls leaves some data in the tcp buffer in order for select to work).

gnutls_record_disable_padding

Function: void gnutls_record_disable_padding (gnutls_session_t session)

session: is a gnutls_session_t structure.

Used to disabled padding in TLS 1.0 and above. Normally you do not need to use this function, but there are buggy clients that complain if a server pads the encrypted data. This of course will disable protection against statistical attacks on the data.

Normally only servers that require maximum compatibility with everything out there, need to call this function.

gnutls_record_get_direction

Function: int gnutls_record_get_direction (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function provides information about the internals of the record protocol and is only useful if a prior gnutls function call (e.g. gnutls_handshake()) was interrupted for some reason, that is, if a function returned GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN. In such a case, you might want to call select() or poll() before calling the interrupted gnutls function again. To tell you whether a file descriptor should be selected for either reading or writing, gnutls_record_get_direction() returns 0 if the interrupted function was trying to read data, and 1 if it was trying to write data.

Returns: 0 if trying to read data, 1 if trying to write data.

gnutls_record_get_max_size

Function: size_t gnutls_record_get_max_size (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function returns the maximum record packet size in this connection. The maximum record size is negotiated by the client after the first handshake message.

gnutls_record_recv

Function: ssize_t gnutls_record_recv (gnutls_session_t session, void * data, size_t sizeofdata)

session: is a gnutls_session_t structure.

data: the buffer that the data will be read into

sizeofdata: the number of requested bytes

This function has the similar semantics with recv(). The only difference is that is accepts a GNUTLS session, and uses different error codes.

In the special case that a server requests a renegotiation, the client may receive an error code of GNUTLS_E_REHANDSHAKE. This message may be simply ignored, replied with an alert containing NO_RENEGOTIATION, or replied with a new handshake, depending on the client's will.

If EINTR is returned by the internal push function (the default is recv()) then GNUTLS_E_INTERRUPTED will be returned. If GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN is returned, you must call this function again to get the data. See also gnutls_record_get_direction().

A server may also receive GNUTLS_E_REHANDSHAKE when a client has initiated a handshake. In that case the server can only initiate a handshake or terminate the connection.

Returns: the number of bytes received and zero on EOF. A negative error code is returned in case of an error. The number of bytes received might be less than sizeofdata.

gnutls_record_send

Function: ssize_t gnutls_record_send (gnutls_session_t session, const void * data, size_t sizeofdata)

session: is a gnutls_session_t structure.

data: contains the data to send

sizeofdata: is the length of the data

This function has the similar semantics with send(). The only difference is that is accepts a GNUTLS session, and uses different error codes.

Note that if the send buffer is full, send() will block this function. See the send() documentation for full information. You can replace the default push function by using gnutls_transport_set_ptr2() with a call to send() with a MSG_DONTWAIT flag if blocking is a problem.

If the EINTR is returned by the internal push function (the default is send()} then GNUTLS_E_INTERRUPTED will be returned. If GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN is returned, you must call this function again, with the same parameters; alternatively you could provide a NULL pointer for data, and 0 for size. cf. gnutls_record_get_direction().

Returns: the number of bytes sent, or a negative error code. The number of bytes sent might be less than sizeofdata. The maximum number of bytes this function can send in a single call depends on the negotiated maximum record size.

gnutls_record_set_max_size

Function: ssize_t gnutls_record_set_max_size (gnutls_session_t session, size_t size)

session: is a gnutls_session_t structure.

size: is the new size

This function sets the maximum record packet size in this connection. This property can only be set to clients. The server may choose not to accept the requested size.

Acceptable values are 512(=2^9), 1024(=2^10), 2048(=2^11) and 4096(=2^12). Returns 0 on success. The requested record size does get in effect immediately only while sending data. The receive part will take effect after a successful handshake.

This function uses a TLS extension called 'max record size'. Not all TLS implementations use or even understand this extension.

gnutls_rehandshake

Function: int gnutls_rehandshake (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function will renegotiate security parameters with the client. This should only be called in case of a server.

This message informs the peer that we want to renegotiate parameters (perform a handshake).

If this function succeeds (returns 0), you must call the gnutls_handshake() function in order to negotiate the new parameters.

If the client does not wish to renegotiate parameters he will should with an alert message, thus the return code will be GNUTLS_E_WARNING_ALERT_RECEIVED and the alert will be GNUTLS_A_NO_RENEGOTIATION. A client may also choose to ignore this message.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

gnutls_rsa_export_get_modulus_bits

Function: int gnutls_rsa_export_get_modulus_bits (gnutls_session_t session)

session: is a gnutls session

Get the export RSA parameter's modulus size.

Returns: the bits used in the last RSA-EXPORT key exchange with the peer, or a negative value in case of error.

gnutls_rsa_export_get_pubkey

Function: int gnutls_rsa_export_get_pubkey (gnutls_session_t session, gnutls_datum_t * exponent, gnutls_datum_t * modulus)

session: is a gnutls session

exponent: will hold the exponent.

modulus: will hold the modulus.

This function will return the peer's public key exponent and modulus used in the last RSA-EXPORT authentication. The output parameters must be freed with gnutls_free().

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_rsa_params_cpy

Function: int gnutls_rsa_params_cpy (gnutls_rsa_params_t dst, gnutls_rsa_params_t src)

dst: Is the destination structure, which should be initialized.

src: Is the source structure

This function will copy the RSA parameters structure from source to destination.

gnutls_rsa_params_deinit

Function: void gnutls_rsa_params_deinit (gnutls_rsa_params_t rsa_params)

rsa_params: Is a structure that holds the parameters

This function will deinitialize the RSA parameters structure.

gnutls_rsa_params_export_pkcs1

Function: int gnutls_rsa_params_export_pkcs1 (gnutls_rsa_params_t params, gnutls_x509_crt_fmt_t format, unsigned char * params_data, size_t * params_data_size)

params: Holds the RSA parameters

format: the format of output params. One of PEM or DER.

params_data: will contain a PKCS1 RSAPublicKey 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 RSA parameters to a PKCS1 RSAPublicKey structure. 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 RSA PRIVATE KEY".

In case of failure a negative value will be returned, and 0 on success.

gnutls_rsa_params_export_raw

Function: int gnutls_rsa_params_export_raw (gnutls_rsa_params_t params, gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u, unsigned int * bits)

params: a structure that holds the rsa parameters

m: will hold the modulus

e: will hold the public exponent

d: will hold the private exponent

p: will hold the first prime (p)

q: will hold the second prime (q)

u: will hold the coefficient

bits: if non null will hold the prime's number of bits

This function will export the RSA parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

gnutls_rsa_params_generate2

Function: int gnutls_rsa_params_generate2 (gnutls_rsa_params_t params, unsigned int bits)

params: The structure where the parameters will be stored

bits: is the prime's number of bits

This function will generate new temporary RSA parameters for use in RSA-EXPORT ciphersuites. This function is normally slow.

Note that if the parameters are to be used in export cipher suites the bits value should be 512 or less. Also note that the generation of new RSA parameters is only useful to servers. Clients use the parameters sent by the server, thus it's no use calling this in client side.

gnutls_rsa_params_import_pkcs1

Function: int gnutls_rsa_params_import_pkcs1 (gnutls_rsa_params_t params, const gnutls_datum_t * pkcs1_params, gnutls_x509_crt_fmt_t format)

params: A structure where the parameters will be copied to

pkcs1_params: should contain a PKCS1 RSAPublicKey structure PEM or DER encoded

format: the format of params. PEM or DER.

This function will extract the RSAPublicKey found in a PKCS1 formatted structure.

If the structure is PEM encoded, it should have a header of "BEGIN RSA PRIVATE KEY".

In case of failure a negative value will be returned, and 0 on success.

gnutls_rsa_params_import_raw

Function: int gnutls_rsa_params_import_raw (gnutls_rsa_params_t rsa_params, const gnutls_datum_t * m, const gnutls_datum_t * e, const gnutls_datum_t * d, const gnutls_datum_t * p, const gnutls_datum_t * q, const gnutls_datum_t * u)

rsa_params: Is a structure will hold the parameters

m: holds the modulus

e: holds the public exponent

d: holds the private exponent

p: holds the first prime (p)

q: holds the second prime (q)

u: holds the coefficient

This function will replace the parameters in the given structure. The new parameters should be stored in the appropriate gnutls_datum.

gnutls_rsa_params_init

Function: int gnutls_rsa_params_init (gnutls_rsa_params_t * rsa_params)

rsa_params: Is a structure that will hold the parameters

This function will initialize the temporary RSA parameters structure.

gnutls_server_name_get

Function: int gnutls_server_name_get (gnutls_session_t session, void * data, size_t * data_length, unsigned int * type, unsigned int indx)

session: is a gnutls_session_t structure.

data: will hold the data

data_length: will hold the data length. Must hold the maximum size of data.

type: will hold the server name indicator type

indx: is the index of the server_name

This function will allow you to get the name indication (if any), a client has sent. The name indication may be any of the enumeration gnutls_server_name_type_t.

If type is GNUTLS_NAME_DNS, then this function is to be used by servers that support virtual hosting, and the data will be a null terminated UTF-8 string.

If data has not enough size to hold the server name GNUTLS_E_SHORT_MEMORY_BUFFER is returned, and data_length will hold the required size.

index is used to retrieve more than one server names (if sent by the client). The first server name has an index of 0, the second 1 and so on. If no name with the given index exists GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.

gnutls_server_name_set

Function: int gnutls_server_name_set (gnutls_session_t session, gnutls_server_name_type_t type, const void * name, size_t name_length)

session: is a gnutls_session_t structure.

type: specifies the indicator type

name: is a string that contains the server name.

name_length: holds the length of name

This function is to be used by clients that want to inform (via a TLS extension mechanism) the server of the name they connected to. This should be used by clients that connect to servers that do virtual hosting.

The value of name depends on the ind type. In case of GNUTLS_NAME_DNS, an ASCII or UTF-8 null terminated string, without the trailing dot, is expected. IPv4 or IPv6 addresses are not permitted.

gnutls_session_enable_compatibility_mode

Function: void gnutls_session_enable_compatibility_mode (gnutls_session_t session)

session: is a gnutls_session_t structure.

This function can be used to disable certain (security) features in TLS in order to maintain maximum compatibility with buggy clients. It is equivalent to calling: gnutls_record_disable_padding()

Normally only servers that require maximum compatibility with everything out there, need to call this function.

gnutls_session_get_client_random

Function: const void * gnutls_session_get_client_random (gnutls_session_t session)

session: is a gnutls_session_t structure.

Return a pointer to the 32-byte client random field used in the session. The pointer must not be modified or deallocated.

If a client random value has not yet been established, the output will be garbage; in particular, a NULL return value should not be expected.

Returns: pointer to client random data.

gnutls_session_get_data2

Function: int gnutls_session_get_data2 (gnutls_session_t session, gnutls_datum_t * data)

session: is a gnutls_session_t structure.

Returns all session parameters, in order to support resuming. The client should call this, and keep the returned session, if he wants to resume that current version later by calling gnutls_session_set_data() This function must be called after a successful handshake. The returned datum must be freed with gnutls_free().

Resuming sessions is really useful and speedups connections after a succesful one.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_session_get_data

Function: int gnutls_session_get_data (gnutls_session_t session, void * session_data, size_t * session_data_size)

session: is a gnutls_session_t structure.

session_data: is a pointer to space to hold the session.

session_data_size: is the session_data's size, or it will be set by the function.

Returns all session parameters, in order to support resuming. The client should call this, and keep the returned session, if he wants to resume that current version later by calling gnutls_session_set_data() This function must be called after a successful handshake.

Resuming sessions is really useful and speedups connections after a succesful one.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_session_get_id

Function: int gnutls_session_get_id (gnutls_session_t session, void * session_id, size_t * session_id_size)

session: is a gnutls_session_t structure.

session_id: is a pointer to space to hold the session id.

session_id_size: is the session id's size, or it will be set by the function.

Returns the current session id. This can be used if you want to check if the next session you tried to resume was actually resumed. This is because resumed sessions have the same sessionID with the original session.

Session id is some data set by the server, that identify the current session. In TLS 1.0 and SSL 3.0 session id is always less than 32 bytes.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_session_get_master_secret

Function: const void * gnutls_session_get_master_secret (gnutls_session_t session)

session: is a gnutls_session_t structure.

Return a pointer to the 48-byte master secret in the session. The pointer must not be modified or deallocated.

If a master secret value has not yet been established, the output will be garbage; in particular, a NULL return value should not be expected.

Consider using gnutls_prf() rather than extracting the master secret and use it to derive further data.

Returns: pointer to master secret data.

gnutls_session_get_ptr

Function: void * gnutls_session_get_ptr (gnutls_session_t session)

session: is a gnutls_session_t structure.

Get user pointer for session. Useful in callbacks. This is the pointer set with gnutls_session_set_ptr().

Returns: the user given pointer from the session structure, or NULL if it was never set.

gnutls_session_get_server_random

Function: const void * gnutls_session_get_server_random (gnutls_session_t session)

session: is a gnutls_session_t structure.

Return a pointer to the 32-byte server random field used in the session. The pointer must not be modified or deallocated.

If a server random value has not yet been established, the output will be garbage; in particular, a NULL return value should not be expected.

Returns: pointer to server random data.

gnutls_session_is_resumed

Function: int gnutls_session_is_resumed (gnutls_session_t session)

session: is a gnutls_session_t structure.

Check whether session is resumed or not.

Returns: non zero if this session is resumed, or a zero if this is a new session.

gnutls_session_set_data

Function: int gnutls_session_set_data (gnutls_session_t session, const void * session_data, size_t session_data_size)

session: is a gnutls_session_t structure.

session_data: is a pointer to space to hold the session.

session_data_size: is the session's size

Sets all session parameters, in order to resume a previously established session. The session data given must be the one returned by gnutls_session_get_data(). This function should be called before gnutls_handshake().

Keep in mind that session resuming is advisory. The server may choose not to resume the session, thus a full handshake will be performed.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_session_set_finished_function

Function: void gnutls_session_set_finished_function (gnutls_session_t session, gnutls_finished_callback_func finished_func)

session: is a gnutls_session_t structure.

finished_func: a gnutls_finished_callback_func callback.

Register a callback function for the session that will be called when a TLS Finished message has been generated. The function is typically used to copy away the TLS finished message for later use as a channel binding or similar purpose.

The callback should follow this prototype: void callback (gnutls_session_t session, const void *finished, size_t len);

The finished parameter will contain the binary TLS finished message, and len will contains its length. For SSLv3 connections, the len parameter will be 36 and for TLS connections it will be 12.

It is recommended that the function returns quickly in order to not delay the handshake. Use the function to store a copy of the TLS finished message for later use.

Since: 2.6.0

gnutls_session_set_ptr

Function: void gnutls_session_set_ptr (gnutls_session_t session, void * ptr)

session: is a gnutls_session_t structure.

ptr: is the user pointer

This function will set (associate) the user given pointer ptr to the session structure. This is pointer can be accessed with gnutls_session_get_ptr().

gnutls_set_default_export_priority

Function: int gnutls_set_default_export_priority (gnutls_session_t session)

session: is a gnutls_session_t structure.

Sets some default priority on the ciphers, key exchange methods, macs and compression methods. This function also includes weak algorithms.

This is the same as calling: gnutls_priority_set_direct (session, "EXPORT", NULL);

This function is kept around for backwards compatibility, but because of its wide use it is still fully supported. If you wish to allow users to provide a string that specify which ciphers to use (which is recommended), you should use gnutls_priority_set_direct() or gnutls_priority_set() instead.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_set_default_priority

Function: int gnutls_set_default_priority (gnutls_session_t session)

session: is a gnutls_session_t structure.

Sets some default priority on the ciphers, key exchange methods, macs and compression methods.

This is the same as calling: gnutls_priority_set_direct (session, "NORMAL", NULL);

This function is kept around for backwards compatibility, but because of its wide use it is still fully supported. If you wish to allow users to provide a string that specify which ciphers to use (which is recommended), you should use gnutls_priority_set_direct() or gnutls_priority_set() instead.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_sign_algorithm_get_name

Function: const char * gnutls_sign_algorithm_get_name (gnutls_sign_algorithm_t sign)

Convert a gnutls_sign_algorithm_t value to a string.

Returns: a string that contains the name of the specified sign algorithm, or NULL.

gnutls_sign_callback_get

Function: gnutls_sign_func gnutls_sign_callback_get (gnutls_session_t session, void ** userdata)

session: is a gnutls session

userdata: if non-NULL, will be set to abstract callback pointer.

Retrieve the callback function, and its userdata pointer.

Returns: The function pointer set by gnutls_sign_callback_set(), or if not set, NULL.

gnutls_sign_callback_set

Function: void gnutls_sign_callback_set (gnutls_session_t session, gnutls_sign_func sign_func, void * userdata)

session: is a gnutls session

sign_func: function pointer to application's sign callback.

userdata: void pointer that will be passed to sign callback.

Set the callback function. The function must have this prototype:

typedef int (*gnutls_sign_func) (gnutls_session_t session, void *userdata, gnutls_certificate_type_t cert_type, const gnutls_datum_t * cert, const gnutls_datum_t * hash, gnutls_datum_t * signature);

The userdata parameter is passed to the sign_func verbatim, and can be used to store application-specific data needed in the callback function. See also gnutls_sign_callback_get().

gnutls_sign_get_id

Function: gnutls_sign_algorithm_t gnutls_sign_get_id (const char * name)

name: is a MAC algorithm name

The names are compared in a case insensitive way.

Returns: return a gnutls_sign_algorithm_t value corresponding to the specified cipher, or GNUTLS_SIGN_UNKNOWN on error.

gnutls_sign_get_name

Function: const char * gnutls_sign_get_name (gnutls_sign_algorithm_t algorithm)

algorithm: is a public key signature algorithm

Convert a gnutls_sign_algorithm_t value to a string.

Returns: a pointer to a string that contains the name of the specified public key signature algorithm, or NULL.

Since: 2.6.0

gnutls_sign_list

Function: const gnutls_sign_algorithm_t * gnutls_sign_list ( void)

Get a list of supported public key signature algorithms.

Returns: a zero-terminated list of gnutls_sign_algorithm_t integers indicating the available ciphers.

gnutls_srp_allocate_client_credentials

Function: int gnutls_srp_allocate_client_credentials (gnutls_srp_client_credentials_t * sc)

sc: is a pointer to an gnutls_srp_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, or an error code.

gnutls_srp_allocate_server_credentials

Function: int gnutls_srp_allocate_server_credentials (gnutls_srp_server_credentials_t * sc)

sc: is a pointer to an gnutls_srp_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, or an error code.

gnutls_srp_base64_decode_alloc

Function: int gnutls_srp_base64_decode_alloc (const gnutls_datum_t * b64_data, gnutls_datum_t * result)

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. It will decode using the base64 algorithm as used in libsrp.

You should use gnutls_free() to free the returned data.

Warning! This base64 encoding is not the "standard" encoding, so do not use it for non-SRP purposes.

Returns: 0 on success, or an error code.

gnutls_srp_base64_decode

Function: int gnutls_srp_base64_decode (const gnutls_datum_t * b64_data, char * result, size_t * result_size)

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, using the base64 encoding found in libsrp.

Note that b64_data should be null terminated.

Warning! This base64 encoding is not the "standard" encoding, so do not use it for non-SRP purposes.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the buffer given is not long enough, or 0 on success.

gnutls_srp_base64_encode_alloc

Function: int gnutls_srp_base64_encode_alloc (const gnutls_datum_t * data, gnutls_datum_t * result)

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 SRP password files. This function will allocate the required memory to hold the encoded data.

You should use gnutls_free() to free the returned data.

Warning! This base64 encoding is not the "standard" encoding, so do not use it for non-SRP purposes.

Returns: 0 on success, or an error code.

gnutls_srp_base64_encode

Function: int gnutls_srp_base64_encode (const gnutls_datum_t * data, char * result, size_t * result_size)

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, as used in the libsrp. This is the encoding used in SRP password files. If the provided buffer is not long enough GNUTLS_E_SHORT_MEMORY_BUFFER is returned.

Warning! This base64 encoding is not the "standard" encoding, so do not use it for non-SRP purposes.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the buffer given is not long enough, or 0 on success.

gnutls_srp_free_client_credentials

Function: void gnutls_srp_free_client_credentials (gnutls_srp_client_credentials_t sc)

sc: is an gnutls_srp_client_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_srp_free_server_credentials

Function: void gnutls_srp_free_server_credentials (gnutls_srp_server_credentials_t sc)

sc: is an gnutls_srp_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_srp_server_get_username

Function: const char * gnutls_srp_server_get_username (gnutls_session_t session)

session: is a gnutls session

This function will return the username of the peer. This should only be called in case of SRP authentication and in case of a server. Returns NULL in case of an error.

Returns: SRP username of the peer, or NULL in case of error.

gnutls_srp_set_client_credentials_function

Function: void gnutls_srp_set_client_credentials_function (gnutls_srp_client_credentials_t cred, gnutls_srp_client_credentials_function * func)

cred: is a gnutls_srp_server_credentials_t structure.

func: is the callback function

This function can be used to set a callback to retrieve the username and password for client SRP authentication.

The callback's function form is:

int (*callback)(gnutls_session_t, char** username, char**password);

The username and password must be allocated using gnutls_malloc(). username and password should be ASCII strings or UTF-8 strings prepared using the "SASLprep" profile of "stringprep".

The callback function will be called once per handshake before the initial hello message is sent.

The callback should not return a negative error code the second time called, since the handshake procedure will be aborted.

The callback function should return 0 on success. -1 indicates an error.

gnutls_srp_set_client_credentials

Function: int gnutls_srp_set_client_credentials (gnutls_srp_client_credentials_t res, const char * username, const char * password)

res: is an gnutls_srp_client_credentials_t structure.

username: is the user's userid

password: is the user's password

This function sets the username and password, in a gnutls_srp_client_credentials_t structure. Those will be used in SRP authentication. username and password should be ASCII strings or UTF-8 strings prepared using the "SASLprep" profile of "stringprep".

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, or an error code.

gnutls_srp_set_prime_bits

Function: void gnutls_srp_set_prime_bits (gnutls_session_t session, unsigned int bits)

session: is a gnutls_session_t structure.

bits: is the number of bits

This function sets the minimum accepted number of bits, for use in an SRP key exchange. If zero, the default 2048 bits will be used.

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_RECEIVED_ILLEGAL_PARAMETER will be returned by the handshake.

Since: 2.6.0

gnutls_srp_set_server_credentials_file

Function: int gnutls_srp_set_server_credentials_file (gnutls_srp_server_credentials_t res, const char * password_file, const char * password_conf_file)

res: is an gnutls_srp_server_credentials_t structure.

password_file: is the SRP password file (tpasswd)

password_conf_file: is the SRP password conf file (tpasswd.conf)

This function sets the password files, in a gnutls_srp_server_credentials_t structure. Those password files hold usernames and verifiers and will be used for SRP authentication.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, or an error code.

gnutls_srp_set_server_credentials_function

Function: void gnutls_srp_set_server_credentials_function (gnutls_srp_server_credentials_t cred, gnutls_srp_server_credentials_function * func)

cred: is a gnutls_srp_server_credentials_t structure.

func: is the callback function

This function can be used to set a callback to retrieve the user's SRP credentials. The callback's function form is: int (*callback)(gnutls_session_t, const char* username, gnutls_datum_t* salt, gnutls_datum_t *verifier, gnutls_datum_t* g, gnutls_datum_t* n);

username contains the actual username. The salt, verifier, generator and prime must be filled in using the gnutls_malloc(). For convenience prime and generator may also be one of the static parameters defined in extra.h.

In case the callback returned a negative number then gnutls will assume that the username does not exist.

In order to prevent attackers from guessing valid usernames, if a user does not exist, g and n values should be filled in using a random user's parameters. In that case the callback must return the special value (1).

The callback function will only be called once per handshake. The callback function should return 0 on success, while -1 indicates an error.

gnutls_srp_verifier

Function: int gnutls_srp_verifier (const char * username, const char * password, const gnutls_datum_t * salt, const gnutls_datum_t * generator, const gnutls_datum_t * prime, gnutls_datum_t * res)

username: is the user's name

password: is the user's password

salt: should be some randomly generated bytes

generator: is the generator of the group

prime: is the group's prime

res: where the verifier will be stored.

This function will create an SRP verifier, as specified in RFC2945. The prime and generator should be one of the static parameters defined in gnutls/extra.h or may be generated using the libgcrypt functions gcry_prime_generate() and gcry_prime_group_generator().

The verifier will be allocated with malloc and will be stored in res using binary format.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, or an error code.

gnutls_strerror_name

Function: const char * gnutls_strerror_name (int error)

error: is an error returned by a gnutls function.

Return the GnuTLS error code define as a string. For example, gnutls_strerror_name (GNUTLS_E_DH_PRIME_UNACCEPTABLE) will return the string "GNUTLS_E_DH_PRIME_UNACCEPTABLE".

Returns: A string corresponding to the symbol name of the error code.

Since: 2.6.0

gnutls_strerror

Function: const char * gnutls_strerror (int error)

error: is a GnuTLS error code, a negative value

This function is similar to strerror(). Differences: it accepts an error number returned by a gnutls function; In case of an unknown error a descriptive string is sent instead of NULL.

Error codes are always a negative value.

Returns: A string explaining the GnuTLS error message.

gnutls_transport_get_ptr2

Function: void gnutls_transport_get_ptr2 (gnutls_session_t session, gnutls_transport_ptr_t * recv_ptr, gnutls_transport_ptr_t * send_ptr)

session: is a gnutls_session_t structure.

recv_ptr: will hold the value for the pull function

send_ptr: will hold the value for the push function

Used to get the arguments of the transport functions (like PUSH and PULL). These should have been set using gnutls_transport_set_ptr2().

gnutls_transport_get_ptr

Function: gnutls_transport_ptr_t gnutls_transport_get_ptr (gnutls_session_t session)

session: is a gnutls_session_t structure.

Used to get the first argument of the transport function (like PUSH and PULL). This must have been set using gnutls_transport_set_ptr().

Returns: first argument of the transport function.

gnutls_transport_set_errno

Function: void gnutls_transport_set_errno (gnutls_session_t session, int err)

session: is a gnutls_session_t structure.

err: error value to store in session-specific errno variable.

Store err in the session-specific errno variable. Useful values for err is EAGAIN and EINTR, other values are treated will be treated as real errors in the push/pull function.

This function is useful in replacement push/pull functions set by gnutls_transport_set_push_function and gnutls_transport_set_pullpush_function under Windows, where the replacement push/pull may not have access to the same errno variable that is used by GnuTLS (e.g., the application is linked to msvcr71.dll and gnutls is linked to msvcrt.dll).

If you don't have the session variable easily accessible from the push/pull function, and don't worry about thread conflicts, you can also use gnutls_transport_set_global_errno().

gnutls_transport_set_global_errno

Function: void gnutls_transport_set_global_errno (int err)

err: error value to store in global errno variable.

Store err in the global errno variable. Useful values for err is EAGAIN and EINTR, other values are treated will be treated as real errors in the push/pull function.

This function is useful in replacement push/pull functions set by gnutls_transport_set_push_function and gnutls_transport_set_pullpush_function under Windows, where the replacement push/pull may not have access to the same errno variable that is used by GnuTLS (e.g., the application is linked to msvcr71.dll and gnutls is linked to msvcrt.dll).

Whether this function is thread safe or not depends on whether the global variable errno is thread safe, some system libraries make it a thread-local variable. When feasible, using the guaranteed thread-safe gnutls_transport_set_errno() may be better.

gnutls_transport_set_lowat

Function: void gnutls_transport_set_lowat (gnutls_session_t session, int num)

session: is a gnutls_session_t structure.

num: is the low water value.

Used to set the lowat value in order for select to check if there are pending data to socket buffer. Used only if you have changed the default low water value (default is 1). Normally you will not need that function. This function is only useful if using berkeley style sockets. Otherwise it must be called and set lowat to zero.

gnutls_transport_set_ptr2

Function: void gnutls_transport_set_ptr2 (gnutls_session_t session, gnutls_transport_ptr_t recv_ptr, gnutls_transport_ptr_t send_ptr)

session: is a gnutls_session_t structure.

recv_ptr: is the value for the pull function

send_ptr: is the value for the push function

Used to set the first argument of the transport function (like PUSH and PULL). In berkeley style sockets this function will set the connection handle. With this function you can use two different pointers for receiving and sending.

gnutls_transport_set_ptr

Function: void gnutls_transport_set_ptr (gnutls_session_t session, gnutls_transport_ptr_t ptr)

session: is a gnutls_session_t structure.

ptr: is the value.

Used to set the first argument of the transport function (like PUSH and PULL). In berkeley style sockets this function will set the connection handle.

gnutls_transport_set_pull_function

Function: void gnutls_transport_set_pull_function (gnutls_session_t session, gnutls_pull_func pull_func)

session: gnutls session

pull_func: a callback function similar to read()

This is the function where you set a function for gnutls to receive data. Normally, if you use berkeley style sockets, do not need to use this function since the default (recv(2)) will probably be ok.

PULL_FUNC is of the form, ssize_t (*gnutls_pull_func)(gnutls_transport_ptr_t, void*, size_t);

gnutls_transport_set_push_function

Function: void gnutls_transport_set_push_function (gnutls_session_t session, gnutls_push_func push_func)

session: gnutls session

push_func: a callback function similar to write()

This is the function where you set a push function for gnutls to use in order to send data. If you are going to use berkeley style sockets, you do not need to use this function since the default (send(2)) will probably be ok. Otherwise you should specify this function for gnutls to be able to send data.

PUSH_FUNC is of the form, ssize_t (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2 X.509 Certificate Functions

The following functions are to be used for X.509 certificate handling. Their prototypes lie in `gnutls/x509.h'.

gnutls_pkcs12_bag_decrypt

Function: int gnutls_pkcs12_bag_decrypt (gnutls_pkcs12_bag_t bag, const char * pass)

bag: The bag

pass: The password used for encryption. This can only be ASCII.

This function will decrypt the given encrypted bag and return 0 on success.

gnutls_pkcs12_bag_deinit

Function: void gnutls_pkcs12_bag_deinit (gnutls_pkcs12_bag_t bag)

bag: The structure to be initialized

This function will deinitialize a PKCS12 Bag structure.

gnutls_pkcs12_bag_encrypt

Function: int gnutls_pkcs12_bag_encrypt (gnutls_pkcs12_bag_t bag, const char * pass, unsigned int flags)

bag: The bag

pass: The password used for encryption. This can only be ASCII.

flags: should be one of gnutls_pkcs_encrypt_flags_t elements bitwise or'd

This function will encrypt the given bag and return 0 on success.

gnutls_pkcs12_bag_get_count

Function: int gnutls_pkcs12_bag_get_count (gnutls_pkcs12_bag_t bag)

bag: The bag

This function will return the number of the elements withing the bag.

gnutls_pkcs12_bag_get_data

Function: int gnutls_pkcs12_bag_get_data (gnutls_pkcs12_bag_t bag, int indx, gnutls_datum_t * data)

bag: The bag

indx: The element of the bag to get the data from

data: where the bag's data will be. Should be treated as constant.

This function will return the bag's data. The data is a constant that is stored into the bag. Should not be accessed after the bag is deleted.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative error code on error.

gnutls_pkcs12_bag_get_friendly_name

Function: int gnutls_pkcs12_bag_get_friendly_name (gnutls_pkcs12_bag_t bag, int indx, char ** name)

bag: The bag

indx: The bag's element to add the id

name: will hold a pointer to the name (to be treated as const)

This function will return the friendly name, of the specified bag element. The key ID is usually used to distinguish the local private key and the certificate pair.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. or a negative value on error.

gnutls_pkcs12_bag_get_key_id

Function: int gnutls_pkcs12_bag_get_key_id (gnutls_pkcs12_bag_t bag, int indx, gnutls_datum_t * id)

bag: The bag

indx: The bag's element to add the id

id: where the ID will be copied (to be treated as const)

This function will return the key ID, of the specified bag element. The key ID is usually used to distinguish the local private key and the certificate pair.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. or a negative value on error.

gnutls_pkcs12_bag_get_type

Function: gnutls_pkcs12_bag_type_t gnutls_pkcs12_bag_get_type (gnutls_pkcs12_bag_t bag, int indx)

bag: The bag

indx: The element of the bag to get the type

This function will return the bag's type. One of the gnutls_pkcs12_bag_type_t enumerations.

gnutls_pkcs12_bag_init

Function: int gnutls_pkcs12_bag_init (gnutls_pkcs12_bag_t * bag)

bag: The structure to be initialized

This function will initialize a PKCS12 bag structure. PKCS12 Bags usually contain private keys, lists of X.509 Certificates and X.509 Certificate revocation lists.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs12_bag_set_crl

Function: int gnutls_pkcs12_bag_set_crl (gnutls_pkcs12_bag_t bag, gnutls_x509_crl_t crl)

bag: The bag

crl: the CRL to be copied.

This function will insert the given CRL into the bag. This is just a wrapper over gnutls_pkcs12_bag_set_data().

Returns: the index of the added bag on success, or a negative value on failure.

gnutls_pkcs12_bag_set_crt

Function: int gnutls_pkcs12_bag_set_crt (gnutls_pkcs12_bag_t bag, gnutls_x509_crt_t crt)

bag: The bag

crt: the certificate to be copied.

This function will insert the given certificate into the bag. This is just a wrapper over gnutls_pkcs12_bag_set_data().

Returns: the index of the added bag on success, or a negative value on failure.

gnutls_pkcs12_bag_set_data

Function: int gnutls_pkcs12_bag_set_data (gnutls_pkcs12_bag_t bag, gnutls_pkcs12_bag_type_t type, const gnutls_datum_t * data)

bag: The bag

type: The data's type

data: the data to be copied.

This function will insert the given data of the given type into the bag.

Returns: the index of the added bag on success, or a negative value on error.

gnutls_pkcs12_bag_set_friendly_name

Function: int gnutls_pkcs12_bag_set_friendly_name (gnutls_pkcs12_bag_t bag, int indx, const char * name)

bag: The bag

indx: The bag's element to add the id

name: the name

This function will add the given key friendly name, to the specified, by the index, bag element. The name will be encoded as a 'Friendly name' bag attribute, which is usually used to set a user name to the local private key and the certificate pair.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. or a negative value on error.

gnutls_pkcs12_bag_set_key_id

Function: int gnutls_pkcs12_bag_set_key_id (gnutls_pkcs12_bag_t bag, int indx, const gnutls_datum_t * id)

bag: The bag

indx: The bag's element to add the id

id: the ID

This function will add the given key ID, to the specified, by the index, bag element. The key ID will be encoded as a 'Local key identifier' bag attribute, which is usually used to distinguish the local private key and the certificate pair.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. or a negative value on error.

gnutls_pkcs12_deinit

Function: void gnutls_pkcs12_deinit (gnutls_pkcs12_t pkcs12)

pkcs12: The structure to be initialized

This function will deinitialize a PKCS12 structure.

gnutls_pkcs12_export

Function: int gnutls_pkcs12_export (gnutls_pkcs12_t pkcs12, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

pkcs12: Holds the pkcs12 structure

format: the format of output params. One of PEM or DER.

output_data: will contain a structure PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the pkcs12 structure to DER or PEM format.

If the buffer provided is not long enough to hold the output, then *output_data_size will be updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN PKCS12".

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_pkcs12_generate_mac

Function: int gnutls_pkcs12_generate_mac (gnutls_pkcs12_t pkcs12, const char * pass)

pkcs12: should contain a gnutls_pkcs12_t structure

pass: The password for the MAC

This function will generate a MAC for the PKCS12 structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs12_get_bag

Function: int gnutls_pkcs12_get_bag (gnutls_pkcs12_t pkcs12, int indx, gnutls_pkcs12_bag_t bag)

pkcs12: should contain a gnutls_pkcs12_t structure

indx: contains the index of the bag to extract

bag: An initialized bag, where the contents of the bag will be copied

This function will return a Bag from the PKCS12 structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

After the last Bag has been read GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_pkcs12_import

Function: int gnutls_pkcs12_import (gnutls_pkcs12_t pkcs12, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format, unsigned int flags)

pkcs12: The structure to store the parsed PKCS12.

data: The DER or PEM encoded PKCS12.

format: One of DER or PEM

flags: an ORed sequence of gnutls_privkey_pkcs8_flags

This function will convert the given DER or PEM encoded PKCS12 to the native gnutls_pkcs12_t format. The output will be stored in 'pkcs12'.

If the PKCS12 is PEM encoded it should have a header of "PKCS12".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs12_init

Function: int gnutls_pkcs12_init (gnutls_pkcs12_t * pkcs12)

pkcs12: The structure to be initialized

This function will initialize a PKCS12 structure. PKCS12 structures usually contain lists of X.509 Certificates and X.509 Certificate revocation lists.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs12_set_bag

Function: int gnutls_pkcs12_set_bag (gnutls_pkcs12_t pkcs12, gnutls_pkcs12_bag_t bag)

pkcs12: should contain a gnutls_pkcs12_t structure

bag: An initialized bag

This function will insert a Bag into the PKCS12 structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs12_verify_mac

Function: int gnutls_pkcs12_verify_mac (gnutls_pkcs12_t pkcs12, const char * pass)

pkcs12: should contain a gnutls_pkcs12_t structure

pass: The password for the MAC

This function will verify the MAC for the PKCS12 structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_deinit

Function: void gnutls_pkcs7_deinit (gnutls_pkcs7_t pkcs7)

pkcs7: The structure to be initialized

This function will deinitialize a PKCS7 structure.

gnutls_pkcs7_delete_crl

Function: int gnutls_pkcs7_delete_crl (gnutls_pkcs7_t pkcs7, int indx)

indx: the index of the crl to delete

This function will delete a crl from a PKCS7 or RFC2630 crl set. Index starts from 0. Returns 0 on success.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_delete_crt

Function: int gnutls_pkcs7_delete_crt (gnutls_pkcs7_t pkcs7, int indx)

indx: the index of the certificate to delete

This function will delete a certificate from a PKCS7 or RFC2630 certificate set. Index starts from 0. Returns 0 on success.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_export

Function: int gnutls_pkcs7_export (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

pkcs7: Holds the pkcs7 structure

format: the format of output params. One of PEM or DER.

output_data: will contain a structure PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the pkcs7 structure to DER or PEM format.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN PKCS7".

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_pkcs7_get_crl_count

Function: int gnutls_pkcs7_get_crl_count (gnutls_pkcs7_t pkcs7)

This function will return the number of certifcates in the PKCS7 or RFC2630 crl set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_get_crl_raw

Function: int gnutls_pkcs7_get_crl_raw (gnutls_pkcs7_t pkcs7, int indx, void * crl, size_t * crl_size)

indx: contains the index of the crl to extract

crl: the contents of the crl will be copied there (may be null)

crl_size: should hold the size of the crl

This function will return a crl of the PKCS7 or RFC2630 crl set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. If the provided buffer is not long enough, then crl_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER is returned. After the last crl has been read GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_pkcs7_get_crt_count

Function: int gnutls_pkcs7_get_crt_count (gnutls_pkcs7_t pkcs7)

This function will return the number of certifcates in the PKCS7 or RFC2630 certificate set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_get_crt_raw

Function: int gnutls_pkcs7_get_crt_raw (gnutls_pkcs7_t pkcs7, int indx, void * certificate, size_t * certificate_size)

indx: contains the index of the certificate to extract

certificate: the contents of the certificate will be copied there (may be null)

certificate_size: should hold the size of the certificate

This function will return a certificate of the PKCS7 or RFC2630 certificate set.

After the last certificate has been read GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. If the provided buffer is not long enough, then certificate_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER is returned.

gnutls_pkcs7_import

Function: int gnutls_pkcs7_import (gnutls_pkcs7_t pkcs7, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format)

pkcs7: The structure to store the parsed PKCS7.

data: The DER or PEM encoded PKCS7.

format: One of DER or PEM

This function will convert the given DER or PEM encoded PKCS7 to the native gnutls_pkcs7_t format. The output will be stored in 'pkcs7'.

If the PKCS7 is PEM encoded it should have a header of "PKCS7".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_init

Function: int gnutls_pkcs7_init (gnutls_pkcs7_t * pkcs7)

pkcs7: The structure to be initialized

This function will initialize a PKCS7 structure. PKCS7 structures usually contain lists of X.509 Certificates and X.509 Certificate revocation lists.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_set_crl_raw

Function: int gnutls_pkcs7_set_crl_raw (gnutls_pkcs7_t pkcs7, const gnutls_datum_t * crl)

crl: the DER encoded crl to be added

This function will add a crl to the PKCS7 or RFC2630 crl set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_set_crl

Function: int gnutls_pkcs7_set_crl (gnutls_pkcs7_t pkcs7, gnutls_x509_crl_t crl)

crl: the DER encoded crl to be added

This function will add a parsed CRL to the PKCS7 or RFC2630 crl set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_set_crt_raw

Function: int gnutls_pkcs7_set_crt_raw (gnutls_pkcs7_t pkcs7, const gnutls_datum_t * crt)

crt: the DER encoded certificate to be added

This function will add a certificate to the PKCS7 or RFC2630 certificate set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_pkcs7_set_crt

Function: int gnutls_pkcs7_set_crt (gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t crt)

crt: the certificate to be copied.

This function will add a parsed certificate to the PKCS7 or RFC2630 certificate set. This is a wrapper function over gnutls_pkcs7_set_crt_raw() .

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_check_issuer

Function: int gnutls_x509_crl_check_issuer (gnutls_x509_crl_t cert, gnutls_x509_crt_t issuer)

issuer: is the certificate of a possible issuer

This function will check if the given CRL was issued by the given issuer certificate. It will return true (1) if the given CRL was issued by the given issuer, and false (0) if not.

A negative value is returned in case of an error.

gnutls_x509_crl_deinit

Function: void gnutls_x509_crl_deinit (gnutls_x509_crl_t crl)

crl: The structure to be initialized

This function will deinitialize a CRL structure.

gnutls_x509_crl_export

Function: int gnutls_x509_crl_export (gnutls_x509_crl_t crl, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

crl: Holds the revocation list

format: the format of output params. One of PEM or DER.

output_data: will contain a private key PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the revocation list to DER or PEM format.

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 X509 CRL".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. and a negative value on failure.

gnutls_x509_crl_get_crt_count

Function: int gnutls_x509_crl_get_crt_count (gnutls_x509_crl_t crl)

crl: should contain a gnutls_x509_crl_t structure

This function will return the number of revoked certificates in the given CRL.

Returns: number of certificates, a negative value on failure.

gnutls_x509_crl_get_crt_serial

Function: int gnutls_x509_crl_get_crt_serial (gnutls_x509_crl_t crl, int indx, unsigned char * serial, size_t * serial_size, time_t * t)

crl: should contain a gnutls_x509_crl_t structure

indx: the index of the certificate to extract (starting from 0)

serial: where the serial number will be copied

serial_size: initially holds the size of serial

t: if non null, will hold the time this certificate was revoked

This function will retrieve the serial number of the specified, by the index, revoked certificate.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. and a negative value on error.

gnutls_x509_crl_get_dn_oid

Function: int gnutls_x509_crl_get_dn_oid (gnutls_x509_crl_t crl, int indx, void * oid, size_t * sizeof_oid)

crl: should contain a gnutls_x509_crl_t structure

indx: Specifies which DN OID to send. Use zero to get the first one.

oid: a pointer to a structure to hold the name (may be null)

sizeof_oid: initially holds the size of 'oid'

This function will extract the requested OID of the name of the CRL issuer, specified by the given index.

If oid is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the sizeof_oid will be updated with the required size. On success 0 is returned.

gnutls_x509_crl_get_issuer_dn_by_oid

Function: int gnutls_x509_crl_get_issuer_dn_by_oid (gnutls_x509_crl_t crl, const char * oid, int indx, unsigned int raw_flag, void * buf, size_t * sizeof_buf)

crl: should contain a gnutls_x509_crl_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the RDN, this specifies which to send. Use zero to get the first one.

raw_flag: If non zero returns the raw DER data of the DN part.

buf: a pointer to a structure to hold the peer's name (may be null)

sizeof_buf: initially holds the size of buf

This function will extract the part of the name of the CRL issuer specified by the given OID. The output will be encoded as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

Some helper macros with popular OIDs can be found in gnutls/x509.h If raw flag is zero, this function will only return known OIDs as text. Other OIDs will be DER encoded, as described in RFC2253 - in hex format with a '\#' prefix. You can check about known OIDs using gnutls_x509_dn_oid_known().

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the sizeof_buf will be updated with the required size, and 0 on success.

gnutls_x509_crl_get_issuer_dn

Function: int gnutls_x509_crl_get_issuer_dn (const gnutls_x509_crl_t crl, char * buf, size_t * sizeof_buf)

crl: should contain a gnutls_x509_crl_t structure

buf: a pointer to a structure to hold the peer's name (may be null)

sizeof_buf: initially holds the size of buf

This function will copy the name of the CRL issuer in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

If buf is NULL then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the sizeof_buf will be updated with the required size, and 0 on success.

gnutls_x509_crl_get_next_update

Function: time_t gnutls_x509_crl_get_next_update (gnutls_x509_crl_t crl)

crl: should contain a gnutls_x509_crl_t structure

This function will return the time the next CRL will be issued. This field is optional in a CRL so it might be normal to get an error instead.

Returns: when the next CRL will be issued, or (time_t)-1 on error.

gnutls_x509_crl_get_signature_algorithm

Function: int gnutls_x509_crl_get_signature_algorithm (gnutls_x509_crl_t crl)

crl: should contain a gnutls_x509_crl_t structure

This function will return a value of the gnutls_sign_algorithm_t enumeration that is the signature algorithm.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_get_signature

Function: int gnutls_x509_crl_get_signature (gnutls_x509_crl_t crl, char * sig, size_t * sizeof_sig)

crl: should contain a gnutls_x509_crl_t structure

sig: a pointer where the signature part will be copied (may be null).

sizeof_sig: initially holds the size of sig

This function will extract the signature field of a CRL.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. and a negative value on error.

gnutls_x509_crl_get_this_update

Function: time_t gnutls_x509_crl_get_this_update (gnutls_x509_crl_t crl)

crl: should contain a gnutls_x509_crl_t structure

This function will return the time this CRL was issued.

Returns: when the CRL was issued, or (time_t)-1 on error.

gnutls_x509_crl_get_version

Function: int gnutls_x509_crl_get_version (gnutls_x509_crl_t crl)

crl: should contain a gnutls_x509_crl_t structure

This function will return the version of the specified CRL.

Returns: The version number, or a negative value on error.

gnutls_x509_crl_import

Function: int gnutls_x509_crl_import (gnutls_x509_crl_t crl, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format)

crl: The structure to store the parsed CRL.

data: The DER or PEM encoded CRL.

format: One of DER or PEM

This function will convert the given DER or PEM encoded CRL to the native gnutls_x509_crl_t format. The output will be stored in 'crl'.

If the CRL is PEM encoded it should have a header of "X509 CRL".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_init

Function: int gnutls_x509_crl_init (gnutls_x509_crl_t * crl)

crl: The structure to be initialized

This function will initialize a CRL structure. CRL stands for Certificate Revocation List. A revocation list usually contains lists of certificate serial numbers that have been revoked by an Authority. The revocation lists are always signed with the authority's private key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_print

Function: int gnutls_x509_crl_print (gnutls_x509_crl_t crl, gnutls_certificate_print_formats_t format, gnutls_datum_t * out)

crl: The structure to be printed

format: Indicate the format to use

out: Newly allocated datum with zero terminated string.

This function will pretty print a X.509 certificate revocation list, suitable for display to a human.

The output out needs to be deallocate using gnutls_free().

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_set_crt_serial

Function: int gnutls_x509_crl_set_crt_serial (gnutls_x509_crl_t crl, const void * serial, size_t serial_size, time_t revocation_time)

crl: should contain a gnutls_x509_crl_t structure

serial: The revoked certificate's serial number

serial_size: Holds the size of the serial field.

revocation_time: The time this certificate was revoked

This function will set a revoked certificate's serial number to the CRL.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_set_crt

Function: int gnutls_x509_crl_set_crt (gnutls_x509_crl_t crl, gnutls_x509_crt_t crt, time_t revocation_time)

crl: should contain a gnutls_x509_crl_t structure

crt: a certificate of type gnutls_x509_crt_t with the revoked certificate

revocation_time: The time this certificate was revoked

This function will set a revoked certificate's serial number to the CRL.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_set_next_update

Function: int gnutls_x509_crl_set_next_update (gnutls_x509_crl_t crl, time_t exp_time)

crl: should contain a gnutls_x509_crl_t structure

exp_time: The actual time

This function will set the time this CRL will be updated.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_set_this_update

Function: int gnutls_x509_crl_set_this_update (gnutls_x509_crl_t crl, time_t act_time)

crl: should contain a gnutls_x509_crl_t structure

act_time: The actual time

This function will set the time this CRL was issued.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_set_version

Function: int gnutls_x509_crl_set_version (gnutls_x509_crl_t crl, unsigned int version)

crl: should contain a gnutls_x509_crl_t structure

version: holds the version number. For CRLv1 crls must be 1.

This function will set the version of the CRL. This must be one for CRL version 1, and so on. The CRLs generated by gnutls should have a version number of 2.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_sign2

Function: int gnutls_x509_crl_sign2 (gnutls_x509_crl_t crl, gnutls_x509_crt_t issuer, gnutls_x509_privkey_t issuer_key, gnutls_digest_algorithm_t dig, unsigned int flags)

crl: should contain a gnutls_x509_crl_t structure

issuer: is the certificate of the certificate issuer

issuer_key: holds the issuer's private key

dig: The message digest to use. GNUTLS_DIG_SHA1 is the safe choice unless you know what you're doing.

flags: must be 0

This function will sign the CRL with the issuer's private key, and will copy the issuer's information into the CRL.

This must be the last step in a certificate CRL since all the previously set parameters are now signed.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_sign

Function: int gnutls_x509_crl_sign (gnutls_x509_crl_t crl, gnutls_x509_crt_t issuer, gnutls_x509_privkey_t issuer_key)

crl: should contain a gnutls_x509_crl_t structure

issuer: is the certificate of the certificate issuer

issuer_key: holds the issuer's private key

This function is the same a gnutls_x509_crl_sign2() with no flags, and SHA1 as the hash algorithm.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crl_verify

Function: int gnutls_x509_crl_verify (gnutls_x509_crl_t crl, const gnutls_x509_crt_t * CA_list, int CA_list_length, unsigned int flags, unsigned int * verify)

crl: is the crl to be verified

CA_list: is a certificate list that is considered to be trusted one

CA_list_length: holds the number of CA certificates in CA_list

flags: Flags that may be used to change the verification algorithm. Use OR of the gnutls_certificate_verify_flags enumerations.

verify: will hold the crl verification output.

This function will try to verify the given crl and return its status. See gnutls_x509_crt_list_verify() for a detailed description of return values.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crq_deinit

Function: void gnutls_x509_crq_deinit (gnutls_x509_crq_t crq)

crq: The structure to be initialized

This function will deinitialize a CRL structure.

gnutls_x509_crq_export

Function: int gnutls_x509_crq_export (gnutls_x509_crq_t crq, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

crq: Holds the request

format: the format of output params. One of PEM or DER.

output_data: will contain a certificate request PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the certificate request to a PKCS10

If the buffer provided is not long enough to hold the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be returned and *output_data_size will be updated.

If the structure is PEM encoded, it will have a header of "BEGIN NEW CERTIFICATE REQUEST".

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_x509_crq_get_attribute_by_oid

Function: int gnutls_x509_crq_get_attribute_by_oid (gnutls_x509_crq_t crq, const char * oid, int indx, void * buf, size_t * sizeof_buf)

crq: should contain a gnutls_x509_crq_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the attribute list, this specifies which to send. Use zero to get the first one.

buf: a pointer to a structure to hold the attribute data (may be null)

sizeof_buf: initially holds the size of buf

This function will return the attribute in the certificate request specified by the given Object ID. The attribute will be DER encoded.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_get_challenge_password

Function: int gnutls_x509_crq_get_challenge_password (gnutls_x509_crq_t crq, char * pass, size_t * sizeof_pass)

crq: should contain a gnutls_x509_crq_t structure

pass: will hold a null terminated password

sizeof_pass: Initially holds the size of pass.

This function will return the challenge password in the request.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_get_dn_by_oid

Function: int gnutls_x509_crq_get_dn_by_oid (gnutls_x509_crq_t crq, const char * oid, int indx, unsigned int raw_flag, void * buf, size_t * sizeof_buf)

crq: should contain a gnutls_x509_crq_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the RDN, this specifies which to send. Use zero to get the first one.

raw_flag: If non zero returns the raw DER data of the DN part.

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

This function will extract the part of the name of the Certificate request subject, specified by the given OID. The output will be encoded as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

Some helper macros with popular OIDs can be found in gnutls/x509.h If raw flag is zero, this function will only return known OIDs as text. Other OIDs will be DER encoded, as described in RFC2253 - in hex format with a '\#' prefix. You can check about known OIDs using gnutls_x509_dn_oid_known().

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crq_get_dn_oid

Function: int gnutls_x509_crq_get_dn_oid (gnutls_x509_crq_t crq, int indx, void * oid, size_t * sizeof_oid)

crq: should contain a gnutls_x509_crq_t structure

indx: Specifies which DN OID to send. Use zero to get the first one.

oid: a pointer to a structure to hold the name (may be null)

sizeof_oid: initially holds the size of oid

This function will extract the requested OID of the name of the Certificate request subject, specified by the given index.

If oid is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_oid will be updated with the required size. On success 0 is returned.

gnutls_x509_crq_get_dn

Function: int gnutls_x509_crq_get_dn (gnutls_x509_crq_t crq, char * buf, size_t * sizeof_buf)

crq: should contain a gnutls_x509_crq_t structure

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

This function will copy the name of the Certificate request subject in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crq_get_pk_algorithm

Function: int gnutls_x509_crq_get_pk_algorithm (gnutls_x509_crq_t crq, unsigned int * bits)

crq: should contain a gnutls_x509_crq_t structure

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of a PKCS \10 certificate request.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

gnutls_x509_crq_get_version

Function: int gnutls_x509_crq_get_version (gnutls_x509_crq_t crq)

crq: should contain a gnutls_x509_crq_t structure

This function will return the version of the specified Certificate request.

Returns: version of certificate request, or a negative value on error.

gnutls_x509_crq_import

Function: int gnutls_x509_crq_import (gnutls_x509_crq_t crq, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format)

crq: The structure to store the parsed certificate request.

data: The DER or PEM encoded certificate.

format: One of DER or PEM

This function will convert the given DER or PEM encoded Certificate to the native gnutls_x509_crq_t format. The output will be stored in cert.

If the Certificate is PEM encoded it should have a header of "NEW CERTIFICATE REQUEST".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_init

Function: int gnutls_x509_crq_init (gnutls_x509_crq_t * crq)

crq: The structure to be initialized

This function will initialize a PKCS10 certificate request structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_set_attribute_by_oid

Function: int gnutls_x509_crq_set_attribute_by_oid (gnutls_x509_crq_t crq, const char * oid, void * buf, size_t sizeof_buf)

crq: should contain a gnutls_x509_crq_t structure

oid: holds an Object Identified in null terminated string

buf: a pointer to a structure that holds the attribute data

sizeof_buf: holds the size of buf

This function will set the attribute in the certificate request specified by the given Object ID. The attribute must be be DER encoded.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_set_challenge_password

Function: int gnutls_x509_crq_set_challenge_password (gnutls_x509_crq_t crq, const char * pass)

crq: should contain a gnutls_x509_crq_t structure

pass: holds a null terminated password

This function will set a challenge password to be used when revoking the request.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_set_dn_by_oid

Function: int gnutls_x509_crq_set_dn_by_oid (gnutls_x509_crq_t crq, const char * oid, unsigned int raw_flag, const void * data, unsigned int sizeof_data)

crq: should contain a gnutls_x509_crq_t structure

oid: holds an Object Identifier in a null terminated string

raw_flag: must be 0, or 1 if the data are DER encoded

data: a pointer to the input data

sizeof_data: holds the size of data

This function will set the part of the name of the Certificate request subject, specified by the given OID. The input string should be ASCII or UTF-8 encoded.

Some helper macros with popular OIDs can be found in gnutls/x509.h With this function you can only set the known OIDs. You can test for known OIDs using gnutls_x509_dn_oid_known(). For OIDs that are not known (by gnutls) you should properly DER encode your data, and call this function with raw_flag set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_set_key_rsa_raw

Function: int gnutls_x509_crq_set_key_rsa_raw (gnutls_x509_crq_t crq, const gnutls_datum_t * m, const gnutls_datum_t * e)

crq: should contain a gnutls_x509_crq_t structure

m: holds the modulus

e: holds the public exponent

This function will set the public parameters from the given private key to the request. Only RSA keys are currently supported.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.6.0

gnutls_x509_crq_set_key

Function: int gnutls_x509_crq_set_key (gnutls_x509_crq_t crq, gnutls_x509_privkey_t key)

crq: should contain a gnutls_x509_crq_t structure

key: holds a private key

This function will set the public parameters from the given private key to the request. Only RSA keys are currently supported.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_set_version

Function: int gnutls_x509_crq_set_version (gnutls_x509_crq_t crq, unsigned int version)

crq: should contain a gnutls_x509_crq_t structure

version: holds the version number. For v1 Requests must be 1.

This function will set the version of the certificate request. For version 1 requests this must be one.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crq_sign2

Function: int gnutls_x509_crq_sign2 (gnutls_x509_crq_t crq, gnutls_x509_privkey_t key, gnutls_digest_algorithm_t dig, unsigned int flags)

crq: should contain a gnutls_x509_crq_t structure

key: holds a private key

dig: The message digest to use, GNUTLS_DIG_SHA1 is the safe choice unless you know what you're doing.

flags: must be 0

This function will sign the certificate request with a private key. This must be the same key as the one used in gnutls_x509_crt_set_key() since a certificate request is self signed.

This must be the last step in a certificate request generation since all the previously set parameters are now signed.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error. GNUTLS_E_ASN1_VALUE_NOT_FOUND is returned if you didn't set all information in the certificate request (e.g., the version using gnutls_x509_crq_set_version()).

gnutls_x509_crq_sign

Function: int gnutls_x509_crq_sign (gnutls_x509_crq_t crq, gnutls_x509_privkey_t key)

crq: should contain a gnutls_x509_crq_t structure

key: holds a private key

This function is the same a gnutls_x509_crq_sign2() with no flags, and SHA1 as the hash algorithm.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_check_hostname

Function: int gnutls_x509_crt_check_hostname (gnutls_x509_crt_t cert, const char * hostname)

cert: should contain an gnutls_x509_crt_t structure

hostname: A null terminated string that contains a DNS name

This function will check if the given certificate's subject matches the given hostname. This is a basic implementation of the matching described in RFC2818 (HTTPS), which takes into account wildcards, and the DNSName/IPAddress subject alternative name PKIX extension.

Returns: non zero for a successful match, and zero on failure.

gnutls_x509_crt_check_issuer

Function: int gnutls_x509_crt_check_issuer (gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer)

cert: is the certificate to be checked

issuer: is the certificate of a possible issuer

This function will check if the given certificate was issued by the given issuer. It will return true (1) if the given certificate is issued by the given issuer, and false (0) if not.

A negative value is returned in case of an error.

gnutls_x509_crt_check_revocation

Function: int gnutls_x509_crt_check_revocation (gnutls_x509_crt_t cert, const gnutls_x509_crl_t * crl_list, int crl_list_length)

cert: should contain a gnutls_x509_crt_t structure

crl_list: should contain a list of gnutls_x509_crl_t structures

crl_list_length: the length of the crl_list

This function will return check if the given certificate is revoked. It is assumed that the CRLs have been verified before.

Returns: 0 if the certificate is NOT revoked, and 1 if it is. A negative value is returned on error.

gnutls_x509_crt_cpy_crl_dist_points

Function: int gnutls_x509_crt_cpy_crl_dist_points (gnutls_x509_crt_t dst, gnutls_x509_crt_t src)

dst: a certificate of type gnutls_x509_crt_t

src: the certificate where the dist points will be copied from

This function will copy the CRL distribution points certificate extension, from the source to the destination certificate. This may be useful to copy from a CA certificate to issued ones.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_deinit

Function: void gnutls_x509_crt_deinit (gnutls_x509_crt_t cert)

cert: The structure to be initialized

This function will deinitialize a CRL structure.

gnutls_x509_crt_export

Function: int gnutls_x509_crt_export (gnutls_x509_crt_t cert, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

cert: Holds the certificate

format: the format of output params. One of PEM or DER.

output_data: will contain a certificate PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the certificate to DER or PEM format.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_x509_crt_get_activation_time

Function: time_t gnutls_x509_crt_get_activation_time (gnutls_x509_crt_t cert)

cert: should contain a gnutls_x509_crt_t structure

This function will return the time this Certificate was or will be activated.

Returns: activation time, or (time_t)-1 on error.

gnutls_x509_crt_get_authority_key_id

Function: int gnutls_x509_crt_get_authority_key_id (gnutls_x509_crt_t cert, void * ret, size_t * ret_size, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

critical: will be non zero if the extension is marked as critical (may be null)

This function will return the X.509v3 certificate authority's key identifier. This is obtained by the X.509 Authority Key identifier extension field (2.5.29.35). Note that this function only returns the keyIdentifier field of the extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crt_get_basic_constraints

Function: int gnutls_x509_crt_get_basic_constraints (gnutls_x509_crt_t cert, unsigned int * critical, int * ca, int * pathlen)

cert: should contain a gnutls_x509_crt_t structure

critical: will be non zero if the extension is marked as critical

ca: pointer to output integer indicating CA status, may be NULL, value is 1 if the certificate CA flag is set, 0 otherwise.

pathlen: pointer to output integer indicating path length (may be NULL), non-negative values indicate a present pathLenConstraint field and the actual value, -1 indicate that the field is absent.

This function will read the certificate's basic constraints, and return the certificates CA status. It reads the basicConstraints X.509 extension (2.5.29.19).

Return value: If the certificate is a CA a positive value will be returned, or zero if the certificate does not have CA flag set. A negative value may be returned in case of errors. If the certificate does not contain the basicConstraints extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_ca_status

Function: int gnutls_x509_crt_get_ca_status (gnutls_x509_crt_t cert, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

critical: will be non zero if the extension is marked as critical

This function will return certificates CA status, by reading the basicConstraints X.509 extension (2.5.29.19). If the certificate is a CA a positive value will be returned, or zero if the certificate does not have CA flag set.

Use gnutls_x509_crt_get_basic_constraints() if you want to read the pathLenConstraint field too.

A negative value may be returned in case of parsing error. If the certificate does not contain the basicConstraints extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_crl_dist_points

Function: int gnutls_x509_crt_get_crl_dist_points (gnutls_x509_crt_t cert, unsigned int seq, void * ret, size_t * ret_size, unsigned int * reason_flags, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

seq: specifies the sequence number of the distribution point (0 for the first one, 1 for the second etc.)

ret: is the place where the distribution point will be copied to

ret_size: holds the size of ret.

reason_flags: Revocation reasons flags.

critical: will be non zero if the extension is marked as critical (may be null)

This function will return the CRL distribution points (2.5.29.31), contained in the given certificate.

reason_flags should be an ORed sequence of GNUTLS_CRL_REASON_UNUSED, GNUTLS_CRL_REASON_KEY_COMPROMISE, GNUTLS_CRL_REASON_CA_COMPROMISE, GNUTLS_CRL_REASON_AFFILIATION_CHANGED, GNUTLS_CRL_REASON_SUPERSEEDED, GNUTLS_CRL_REASON_CESSATION_OF_OPERATION, GNUTLS_CRL_REASON_CERTIFICATE_HOLD, GNUTLS_CRL_REASON_PRIVILEGE_WITHDRAWN, GNUTLS_CRL_REASON_AA_COMPROMISE, or zero for all possible reasons.

This is specified in X509v3 Certificate Extensions. GNUTLS will return the distribution point type, or a negative error code on error.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER and updates &ret_size if &ret_size is not enough to hold the distribution point, or the type of the distribution point if everything was ok. The type is one of the enumerated gnutls_x509_subject_alt_name_t. If the certificate does not have an Alternative name with the specified sequence number then GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.

gnutls_x509_crt_get_dn_by_oid

Function: int gnutls_x509_crt_get_dn_by_oid (gnutls_x509_crt_t cert, const char * oid, int indx, unsigned int raw_flag, void * buf, size_t * sizeof_buf)

cert: should contain a gnutls_x509_crt_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the RDN, this specifies which to send. Use zero to get the first one.

raw_flag: If non zero returns the raw DER data of the DN part.

buf: a pointer where the DN part will be copied (may be null).

sizeof_buf: initially holds the size of buf

This function will extract the part of the name of the Certificate subject specified by the given OID. The output, if the raw flag is not used, will be encoded as described in RFC2253. Thus a string that is ASCII or UTF-8 encoded, depending on the certificate data.

Some helper macros with popular OIDs can be found in gnutls/x509.h If raw flag is zero, this function will only return known OIDs as text. Other OIDs will be DER encoded, as described in RFC2253 - in hex format with a '\#' prefix. You can check about known OIDs using gnutls_x509_dn_oid_known().

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_dn_oid

Function: int gnutls_x509_crt_get_dn_oid (gnutls_x509_crt_t cert, int indx, void * oid, size_t * sizeof_oid)

cert: should contain a gnutls_x509_crt_t structure

indx: This specifies which OID to return. Use zero to get the first one.

oid: a pointer to a buffer to hold the OID (may be null)

sizeof_oid: initially holds the size of oid

This function will extract the OIDs of the name of the Certificate subject specified by the given index.

If oid is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_oid will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_dn

Function: int gnutls_x509_crt_get_dn (gnutls_x509_crt_t cert, char * buf, size_t * sizeof_buf)

cert: should contain a gnutls_x509_crt_t structure

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

This function will copy the name of the Certificate in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_expiration_time

Function: time_t gnutls_x509_crt_get_expiration_time (gnutls_x509_crt_t cert)

cert: should contain a gnutls_x509_crt_t structure

This function will return the time this Certificate was or will be expired.

Returns: expiration time, or (time_t)-1 on error.

gnutls_x509_crt_get_extension_by_oid

Function: int gnutls_x509_crt_get_extension_by_oid (gnutls_x509_crt_t cert, const char * oid, int indx, void * buf, size_t * sizeof_buf, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the extensions, this specifies which to send. Use zero to get the first one.

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

critical: will be non zero if the extension is marked as critical

This function will return the extension specified by the OID in the certificate. The extensions will be returned as binary data DER encoded, in the provided buffer.

A negative value may be returned in case of parsing error. If the certificate does not contain the specified extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_extension_data

Function: int gnutls_x509_crt_get_extension_data (gnutls_x509_crt_t cert, int indx, void * data, size_t * sizeof_data)

cert: should contain a gnutls_x509_crt_t structure

indx: Specifies which extension OID to send. Use zero to get the first one.

data: a pointer to a structure to hold the data (may be null)

sizeof_data: initially holds the size of oid

This function will return the requested extension data in the certificate. The extension data will be stored as a string in the provided buffer.

Use gnutls_x509_crt_get_extension_info() to extract the OID and critical flag. Use gnutls_x509_crt_get_extension_by_oid() instead, if you want to get data indexed by the extension OID rather than sequence.

Return 0 on success. A negative value may be returned in case of parsing error. If you have reached the last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_extension_info

Function: int gnutls_x509_crt_get_extension_info (gnutls_x509_crt_t cert, int indx, void * oid, size_t * sizeof_oid, int * critical)

cert: should contain a gnutls_x509_crt_t structure

indx: Specifies which extension OID to send. Use zero to get the first one.

oid: a pointer to a structure to hold the OID

sizeof_oid: initially holds the maximum size of oid, on return holds actual size of oid.

critical: output variable with critical flag, may be NULL.

This function will return the requested extension OID in the certificate, and the critical flag for it. The extension OID will be stored as a string in the provided buffer. Use gnutls_x509_crt_get_extension_data() to extract the data.

If the buffer provided is not long enough to hold the output, then *sizeof_oid is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

Return 0 on success. A negative value may be returned in case of parsing error. If you have reached the last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_extension_oid

Function: int gnutls_x509_crt_get_extension_oid (gnutls_x509_crt_t cert, int indx, void * oid, size_t * sizeof_oid)

cert: should contain a gnutls_x509_crt_t structure

indx: Specifies which extension OID to send. Use zero to get the first one.

oid: a pointer to a structure to hold the OID (may be null)

sizeof_oid: initially holds the size of oid

This function will return the requested extension OID in the certificate. The extension OID will be stored as a string in the provided buffer.

A negative value may be returned in case of parsing error. If your have reached the last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_fingerprint

Function: int gnutls_x509_crt_get_fingerprint (gnutls_x509_crt_t cert, gnutls_digest_algorithm_t algo, void * buf, size_t * sizeof_buf)

cert: should contain a gnutls_x509_crt_t structure

algo: is a digest algorithm

buf: a pointer to a structure to hold the fingerprint (may be null)

sizeof_buf: initially holds the size of buf

This function will calculate and copy the certificate's fingerprint in the provided buffer.

If the buffer is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_issuer_dn_by_oid

Function: int gnutls_x509_crt_get_issuer_dn_by_oid (gnutls_x509_crt_t cert, const char * oid, int indx, unsigned int raw_flag, void * buf, size_t * sizeof_buf)

cert: should contain a gnutls_x509_crt_t structure

oid: holds an Object Identified in null terminated string

indx: In case multiple same OIDs exist in the RDN, this specifies which to send. Use zero to get the first one.

raw_flag: If non zero returns the raw DER data of the DN part.

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

This function will extract the part of the name of the Certificate issuer specified by the given OID. The output, if the raw flag is not used, will be encoded as described in RFC2253. Thus a string that is ASCII or UTF-8 encoded, depending on the certificate data.

Some helper macros with popular OIDs can be found in gnutls/x509.h If raw flag is zero, this function will only return known OIDs as text. Other OIDs will be DER encoded, as described in RFC2253 - in hex format with a '\#' prefix. You can check about known OIDs using gnutls_x509_dn_oid_known().

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_issuer_dn_oid

Function: int gnutls_x509_crt_get_issuer_dn_oid (gnutls_x509_crt_t cert, int indx, void * oid, size_t * sizeof_oid)

cert: should contain a gnutls_x509_crt_t structure

indx: This specifies which OID to return. Use zero to get the first one.

oid: a pointer to a buffer to hold the OID (may be null)

sizeof_oid: initially holds the size of oid

This function will extract the OIDs of the name of the Certificate issuer specified by the given index.

If oid is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_oid will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_issuer_dn

Function: int gnutls_x509_crt_get_issuer_dn (gnutls_x509_crt_t cert, char * buf, size_t * sizeof_buf)

cert: should contain a gnutls_x509_crt_t structure

buf: a pointer to a structure to hold the name (may be null)

sizeof_buf: initially holds the size of buf

This function will copy the name of the Certificate issuer in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.

If buf is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_buf will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_issuer

Function: int gnutls_x509_crt_get_issuer (gnutls_x509_crt_t cert, gnutls_x509_dn_t * dn)

cert: should contain a gnutls_x509_crt_t structure

dn: output variable with pointer to opaque DN

Return the Certificate's Issuer DN as an opaque data type. You may use gnutls_x509_dn_get_rdn_ava() to decode the DN.

Note that dn should be treated as constant. Because points into the cert object, you may not deallocate cert and continue to access dn.

Returns: Returns 0 on success, or an error code.

gnutls_x509_crt_get_key_id

Function: int gnutls_x509_crt_get_key_id (gnutls_x509_crt_t crt, unsigned int flags, unsigned char * output_data, size_t * output_data_size)

crt: Holds the certificate

flags: should be 0 for now

output_data: will contain the key ID

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will return a unique ID the depends on the public key parameters. This ID can be used in checking whether a certificate corresponds to the given private key.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned. The output will normally be a SHA-1 hash output, which is 20 bytes.

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_x509_crt_get_key_purpose_oid

Function: int gnutls_x509_crt_get_key_purpose_oid (gnutls_x509_crt_t cert, int indx, void * oid, size_t * sizeof_oid, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

indx: This specifies which OID to return. Use zero to get the first one.

oid: a pointer to a buffer to hold the OID (may be null)

sizeof_oid: initially holds the size of oid

This function will extract the key purpose OIDs of the Certificate specified by the given index. These are stored in the Extended Key Usage extension (2.5.29.37) See the GNUTLS_KP_* definitions for human readable names.

If oid is null then only the size will be filled.

Returns: GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not long enough, and in that case the *sizeof_oid will be updated with the required size. On success 0 is returned.

gnutls_x509_crt_get_key_usage

Function: int gnutls_x509_crt_get_key_usage (gnutls_x509_crt_t cert, unsigned int * key_usage, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

key_usage: where the key usage bits will be stored

critical: will be non zero if the extension is marked as critical

This function will return certificate's key usage, by reading the keyUsage X.509 extension (2.5.29.15). The key usage value will

ORed values of the: GNUTLS_KEY_DIGITAL_SIGNATURE, GNUTLS_KEY_NON_REPUDIATION, GNUTLS_KEY_KEY_ENCIPHERMENT, GNUTLS_KEY_DATA_ENCIPHERMENT, GNUTLS_KEY_KEY_AGREEMENT, GNUTLS_KEY_KEY_CERT_SIGN, GNUTLS_KEY_CRL_SIGN, GNUTLS_KEY_ENCIPHER_ONLY, GNUTLS_KEY_DECIPHER_ONLY.

Returns: the certificate key usage, or a negative value in case of parsing error. If the certificate does not contain the keyUsage extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_pk_algorithm

Function: int gnutls_x509_crt_get_pk_algorithm (gnutls_x509_crt_t cert, unsigned int * bits)

cert: should contain a gnutls_x509_crt_t structure

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of an X.509 certificate.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

gnutls_x509_crt_get_pk_dsa_raw

Function: int gnutls_x509_crt_get_pk_dsa_raw (gnutls_x509_crt_t crt, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y)

crt: Holds the certificate

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

This function will export the DSA public key's parameters found in the given certificate. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

gnutls_x509_crt_get_pk_rsa_raw

Function: int gnutls_x509_crt_get_pk_rsa_raw (gnutls_x509_crt_t crt, gnutls_datum_t * m, gnutls_datum_t * e)

crt: Holds the certificate

m: will hold the modulus

e: will hold the public exponent

This function will export the RSA public key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

gnutls_x509_crt_get_proxy

Function: int gnutls_x509_crt_get_proxy (gnutls_x509_crt_t cert, unsigned int * critical, int * pathlen, char ** policyLanguage, char ** policy, size_t * sizeof_policy)

cert: should contain a gnutls_x509_crt_t structure

critical: will be non zero if the extension is marked as critical

pathlen: pointer to output integer indicating path length (may be NULL), non-negative values indicate a present pCPathLenConstraint field and the actual value, -1 indicate that the field is absent.

This function will read the certificate's basic constraints, and return the certificates CA status. It reads the basicConstraints X.509 extension (2.5.29.19).

Return value: If the certificate is a CA a positive value will be returned, or zero if the certificate does not have CA flag set. A negative value may be returned in case of errors. If the certificate does not contain the basicConstraints extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.

gnutls_x509_crt_get_raw_dn

Function: int gnutls_x509_crt_get_raw_dn (gnutls_x509_crt_t cert, gnutls_datum_t * start)

cert: should contain a gnutls_x509_crt_t structure

start: will hold the starting point of the DN

This function will return a pointer to the DER encoded DN structure and the length.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. or a negative value on error.

gnutls_x509_crt_get_raw_issuer_dn

Function: int gnutls_x509_crt_get_raw_issuer_dn (gnutls_x509_crt_t cert, gnutls_datum_t * start)

cert: should contain a gnutls_x509_crt_t structure

start: will hold the starting point of the DN

This function will return a pointer to the DER encoded DN structure and the length.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.or a negative value on error.

gnutls_x509_crt_get_serial

Function: int gnutls_x509_crt_get_serial (gnutls_x509_crt_t cert, void * result, size_t * result_size)

cert: should contain a gnutls_x509_crt_t structure

result: The place where the serial number will be copied

result_size: Holds the size of the result field.

This function will return the X.509 certificate's serial number. This is obtained by the X509 Certificate serialNumber field. Serial is not always a 32 or 64bit number. Some CAs use large serial numbers, thus it may be wise to handle it as something opaque.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crt_get_signature_algorithm

Function: int gnutls_x509_crt_get_signature_algorithm (gnutls_x509_crt_t cert)

cert: should contain a gnutls_x509_crt_t structure

This function will return a value of the gnutls_sign_algorithm_t enumeration that is the signature algorithm.

Returns: a gnutls_sign_algorithm_t value, or a negative value on error.

gnutls_x509_crt_get_signature

Function: int gnutls_x509_crt_get_signature (gnutls_x509_crt_t cert, char * sig, size_t * sizeof_sig)

cert: should contain a gnutls_x509_crt_t structure

sig: a pointer where the signature part will be copied (may be null).

sizeof_sig: initially holds the size of sig

This function will extract the signature field of a certificate.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value. and a negative value on error.

gnutls_x509_crt_get_subject_alt_name2

Function: int gnutls_x509_crt_get_subject_alt_name2 (gnutls_x509_crt_t cert, unsigned int seq, void * ret, size_t * ret_size, unsigned int * ret_type, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

seq: specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.)

ret: is the place where the alternative name will be copied to

ret_size: holds the size of ret.

ret_type: holds the type of the alternative name (one of gnutls_x509_subject_alt_name_t).

critical: will be non zero if the extension is marked as critical (may be null)

This function will return the alternative names, contained in the given certificate. It is the same as gnutls_x509_crt_get_subject_alt_name() except for the fact that it will return the type of the alternative name in ret_type even if the function fails for some reason (i.e. the buffer provided is not enough).

The return values are the same as with gnutls_x509_crt_get_subject_alt_name().

gnutls_x509_crt_get_subject_alt_name

Function: int gnutls_x509_crt_get_subject_alt_name (gnutls_x509_crt_t cert, unsigned int seq, void * ret, size_t * ret_size, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

seq: specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.)

ret: is the place where the alternative name will be copied to

ret_size: holds the size of ret.

critical: will be non zero if the extension is marked as critical (may be null)

This function will return the alternative names, contained in the given certificate.

This is specified in X509v3 Certificate Extensions. GNUTLS will return the Alternative name (2.5.29.17), or a negative error code.

When the SAN type is otherName, it will extract the data in the otherName's value field, and GNUTLS_SAN_OTHERNAME is returned. You may use gnutls_x509_crt_get_subject_alt_othername_oid() to get the corresponding OID and the "virtual" SAN types (e.g., GNUTLS_SAN_OTHERNAME_XMPP).

If an otherName OID is known, the data will be decoded. Otherwise the returned data will be DER encoded, and you will have to decode it yourself. Currently, only the RFC 3920 id-on-xmppAddr SAN is recognized.

Returns: the alternative subject name type on success, one of the enumerated gnutls_x509_subject_alt_name_t. It will return GNUTLS_E_SHORT_MEMORY_BUFFER if ret_size is not large enough to hold the value. In that case ret_size will be updated with the required size. If the certificate does not have an Alternative name with the specified sequence number then GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.

gnutls_x509_crt_get_subject_alt_othername_oid

Function: int gnutls_x509_crt_get_subject_alt_othername_oid (gnutls_x509_crt_t cert, unsigned int seq, void * ret, size_t * ret_size)

cert: should contain a gnutls_x509_crt_t structure

seq: specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.)

ret: is the place where the otherName OID will be copied to

ret_size: holds the size of ret.

This function will extract the type OID of an otherName Subject Alternative Name, contained in the given certificate, and return the type as an enumerated element.

This function is only useful if gnutls_x509_crt_get_subject_alt_name() returned GNUTLS_SAN_OTHERNAME.

Returns: the alternative subject name type on success, one of the enumerated gnutls_x509_subject_alt_name_t. For supported OIDs, it will return one of the virtual (GNUTLS_SAN_OTHERNAME_*) types, e.g. GNUTLS_SAN_OTHERNAME_XMPP, and GNUTLS_SAN_OTHERNAME for unknown OIDs. It will return GNUTLS_E_SHORT_MEMORY_BUFFER if ret_size is not large enough to hold the value. In that case ret_size will be updated with the required size. If the certificate does not have an Alternative name with the specified sequence number and with the otherName type then GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.

gnutls_x509_crt_get_subject_key_id

Function: int gnutls_x509_crt_get_subject_key_id (gnutls_x509_crt_t cert, void * ret, size_t * ret_size, unsigned int * critical)

cert: should contain a gnutls_x509_crt_t structure

ret: The place where the identifier will be copied

ret_size: Holds the size of the result field.

critical: will be non zero if the extension is marked as critical (may be null)

This function will return the X.509v3 certificate's subject key identifier. This is obtained by the X.509 Subject Key identifier extension field (2.5.29.14).

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crt_get_subject

Function: int gnutls_x509_crt_get_subject (gnutls_x509_crt_t cert, gnutls_x509_dn_t * dn)

cert: should contain a gnutls_x509_crt_t structure

dn: output variable with pointer to opaque DN.

Return the Certificate's Subject DN as an opaque data type. You may use gnutls_x509_dn_get_rdn_ava() to decode the DN.

Note that dn should be treated as constant. Because points into the cert object, you may not deallocate cert and continue to access dn.

Returns: Returns 0 on success, or an error code.

gnutls_x509_crt_get_version

Function: int gnutls_x509_crt_get_version (gnutls_x509_crt_t cert)

cert: should contain a gnutls_x509_crt_t structure

This function will return the version of the specified Certificate.

Returns: version of certificate, or a negative value on error.

gnutls_x509_crt_import

Function: int gnutls_x509_crt_import (gnutls_x509_crt_t cert, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format)

cert: The structure to store the parsed certificate.

data: The DER or PEM encoded certificate.

format: One of DER or PEM

This function will convert the given DER or PEM encoded Certificate to the native gnutls_x509_crt_t format. The output will be stored in cert.

If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_init

Function: int gnutls_x509_crt_init (gnutls_x509_crt_t * cert)

cert: The structure to be initialized

This function will initialize an X.509 certificate structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_list_import

Function: int gnutls_x509_crt_list_import (gnutls_x509_crt_t * certs, unsigned int * cert_max, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format, unsigned int flags)

certs: The structures to store the parsed certificate. Must not be initialized.

cert_max: Initially must hold the maximum number of certs. It will be updated with the number of certs available.

data: The PEM encoded certificate.

format: One of DER or PEM.

flags: must be zero or an OR'd sequence of gnutls_certificate_import_flags.

This function will convert the given PEM encoded certificate list to the native gnutls_x509_crt_t format. The output will be stored in certs. They will be automatically initialized.

If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".

Returns: the number of certificates read or a negative error value.

gnutls_x509_crt_list_verify

Function: int gnutls_x509_crt_list_verify (const gnutls_x509_crt_t * cert_list, int cert_list_length, const gnutls_x509_crt_t * CA_list, int CA_list_length, const gnutls_x509_crl_t * CRL_list, int CRL_list_length, unsigned int flags, unsigned int * verify)

cert_list: is the certificate list to be verified

cert_list_length: holds the number of certificate in cert_list

CA_list: is the CA list which will be used in verification

CA_list_length: holds the number of CA certificate in CA_list

CRL_list: holds a list of CRLs.

CRL_list_length: the length of CRL list.

flags: Flags that may be used to change the verification algorithm. Use OR of the gnutls_certificate_verify_flags enumerations.

verify: will hold the certificate verification output.

This function will try to verify the given certificate list and return its status. If no flags are specified (0), this function will use the basicConstraints (2.5.29.19) PKIX extension. This means that only a certificate authority is allowed to sign a certificate.

You must also check the peer's name in order to check if the verified certificate belongs to the actual peer.

The certificate verification output will be put in verify and will be one or more of the gnutls_certificate_status_t enumerated elements bitwise or'd. For a more detailed verification status use gnutls_x509_crt_verify() per list element.

GNUTLS_CERT_INVALID: the certificate chain is not valid.

GNUTLS_CERT_REVOKED: a certificate in the chain has been revoked.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crt_print

Function: int gnutls_x509_crt_print (gnutls_x509_crt_t cert, gnutls_certificate_print_formats_t format, gnutls_datum_t * out)

cert: The structure to be printed

format: Indicate the format to use

out: Newly allocated datum with zero terminated string.

This function will pretty print a X.509 certificate, suitable for display to a human.

If the format is GNUTLS_CRT_PRINT_FULL then all fields of the certificate will be output, on multiple lines. The GNUTLS_CRT_PRINT_ONELINE format will generate one line with some selected fields, which is useful for logging purposes.

The output out needs to be deallocate using gnutls_free().

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_activation_time

Function: int gnutls_x509_crt_set_activation_time (gnutls_x509_crt_t cert, time_t act_time)

cert: a certificate of type gnutls_x509_crt_t

act_time: The actual time

This function will set the time this Certificate was or will be activated.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_authority_key_id

Function: int gnutls_x509_crt_set_authority_key_id (gnutls_x509_crt_t cert, const void * id, size_t id_size)

cert: a certificate of type gnutls_x509_crt_t

id: The key ID

id_size: Holds the size of the serial field.

This function will set the X.509 certificate's authority key ID extension. Only the keyIdentifier field can be set with this function.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_basic_constraints

Function: int gnutls_x509_crt_set_basic_constraints (gnutls_x509_crt_t crt, unsigned int ca, int pathLenConstraint)

crt: a certificate of type gnutls_x509_crt_t

ca: true(1) or false(0). Depending on the Certificate authority status.

pathLenConstraint: non-negative values indicate maximum length of path, and negative values indicate that the pathLenConstraints field should not be present.

This function will set the basicConstraints certificate extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_ca_status

Function: int gnutls_x509_crt_set_ca_status (gnutls_x509_crt_t crt, unsigned int ca)

crt: a certificate of type gnutls_x509_crt_t

ca: true(1) or false(0). Depending on the Certificate authority status.

This function will set the basicConstraints certificate extension. Use gnutls_x509_crt_set_basic_constraints() if you want to control the pathLenConstraint field too.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_crl_dist_points2

Function: int gnutls_x509_crt_set_crl_dist_points2 (gnutls_x509_crt_t crt, gnutls_x509_subject_alt_name_t type, const void * data, unsigned int data_size, unsigned int reason_flags)

crt: a certificate of type gnutls_x509_crt_t

type: is one of the gnutls_x509_subject_alt_name_t enumerations

data: The data to be set

data_size: The data size

reason_flags: revocation reasons

This function will set the CRL distribution points certificate extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.6.0

gnutls_x509_crt_set_crl_dist_points

Function: int gnutls_x509_crt_set_crl_dist_points (gnutls_x509_crt_t crt, gnutls_x509_subject_alt_name_t type, const void * data_string, unsigned int reason_flags)

crt: a certificate of type gnutls_x509_crt_t

type: is one of the gnutls_x509_subject_alt_name_t enumerations

data_string: The data to be set

reason_flags: revocation reasons

This function will set the CRL distribution points certificate extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_crq

Function: int gnutls_x509_crt_set_crq (gnutls_x509_crt_t crt, gnutls_x509_crq_t crq)

crt: a certificate of type gnutls_x509_crt_t

crq: holds a certificate request

This function will set the name and public parameters from the given certificate request to the certificate. Only RSA keys are currently supported.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_dn_by_oid

Function: int gnutls_x509_crt_set_dn_by_oid (gnutls_x509_crt_t crt, const char * oid, unsigned int raw_flag, const void * name, unsigned int sizeof_name)

crt: a certificate of type gnutls_x509_crt_t

oid: holds an Object Identifier in a null terminated string

raw_flag: must be 0, or 1 if the data are DER encoded

name: a pointer to the name

sizeof_name: holds the size of name

This function will set the part of the name of the Certificate subject, specified by the given OID. The input string should be ASCII or UTF-8 encoded.

Some helper macros with popular OIDs can be found in gnutls/x509.h With this function you can only set the known OIDs. You can test for known OIDs using gnutls_x509_dn_oid_known(). For OIDs that are not known (by gnutls) you should properly DER encode your data, and call this function with raw_flag set.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_expiration_time

Function: int gnutls_x509_crt_set_expiration_time (gnutls_x509_crt_t cert, time_t exp_time)

cert: a certificate of type gnutls_x509_crt_t

exp_time: The actual time

This function will set the time this Certificate will expire.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_extension_by_oid

Function: int gnutls_x509_crt_set_extension_by_oid (gnutls_x509_crt_t crt, const char * oid, const void * buf, size_t sizeof_buf, unsigned int critical)

crt: a certificate of type gnutls_x509_crt_t

oid: holds an Object Identified in null terminated string

buf: a pointer to a DER encoded data

sizeof_buf: holds the size of buf

critical: should be non zero if the extension is to be marked as critical

This function will set an the extension, by the specified OID, in the certificate. The extension data should be binary data DER encoded.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_crt_set_issuer_dn_by_oid

Function: int gnutls_x509_crt_set_issuer_dn_by_oid (gnutls_x509_crt_t crt, const char * oid, unsigned int raw_flag, const void * name, unsigned int sizeof_name)

crt: a certificate of type gnutls_x509_crt_t

oid: holds an Object Identifier in a null terminated string

raw_flag: must be 0, or 1 if the data are DER encoded

name: a pointer to the name

sizeof_name: holds the size of name

This function will set the part of the name of the Certificate issuer, specified by the given OID. The input string should be ASCII or UTF-8 encoded.

Some helper macros with popular OIDs can be found in gnutls/x509.h With this function you can only set the known OIDs. You can test for known OIDs using gnutls_x509_dn_oid_known(). For OIDs that are not known (by gnutls) you should properly DER encode your data, and call this function with raw_flag set.

Normally you do not need to call this function, since the signing operation will copy the signer's name as the issuer of the certificate.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_key_purpose_oid

Function: int gnutls_x509_crt_set_key_purpose_oid (gnutls_x509_crt_t cert, const void * oid, unsigned int critical)

cert: a certificate of type gnutls_x509_crt_t

oid: a pointer to a null terminated string that holds the OID

critical: Whether this extension will be critical or not

This function will set the key purpose OIDs of the Certificate. These are stored in the Extended Key Usage extension (2.5.29.37) See the GNUTLS_KP_* definitions for human readable names.

Subsequent calls to this function will append OIDs to the OID list.

On success 0 is returned.

gnutls_x509_crt_set_key_usage

Function: int gnutls_x509_crt_set_key_usage (gnutls_x509_crt_t crt, unsigned int usage)

crt: a certificate of type gnutls_x509_crt_t

usage: an ORed sequence of the GNUTLS_KEY_* elements.

This function will set the keyUsage certificate extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_key

Function: int gnutls_x509_crt_set_key (gnutls_x509_crt_t crt, gnutls_x509_privkey_t key)

crt: a certificate of type gnutls_x509_crt_t

key: holds a private key

This function will set the public parameters from the given private key to the certificate. Only RSA keys are currently supported.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_proxy_dn

Function: int gnutls_x509_crt_set_proxy_dn (gnutls_x509_crt_t crt, gnutls_x509_crt_t eecrt, unsigned int raw_flag, const void * name, unsigned int sizeof_name)

crt: a gnutls_x509_crt_t structure with the new proxy cert

eecrt: the end entity certificate that will be issuing the proxy

raw_flag: must be 0, or 1 if the CN is DER encoded

name: a pointer to the CN name, may be NULL (but MUST then be added later)

sizeof_name: holds the size of name

This function will set the subject in crt to the end entity's eecrt subject name, and add a single Common Name component name of size sizeof_name. This corresponds to the required proxy certificate naming style. Note that if name is NULL, you MUST set it later by using gnutls_x509_crt_set_dn_by_oid() or similar.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_proxy

Function: int gnutls_x509_crt_set_proxy (gnutls_x509_crt_t crt, int pathLenConstraint, const char * policyLanguage, const char * policy, size_t sizeof_policy)

crt: a certificate of type gnutls_x509_crt_t

pathLenConstraint: non-negative values indicate maximum length of path, and negative values indicate that the pathLenConstraints field should not be present.

policyLanguage: OID describing the language of policy.

policy: opaque byte array with policy language, can be NULL

sizeof_policy: size of policy.

This function will set the proxyCertInfo extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_serial

Function: int gnutls_x509_crt_set_serial (gnutls_x509_crt_t cert, const void * serial, size_t serial_size)

cert: a certificate of type gnutls_x509_crt_t

serial: The serial number

serial_size: Holds the size of the serial field.

This function will set the X.509 certificate's serial number. Serial is not always a 32 or 64bit number. Some CAs use large serial numbers, thus it may be wise to handle it as something opaque.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_subject_alt_name

Function: int gnutls_x509_crt_set_subject_alt_name (gnutls_x509_crt_t crt, gnutls_x509_subject_alt_name_t type, const void * data, unsigned int data_size, unsigned int flags)

crt: a certificate of type gnutls_x509_crt_t

type: is one of the gnutls_x509_subject_alt_name_t enumerations

data: The data to be set

data_size: The size of data to be set

flags: GNUTLS_FSAN_SET to clear previous data or GNUTLS_FSAN_APPEND to append.

This function will set the subject alternative name certificate extension. It can set the following types:

&GNUTLS_SAN_DNSNAME: as a text string

&GNUTLS_SAN_RFC822NAME: as a text string

&GNUTLS_SAN_URI: as a text string

&GNUTLS_SAN_IPADDRESS: as a binary IP address (4 or 16 bytes)

Other values can be set as binary values with the proper DER encoding.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.6.0

gnutls_x509_crt_set_subject_alternative_name

Function: int gnutls_x509_crt_set_subject_alternative_name (gnutls_x509_crt_t crt, gnutls_x509_subject_alt_name_t type, const char * data_string)

crt: a certificate of type gnutls_x509_crt_t

type: is one of the gnutls_x509_subject_alt_name_t enumerations

data_string: The data to be set, a zero terminated string

This function will set the subject alternative name certificate extension. This function assumes that data can be expressed as a null terminated string.

The name of the function is unfortunate since it is incosistent with gnutls_x509_crt_get_subject_alt_name().

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_subject_key_id

Function: int gnutls_x509_crt_set_subject_key_id (gnutls_x509_crt_t cert, const void * id, size_t id_size)

cert: a certificate of type gnutls_x509_crt_t

id: The key ID

id_size: Holds the size of the serial field.

This function will set the X.509 certificate's subject key ID extension.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_set_version

Function: int gnutls_x509_crt_set_version (gnutls_x509_crt_t crt, unsigned int version)

crt: a certificate of type gnutls_x509_crt_t

version: holds the version number. For X.509v1 certificates must be 1.

This function will set the version of the certificate. This must be one for X.509 version 1, and so on. Plain certificates without extensions must have version set to one.

To create well-formed certificates, you must specify version 3 if you use any certificate extensions. Extensions are created by functions such as gnutls_x509_crt_set_subject_alt_name() or gnutls_x509_crt_set_key_usage().

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_sign2

Function: int gnutls_x509_crt_sign2 (gnutls_x509_crt_t crt, gnutls_x509_crt_t issuer, gnutls_x509_privkey_t issuer_key, gnutls_digest_algorithm_t dig, unsigned int flags)

crt: a certificate of type gnutls_x509_crt_t

issuer: is the certificate of the certificate issuer

issuer_key: holds the issuer's private key

dig: The message digest to use, GNUTLS_DIG_SHA1 is a safe choice

flags: must be 0

This function will sign the certificate with the issuer's private key, and will copy the issuer's information into the certificate.

This must be the last step in a certificate generation since all the previously set parameters are now signed.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_sign

Function: int gnutls_x509_crt_sign (gnutls_x509_crt_t crt, gnutls_x509_crt_t issuer, gnutls_x509_privkey_t issuer_key)

crt: a certificate of type gnutls_x509_crt_t

issuer: is the certificate of the certificate issuer

issuer_key: holds the issuer's private key

This function is the same a gnutls_x509_crt_sign2() with no flags, and SHA1 as the hash algorithm.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_crt_verify_data

Function: int gnutls_x509_crt_verify_data (gnutls_x509_crt_t crt, unsigned int flags, const gnutls_datum_t * data, const gnutls_datum_t * signature)

crt: Holds the certificate

flags: should be 0 for now

data: holds the data to be signed

signature: contains the signature

This function will verify the given signed data, using the parameters from the certificate.

Returns: In case of a verification failure 0 is returned, and 1 on success.

gnutls_x509_crt_verify

Function: int gnutls_x509_crt_verify (gnutls_x509_crt_t cert, const gnutls_x509_crt_t * CA_list, int CA_list_length, unsigned int flags, unsigned int * verify)

cert: is the certificate to be verified

CA_list: is one certificate that is considered to be trusted one

CA_list_length: holds the number of CA certificate in CA_list

flags: Flags that may be used to change the verification algorithm. Use OR of the gnutls_certificate_verify_flags enumerations.

verify: will hold the certificate verification output.

This function will try to verify the given certificate and return its status. The verification output in this functions cannot be GNUTLS_CERT_NOT_VALID.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.and a negative value in case of an error.

gnutls_x509_dn_deinit

Function: void gnutls_x509_dn_deinit (gnutls_x509_dn_t idn)

idn: a DN opaque object pointer.

This function deallocates the DN object as returned by gnutls_x509_dn_import().

Since: 2.4.0

gnutls_x509_dn_export

Function: int gnutls_x509_dn_export (gnutls_x509_dn_t dn, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

dn: Holds the opaque DN object

format: the format of output params. One of PEM or DER.

output_data: will contain a DN PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the DN to DER or PEM format.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN NAME".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_dn_get_rdn_ava

Function: int gnutls_x509_dn_get_rdn_ava (gnutls_x509_dn_t dn, int irdn, int iava, gnutls_x509_ava_st * ava)

dn: input variable with opaque DN pointer

irdn: index of RDN

iava: index of AVA.

ava: Pointer to structure which will hold output information.

Get pointers to data within the DN.

Note that ava will contain pointers into the dn structure, so you should not modify any data or deallocate it. Note also that the DN in turn points into the original certificate structure, and thus you may not deallocate the certificate and continue to access dn.

Returns: Returns 0 on success, or an error code.

gnutls_x509_dn_import

Function: int gnutls_x509_dn_import (gnutls_x509_dn_t odn, const gnutls_datum_t * data)

odn: the structure that will hold the imported DN

data: should contain a DER encoded RDN sequence

This function parses an RDN sequence and stores the result to a gnutls_x509_dn_t structure. The structure must have been initialized with gnutls_x509_dn_init(). You may use gnutls_x509_dn_get_rdn_ava() to decode the DN. This function parses an RDN sequence and stores the result to a gnutls_x509_dn_t structure. The structure must have been initialized with gnutls_x509_dn_init(). You may use gnutls_x509_dn_get_rdn_ava() to decode the DN.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.4.0

gnutls_x509_dn_init

Function: int gnutls_x509_dn_init (gnutls_x509_dn_t * odn)

odn: the object to be initialized

This function initializes a gnutls_x509_dn_t structure.

The object returned must be deallocated using gnutls_x509_dn_deinit().

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.4.0

gnutls_x509_dn_oid_known

Function: int gnutls_x509_dn_oid_known (const char * oid)

oid: holds an Object Identifier in a null terminated string

This function will inform about known DN OIDs. This is useful since functions like gnutls_x509_crt_set_dn_by_oid() use the information on known OIDs to properly encode their input. Object Identifiers that are not known are not encoded by these functions, and their input is stored directly into the ASN.1 structure. In that case of unknown OIDs, you have the responsibility of DER encoding your data.

Returns: 1 on known OIDs and 0 otherwise.

gnutls_x509_privkey_cpy

Function: int gnutls_x509_privkey_cpy (gnutls_x509_privkey_t dst, gnutls_x509_privkey_t src)

dst: The destination key, which should be initialized.

src: The source key

This function will copy a private key from source to destination key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_deinit

Function: void gnutls_x509_privkey_deinit (gnutls_x509_privkey_t key)

key: The structure to be initialized

This function will deinitialize a private key structure.

gnutls_x509_privkey_export_dsa_raw

Function: int gnutls_x509_privkey_export_dsa_raw (gnutls_x509_privkey_t key, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y, gnutls_datum_t * x)

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

x: will hold the x

This function will export the DSA private key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_export_pkcs8

Function: int gnutls_x509_privkey_export_pkcs8 (gnutls_x509_privkey_t key, gnutls_x509_crt_fmt_t format, const char * password, unsigned int flags, void * output_data, size_t * output_data_size)

key: Holds the key

format: the format of output params. One of PEM or DER.

password: the password that will be used to encrypt the key.

flags: an ORed sequence of gnutls_pkcs_encrypt_flags_t

output_data: will contain a private key PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the private key to a PKCS8 structure. Both RSA and DSA keys can be exported. For DSA keys we use PKCS 11 definitions. If the flags do not specify the encryption cipher, then the default 3DES (PBES2) will be used.

The password can be either ASCII or UTF-8 in the default PBES2 encryption schemas, or ASCII for the PKCS12 schemas.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN ENCRYPTED PRIVATE KEY" or "BEGIN PRIVATE KEY" if encryption is not used.

Return value: In case of failure a negative value will be returned, and 0 on success.

gnutls_x509_privkey_export_rsa_raw

Function: int gnutls_x509_privkey_export_rsa_raw (gnutls_x509_privkey_t key, gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u)

key: a structure that holds the rsa parameters

m: will hold the modulus

e: will hold the public exponent

d: will hold the private exponent

p: will hold the first prime (p)

q: will hold the second prime (q)

u: will hold the coefficient

This function will export the RSA private key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_export

Function: int gnutls_x509_privkey_export (gnutls_x509_privkey_t key, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

key: Holds the key

format: the format of output params. One of PEM or DER.

output_data: will contain a private key PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the private key to a PKCS1 structure for RSA keys, or an integer sequence for DSA keys. The DSA keys are in the same format with the parameters used by openssl.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN RSA PRIVATE KEY".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_fix

Function: int gnutls_x509_privkey_fix (gnutls_x509_privkey_t key)

key: Holds the key

This function will recalculate the secondary parameters in a key. In RSA keys, this can be the coefficient and exponent1,2.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_generate

Function: int gnutls_x509_privkey_generate (gnutls_x509_privkey_t key, gnutls_pk_algorithm_t algo, unsigned int bits, unsigned int flags)

key: should contain a gnutls_x509_privkey_t structure

algo: is one of RSA or DSA.

bits: the size of the modulus

flags: unused for now. Must be 0.

This function will generate a random private key. Note that this function must be called on an empty private key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_get_key_id

Function: int gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t key, unsigned int flags, unsigned char * output_data, size_t * output_data_size)

key: Holds the key

flags: should be 0 for now

output_data: will contain the key ID

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will return a unique ID the depends on the public key parameters. This ID can be used in checking whether a certificate corresponds to the given key.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned. The output will normally be a SHA-1 hash output, which is 20 bytes.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_get_pk_algorithm

Function: int gnutls_x509_privkey_get_pk_algorithm (gnutls_x509_privkey_t key)

key: should contain a gnutls_x509_privkey_t structure

This function will return the public key algorithm of a private key.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

gnutls_x509_privkey_import_dsa_raw

Function: int gnutls_x509_privkey_import_dsa_raw (gnutls_x509_privkey_t key, const gnutls_datum_t * p, const gnutls_datum_t * q, const gnutls_datum_t * g, const gnutls_datum_t * y, const gnutls_datum_t * x)

key: The structure to store the parsed key

p: holds the p

q: holds the q

g: holds the g

y: holds the y

x: holds the x

This function will convert the given DSA raw parameters to the native gnutls_x509_privkey_t format. The output will be stored in key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_import_pkcs8

Function: int gnutls_x509_privkey_import_pkcs8 (gnutls_x509_privkey_t key, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format, const char * password, unsigned int flags)

key: The structure to store the parsed key

data: The DER or PEM encoded key.

format: One of DER or PEM

password: the password to decrypt the key (if it is encrypted).

flags: 0 if encrypted or GNUTLS_PKCS_PLAIN if not encrypted.

This function will convert the given DER or PEM encoded PKCS8 2.0 encrypted key to the native gnutls_x509_privkey_t format. The output will be stored in key. Both RSA and DSA keys can be imported, and flags can only be used to indicate an unencrypted key.

The password can be either ASCII or UTF-8 in the default PBES2 encryption schemas, or ASCII for the PKCS12 schemas.

If the Certificate is PEM encoded it should have a header of "ENCRYPTED PRIVATE KEY", or "PRIVATE KEY". You only need to specify the flags if the key is DER encoded, since in that case the encryption status cannot be auto-detected.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_import_rsa_raw

Function: int gnutls_x509_privkey_import_rsa_raw (gnutls_x509_privkey_t key, const gnutls_datum_t * m, const gnutls_datum_t * e, const gnutls_datum_t * d, const gnutls_datum_t * p, const gnutls_datum_t * q, const gnutls_datum_t * u)

key: The structure to store the parsed key

m: holds the modulus

e: holds the public exponent

d: holds the private exponent

p: holds the first prime (p)

q: holds the second prime (q)

u: holds the coefficient

This function will convert the given RSA raw parameters to the native gnutls_x509_privkey_t format. The output will be stored in key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_import

Function: int gnutls_x509_privkey_import (gnutls_x509_privkey_t key, const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format)

key: The structure to store the parsed key

data: The DER or PEM encoded certificate.

format: One of DER or PEM

This function will convert the given DER or PEM encoded key to the native gnutls_x509_privkey_t format. The output will be stored in key .

If the key is PEM encoded it should have a header of "RSA PRIVATE KEY", or "DSA PRIVATE KEY".

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_init

Function: int gnutls_x509_privkey_init (gnutls_x509_privkey_t * key)

key: The structure to be initialized

This function will initialize an private key structure.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_sign_data

Function: int gnutls_x509_privkey_sign_data (gnutls_x509_privkey_t key, gnutls_digest_algorithm_t digest, unsigned int flags, const gnutls_datum_t * data, void * signature, size_t * signature_size)

key: Holds the key

digest: should be MD5 or SHA1

flags: should be 0 for now

data: holds the data to be signed

signature: will contain the signature

signature_size: holds the size of signature (and will be replaced by the new size)

This function will sign the given data using a signature algorithm supported by the private key. Signature algorithms are always used together with a hash functions. Different hash functions may be used for the RSA algorithm, but only SHA-1 for the DSA keys.

If the buffer provided is not long enough to hold the output, then *signature_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_sign_hash

Function: int gnutls_x509_privkey_sign_hash (gnutls_x509_privkey_t key, const gnutls_datum_t * hash, gnutls_datum_t * signature)

key: Holds the key

hash: holds the data to be signed

signature: will contain newly allocated signature

This function will sign the given hash using the private key.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_x509_privkey_verify_data

Function: int gnutls_x509_privkey_verify_data (gnutls_x509_privkey_t key, unsigned int flags, const gnutls_datum_t * data, const gnutls_datum_t * signature)

key: Holds the key

flags: should be 0 for now

data: holds the data to be signed

signature: contains the signature

This function will verify the given signed data, using the parameters in the private key.

Returns: In case of a verification failure 0 is returned, and 1 on success.

gnutls_x509_rdn_get_by_oid

Function: int gnutls_x509_rdn_get_by_oid (const gnutls_datum_t * idn, const char * oid, int indx, unsigned int raw_flag, void * buf, size_t * sizeof_buf)

idn: should contain a DER encoded RDN sequence

oid: an Object Identifier

indx: In case multiple same OIDs exist in the RDN indicates which to send. Use 0 for the first one.

raw_flag: If non zero then the raw DER data are returned.

buf: a pointer to a structure to hold the peer's name

sizeof_buf: holds the size of buf

This function will return the name of the given Object identifier, of the RDN sequence. The name will be encoded using the rules from RFC2253.

Returns: On success, GNUTLS_E_SUCCESS is returned, or GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *sizeof_buf is updated if the provided buffer is not long enough, otherwise a negative error value.

gnutls_x509_rdn_get_oid

Function: int gnutls_x509_rdn_get_oid (const gnutls_datum_t * idn, int indx, void * buf, size_t * sizeof_buf)

idn: should contain a DER encoded RDN sequence

indx: Indicates which OID to return. Use 0 for the first one.

This function will return the specified Object identifier, of the RDN sequence.

Returns: On success, GNUTLS_E_SUCCESS is returned, or GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *sizeof_buf is updated if the provided buffer is not long enough, otherwise a negative error value.

Since: 2.4.0

gnutls_x509_rdn_get

Function: int gnutls_x509_rdn_get (const gnutls_datum_t * idn, char * buf, size_t * sizeof_buf)

idn: should contain a DER encoded RDN sequence

buf: a pointer to a structure to hold the peer's name

sizeof_buf: holds the size of buf

This function will return the name of the given RDN sequence. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253.

Returns: On success, GNUTLS_E_SUCCESS is returned, or GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *sizeof_buf is updated if the provided buffer is not long enough, otherwise a negative error value.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.3 GnuTLS-extra Functions

These functions are only available in the GPLv3+ version of the library called gnutls-extra. The prototypes for this library lie in `gnutls/extra.h'.

gnutls_extra_check_version

Function: const char * gnutls_extra_check_version (const char * req_version)

req_version: the version to check

Check that the version of the gnutls-extra 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.

gnutls_global_init_extra

Function: int gnutls_global_init_extra ( void)

This function initializes the global state of gnutls-extra library to defaults. Returns zero on success.

Note that gnutls_global_init() has to be called before this function. If this function is not called then the gnutls-extra library will not be usable.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.4 OpenPGP Functions

The following functions are to be used for OpenPGP certificate handling. Their prototypes lie in `gnutls/openpgp.h'.

gnutls_certificate_set_openpgp_key_file2

Function: int gnutls_certificate_set_openpgp_key_file2 (gnutls_certificate_credentials_t res, const char * certfile, const char * keyfile, const char * subkey_id, gnutls_openpgp_crt_fmt_t format)

res: the destination context to save the data.

certfile: the file that contains the public key.

keyfile: the file that contains the secret key.

subkey_id: a hex encoded subkey id

format: the format of the keys

This funtion is used to load OpenPGP keys into the GnuTLS credential structure. The files should contain non encrypted keys.

The special keyword "auto" is also accepted as &subkey_id. In that case the gnutls_openpgp_crt_get_auth_subkey() will be used to retrieve the subkey.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.4.0

gnutls_certificate_set_openpgp_key_file

Function: int gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t res, const char * certfile, const char * keyfile, gnutls_openpgp_crt_fmt_t format)

res: the destination context to save the data.

certfile: the file that contains the public key.

keyfile: the file that contains the secret key.

format: the format of the keys

This funtion is used to load OpenPGP keys into the GnuTLS credentials structure. The files should only contain one key which is not encrypted.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_certificate_set_openpgp_key_mem2

Function: int gnutls_certificate_set_openpgp_key_mem2 (gnutls_certificate_credentials_t res, const gnutls_datum_t * icert, const gnutls_datum_t * ikey, const char * subkey_id, gnutls_openpgp_crt_fmt_t format)

res: the destination context to save the data.

subkey_id: a hex encoded subkey id

format: the format of the keys

This funtion is used to load OpenPGP keys into the GnuTLS credentials structure. The files should only contain one key which is not encrypted.

The special keyword "auto" is also accepted as &subkey_id. In that case the gnutls_openpgp_crt_get_auth_subkey() will be used to retrieve the subkey.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

Since: 2.4.0

gnutls_certificate_set_openpgp_key_mem

Function: int gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t res, const gnutls_datum_t * icert, const gnutls_datum_t * ikey, gnutls_openpgp_crt_fmt_t format)

res: the destination context to save the data.

format: the format of the keys

This funtion is used to load OpenPGP keys into the GnuTLS credential structure. The files should contain non encrypted keys.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_certificate_set_openpgp_keyring_file

Function: int gnutls_certificate_set_openpgp_keyring_file (gnutls_certificate_credentials_t c, const char * file, gnutls_openpgp_crt_fmt_t format)

c: A certificate credentials structure

file: filename of the keyring.

The function is used to set keyrings that will be used internally by various OpenPGP functions. For example to find a key when it is needed for an operations. The keyring will also be used at the verification functions.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_certificate_set_openpgp_keyring_mem

Function: int gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t c, const opaque * data, size_t dlen, gnutls_openpgp_crt_fmt_t format)

c: A certificate credentials structure

data: buffer with keyring data.

dlen: length of data buffer.

The function is used to set keyrings that will be used internally by various OpenPGP functions. For example to find a key when it is needed for an operations. The keyring will also be used at the verification functions.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_certificate_set_openpgp_key

Function: int gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t res, gnutls_openpgp_crt_t crt, gnutls_openpgp_privkey_t pkey)

res: is an gnutls_certificate_credentials_t structure.

pkey: is an openpgp private 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).

With this function the subkeys of the certificate are not used.

gnutls_openpgp_crt_check_hostname

Function: int gnutls_openpgp_crt_check_hostname (gnutls_openpgp_crt_t key, const char * hostname)

key: should contain an gnutls_openpgp_crt_t structure

hostname: A null terminated string that contains a DNS name

This function will check if the given key's owner matches the given hostname. This is a basic implementation of the matching described in RFC2818 (HTTPS), which takes into account wildcards.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_deinit

Function: void gnutls_openpgp_crt_deinit (gnutls_openpgp_crt_t key)

key: The structure to be initialized

This function will deinitialize a key structure.

gnutls_openpgp_crt_export

Function: int gnutls_openpgp_crt_export (gnutls_openpgp_crt_t key, gnutls_openpgp_crt_fmt_t format, void * output_data, size_t * output_data_size)

key: Holds the key.

format: One of gnutls_openpgp_crt_fmt_t elements.

output_data: will contain the key base64 encoded or raw

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will convert the given key to RAW or Base64 format. If the buffer provided is not long enough to hold the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_get_auth_subkey

Function: int gnutls_openpgp_crt_get_auth_subkey (gnutls_openpgp_crt_t crt, gnutls_openpgp_keyid_t keyid, unsigned int flag)

keyid: the struct to save the keyid.

flag: Non zero indicates that a valid subkey is always returned.

Returns the 64-bit keyID of the first valid OpenPGP subkey marked for authentication. If flag is non zero and no authentication subkey exists, then a valid subkey will be returned even if it is not marked for authentication. Returns the 64-bit keyID of the first valid OpenPGP subkey marked for authentication. If flag is non zero and no authentication subkey exists, then a valid subkey will be returned even if it is not marked for authentication.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_get_creation_time

Function: time_t gnutls_openpgp_crt_get_creation_time (gnutls_openpgp_crt_t key)

key: the structure that contains the OpenPGP public key.

Get key creation time.

Returns: the timestamp when the OpenPGP key was created.

gnutls_openpgp_crt_get_expiration_time

Function: time_t gnutls_openpgp_crt_get_expiration_time (gnutls_openpgp_crt_t key)

key: the structure that contains the OpenPGP public key.

Get key expiration time. A value of '0' means that the key doesn't expire at all.

Returns: the time when the OpenPGP key expires.

gnutls_openpgp_crt_get_fingerprint

Function: int gnutls_openpgp_crt_get_fingerprint (gnutls_openpgp_crt_t key, void * fpr, size_t * fprlen)

key: the raw data that contains the OpenPGP public key.

fpr: the buffer to save the fingerprint, must hold at least 20 bytes.

fprlen: the integer to save the length of the fingerprint.

Get key fingerprint. Depending on the algorithm, the fingerprint can be 16 or 20 bytes.

Returns: On success, 0 is returned. Otherwise, an error code.

gnutls_openpgp_crt_get_key_id

Function: int gnutls_openpgp_crt_get_key_id (gnutls_openpgp_crt_t key, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the buffer to save the keyid.

Get key id string.

Returns: the 64-bit keyID of the OpenPGP key.

Since: 2.4.0

gnutls_openpgp_crt_get_key_usage

Function: int gnutls_openpgp_crt_get_key_usage (gnutls_openpgp_crt_t key, unsigned int * key_usage)

key: should contain a gnutls_openpgp_crt_t structure

key_usage: where the key usage bits will be stored

This function will return certificate's key usage, by checking the key algorithm. The key usage value will ORed values of the: GNUTLS_KEY_DIGITAL_SIGNATURE, GNUTLS_KEY_KEY_ENCIPHERMENT.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_get_name

Function: int gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key, int idx, char * buf, size_t * sizeof_buf)

key: the structure that contains the OpenPGP public key.

idx: the index of the ID to extract

buf: a pointer to a structure to hold the name

sizeof_buf: holds the maximum size of buf, on return hold the actual/required size of buf.

Extracts the userID from the parsed OpenPGP key.

Returns: GNUTLS_E_SUCCESS on success, and if the index of the ID does not exist GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE, or an error code.

gnutls_openpgp_crt_get_pk_algorithm

Function: gnutls_pk_algorithm_t gnutls_openpgp_crt_get_pk_algorithm (gnutls_openpgp_crt_t key, unsigned int * bits)

key: is an OpenPGP key

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of an OpenPGP certificate.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

gnutls_openpgp_crt_get_pk_dsa_raw

Function: int gnutls_openpgp_crt_get_pk_dsa_raw (gnutls_openpgp_crt_t crt, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y)

crt: Holds the certificate

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

This function will export the DSA public key's parameters found in the given certificate. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_crt_get_pk_rsa_raw

Function: int gnutls_openpgp_crt_get_pk_rsa_raw (gnutls_openpgp_crt_t crt, gnutls_datum_t * m, gnutls_datum_t * e)

crt: Holds the certificate

m: will hold the modulus

e: will hold the public exponent

This function will export the RSA public key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_crt_get_preferred_key_id

Function: int gnutls_openpgp_crt_get_preferred_key_id (gnutls_openpgp_crt_t key, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the struct to save the keyid.

Get preferred key id. If it hasn't been set it returns GNUTLS_E_INVALID_REQUEST.

Returns: the 64-bit preferred keyID of the OpenPGP key.

gnutls_openpgp_crt_get_revoked_status

Function: int gnutls_openpgp_crt_get_revoked_status (gnutls_openpgp_crt_t key)

key: the structure that contains the OpenPGP public key.

Get revocation status of key.

Returns: true (1) if the key has been revoked, or false (0) if it has not.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_count

Function: int gnutls_openpgp_crt_get_subkey_count (gnutls_openpgp_crt_t key)

key: is an OpenPGP key

This function will return the number of subkeys present in the given OpenPGP certificate.

Returns: the number of subkeys, or a negative value on error.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_creation_time

Function: time_t gnutls_openpgp_crt_get_subkey_creation_time (gnutls_openpgp_crt_t key, unsigned int idx)

key: the structure that contains the OpenPGP public key.

idx: the subkey index

Get subkey creation time.

Returns: the timestamp when the OpenPGP sub-key was created.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_expiration_time

Function: time_t gnutls_openpgp_crt_get_subkey_expiration_time (gnutls_openpgp_crt_t key, unsigned int idx)

key: the structure that contains the OpenPGP public key.

idx: the subkey index

Get subkey expiration time. A value of '0' means that the key doesn't expire at all.

Returns: the time when the OpenPGP key expires.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_fingerprint

Function: int gnutls_openpgp_crt_get_subkey_fingerprint (gnutls_openpgp_crt_t key, unsigned int idx, void * fpr, size_t * fprlen)

key: the raw data that contains the OpenPGP public key.

idx: the subkey index

fpr: the buffer to save the fingerprint, must hold at least 20 bytes.

fprlen: the integer to save the length of the fingerprint.

Get key fingerprint of a subkey. Depending on the algorithm, the fingerprint can be 16 or 20 bytes.

Returns: On success, 0 is returned. Otherwise, an error code.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_idx

Function: int gnutls_openpgp_crt_get_subkey_idx (gnutls_openpgp_crt_t key, const gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the keyid.

Get subkey's index.

Returns: the index of the subkey or a negative error value.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_id

Function: int gnutls_openpgp_crt_get_subkey_id (gnutls_openpgp_crt_t key, unsigned int idx, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

idx: the subkey index

keyid: the buffer to save the keyid.

Get the subkey's key-id.

Returns: the 64-bit keyID of the OpenPGP key.

gnutls_openpgp_crt_get_subkey_pk_algorithm

Function: gnutls_pk_algorithm_t gnutls_openpgp_crt_get_subkey_pk_algorithm (gnutls_openpgp_crt_t key, unsigned int idx, unsigned int * bits)

key: is an OpenPGP key

idx: is the subkey index

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of a subkey of an OpenPGP certificate.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_pk_dsa_raw

Function: int gnutls_openpgp_crt_get_subkey_pk_dsa_raw (gnutls_openpgp_crt_t crt, unsigned int idx, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y)

crt: Holds the certificate

idx: Is the subkey index

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

This function will export the DSA public key's parameters found in the given certificate. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_pk_rsa_raw

Function: int gnutls_openpgp_crt_get_subkey_pk_rsa_raw (gnutls_openpgp_crt_t crt, unsigned int idx, gnutls_datum_t * m, gnutls_datum_t * e)

crt: Holds the certificate

idx: Is the subkey index

m: will hold the modulus

e: will hold the public exponent

This function will export the RSA public key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_revoked_status

Function: int gnutls_openpgp_crt_get_subkey_revoked_status (gnutls_openpgp_crt_t key, unsigned int idx)

key: the structure that contains the OpenPGP public key.

idx: is the subkey index

Get subkey revocation status. A negative value indicates an error.

Returns: true (1) if the key has been revoked, or false (0) if it has not.

Since: 2.4.0

gnutls_openpgp_crt_get_subkey_usage

Function: int gnutls_openpgp_crt_get_subkey_usage (gnutls_openpgp_crt_t key, unsigned int idx, unsigned int * key_usage)

key: should contain a gnutls_openpgp_crt_t structure

idx: the subkey index

key_usage: where the key usage bits will be stored

This function will return certificate's key usage, by checking the key algorithm. The key usage value will ORed values of GNUTLS_KEY_DIGITAL_SIGNATURE or GNUTLS_KEY_KEY_ENCIPHERMENT.

A negative value may be returned in case of parsing error.

Returns: key usage value.

Since: 2.4.0

gnutls_openpgp_crt_get_version

Function: int gnutls_openpgp_crt_get_version (gnutls_openpgp_crt_t key)

key: the structure that contains the OpenPGP public key.

Extract the version of the OpenPGP key.

Returns: the version number is returned, or a negative value on errors.

gnutls_openpgp_crt_import

Function: int gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, const gnutls_datum_t * data, gnutls_openpgp_crt_fmt_t format)

key: The structure to store the parsed key.

data: The RAW or BASE64 encoded key.

format: One of gnutls_openpgp_crt_fmt_t elements.

This function will convert the given RAW or Base64 encoded key to the native gnutls_openpgp_crt_t format. The output will be stored in 'key'.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_init

Function: int gnutls_openpgp_crt_init (gnutls_openpgp_crt_t * key)

key: The structure to be initialized

This function will initialize an OpenPGP key structure.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_print

Function: int gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert, gnutls_certificate_print_formats_t format, gnutls_datum_t * out)

cert: The structure to be printed

format: Indicate the format to use

out: Newly allocated datum with zero terminated string.

This function will pretty print an OpenPGP certificate, suitable for display to a human.

The format should be zero for future compatibility.

The output out needs to be deallocate using gnutls_free().

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_set_preferred_key_id

Function: int gnutls_openpgp_crt_set_preferred_key_id (gnutls_openpgp_crt_t key, const gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the selected keyid

This allows setting a preferred key id for the given certificate. This key will be used by functions that involve key handling.

gnutls_openpgp_crt_verify_ring

Function: int gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t key, gnutls_openpgp_keyring_t keyring, unsigned int flags, unsigned int * verify)

key: the structure that holds the key.

keyring: holds the keyring to check against

flags: unused (should be 0)

verify: will hold the certificate verification output.

Verify all signatures in the key, using the given set of keys (keyring).

The key verification output will be put in verify and will be one or more of the gnutls_certificate_status_t enumerated elements bitwise or'd.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_crt_verify_self

Function: int gnutls_openpgp_crt_verify_self (gnutls_openpgp_crt_t key, unsigned int flags, unsigned int * verify)

key: the structure that holds the key.

flags: unused (should be 0)

verify: will hold the key verification output.

Verifies the self signature in the key. The key verification output will be put in verify and will be one or more of the gnutls_certificate_status_t enumerated elements bitwise or'd.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_keyring_check_id

Function: int gnutls_openpgp_keyring_check_id (gnutls_openpgp_keyring_t ring, const gnutls_openpgp_keyid_t keyid, unsigned int flags)

ring: holds the keyring to check against

keyid: will hold the keyid to check for.

flags: unused (should be 0)

Check if a given key ID exists in the keyring.

Returns: GNUTLS_E_SUCCESS on success (if keyid exists) and a negative error code on failure.

gnutls_openpgp_keyring_deinit

Function: void gnutls_openpgp_keyring_deinit (gnutls_openpgp_keyring_t keyring)

keyring: The structure to be initialized

This function will deinitialize a keyring structure.

gnutls_openpgp_keyring_get_crt_count

Function: int gnutls_openpgp_keyring_get_crt_count (gnutls_openpgp_keyring_t ring)

ring: is an OpenPGP key ring

This function will return the number of OpenPGP certificates present in the given keyring.

Returns: the number of subkeys, or a negative value on error.

gnutls_openpgp_keyring_get_crt

Function: int gnutls_openpgp_keyring_get_crt (gnutls_openpgp_keyring_t ring, unsigned int idx, gnutls_openpgp_crt_t * cert)

idx: the index of the certificate to export

This function will extract an OpenPGP certificate from the given keyring. If the index given is out of range GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned. The returned structure needs to be deinited.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_keyring_import

Function: int gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring, const gnutls_datum_t * data, gnutls_openpgp_crt_fmt_t format)

keyring: The structure to store the parsed key.

data: The RAW or BASE64 encoded keyring.

format: One of gnutls_openpgp_keyring_fmt elements.

This function will convert the given RAW or Base64 encoded keyring to the native gnutls_openpgp_keyring_t format. The output will be stored in 'keyring'.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_keyring_init

Function: int gnutls_openpgp_keyring_init (gnutls_openpgp_keyring_t * keyring)

keyring: The structure to be initialized

This function will initialize an keyring structure.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_privkey_deinit

Function: void gnutls_openpgp_privkey_deinit (gnutls_openpgp_privkey_t key)

key: The structure to be initialized

This function will deinitialize a key structure.

gnutls_openpgp_privkey_export_dsa_raw

Function: int gnutls_openpgp_privkey_export_dsa_raw (gnutls_openpgp_privkey_t pkey, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y, gnutls_datum_t * x)

pkey: Holds the certificate

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

x: will hold the x

This function will export the DSA private key's parameters found in the given certificate. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_privkey_export_rsa_raw

Function: int gnutls_openpgp_privkey_export_rsa_raw (gnutls_openpgp_privkey_t pkey, gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u)

pkey: Holds the certificate

m: will hold the modulus

e: will hold the public exponent

d: will hold the private exponent

p: will hold the first prime (p)

q: will hold the second prime (q)

u: will hold the coefficient

This function will export the RSA private key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_privkey_export_subkey_dsa_raw

Function: int gnutls_openpgp_privkey_export_subkey_dsa_raw (gnutls_openpgp_privkey_t pkey, unsigned int idx, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g, gnutls_datum_t * y, gnutls_datum_t * x)

pkey: Holds the certificate

idx: Is the subkey index

p: will hold the p

q: will hold the q

g: will hold the g

y: will hold the y

x: will hold the x

This function will export the DSA private key's parameters found in the given certificate. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_privkey_export_subkey_rsa_raw

Function: int gnutls_openpgp_privkey_export_subkey_rsa_raw (gnutls_openpgp_privkey_t pkey, unsigned int idx, gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u)

pkey: Holds the certificate

idx: Is the subkey index

m: will hold the modulus

e: will hold the public exponent

d: will hold the private exponent

p: will hold the first prime (p)

q: will hold the second prime (q)

u: will hold the coefficient

This function will export the RSA private key's parameters found in the given structure. The new parameters will be allocated using gnutls_malloc() and will be stored in the appropriate datum.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Since: 2.4.0

gnutls_openpgp_privkey_export

Function: int gnutls_openpgp_privkey_export (gnutls_openpgp_privkey_t key, gnutls_openpgp_crt_fmt_t format, const char * password, unsigned int flags, void * output_data, size_t * output_data_size)

key: Holds the key.

format: One of gnutls_openpgp_crt_fmt_t elements.

password: the password that will be used to encrypt the key. (unused for now)

flags: zero for future compatibility

output_data: will contain the key base64 encoded or raw

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will convert the given key to RAW or Base64 format. If the buffer provided is not long enough to hold the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

Since: 2.4.0

gnutls_openpgp_privkey_get_fingerprint

Function: int gnutls_openpgp_privkey_get_fingerprint (gnutls_openpgp_privkey_t key, void * fpr, size_t * fprlen)

key: the raw data that contains the OpenPGP secret key.

fpr: the buffer to save the fingerprint, must hold at least 20 bytes.

fprlen: the integer to save the length of the fingerprint.

Get the fingerprint of the OpenPGP key. Depends on the algorithm, the fingerprint can be 16 or 20 bytes.

Returns: On success, 0 is returned, or an error code.

Since: 2.4.0

gnutls_openpgp_privkey_get_key_id

Function: int gnutls_openpgp_privkey_get_key_id (gnutls_openpgp_privkey_t key, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP secret key.

keyid: the buffer to save the keyid.

Get key-id.

Returns: the 64-bit keyID of the OpenPGP key.

Since: 2.4.0

gnutls_openpgp_privkey_get_pk_algorithm

Function: gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key, unsigned int * bits)

key: is an OpenPGP key

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of an OpenPGP certificate.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

Since: 2.4.0

gnutls_openpgp_privkey_get_preferred_key_id

Function: int gnutls_openpgp_privkey_get_preferred_key_id (gnutls_openpgp_privkey_t key, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the struct to save the keyid.

Get the preferred key-id for the key.

Returns: the 64-bit preferred keyID of the OpenPGP key, or if it hasn't been set it returns GNUTLS_E_INVALID_REQUEST.

gnutls_openpgp_privkey_get_revoked_status

Function: int gnutls_openpgp_privkey_get_revoked_status (gnutls_openpgp_privkey_t key)

key: the structure that contains the OpenPGP private key.

Get revocation status of key.

Returns: true (1) if the key has been revoked, or false (0) if it has not, or a negative value indicates an error.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_count

Function: int gnutls_openpgp_privkey_get_subkey_count (gnutls_openpgp_privkey_t key)

key: is an OpenPGP key

This function will return the number of subkeys present in the given OpenPGP certificate.

Returns: the number of subkeys, or a negative value on error.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_creation_time

Function: time_t gnutls_openpgp_privkey_get_subkey_creation_time (gnutls_openpgp_privkey_t key, unsigned int idx)

key: the structure that contains the OpenPGP private key.

idx: the subkey index

Get subkey creation time.

Returns: the timestamp when the OpenPGP key was created.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_expiration_time

Function: time_t gnutls_openpgp_privkey_get_subkey_expiration_time (gnutls_openpgp_privkey_t key, unsigned int idx)

key: the structure that contains the OpenPGP private key.

idx: the subkey index

Get subkey expiration time. A value of '0' means that the key doesn't expire at all.

Returns: the time when the OpenPGP key expires.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_fingerprint

Function: int gnutls_openpgp_privkey_get_subkey_fingerprint (gnutls_openpgp_privkey_t key, unsigned int idx, void * fpr, size_t * fprlen)

key: the raw data that contains the OpenPGP secret key.

idx: the subkey index

fpr: the buffer to save the fingerprint, must hold at least 20 bytes.

fprlen: the integer to save the length of the fingerprint.

Get the fingerprint of an OpenPGP subkey. Depends on the algorithm, the fingerprint can be 16 or 20 bytes.

Returns: On success, 0 is returned, or an error code.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_idx

Function: int gnutls_openpgp_privkey_get_subkey_idx (gnutls_openpgp_privkey_t key, const gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP private key.

keyid: the keyid.

Get index of subkey.

Returns: the index of the subkey or a negative error value.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_id

Function: int gnutls_openpgp_privkey_get_subkey_id (gnutls_openpgp_privkey_t key, unsigned int idx, gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP secret key.

idx: the subkey index

keyid: the buffer to save the keyid.

Get the key-id for the subkey.

Returns: the 64-bit keyID of the OpenPGP key.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_pk_algorithm

Function: gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t key, unsigned int idx, unsigned int * bits)

key: is an OpenPGP key

idx: is the subkey index

bits: if bits is non null it will hold the size of the parameters' in bits

This function will return the public key algorithm of a subkey of an OpenPGP certificate.

If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.

Returns: a member of the gnutls_pk_algorithm_t enumeration on success, or a negative value on error.

Since: 2.4.0

gnutls_openpgp_privkey_get_subkey_revoked_status

Function: int gnutls_openpgp_privkey_get_subkey_revoked_status (gnutls_openpgp_privkey_t key, unsigned int idx)

key: the structure that contains the OpenPGP private key.

idx: is the subkey index

Get revocation status of key.

Returns: true (1) if the key has been revoked, or false (0) if it has not, or a negative value indicates an error.

Since: 2.4.0

gnutls_openpgp_privkey_import

Function: int gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, const gnutls_datum_t * data, gnutls_openpgp_crt_fmt_t format, const char * password, unsigned int flags)

key: The structure to store the parsed key.

data: The RAW or BASE64 encoded key.

format: One of gnutls_openpgp_crt_fmt_t elements.

password: (unused for now)

flags: should be zero

This function will convert the given RAW or Base64 encoded key to the native gnutls_openpgp_privkey_t format. The output will be stored in 'key'.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_privkey_init

Function: int gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key)

key: The structure to be initialized

This function will initialize an OpenPGP key structure.

Returns: GNUTLS_E_SUCCESS on success, or an error code.

gnutls_openpgp_privkey_set_preferred_key_id

Function: int gnutls_openpgp_privkey_set_preferred_key_id (gnutls_openpgp_privkey_t key, const gnutls_openpgp_keyid_t keyid)

key: the structure that contains the OpenPGP public key.

keyid: the selected keyid

This allows setting a preferred key id for the given certificate. This key will be used by functions that involve key handling.

Returns: On success, 0 is returned, or an error code.

gnutls_openpgp_privkey_sign_hash

Function: int gnutls_openpgp_privkey_sign_hash (gnutls_openpgp_privkey_t key, const gnutls_datum_t * hash, gnutls_datum_t * signature)

key: Holds the key

hash: holds the data to be signed

signature: will contain newly allocated signature

This function will sign the given hash using the private key. You should use gnutls_openpgp_privkey_set_subkey() before calling this function to set the subkey to use.

Returns: On success, GNUTLS_E_SUCCESS is returned, otherwise a negative error value.

gnutls_openpgp_set_recv_key_function

Function: void gnutls_openpgp_set_recv_key_function (gnutls_session_t session, gnutls_openpgp_recv_key_func func)

session: a TLS session

func: the callback

This funtion will set a key retrieval function for OpenPGP keys. This callback is only useful in server side, and will be used if the peer sent a key fingerprint instead of a full key.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.5 TLS Inner Application (TLS/IA) Functions

The following functions are used for TLS Inner Application (TLS/IA). Their prototypes lie in `gnutls/extra.h'. You need to link with `libgnutls-extra' to be able to use these functions (see section GnuTLS-extra Functions).

The typical control flow in an TLS/IA client (that would not require an Application Phase for resumed sessions) would be similar to the following:

 
int client_avp (gnuls_session_t *session, void *ptr,
                const char *last, size_t lastlen,
		char **new, size_t *newlen)
{
...
}
...
int main ()
{
  gnutls_ia_client_credentials_t iacred;
...
  gnutls_init (&session, GNUTLS_CLIENT);
...
  /* Enable TLS/IA. */
  gnutls_ia_allocate_client_credentials(&iacred);
  gnutls_ia_set_client_avp_function(iacred, client_avp);
  gnutls_credentials_set (session, GNUTLS_CRD_IA, iacred);
...
  ret = gnutls_handshake (session);
  // Error handling...
...
  if (gnutls_ia_handshake_p (session))
    {
      ret = gnutls_ia_handshake (session);
      // Error handling...
...

See below for detailed descriptions of all the functions used above.

The function client_avp would have to be implemented by your application. The function is responsible for handling the AVP data. See gnutls_ia_set_client_avp_function below for more information on how that function should be implemented.

The control flow in a typical server is similar to the above, use gnutls_ia_server_credentials_t instead of gnutls_ia_client_credentials_t, and replace the call to the client functions with the corresponding server functions.

gnutls_ia_allocate_client_credentials

Function: int gnutls_ia_allocate_client_credentials (gnutls_ia_client_credentials_t * sc)

sc: is a pointer to an gnutls_ia_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Adding this credential to a session will enable TLS/IA, and will require an Application Phase after the TLS handshake (if the server support TLS/IA). Use gnutls_ia_require_inner_phase() to toggle the TLS/IA mode.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_ia_allocate_server_credentials

Function: int gnutls_ia_allocate_server_credentials (gnutls_ia_server_credentials_t * sc)

sc: is a pointer to an gnutls_ia_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to allocate it.

Adding this credential to a session will enable TLS/IA, and will require an Application Phase after the TLS handshake (if the client support TLS/IA). Use gnutls_ia_require_inner_phase() to toggle the TLS/IA mode.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise an error code is returned.

gnutls_ia_enable

Function: void gnutls_ia_enable (gnutls_session_t session, int allow_skip_on_resume)

session: is a gnutls_session_t structure.

allow_skip_on_resume: non-zero if local party allows to skip the TLS/IA application phases for a resumed session.

Specify whether we must advertise support for the TLS/IA extension during the handshake.

At the client side, we always advertise TLS/IA if gnutls_ia_enable was called before the handshake; at the server side, we also require that the client has advertised that it wants to run TLS/IA before including the advertisement, as required by the protocol.

Similarly, at the client side we always advertise that we allow TLS/IA to be skipped for resumed sessions if allow_skip_on_resume is non-zero; at the server side, we also require that the session is indeed resumable and that the client has also advertised that it allows TLS/IA to be skipped for resumed sessions.

After the TLS handshake, call gnutls_ia_handshake_p() to find out whether both parties agreed to do a TLS/IA handshake, before calling gnutls_ia_handshake() or one of the lower level gnutls_ia_* functions.

gnutls_ia_endphase_send

Function: int gnutls_ia_endphase_send (gnutls_session_t session, int final_p)

session: is a gnutls_session_t structure.

final_p: Set iff this should signal the final phase.

Send a TLS/IA end phase message.

In the client, this should only be used to acknowledge an end phase message sent by the server.

In the server, this can be called instead of gnutls_ia_send() if the server wishes to end an application phase.

Return value: Return 0 on success, or an error code.

gnutls_ia_extract_inner_secret

Function: void gnutls_ia_extract_inner_secret (gnutls_session_t session, char * buffer)

session: is a gnutls_session_t structure.

buffer: pre-allocated buffer to hold 48 bytes of inner secret.

Copy the 48 bytes large inner secret into the specified buffer

This function is typically used after the TLS/IA handshake has concluded. The TLS/IA inner secret can be used as input to a PRF to derive session keys. Do not use the inner secret directly as a session key, because for a resumed session that does not include an application phase, the inner secret will be identical to the inner secret in the original session. It is important to include, for example, the client and server randomness when deriving a sesssion key from the inner secret.

gnutls_ia_free_client_credentials

Function: void gnutls_ia_free_client_credentials (gnutls_ia_client_credentials_t sc)

sc: is an gnutls_ia_client_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_ia_free_server_credentials

Function: void gnutls_ia_free_server_credentials (gnutls_ia_server_credentials_t sc)

sc: is an gnutls_ia_server_credentials_t structure.

This structure is complex enough to manipulate directly thus this helper function is provided in order to free (deallocate) it.

gnutls_ia_generate_challenge

Function: int gnutls_ia_generate_challenge (gnutls_session_t session, size_t buffer_size, char * buffer)

session: is a gnutls_session_t structure.

buffer_size: size of output buffer.

buffer: pre-allocated buffer to contain buffer_size bytes of output.

Generate an application challenge that the client cannot control or predict, based on the TLS/IA inner secret.

Return value: Returns 0 on success, or an negative error code.

gnutls_ia_get_client_avp_ptr

Function: void * gnutls_ia_get_client_avp_ptr (gnutls_ia_client_credentials_t cred)

cred: is a gnutls_ia_client_credentials_t structure.

Returns the pointer that will be provided to the TLS/IA callback function as the first argument.

Returns: The client callback data pointer.

gnutls_ia_get_server_avp_ptr

Function: void * gnutls_ia_get_server_avp_ptr (gnutls_ia_server_credentials_t cred)

cred: is a gnutls_ia_client_credentials_t structure.

Returns the pointer that will be provided to the TLS/IA callback function as the first argument.

Returns: The server callback data pointer.

gnutls_ia_handshake_p

Function: int gnutls_ia_handshake_p (gnutls_session_t session)

session: is a gnutls_session_t structure.

Predicate to be used after gnutls_handshake() to decide whether to invoke gnutls_ia_handshake(). Usable by both clients and servers.

Return value: non-zero if TLS/IA handshake is expected, zero otherwise.

gnutls_ia_handshake

Function: int gnutls_ia_handshake (gnutls_session_t session)

session: is a gnutls_session_t structure.

Perform a TLS/IA handshake. This should be called after gnutls_handshake() iff gnutls_ia_handshake_p().

Return 0 on success, or an error code.

gnutls_ia_permute_inner_secret

Function: int gnutls_ia_permute_inner_secret (gnutls_session_t session, size_t session_keys_size, const char * session_keys)

session: is a gnutls_session_t structure.

session_keys_size: Size of generated session keys (0 if none).

session_keys: Generated session keys, used to permute inner secret (NULL if none).

Permute the inner secret using the generated session keys.

This can be called in the TLS/IA AVP callback to mix any generated session keys with the TLS/IA inner secret.

Return value: Return zero on success, or a negative error code.

gnutls_ia_recv

Function: ssize_t gnutls_ia_recv (gnutls_session_t session, char * data, size_t sizeofdata)

session: is a gnutls_session_t structure.

data: the buffer that the data will be read into, must hold >= 12 bytes.

sizeofdata: the number of requested bytes, must be >= 12.

Receive TLS/IA data. This function has the similar semantics with recv(). The only difference is that is accepts a GNUTLS session, and uses different error codes.

If the server attempt to finish an application phase, this function will return GNUTLS_E_WARNING_IA_IPHF_RECEIVED or GNUTLS_E_WARNING_IA_FPHF_RECEIVED. The caller should then invoke gnutls_ia_verify_endphase(), and if it runs the client side, also send an endphase message of its own using gnutls_ia_endphase_send.

If EINTR is returned by the internal push function (the default is code{recv()}) then GNUTLS_E_INTERRUPTED will be returned. If GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN is returned, you must call this function again, with the same parameters; alternatively you could provide a NULL pointer for data, and 0 for size.

Returns: The number of bytes received. A negative error code is returned in case of an error. The GNUTLS_E_WARNING_IA_IPHF_RECEIVED and GNUTLS_E_WARNING_IA_FPHF_RECEIVED errors are returned when an application phase finished message has been sent by the server.

gnutls_ia_send

Function: ssize_t gnutls_ia_send (gnutls_session_t session, const char * data, size_t sizeofdata)

session: is a gnutls_session_t structure.

data: contains the data to send

sizeofdata: is the length of the data

Send TLS/IA application payload data. This function has the similar semantics with send(). The only difference is that is accepts a GNUTLS session, and uses different error codes.

The TLS/IA protocol is synchronous, so you cannot send more than one packet at a time. The client always send the first packet.

To finish an application phase in the server, use gnutls_ia_endphase_send(). The client cannot end an application phase unilaterally; rather, a client is required to respond with an endphase of its own if gnutls_ia_recv indicates that the server has sent one.

If the EINTR is returned by the internal push function (the default is send()} then GNUTLS_E_INTERRUPTED will be returned. If GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN is returned, you must call this function again, with the same parameters; alternatively you could provide a NULL pointer for data, and 0 for size.

Returns: The number of bytes sent, or a negative error code.

gnutls_ia_set_client_avp_function

Function: void gnutls_ia_set_client_avp_function (gnutls_ia_client_credentials_t cred, gnutls_ia_avp_func avp_func)

cred: is a gnutls_ia_client_credentials_t structure.

avp_func: is the callback function

Set the TLS/IA AVP callback handler used for the session.

The AVP callback is called to process AVPs received from the server, and to get a new AVP to send to the server.

The callback's function form is: int (*avp_func) (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **next, size_t *nextlen);

The session parameter is the gnutls_session_t structure corresponding to the current session. The ptr parameter is the application hook pointer, set through gnutls_ia_set_client_avp_ptr(). The AVP received from the server is present in last of lastlen size, which will be NULL on the first invocation. The newly allocated output AVP to send to the server should be placed in *next of *nextlen size.

The callback may invoke gnutls_ia_permute_inner_secret() to mix any generated session keys with the TLS/IA inner secret.

Return 0 (GNUTLS_IA_APPLICATION_PAYLOAD) on success, or a negative error code to abort the TLS/IA handshake.

Note that the callback must use allocate the next parameter using gnutls_malloc(), because it is released via gnutls_free() by the TLS/IA handshake function.

gnutls_ia_set_client_avp_ptr

Function: void gnutls_ia_set_client_avp_ptr (gnutls_ia_client_credentials_t cred, void * ptr)

cred: is a gnutls_ia_client_credentials_t structure.

ptr: is the pointer

Sets the pointer that will be provided to the TLS/IA callback function as the first argument.

gnutls_ia_set_server_avp_function

Function: void gnutls_ia_set_server_avp_function (gnutls_ia_server_credentials_t cred, gnutls_ia_avp_func avp_func)

cred: is a gnutls_ia_server_credentials_t structure.

Set the TLS/IA AVP callback handler used for the session.

The callback's function form is: int (*avp_func) (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **next, size_t *nextlen);

The session parameter is the gnutls_session_t structure corresponding to the current session. The ptr parameter is the application hook pointer, set through gnutls_ia_set_server_avp_ptr(). The AVP received from the client is present in last of lastlen size. The newly allocated output AVP to send to the client should be placed in *next of *nextlen size.

The AVP callback is called to process incoming AVPs from the client, and to get a new AVP to send to the client. It can also be used to instruct the TLS/IA handshake to do go into the Intermediate or Final phases. It return a negative error code, or an gnutls_ia_apptype_t message type.

The callback may invoke gnutls_ia_permute_inner_secret() to mix any generated session keys with the TLS/IA inner secret.

Specifically, return GNUTLS_IA_APPLICATION_PAYLOAD (0) to send another AVP to the client, return GNUTLS_IA_INTERMEDIATE_PHASE_FINISHED (1) to indicate that an IntermediatePhaseFinished message should be sent, and return GNUTLS_IA_FINAL_PHASE_FINISHED (2) to indicate that an FinalPhaseFinished message should be sent. In the last two cases, the contents of the next and nextlen parameter is not used.

Note that the callback must use allocate the next parameter using gnutls_malloc(), because it is released via gnutls_free() by the TLS/IA handshake function.

gnutls_ia_set_server_avp_ptr

Function: void gnutls_ia_set_server_avp_ptr (gnutls_ia_server_credentials_t cred, void * ptr)

cred: is a gnutls_ia_client_credentials_t structure.

ptr: is the pointer

Sets the pointer that will be provided to the TLS/IA callback function as the first argument.

gnutls_ia_verify_endphase

Function: int gnutls_ia_verify_endphase (gnutls_session_t session, const char * checksum)

session: is a gnutls_session_t structure.

checksum: 12-byte checksum data, received from gnutls_ia_recv().

Verify TLS/IA end phase checksum data. If verification fails, the GNUTLS_A_INNER_APPLICATION_VERIFICATION alert is sent to the other sie.

This function is called when gnutls_ia_recv() return GNUTLS_E_WARNING_IA_IPHF_RECEIVED or GNUTLS_E_WARNING_IA_FPHF_RECEIVED.

Return value: Return 0 on successful verification, or an error code. If the checksum verification of the end phase message fails, GNUTLS_E_IA_VERIFY_FAILED is returned.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.6 Error Codes and Descriptions

The error codes used throughout the library are described below. The return code GNUTLS_E_SUCCESS indicate successful operation, and is guaranteed to have the value 0, so you can use it in logical expressions.

GNUTLS_E_AGAIN:

Function was interrupted.

GNUTLS_E_ASN1_DER_ERROR:

ASN1 parser: Error in DER parsing.

GNUTLS_E_ASN1_DER_OVERFLOW:

ASN1 parser: Overflow in DER parsing.

GNUTLS_E_ASN1_ELEMENT_NOT_FOUND:

ASN1 parser: Element was not found.

GNUTLS_E_ASN1_GENERIC_ERROR:

ASN1 parser: Generic parsing error.

GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND:

ASN1 parser: Identifier was not found

GNUTLS_E_ASN1_SYNTAX_ERROR:

ASN1 parser: Syntax error.

GNUTLS_E_ASN1_TAG_ERROR:

ASN1 parser: Error in TAG.

GNUTLS_E_ASN1_TAG_IMPLICIT:

ASN1 parser: error in implicit tag

GNUTLS_E_ASN1_TYPE_ANY_ERROR:

ASN1 parser: Error in type 'ANY'.

GNUTLS_E_ASN1_VALUE_NOT_FOUND:

ASN1 parser: Value was not found.

GNUTLS_E_ASN1_VALUE_NOT_VALID:

ASN1 parser: Value is not valid.

GNUTLS_E_BASE64_DECODING_ERROR:

Base64 decoding error.

GNUTLS_E_BASE64_ENCODING_ERROR:

Base64 encoding error.

GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR:

Base64 unexpected header error.

GNUTLS_E_CERTIFICATE_ERROR:

Error in the certificate.

GNUTLS_E_CERTIFICATE_KEY_MISMATCH:

The certificate and the given key do not match.

GNUTLS_E_COMPRESSION_FAILED:

Compression of the TLS record packet has failed.

GNUTLS_E_CONSTRAINT_ERROR:

Some constraint limits were reached.

GNUTLS_E_CRYPTO_ALREADY_REGISTERED:

There is already a crypto algorithm with lower priority.

GNUTLS_E_DB_ERROR:

Error in Database backend.

GNUTLS_E_DECOMPRESSION_FAILED:

Decompression of the TLS record packet has failed.

GNUTLS_E_DECRYPTION_FAILED:

Decryption has failed.

GNUTLS_E_DH_PRIME_UNACCEPTABLE:

The Diffie Hellman prime sent by the server is not acceptable (not long enough).

GNUTLS_E_ENCRYPTION_FAILED:

Encryption has failed.

GNUTLS_E_ERROR_IN_FINISHED_PACKET:

An error was encountered at the TLS Finished packet calculation.

GNUTLS_E_EXPIRED:

The requested session has expired.

GNUTLS_E_FATAL_ALERT_RECEIVED:

A TLS fatal alert has been received.

GNUTLS_E_FILE_ERROR:

Error while reading file.

GNUTLS_E_GOT_APPLICATION_DATA:

TLS Application data were received, while expecting handshake data.

GNUTLS_E_HANDSHAKE_TOO_LARGE:

The handshake data size is too large (DoS?), check gnutls_handshake_set_max_packet_length().

GNUTLS_E_HASH_FAILED:

Hashing has failed.

GNUTLS_E_IA_VERIFY_FAILED:

Verifying TLS/IA phase checksum failed

GNUTLS_E_ILLEGAL_SRP_USERNAME:

The SRP username supplied is illegal.

GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY:

The gcrypt library version is too old.

GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY:

The tasn1 library version is too old.

GNUTLS_E_INIT_LIBEXTRA:

The initialization of GnuTLS-extra has failed.

GNUTLS_E_INSUFFICIENT_CREDENTIALS:

Insufficient credentials for that request.

GNUTLS_E_INTERNAL_ERROR:

GnuTLS internal error.

GNUTLS_E_INTERRUPTED:

Function was interrupted.

GNUTLS_E_INVALID_PASSWORD:

The given password contains invalid characters.

GNUTLS_E_INVALID_REQUEST:

The request is invalid.

GNUTLS_E_INVALID_SESSION:

The specified session has been invalidated for some reason.

GNUTLS_E_KEY_USAGE_VIOLATION:

Key usage violation in certificate has been detected.

GNUTLS_E_LARGE_PACKET:

A large TLS record packet was received.

GNUTLS_E_LIBRARY_VERSION_MISMATCH:

The GnuTLS library version does not match the GnuTLS-extra library version.

GNUTLS_E_LZO_INIT_FAILED:

The initialization of LZO has failed.

GNUTLS_E_MAC_VERIFY_FAILED:

The Message Authentication Code verification failed.

GNUTLS_E_MEMORY_ERROR:

Internal error in memory allocation.

GNUTLS_E_MPI_PRINT_FAILED:

Could not export a large integer.

GNUTLS_E_MPI_SCAN_FAILED:

The scanning of a large integer has failed.

GNUTLS_E_NO_CERTIFICATE_FOUND:

The peer did not send any certificate.

GNUTLS_E_NO_CIPHER_SUITES:

No supported cipher suites have been found.

GNUTLS_E_NO_COMPRESSION_ALGORITHMS:

No supported compression algorithms have been found.

GNUTLS_E_NO_TEMPORARY_DH_PARAMS:

No temporary DH parameters were found.

GNUTLS_E_NO_TEMPORARY_RSA_PARAMS:

No temporary RSA parameters were found.

GNUTLS_E_OPENPGP_FINGERPRINT_UNSUPPORTED:

The OpenPGP fingerprint is not supported.

GNUTLS_E_OPENPGP_GETKEY_FAILED:

Could not get OpenPGP key.

GNUTLS_E_OPENPGP_KEYRING_ERROR:

Error loading the keyring.

GNUTLS_E_OPENPGP_SUBKEY_ERROR:

Could not find OpenPGP subkey.

GNUTLS_E_OPENPGP_UID_REVOKED:

The OpenPGP User ID is revoked.

GNUTLS_E_PKCS1_WRONG_PAD:

Wrong padding in PKCS1 packet.

GNUTLS_E_PK_DECRYPTION_FAILED:

Public key decryption has failed.

GNUTLS_E_PK_ENCRYPTION_FAILED:

Public key encryption has failed.

GNUTLS_E_PK_SIGN_FAILED:

Public key signing has failed.

GNUTLS_E_PK_SIG_VERIFY_FAILED:

Public key signature verification has failed.

GNUTLS_E_PULL_ERROR:

Error in the pull function.

GNUTLS_E_PUSH_ERROR:

Error in the push function.

GNUTLS_E_RANDOM_FAILED:

Failed to acquire random data.

GNUTLS_E_RECEIVED_ILLEGAL_EXTENSION:

An illegal TLS extension was received.

GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER:

An illegal parameter has been received.

GNUTLS_E_RECORD_LIMIT_REACHED:

The upper limit of record packet sequence numbers has been reached. Wow!

GNUTLS_E_REHANDSHAKE:

Rehandshake was requested by the peer.

GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE:

The requested data were not available.

GNUTLS_E_SHORT_MEMORY_BUFFER:

The given memory buffer is too short to hold parameters.

GNUTLS_E_SRP_PWD_ERROR:

Error in password file.

GNUTLS_E_SRP_PWD_PARSING_ERROR:

Parsing error in password file.

GNUTLS_E_SUCCESS:

Success.

GNUTLS_E_TOO_MANY_EMPTY_PACKETS:

Too many empty record packets have been received.

GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET:

An unexpected TLS handshake packet was received.

GNUTLS_E_UNEXPECTED_PACKET:

An unexpected TLS packet was received.

GNUTLS_E_UNEXPECTED_PACKET_LENGTH:

A TLS packet with unexpected length was received.

GNUTLS_E_UNKNOWN_ALGORITHM:

The specified algorithm or protocol is unknown.

GNUTLS_E_UNKNOWN_CIPHER_SUITE:

Could not negotiate a supported cipher suite.

GNUTLS_E_UNKNOWN_CIPHER_TYPE:

The cipher type is unsupported.

GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM:

Could not negotiate a supported compression method.

GNUTLS_E_UNKNOWN_HASH_ALGORITHM:

The hash algorithm is unknown.

GNUTLS_E_UNKNOWN_PKCS_BAG_TYPE:

The PKCS structure's bag type is unknown.

GNUTLS_E_UNKNOWN_PKCS_CONTENT_TYPE:

The PKCS structure's content type is unknown.

GNUTLS_E_UNKNOWN_PK_ALGORITHM:

An unknown public key algorithm was encountered.

GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE:

The certificate type is not supported.

GNUTLS_E_UNSUPPORTED_VERSION_PACKET:

A record packet with illegal version was received.

GNUTLS_E_UNWANTED_ALGORITHM:

An algorithm that is not enabled was negotiated.

GNUTLS_E_WARNING_ALERT_RECEIVED:

A TLS warning alert has been received.

GNUTLS_E_WARNING_IA_FPHF_RECEIVED:

Received a TLS/IA Final Phase Finished message

GNUTLS_E_WARNING_IA_IPHF_RECEIVED:

Received a TLS/IA Intermediate Phase Finished message

GNUTLS_E_X509_UNKNOWN_SAN:

Unknown Subject Alternative name in X.509 certificate.

GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE:

The certificate has unsupported attributes.

GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION:

Unsupported critical extension in X.509 certificate.

GNUTLS_E_X509_UNSUPPORTED_OID:

The OID is not supported.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on July, 20 2009 using texi2html 1.76.