Skip to content

Commit

Permalink
Merge pull request #237 from yyamano/refactoring-set_der_certificate
Browse files Browse the repository at this point in the history
Refactor ngx_http_mruby_set_der_certificate()
  • Loading branch information
matsumotory authored Dec 6, 2016
2 parents e89366d + 2dcd232 commit e786298
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/http/ngx_http_mruby_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2415,30 +2415,20 @@ static int ngx_http_mruby_set_der_certificate(ngx_ssl_conn_t *ssl_conn, ngx_str_

bio = BIO_new_file((char *)cert->data, "r");
if (bio == NULL) {
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}

x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
if (x509 == NULL) {
BIO_free(bio);
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}

SSL_certs_clear(ssl_conn);

if (SSL_use_certificate(ssl_conn, x509) == 0) {
X509_free(x509);
BIO_free(bio);
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}

#if 0
if (SSL_set_ex_data(ssl_conn, ngx_ssl_certificate_index, x509) == 0) {
X509_free(x509);
BIO_free(bio);
return NGX_ERROR;
}
#endif

X509_free(x509);
x509 = NULL;

Expand All @@ -2453,25 +2443,29 @@ static int ngx_http_mruby_set_der_certificate(ngx_ssl_conn_t *ssl_conn, ngx_str_
break;
}

BIO_free(bio);
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}

if (SSL_add0_chain_cert(ssl_conn, x509) == 0) {
X509_free(x509);
BIO_free(bio);
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}
}

BIO_free(bio);
bio = NULL;

if (SSL_use_PrivateKey_file(ssl_conn, (char *)key->data, SSL_FILETYPE_PEM) != 1) {
return NGX_ERROR;
goto NGX_MRUBY_SSL_ERROR;
}

return NGX_OK;

NGX_MRUBY_SSL_ERROR:
if (bio)
BIO_free(bio);
if (x509)
X509_free(x509);
return NGX_ERROR;
}

#endif /* NGX_HTTP_SSL */
Expand Down

0 comments on commit e786298

Please sign in to comment.