Skip to content

Commit

Permalink
Merge pull request nghttp2#1126 from nghttp2/nghttpx-expired-client-cert
Browse files Browse the repository at this point in the history
nghttpx: Add an option to accept expired client certificate
  • Loading branch information
tatsuhiro-t authored Feb 10, 2018
2 parents 6515781 + e8af7af commit 39f0ce7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions gennghttpxfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"no-strip-incoming-x-forwarded-proto",
"ocsp-startup",
"no-verify-ocsp",
"verify-client-tolerate-expired",
]

LOGVARS = [
Expand Down
12 changes: 12 additions & 0 deletions src/shrpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,11 @@ SSL/TLS:
Path to file that contains CA certificates to verify
client certificate. The file must be in PEM format. It
can contain multiple certificates.
--verify-client-tolerate-expired
Accept expired client certificate. Operator should
handle the expired client certificate by some means
(e.g., mruby script). Otherwise, this option might
cause a security risk.
--client-private-key-file=<PATH>
Path to file that contains client private key used in
backend client authentication.
Expand Down Expand Up @@ -3406,6 +3411,8 @@ int main(int argc, char **argv) {
{SHRPX_OPT_NO_STRIP_INCOMING_X_FORWARDED_PROTO.c_str(), no_argument,
&flag, 158},
{SHRPX_OPT_SINGLE_PROCESS.c_str(), no_argument, &flag, 159},
{SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED.c_str(), no_argument, &flag,
160},
{nullptr, 0, nullptr, 0}};

int option_index = 0;
Expand Down Expand Up @@ -4167,6 +4174,11 @@ int main(int argc, char **argv) {
cmdcfgs.emplace_back(SHRPX_OPT_SINGLE_PROCESS,
StringRef::from_lit("yes"));
break;
case 160:
// --verify-client-tolerate-expired
cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED,
StringRef::from_lit("yes"));
break;
default:
break;
}
Expand Down
9 changes: 9 additions & 0 deletions src/shrpx_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,11 @@ int option_lookup_token(const char *name, size_t namelen) {
break;
case 30:
switch (name[29]) {
case 'd':
if (util::strieq_l("verify-client-tolerate-expire", name, 29)) {
return SHRPX_OPTID_VERIFY_CLIENT_TOLERATE_EXPIRED;
}
break;
case 'r':
if (util::strieq_l("strip-incoming-x-forwarded-fo", name, 29)) {
return SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR;
Expand Down Expand Up @@ -3554,6 +3559,10 @@ int parse_config(Config *config, int optid, const StringRef &opt,
case SHRPX_OPTID_NO_VERIFY_OCSP:
config->tls.ocsp.no_verify = util::strieq_l("yes", optarg);

return 0;
case SHRPX_OPTID_VERIFY_CLIENT_TOLERATE_EXPIRED:
config->tls.client_verify.tolerate_expired = util::strieq_l("yes", optarg);

return 0;
case SHRPX_OPTID_CONF:
LOG(WARN) << "conf: ignored";
Expand Down
5 changes: 5 additions & 0 deletions src/shrpx_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ constexpr auto SHRPX_OPT_NO_STRIP_INCOMING_X_FORWARDED_PROTO =
StringRef::from_lit("no-strip-incoming-x-forwarded-proto");
constexpr auto SHRPX_OPT_OCSP_STARTUP = StringRef::from_lit("ocsp-startup");
constexpr auto SHRPX_OPT_NO_VERIFY_OCSP = StringRef::from_lit("no-verify-ocsp");
constexpr auto SHRPX_OPT_VERIFY_CLIENT_TOLERATE_EXPIRED =
StringRef::from_lit("verify-client-tolerate-expired");

constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8;

Expand Down Expand Up @@ -602,6 +604,8 @@ struct TLSConfig {
// certificate validation
StringRef cacert;
bool enabled;
// true if we accept an expired client certificate.
bool tolerate_expired;
} client_verify;

// Client (backend connection) TLS configuration.
Expand Down Expand Up @@ -1125,6 +1129,7 @@ enum {
SHRPX_OPTID_USER,
SHRPX_OPTID_VERIFY_CLIENT,
SHRPX_OPTID_VERIFY_CLIENT_CACERT,
SHRPX_OPTID_VERIFY_CLIENT_TOLERATE_EXPIRED,
SHRPX_OPTID_WORKER_FRONTEND_CONNECTIONS,
SHRPX_OPTID_WORKER_READ_BURST,
SHRPX_OPTID_WORKER_READ_RATE,
Expand Down
6 changes: 6 additions & 0 deletions src/shrpx_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
if (!preverify_ok) {
int err = X509_STORE_CTX_get_error(ctx);
int depth = X509_STORE_CTX_get_error_depth(ctx);
if (err == X509_V_ERR_CERT_HAS_EXPIRED && depth == 0 &&
get_config()->tls.client_verify.tolerate_expired) {
LOG(INFO) << "The client certificate has expired, but is accepted by "
"configuration";
return 1;
}
LOG(ERROR) << "client certificate verify error:num=" << err << ":"
<< X509_verify_cert_error_string(err) << ":depth=" << depth;
}
Expand Down

0 comments on commit 39f0ce7

Please sign in to comment.