Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Commit

Permalink
style code & ssl key is exist
Browse files Browse the repository at this point in the history
  • Loading branch information
vislee committed Jun 14, 2019
1 parent 91c57aa commit 5eff25c
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions ngx_http_multiple_ssl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <stdio.h>



typedef struct {
ngx_flag_t multiple_ssl_enable;
ngx_str_t multiple_ssl_cert_path;
Expand Down Expand Up @@ -57,7 +56,6 @@ static ngx_command_t ngx_http_multiple_ssl_commands[] = {
};



static ngx_http_module_t ngx_http_multiple_ssl_module_ctx = {
NULL, /* preconfiguration */
NULL, /* postconfiguration */
Expand All @@ -73,7 +71,6 @@ static ngx_http_module_t ngx_http_multiple_ssl_module_ctx = {
};



ngx_module_t ngx_http_multiple_ssl_module = {
NGX_MODULE_V1,
&ngx_http_multiple_ssl_module_ctx, /* module context */
Expand All @@ -90,7 +87,6 @@ ngx_module_t ngx_http_multiple_ssl_module = {
};



static void *
ngx_http_multiple_ssl_create_srv_conf(ngx_conf_t *cf)
{
Expand All @@ -107,7 +103,6 @@ ngx_http_multiple_ssl_create_srv_conf(ngx_conf_t *cf)
}



static char *
ngx_http_multiple_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
Expand Down Expand Up @@ -135,9 +130,12 @@ ngx_http_multiple_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}

if (ngx_conf_full_name(cf->cycle, &conf->multiple_ssl_cert_path, 0) != NGX_OK) {
if (ngx_conf_full_name(cf->cycle, &conf->multiple_ssl_cert_path, 0)
!= NGX_OK)
{
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"multiple ssl ngx_conf_full_name multiple_ssl_cert_path error");
"multiple ssl ngx_conf_full_name "
"multiple_ssl_cert_path error");

return NGX_CONF_ERROR;
}
Expand Down Expand Up @@ -184,7 +182,6 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)

ngx_http_multiple_ssl_srv_conf_t *mscf;


c = ngx_ssl_get_connection(ssl_conn);
if (c == NULL) {
return 0;
Expand Down Expand Up @@ -214,9 +211,11 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
}

host.data = (u_char *) servername;
ngx_log_error(NGX_LOG_INFO, c->log, 0, "multiple ssl servername \"%V\"", &host);
ngx_log_error(NGX_LOG_INFO, c->log, 0, "multiple ssl servername \"%V\"",
&host);

mscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_multiple_ssl_module);
mscf = ngx_http_get_module_srv_conf(hc->conf_ctx,
ngx_http_multiple_ssl_module);
if (NULL == mscf) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "multiple ssl mscf NULL");
return SSL_TLSEXT_ERR_NOACK;
Expand Down Expand Up @@ -246,7 +245,8 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
}

if (sn_cert[i].key.len > 2
&& sn_cert[i].key.data[0] == '*' && sn_cert[i].key.data[1] == '.'
&& sn_cert[i].key.data[0] == '*'
&& sn_cert[i].key.data[1] == '.'
&& host.len > sn_cert[i].key.len - 1
&& ngx_strncmp(host.data + (host.len - sn_cert[i].key.len + 1),
sn_cert[i].key.data + 1, sn_cert[i].key.len - 1) == 0)
Expand All @@ -261,14 +261,17 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
cert.len = host.len + ngx_strlen(".crt");
cert.data = ngx_pnalloc(c->pool, cert.len);
if (NULL == cert.data) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "multiple ssl ngx_pnalloc cert.data NULL");
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"multiple ssl ngx_pnalloc cert.data NULL");

return SSL_TLSEXT_ERR_NOACK;
}
ngx_memzero(cert.data, cert.len);
ngx_sprintf(cert.data, "%V.crt", &host);
}

if (ngx_get_full_name(c->pool, (ngx_str_t *) &mscf->multiple_ssl_cert_path, &cert) != NGX_OK)
if (ngx_get_full_name(c->pool, (ngx_str_t *) &mscf->multiple_ssl_cert_path,
&cert) != NGX_OK)
{
ngx_log_error(NGX_LOG_ERR, c->log, 0,
"multiple ssl ngx_get_full_name error. servername:\"%V\"", &host);
Expand All @@ -283,11 +286,21 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
key.data[key.len - 2] = 'e';
key.data[key.len - 3] = 'k';

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "multiple ssl cert %V", &cert);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"multiple ssl cert %V", &cert);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "multiple ssl key %V", &key);

if (0 != access((const char *)cert.data, F_OK|R_OK)) {
ngx_log_debug1(NGX_LOG_WARN, c->log, 0, "multiple ssl cert [%V] not exists or not read", &cert);
ngx_log_debug1(NGX_LOG_WARN, c->log, 0,
"multiple ssl cert [%V] not exists or not read", &cert);

return SSL_TLSEXT_ERR_NOACK;
}

if (0 != access((const char *)key.data, F_OK|R_OK)) {
ngx_log_debug1(NGX_LOG_WARN, c->log, 0,
"multiple ssl key [%V] not exists or not read", &key);

return SSL_TLSEXT_ERR_NOACK;
}

Expand All @@ -298,7 +311,8 @@ ngx_http_multiple_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)


static int
ngx_http_multiple_ssl_set_der_certificate(ngx_ssl_conn_t *ssl_conn, ngx_str_t *cert, ngx_str_t *key)
ngx_http_multiple_ssl_set_der_certificate(ngx_ssl_conn_t *ssl_conn,
ngx_str_t *cert, ngx_str_t *key)
{
BIO *bio = NULL;
X509 *x509 = NULL;
Expand Down

0 comments on commit 5eff25c

Please sign in to comment.