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

Last change on this file since 95 was 31, checked in by Nishi, on Sep 16, 2024 at 4:52:02 PM

use uintptr_type

  • Property svn:keywords set to Id
File size: 1.1 KB
RevLine 
[11]1/* $Id: ssl.c 31 2024-09-16 07:52:02Z nishi $ */
2
[16]3#define SOURCE
4
[11]5#include "tw_ssl.h"
[12]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 }
[31]23 struct tw_config_entry* e = tw_vhost_match(s, (__UINTPTR_TYPE__)arg);
[12]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;
[19]28 } else if(config.root.sslkey != NULL && config.root.sslcert != NULL) {
29 SSL_use_PrivateKey_file(ssl, config.root.sslkey, SSL_FILETYPE_PEM);
30 SSL_use_certificate_file(ssl, config.root.sslcert, SSL_FILETYPE_PEM);
[20]31 return 1;
[12]32 } else {
33 return 0;
34 }
35}
36
[31]37SSL_CTX* tw_create_ssl_ctx(__UINTPTR_TYPE__ port) {
[12]38 SSL_CTX* ctx = SSL_CTX_new(TLS_server_method());
39 SSL_CTX_set_cert_cb(ctx, tw_ssl_cert_cb, (void*)port);
40 return ctx;
41}
Note: See TracBrowser for help on using the repository browser.