static int initialize_tls_session_server(int peer_socket,
gnutls_session_t *session,
gnutls_certificate_credentials_t *x509_cred);
+static int initialize_tls_session_both(int flags,
+ int peer_socket,
+ gnutls_session_t *session,
+ gnutls_certificate_credentials_t *x509_cred);
static int fdopen_read_write(int socket, FILE **read_fd, FILE **write_fd);
static int read_http_request(FILE *client_fd, char *request, size_t length);
gnutls_certificate_set_dh_params(*x509_cred, global_tls_dh_params);
- result = gnutls_init(session, GNUTLS_SERVER);
- if (result != GNUTLS_E_SUCCESS) {
- LOG(ERROR,
- "initialize_tls_session_client(): gnutls_init(): %s",
- gnutls_strerror(result));
- gnutls_certificate_free_credentials(*x509_cred);
- return -1;
- }
- result = gnutls_priority_set(*session, global_tls_priority_cache);
- if (result != GNUTLS_E_SUCCESS) {
- LOG(ERROR,
- "initialize_tls_session_client(): gnutls_priority_set(): %s",
- gnutls_strerror(result));
- gnutls_deinit(*session);
- gnutls_certificate_free_credentials(*x509_cred);
- return -1;
- }
- result = gnutls_credentials_set(*session,
- GNUTLS_CRD_CERTIFICATE, *x509_cred);
- if (result != GNUTLS_E_SUCCESS) {
- LOG(ERROR,
- "initialize_tls_session_client(): gnutls_credentials_set(): %s",
- gnutls_strerror(result));
- gnutls_deinit(*session);
- gnutls_certificate_free_credentials(*x509_cred);
- return -1;
- }
-
- gnutls_transport_set_ptr(*session, (gnutls_transport_ptr_t)peer_socket);
-
- return 0;
+ return initialize_tls_session_both(GNUTLS_SERVER,
+ peer_socket, session, x509_cred);
}
static int initialize_tls_session_server(int peer_socket,
gnutls_session_t *session,
return -1;
}
- result = gnutls_init(session, GNUTLS_CLIENT);
+ return initialize_tls_session_both(GNUTLS_CLIENT,
+ peer_socket, session, x509_cred);
+}
+static int initialize_tls_session_both(int flags,
+ int peer_socket,
+ gnutls_session_t *session,
+ gnutls_certificate_credentials_t *x509_cred) {
+ int result;
+
+ result = gnutls_init(session, flags);
if (result != GNUTLS_E_SUCCESS) {
LOG(ERROR,
- "initialize_tls_session_server(): gnutls_init(): %s",
+ "initialize_tls_session_both(): gnutls_init(): %s",
gnutls_strerror(result));
gnutls_certificate_free_credentials(*x509_cred);
return -1;
result = gnutls_priority_set(*session, global_tls_priority_cache);
if (result != GNUTLS_E_SUCCESS) {
LOG(ERROR,
- "initialize_tls_session_server(): gnutls_priority_set(): %s",
+ "initialize_tls_session_both(): gnutls_priority_set(): %s",
gnutls_strerror(result));
gnutls_deinit(*session);
gnutls_certificate_free_credentials(*x509_cred);
GNUTLS_CRD_CERTIFICATE, *x509_cred);
if (result != GNUTLS_E_SUCCESS) {
LOG(ERROR,
- "initialize_tls_session_server(): gnutls_credentials_set(): %s",
+ "initialize_tls_session_both(): gnutls_credentials_set(): %s",
gnutls_strerror(result));
gnutls_deinit(*session);
gnutls_certificate_free_credentials(*x509_cred);