|
70 | 70 | #ifndef SUPPORT_CURLOPT_CAINFO_BLOB |
71 | 71 | #define SUPPORT_CURLOPT_CAINFO_BLOB LIBCURL_VERSION_NUM >= 0x074D00 // 7.77.0 |
72 | 72 | #endif |
| 73 | +#ifndef SUPPORT_CURLOPT_SSLCERT_BLOB |
| 74 | +#define SUPPORT_CURLOPT_SSLCERT_BLOB LIBCURL_VERSION_NUM >= 0x074700 // 7.71.0 |
| 75 | +#endif |
73 | 76 |
|
74 | 77 | namespace cpr { |
75 | 78 |
|
@@ -117,6 +120,38 @@ class DerCert : public CertFile { |
117 | 120 | } |
118 | 121 | }; |
119 | 122 |
|
| 123 | + |
| 124 | +#if SUPPORT_CURLOPT_SSLCERT_BLOB |
| 125 | +class CertBlob { |
| 126 | +public: |
| 127 | + // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) |
| 128 | + CertBlob(std::string&& p_blob) : blob(std::move(p_blob)) {} |
| 129 | + |
| 130 | + virtual ~CertBlob() = default; |
| 131 | + |
| 132 | + std::string blob; |
| 133 | + |
| 134 | + virtual const char* GetCertType() const { |
| 135 | + return "PEM"; |
| 136 | + } |
| 137 | +}; |
| 138 | + |
| 139 | +using PemBlob = CertBlob; |
| 140 | + |
| 141 | +class DerBlob : public CertBlob { |
| 142 | +public: |
| 143 | + template <typename BlobType> |
| 144 | + // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) |
| 145 | + DerBlob(BlobType&& p_blob) : CertBlob(std::move(p_blob)) {} |
| 146 | + |
| 147 | + ~DerBlob() override = default; |
| 148 | + |
| 149 | + const char* GetCertType() const override { |
| 150 | + return "DER"; |
| 151 | + } |
| 152 | +}; |
| 153 | +#endif |
| 154 | + |
120 | 155 | // specify private keyfile for TLS and SSL client cert |
121 | 156 | class KeyFile { |
122 | 157 | public: |
@@ -423,6 +458,9 @@ class NoRevoke { |
423 | 458 | struct SslOptions { |
424 | 459 | // We don't use fs::path here, as this leads to problems using windows |
425 | 460 | std::string cert_file; |
| 461 | +#if SUPPORT_CURLOPT_SSLCERT_BLOB |
| 462 | + util::SecureString cert_blob; |
| 463 | +#endif |
426 | 464 | std::string cert_type; |
427 | 465 | // We don't use fs::path here, as this leads to problems using windows |
428 | 466 | std::string key_file; |
@@ -472,6 +510,12 @@ struct SslOptions { |
472 | 510 | cert_file = opt.filename.string(); |
473 | 511 | cert_type = opt.GetCertType(); |
474 | 512 | } |
| 513 | +#if SUPPORT_CURLOPT_SSLCERT_BLOB |
| 514 | + void SetOption(const ssl::CertBlob& opt) { |
| 515 | + cert_blob = opt.blob; |
| 516 | + cert_type = opt.GetCertType(); |
| 517 | + } |
| 518 | +#endif |
475 | 519 | void SetOption(const ssl::KeyFile& opt) { |
476 | 520 | key_file = opt.filename.string(); |
477 | 521 | key_type = opt.GetKeyType(); |
|
0 commit comments