MCPcopy Create free account
hub / github.com/Icinga/icinga2 / CollectRequestHandler

Function CollectRequestHandler

lib/remote/pkiutility.cpp:382–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382static void CollectRequestHandler(const Dictionary::Ptr& requests, const String& requestFile)
383{
384 Dictionary::Ptr request = Utility::LoadJsonFile(requestFile);
385
386 if (!request)
387 return;
388
389 Dictionary::Ptr result = new Dictionary();
390
391 namespace fs = boost::filesystem;
392 fs::path file(requestFile.Begin(), requestFile.End());
393 String fingerprint = file.stem().string();
394
395 String certRequestText = request->Get("cert_request");
396 result->Set("cert_request", certRequestText);
397
398 Value vcertResponseText;
399
400 if (request->Get("cert_response", &vcertResponseText)) {
401 String certResponseText = vcertResponseText;
402 result->Set("cert_response", certResponseText);
403 }
404
405 std::shared_ptr<X509> certRequest = StringToCertificate(certRequestText);
406
407/* XXX (requires OpenSSL >= 1.0.0)
408 time_t now;
409 time(&now);
410 ASN1_TIME *tm = ASN1_TIME_adj(nullptr, now, 0, 0);
411
412 int day, sec;
413 ASN1_TIME_diff(&day, &sec, tm, X509_get_notBefore(certRequest.get()));
414
415 result->Set("timestamp", static_cast<double>(now) + day * 24 * 60 * 60 + sec); */
416
417 BIO *out = BIO_new(BIO_s_mem());
418 ASN1_TIME_print(out, X509_get_notBefore(certRequest.get()));
419
420 char *data;
421 long length;
422 length = BIO_get_mem_data(out, &data);
423
424 result->Set("timestamp", String(data, data + length));
425 BIO_free(out);
426
427 out = BIO_new(BIO_s_mem());
428 X509_NAME_print_ex(out, X509_get_subject_name(certRequest.get()), 0, XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB);
429
430 length = BIO_get_mem_data(out, &data);
431
432 result->Set("subject", String(data, data + length));
433 BIO_free(out);
434
435 requests->Set(fingerprint, result);
436}
437
438Dictionary::Ptr PkiUtility::GetCertificateRequests(bool removed)
439{

Callers 1

Calls 8

StringToCertificateFunction · 0.85
StringClass · 0.50
BeginMethod · 0.45
EndMethod · 0.45
stringMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected