-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathserver.c
More file actions
58 lines (44 loc) · 1.12 KB
/
Copy pathserver.c
File metadata and controls
58 lines (44 loc) · 1.12 KB
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
#include "common.h"
#include "server.h"
int tcp_listen()
{
int sock;
struct sockaddr_in sin;
int val=1;
if((sock=socket(AF_INET,SOCK_STREAM,0))<0)
err_exit("Couldn't make socket");
memset(&sin,0,sizeof(sin));
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_family=AF_INET;
sin.sin_port=htons(PORT);
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,
&val,sizeof(val));
if(bind(sock,(struct sockaddr *)&sin,
sizeof(sin))<0)
berr_exit("Couldn't bind");
listen(sock,5);
return(sock);
}
void load_dh_params(ctx,file)
SSL_CTX *ctx;
char *file;
{
DH *ret=0;
BIO *bio;
if ((bio=BIO_new_file(file,"r")) == NULL)
berr_exit("Couldn't open DH file");
ret=PEM_read_bio_DHparams(bio,NULL,NULL,
NULL);
BIO_free(bio);
if(SSL_CTX_set_tmp_dh(ctx,ret)<0)
berr_exit("Couldn't set DH parameters");
}
void generate_eph_rsa_key(ctx)
SSL_CTX *ctx;
{
RSA *rsa;
rsa=RSA_generate_key(512,RSA_F4,NULL,NULL);
if (!SSL_CTX_set_tmp_rsa(ctx,rsa))
berr_exit("Couldn't set RSA key");
RSA_free(rsa);
}