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

Function mkcrt

plugins/certifier/certifier.cc:347–395  ·  view source on GitHub ↗

Local helper function that generates a X509 certificate based on SNI

Source from the content-addressed store, hash-verified

345
346/// Local helper function that generates a X509 certificate based on SNI
347static scoped_X509
348mkcrt(const std::string &commonName, int serial)
349{
350 scoped_EVP_PKEY pktmp;
351 scoped_X509 cert;
352
353 cert.reset(X509_new());
354
355 // Set X509V3
356 if (X509_set_version(cert.get(), 2) == 0) {
357 TSError("[%s] %s: failed to set X509V3", PLUGIN_NAME, __func__);
358 return nullptr;
359 }
360
361 // Set serial number
362 ASN1_INTEGER_set(X509_get_serialNumber(cert.get()), serial);
363
364 // Set issuer from CA cert
365 if (X509_set_issuer_name(cert.get(), X509_get_subject_name(ca_cert_scoped.get())) == 0) {
366 TSError("[%s] %s: failed to set certificate issuer", PLUGIN_NAME, __func__);
367 return nullptr;
368 }
369
370 // Set certificate time
371 X509_gmtime_adj(X509_get_notBefore(cert.get()), 0);
372 X509_gmtime_adj(X509_get_notAfter(cert.get()), static_cast<long>(3650) * 24 * 3600);
373
374 // Get handle to subject name
375 X509_NAME *n = X509_get_subject_name(cert.get());
376 // Set common name field
377 if (X509_NAME_add_entry_by_txt(n, "CN", MBSTRING_ASC, (unsigned char *)commonName.c_str(), -1, -1, 0) != 1) {
378 TSError("[%s] %s: failed to add certificate subject CN", PLUGIN_NAME, __func__);
379 return nullptr;
380 }
381
382 // Set Traffic Server public key
383 if (X509_set_pubkey(cert.get(), ca_pkey_scoped.get()) == 0) {
384 TSError("[%s] %s: failed to set certificate public key", PLUGIN_NAME, __func__);
385 return nullptr;
386 }
387
388 // Add the Subject Alternative Name (SAN) extension
389 addSANExtToCert(cert.get(), commonName);
390
391 // Sign the certificate
392 X509_sign(cert.get(), ca_pkey_scoped.get(), EVP_sha256());
393
394 return cert;
395}
396
397static int
398shadow_cert_generator(TSCont contp, TSEvent /* event ATS_UNUSED */, void * /* edata ATS_UNUSED */)

Callers 1

shadow_cert_generatorFunction · 0.85

Calls 5

addSANExtToCertFunction · 0.85
TSErrorFunction · 0.50
resetMethod · 0.45
getMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected