File: https.c

package info (click to toggle)
links2 2.1pre16-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 16,944 kB
  • ctags: 7,154
  • sloc: ansic: 74,279; sh: 3,102; yacc: 1,584; lex: 748; cpp: 530; pascal: 257; makefile: 105; awk: 47; perl: 34
file content (54 lines) | stat: -rw-r--r-- 987 bytes parent folder | download
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
/* https.c
 * HTTPS protocol client implementation
 * (c) 2002 Mikulas Patocka
 * This file is a part of the Links program, released under GPL.
 */

#include "links.h"

#ifndef PATH_MAX
#define PATH_MAX 255
#endif

#ifdef HAVE_SSL

SSL_CTX *context = 0;

SSL *getSSL(void)
{
	if (!context) {
		char f_randfile[PATH_MAX];

		const char *f = RAND_file_name(f_randfile, sizeof(f_randfile));
		if (f && RAND_egd(f)<0) {
			/* Not an EGD, so read and write to it */
			if (RAND_load_file(f_randfile, -1))
				RAND_write_file(f_randfile);
		}
		SSLeay_add_ssl_algorithms();
		context = SSL_CTX_new(SSLv23_client_method());
		SSL_CTX_set_options(context, SSL_OP_ALL);
		SSL_CTX_set_default_verify_paths(context);
	}
	return (SSL_new(context));
}
void ssl_finish(void)
{
	if (context) SSL_CTX_free(context);
}

void https_func(struct connection *c)
{
	c->ssl = (void *)-1;
	http_func(c);
}

#else

void https_func(struct connection *c)
{
	setcstate(c, S_NO_SSL);
	abort_connection(c);
}

#endif