|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2015 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit Service |
4684c1 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
#include <stdint.h>
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include <errno.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/dtls.h>
|
|
Packit Service |
4684c1 |
#include <signal.h>
|
|
Packit Service |
4684c1 |
#include <unistd.h>
|
|
Packit Service |
4684c1 |
#ifndef _WIN32
|
|
Packit Service |
4684c1 |
# include <netinet/in.h>
|
|
Packit Service |
4684c1 |
# include <sys/types.h>
|
|
Packit Service |
4684c1 |
# include <sys/socket.h>
|
|
Packit Service |
4684c1 |
# include <sys/wait.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef _WIN32
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
exit(77);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* These are global */
|
|
Packit Service |
4684c1 |
pid_t child;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void terminate(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int status;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
kill(child, SIGTERM);
|
|
Packit Service |
4684c1 |
wait(&status);
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Tests whether we can send and receive from different processes
|
|
Packit Service |
4684c1 |
* using DTLS, either as server or client. DTLS is a superset of
|
|
Packit Service |
4684c1 |
* TLS, so correct behavior under fork means TLS would operate too.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const char *side = "";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void tls_log_func(int level, const char *str)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
fprintf(stderr, "%s|<%d>| %s", side, level, str);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static unsigned char server_cert_pem[] =
|
|
Packit Service |
4684c1 |
"-----BEGIN CERTIFICATE-----\n"
|
|
Packit Service |
4684c1 |
"MIICHzCCAaWgAwIBAgIBCTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\n"
|
|
Packit Service |
4684c1 |
"A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\n"
|
|
Packit Service |
4684c1 |
"MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjA0MQswCQYDVQQGEwJOTDERMA8G\n"
|
|
Packit Service |
4684c1 |
"A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\n"
|
|
Packit Service |
4684c1 |
"CCqGSM49AwEHA0IABDfMVtl2CR5acj7HWS3/IG7ufPkGkXTQrRS192giWWKSTuUA\n"
|
|
Packit Service |
4684c1 |
"2CMR/+ov0jRdXRa9iojCa3cNVc2KKg76Aci07f+jgZ0wgZowCQYDVR0TBAIwADAd\n"
|
|
Packit Service |
4684c1 |
"BgNVHQ4EFgQUUGGlj9QH2deCAQzlZX+MY0anE74wbgYDVR0jBGcwZYAUnW0gJEkB\n"
|
|
Packit Service |
4684c1 |
"PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xh\n"
|
|
Packit Service |
4684c1 |
"clNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\n"
|
|
Packit Service |
4684c1 |
"CCqGSM49BAMCA2gAMGUCMQCaLFzXptui5WQN8LlO3ddh1hMxx6tzgLvT03MTVK2S\n"
|
|
Packit Service |
4684c1 |
"C12r0Lz3ri/moSEpNZWqPjkCMCE2f53GXcYLqyfyJR078c/xNSUU5+Xxl7VZ414V\n"
|
|
Packit Service |
4684c1 |
"fGa5kHvHARBPc8YAIVIqDvHH1Q==\n"
|
|
Packit Service |
4684c1 |
"-----END CERTIFICATE-----\n";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const gnutls_datum_t server_cert = { server_cert_pem,
|
|
Packit Service |
4684c1 |
sizeof(server_cert_pem)
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static unsigned char server_key_pem[] =
|
|
Packit Service |
4684c1 |
"-----BEGIN EC PRIVATE KEY-----\n"
|
|
Packit Service |
4684c1 |
"MHcCAQEEIPEqEyB2AnCoPL/9U/YDHvdqXYbIogTywwyp6/UfDw6noAoGCCqGSM49\n"
|
|
Packit Service |
4684c1 |
"AwEHoUQDQgAEN8xW2XYJHlpyPsdZLf8gbu58+QaRdNCtFLX3aCJZYpJO5QDYIxH/\n"
|
|
Packit Service |
4684c1 |
"6i/SNF1dFr2KiMJrdw1VzYoqDvoByLTt/w==\n"
|
|
Packit Service |
4684c1 |
"-----END EC PRIVATE KEY-----\n";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const gnutls_datum_t server_key = { server_key_pem,
|
|
Packit Service |
4684c1 |
sizeof(server_key_pem)
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define MSG "hello1111"
|
|
Packit Service |
4684c1 |
#define MSG2 "xxxxxxxxxxxx"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
void do_fork_stuff(gnutls_session_t session)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
pid_t pid;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
char buf[64];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* separate sending from receiving */
|
|
Packit Service |
4684c1 |
pid = fork();
|
|
Packit Service |
4684c1 |
if (pid == -1) {
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
} else if (pid != 0) {
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("client: TLS version is: %s\n",
|
|
Packit Service |
4684c1 |
gnutls_protocol_get_name
|
|
Packit Service |
4684c1 |
(gnutls_protocol_get_version(session)));
|
|
Packit Service |
4684c1 |
sec_sleep(1);
|
|
Packit Service |
4684c1 |
/* the server should reflect our messages */
|
|
Packit Service |
4684c1 |
ret = gnutls_record_recv(session, buf, sizeof(buf));
|
|
Packit Service |
4684c1 |
if (ret != sizeof(MSG)-1 || memcmp(buf, MSG, sizeof(MSG)-1) != 0) {
|
|
Packit Service |
4684c1 |
fail("client: recv failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
fprintf(stderr, "client received: %.*s\n", ret, buf);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_record_recv(session, buf, sizeof(buf));
|
|
Packit Service |
4684c1 |
if (ret != sizeof(MSG2)-1 || memcmp(buf, MSG2, sizeof(MSG2)-1) != 0) {
|
|
Packit Service |
4684c1 |
fail("client: recv2 failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
fprintf(stderr, "client received: %.*s\n", ret, buf);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_record_recv(session, buf, sizeof(buf));
|
|
Packit Service |
4684c1 |
if (ret != 0) {
|
|
Packit Service |
4684c1 |
fail("client: recv3 failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
} else if (pid == 0) { /* child */
|
|
Packit Service |
4684c1 |
ret = gnutls_record_send(session, MSG, sizeof(MSG)-1);
|
|
Packit Service |
4684c1 |
if (ret != sizeof(MSG)-1) {
|
|
Packit Service |
4684c1 |
fail("client: send failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_record_send(session, MSG2, sizeof(MSG2)-1);
|
|
Packit Service |
4684c1 |
if (ret != sizeof(MSG2)-1) {
|
|
Packit Service |
4684c1 |
fail("client: send2 failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
sec_sleep(2);
|
|
Packit Service |
4684c1 |
gnutls_bye(session, GNUTLS_SHUT_WR);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void do_reflect_stuff(gnutls_session_t session)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char buf[64];
|
|
Packit Service |
4684c1 |
unsigned buf_size;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
do {
|
|
Packit Service |
4684c1 |
ret = gnutls_record_recv(session, buf, sizeof(buf));
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("server: recv failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
terminate();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (ret == 0)
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
buf_size = ret;
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
fprintf(stderr, "server received: %.*s\n", buf_size, buf);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_record_send(session, buf, buf_size);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("server: send failed: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
terminate();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
} while(1);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* do not wait for the peer to close the connection.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_bye(session, GNUTLS_SHUT_WR);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void client(int fd, unsigned do_fork)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
gnutls_certificate_credentials_t x509_cred;
|
|
Packit Service |
4684c1 |
gnutls_session_t session;
|
|
Packit Service |
4684c1 |
/* Need to enable anonymous KX specifically. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
global_init();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
side = "client";
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_level(4711);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_certificate_allocate_credentials(&x509_cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Initialize TLS session
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_DATAGRAM);
|
|
Packit Service |
4684c1 |
gnutls_dtls_set_mtu(session, 1500);
|
|
Packit Service |
4684c1 |
gnutls_dtls_set_timeouts(session, 6 * 1000, 60 * 1000);
|
|
Packit Service |
4684c1 |
//gnutls_transport_set_push_function(session, push);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Use default priorities */
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(session,
|
|
Packit Service |
4684c1 |
"NONE:+VERS-DTLS-ALL:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ECDHE-ECDSA:+CURVE-ALL",
|
|
Packit Service |
4684c1 |
NULL);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* put the anonymous credentials to the current session
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_transport_set_int(session, fd);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Perform the TLS handshake
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
do {
|
|
Packit Service |
4684c1 |
ret = gnutls_handshake(session);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("client: Handshake failed\n");
|
|
Packit Service |
4684c1 |
gnutls_perror(ret);
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
} else {
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("client: Handshake was completed\n");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (do_fork)
|
|
Packit Service |
4684c1 |
do_fork_stuff(session);
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
do_reflect_stuff(session);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
close(fd);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_deinit(session);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_certificate_free_credentials(x509_cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
exit(0);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void server(int fd, unsigned do_fork)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
gnutls_certificate_credentials_t x509_cred;
|
|
Packit Service |
4684c1 |
gnutls_session_t session;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* this must be called once in the program
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
global_init();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if 0
|
|
Packit Service |
4684c1 |
if (debug) {
|
|
Packit Service |
4684c1 |
side = "server";
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_level(4711);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_certificate_allocate_credentials(&x509_cred);
|
|
Packit Service |
4684c1 |
gnutls_certificate_set_x509_key_mem(x509_cred, &server_cert,
|
|
Packit Service |
4684c1 |
&server_key,
|
|
Packit Service |
4684c1 |
GNUTLS_X509_FMT_PEM);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_init(&session, GNUTLS_SERVER | GNUTLS_DATAGRAM);
|
|
Packit Service |
4684c1 |
gnutls_dtls_set_timeouts(session, 5 * 1000, 60 * 1000);
|
|
Packit Service |
4684c1 |
gnutls_dtls_set_mtu(session, 400);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* avoid calling all the priority functions, since the defaults
|
|
Packit Service |
4684c1 |
* are adequate.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_priority_set_direct(session,
|
|
Packit Service |
4684c1 |
"NONE:+VERS-DTLS1.2:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ECDHE-ECDSA:+CURVE-ALL",
|
|
Packit Service |
4684c1 |
NULL);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_transport_set_int(session, fd);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
do {
|
|
Packit Service |
4684c1 |
ret = gnutls_handshake(session);
|
|
Packit Service |
4684c1 |
} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
close(fd);
|
|
Packit Service |
4684c1 |
gnutls_deinit(session);
|
|
Packit Service |
4684c1 |
fail("server: Handshake has failed (%s)\n\n",
|
|
Packit Service |
4684c1 |
gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
terminate();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("server: Handshake was completed\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("server: TLS version is: %s\n",
|
|
Packit Service |
4684c1 |
gnutls_protocol_get_name
|
|
Packit Service |
4684c1 |
(gnutls_protocol_get_version(session)));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (do_fork)
|
|
Packit Service |
4684c1 |
do_fork_stuff(session);
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
do_reflect_stuff(session);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
close(fd);
|
|
Packit Service |
4684c1 |
gnutls_deinit(session);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_certificate_free_credentials(x509_cred);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("server: finished\n");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
void run(unsigned do_fork)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int fd[2];
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
perror("socketpair");
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
child = fork();
|
|
Packit Service |
4684c1 |
if (child < 0) {
|
|
Packit Service |
4684c1 |
perror("fork");
|
|
Packit Service |
4684c1 |
fail("fork");
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (child) {
|
|
Packit Service |
4684c1 |
int status;
|
|
Packit Service |
4684c1 |
/* parent */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
close(fd[1]);
|
|
Packit Service |
4684c1 |
client(fd[0], do_fork);
|
|
Packit Service |
4684c1 |
wait(&status);
|
|
Packit Service |
4684c1 |
check_wait_status(status);
|
|
Packit Service |
4684c1 |
} else {
|
|
Packit Service |
4684c1 |
close(fd[0]);
|
|
Packit Service |
4684c1 |
server(fd[1], 1-do_fork);
|
|
Packit Service |
4684c1 |
exit(0);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
signal(SIGPIPE, SIG_IGN);
|
|
Packit Service |
4684c1 |
run(0);
|
|
Packit Service |
4684c1 |
run(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
#endif /* _WIN32 */
|