Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
add a callback member in evhtp_ssl_cfg_t for customized decrypt privf…
Browse files Browse the repository at this point in the history
…ile.

fixes #16
  • Loading branch information
h00360646 committed Jul 22, 2017
1 parent 763168c commit b3a4d42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4585,8 +4585,22 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg)
} /* switch */

SSL_CTX_use_certificate_file(htp->ssl_ctx, cfg->pemfile, SSL_FILETYPE_PEM);
SSL_CTX_use_PrivateKey_file(htp->ssl_ctx,

// decrypt the privfile with user's customized decrypt algo.
if(cfg->customized_privfile_decrypt_cb != NULL) {
EVP_PKEY *pkey = cfg->customized_privfile_decrypt_cb(cfg->privfile ? cfg->privfile : cfg->pemfile);
if(pkey == NULL) {
return -1;
}

SSL_CTX_use_PrivateKey(htp->ssl_ctx, pkey);

//cleanup
EVP_PKEY_free(pkey);
} else {
SSL_CTX_use_PrivateKey_file(htp->ssl_ctx,
cfg->privfile ? cfg->privfile : cfg->pemfile, SSL_FILETYPE_PEM);
}

SSL_CTX_set_session_id_context(htp->ssl_ctx,
(void *)&session_id_context,
Expand Down
2 changes: 2 additions & 0 deletions evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ typedef int (* evhtp_headers_iterator)(evhtp_header_t * header, void * arg);
#ifndef EVHTP_DISABLE_SSL
typedef int (* evhtp_ssl_verify_cb)(int pre_verify, evhtp_x509_store_ctx_t * ctx);
typedef int (* evhtp_ssl_chk_issued_cb)(evhtp_x509_store_ctx_t * ctx, evhtp_x509_t * x, evhtp_x509_t * issuer);
typedef EVP_PKEY* (* evhtp_ssl_privfile_decrypt_cb)(char* privfile);

typedef int (* evhtp_ssl_scache_add)(evhtp_connection_t * connection, unsigned char * sid, int sid_len, evhtp_ssl_sess_t * sess);
typedef void (* evhtp_ssl_scache_del)(evhtp_t * htp, unsigned char * sid, int sid_len);
Expand Down Expand Up @@ -519,6 +520,7 @@ struct evhtp_ssl_cfg_s {
int verify_depth;
evhtp_ssl_verify_cb x509_verify_cb;
evhtp_ssl_chk_issued_cb x509_chk_issued_cb;
evhtp_ssl_privfile_decrypt_cb customized_privfile_decrypt_cb;
long store_flags;
evhtp_ssl_scache_type scache_type;
long scache_timeout;
Expand Down

0 comments on commit b3a4d42

Please sign in to comment.