forked from SWI-Prolog/packages-ssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
82 lines (70 loc) · 1.86 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**********************************************************************
* Filename: client.c
* Purpose: Implementation of SSL client
* Method: OpenSSL
* Author: [email protected]
* Date: Thu May 27 11:11:06 CEST 2004
**********************************************************************/
#include "ssllib.h"
#include "util.h"
int
main()
{
PL_SSL *config = NULL;
PL_SSL_INSTANCE *instance = NULL;
int sock_inst = -1;
/*
* Initialize ssllib
*/
(void) ssl_lib_init();
/*
* SSL preliminaries, creating context and handle for this session.
*/
if ((config = ssl_init(FALSE)) == NULL) {
exit(EXIT_FAILURE);
}
/*
* Set some more parameters
*/
ssl_set_cacert (config, CACERT);
ssl_set_certf (config, CLIENT_CERTF);
ssl_set_keyf (config, CLIENT_KEYF);
ssl_set_password (config, CLIENT_PASSWD);
ssl_set_cert (config, CLIENT_CERT_REQUIRED);
#if 0
ssl_set_peer_cert (config, SERVER_CERT_REQUIRED);
#endif
#if 1
/*
* Install some callback's
*/
ssl_set_cb_cert_verify(config, util_cb_cert_verify, NULL);
#endif
/*
* Establish TCP layer with SSL layer on top of it
*/
ssl_set_host (config, TEST_HOST);
ssl_set_port (config, TEST_PORT);
if ((config->sock = ssl_socket(config)) < 0) {
exit(EXIT_FAILURE);
}
/*
* Start up the client
*/
if ((sock_inst = ssl_connect(config)) < 0) {
exit(EXIT_FAILURE);
}
if ((instance = ssl_ssl(config, sock_inst)) == NULL) {
exit(EXIT_FAILURE);
}
util_run_test(instance);
/*
* Close down SSL, TCP and free all resources
*/
ssl_close(instance);
/*
* Close down SSL, TCP and free all resources
*/
ssl_exit(config);
exit(EXIT_SUCCESS);
}