MCPcopy Create free account
hub / github.com/apache/trafficserver / SSLCreateClientContext

Function SSLCreateClientContext

src/iocore/net/SSLClientUtils.cc:275–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273}
274
275SSL_CTX *
276SSLCreateClientContext(const struct SSLConfigParams *params, const char *ca_bundle_path, const char *ca_bundle_file,
277 const char *cert_path, const char *key_path)
278{
279 std::unique_ptr<SSL_CTX, decltype(&SSL_CTX_free)> ctx(nullptr, &SSL_CTX_free);
280
281 if (nullptr == params || nullptr == cert_path) {
282 return nullptr;
283 }
284
285 ctx.reset(SSLInitClientContext(params));
286
287 if (!ctx) {
288 return nullptr;
289 }
290
291 if (!SSL_CTX_use_certificate_chain_file(ctx.get(), cert_path)) {
292 SSLError("SSLCreateClientContext(): failed to load client certificate: %s",
293 (!cert_path || cert_path[0] == '\0') ? "[empty file name]" : cert_path);
294 return nullptr;
295 }
296
297 if (!key_path || key_path[0] == '\0') {
298 key_path = cert_path;
299 }
300
301 if (!SSL_CTX_use_PrivateKey_file(ctx.get(), key_path, SSL_FILETYPE_PEM)) {
302 SSLError("SSLCreateClientContext(): failed to load client private key: %s",
303 (!key_path || key_path[0] == '\0') ? "[empty file]" : key_path);
304 return nullptr;
305 }
306
307 if (!SSL_CTX_check_private_key(ctx.get())) {
308 SSLError("SSLCreateClientContext(): client private key: %s does not match client certificate: %s",
309 (!key_path || key_path[0] == '\0') ? "[empty file]" : key_path,
310 (!cert_path || cert_path[0] == '\0') ? "[empty file]" : cert_path);
311 return nullptr;
312 }
313
314 if (ca_bundle_file || ca_bundle_path) {
315 if (!SSL_CTX_load_verify_locations(ctx.get(), ca_bundle_file, ca_bundle_path)) {
316 SSLError("SSLCreateClientContext(): Invalid CA Certificate file: %s or CA Certificate path: %s",
317 (!ca_bundle_file || ca_bundle_file[0] == '\0') ? "[empty file name]" : ca_bundle_file,
318 (!ca_bundle_path || ca_bundle_path[0] == '\0') ? "[empty path]" : ca_bundle_path);
319 SSLError("SSLCreateClientContext(): Invalid client CA cert file/CA path.");
320 return nullptr;
321 }
322 } else if (!SSL_CTX_set_default_verify_paths(ctx.get())) {
323 SSLError("SSLCreateClientContext(): failed to set the default verify paths.");
324 return nullptr;
325 }
326 return ctx.release();
327}

Callers 1

TSSslClientCertUpdateFunction · 0.85

Calls 3

resetMethod · 0.45
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected