gnutls_certificate_server_set_request - Linux
Overview
The gnutls_certificate_server_set_request
function sets the type of certificate requested by the server. This certificate will be used to verify the client’s identity.
Syntax
int gnutls_certificate_server_set_request(gnutls_session_t session, unsigned int type);
Options/Flags
| Flag | Description |
|—|—|
| GNUTLS_CERT_REQ_NONE | No certificate is requested. |
| GNUTLS_CERT_REQ_OPTIONAL | A certificate is requested but is not required. |
| GNUTLS_CERT_REQ_MANDATORY | A certificate is required. |
Examples
The following example sets the certificate request type to mandatory:
gnutls_certificate_server_set_request(session, GNUTLS_CERT_REQ_MANDATORY);
Common Issues
- Error setting certificate request type: This error can occur if the session is not valid or if the specified type is not supported.
Integration
The gnutls_certificate_server_set_request
function can be used with other GNUTLS functions to create a secure TLS/SSL connection. For example, the following code snippet shows how to create a server that requires clients to provide a certificate:
// Create a GNUTLS session
gnutls_session_t session = gnutls_create_session();
// Set the certificate request type to mandatory
gnutls_certificate_server_set_request(session, GNUTLS_CERT_REQ_MANDATORY);
// Start the TLS/SSL handshake
gnutls_handshake(session);
// If the handshake was successful, the client's certificate can be retrieved using the gnutls_certificate_client_get() function.