source: Main/trunk/Server/ssl.c@ 16

Last change on this file since 16 was 16, checked in by Nishi, on Sep 14, 2024 at 12:09:52 AM

can parse http now

  • Property svn:keywords set to Id
File size: 897 bytes
Line 
1/* $Id: ssl.c 16 2024-09-13 15:09:52Z nishi $ */
2
3#define SOURCE
4
5#include "tw_ssl.h"
6
7#include "tw_config.h"
8
9#include <stdio.h>
10
11#include <cm_log.h>
12
13extern struct tw_config config;
14
15int tw_ssl_cert_cb(SSL* ssl, void* arg) {
16 const char* s = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
17 if(s != NULL) {
18 cm_log("SSL", "Certificate request for %s", s);
19 } else {
20 s = config.hostname;
21 cm_log("SSL", "Could not get the servername, defaulting to the hostname: %s", s);
22 }
23 struct tw_config_entry* e = tw_vhost_match(s, (uint64_t)arg);
24 if(e != NULL && e->sslkey != NULL && e->sslcert != NULL) {
25 SSL_use_PrivateKey_file(ssl, e->sslkey, SSL_FILETYPE_PEM);
26 SSL_use_certificate_file(ssl, e->sslcert, SSL_FILETYPE_PEM);
27 return 1;
28 } else {
29 return 0;
30 }
31}
32
33SSL_CTX* tw_create_ssl_ctx(uint64_t port) {
34 SSL_CTX* ctx = SSL_CTX_new(TLS_server_method());
35 SSL_CTX_set_cert_cb(ctx, tw_ssl_cert_cb, (void*)port);
36 return ctx;
37}
Note: See TracBrowser for help on using the repository browser.