| 55 | } |
| 56 | |
| 57 | int PkiUtility::SignCsr(const String& csrfile, const String& certfile) |
| 58 | { |
| 59 | char errbuf[256]; |
| 60 | |
| 61 | InitializeOpenSSL(); |
| 62 | |
| 63 | BIO *csrbio = BIO_new_file(csrfile.CStr(), "r"); |
| 64 | X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, nullptr, nullptr, nullptr); |
| 65 | |
| 66 | if (!req) { |
| 67 | ERR_error_string_n(ERR_peek_error(), errbuf, sizeof errbuf); |
| 68 | Log(LogCritical, "SSL") |
| 69 | << "Could not read X509 certificate request from '" << csrfile << "': " << ERR_peek_error() << ", \"" << errbuf << "\""; |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | BIO_free(csrbio); |
| 74 | |
| 75 | std::shared_ptr<EVP_PKEY> pubkey = std::shared_ptr<EVP_PKEY>(X509_REQ_get_pubkey(req), EVP_PKEY_free); |
| 76 | std::shared_ptr<X509> cert = CreateCertIcingaCA(pubkey.get(), X509_REQ_get_subject_name(req), 0, LEAF_VALID_FOR); |
| 77 | |
| 78 | X509_REQ_free(req); |
| 79 | |
| 80 | WriteCert(cert, certfile); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | std::shared_ptr<X509> PkiUtility::FetchCert(const String& host, const String& port) |
| 86 | { |
nothing calls this directly
no test coverage detected