-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "crypto.h" | ||
#include "fmt/format.h" | ||
|
||
iggy::crypto::SSLContext::SSLContext() { | ||
this->ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); | ||
if (!this->ctx) { | ||
std::string errMsg = | ||
fmt::format("Failed to allocate WolfSSL TLS context: {}", wolfSSL_ERR_error_string(wolfSSL_ERR_get_error(), nullptr)); | ||
throw std::runtime_error(errMsg); | ||
} | ||
} | ||
|
||
iggy::crypto::SSLContext::SSLContext(const SSLContext& other) { | ||
this->ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); | ||
} | ||
|
||
iggy::crypto::SSLContext::SSLContext(SSLContext&& other) { | ||
this->ctx = other.ctx; | ||
other.ctx = nullptr; | ||
} | ||
|
||
iggy::crypto::SSLContext::~SSLContext() { | ||
if (this->ctx) { | ||
wolfSSL_CTX_free(this->ctx); | ||
} | ||
} | ||
|
||
iggy::crypto::SSLContext& iggy::crypto::SSLContext::operator=(const iggy::crypto::SSLContext& other) { | ||
if (this != &other) { | ||
if (this->ctx) { | ||
wolfSSL_CTX_free(this->ctx); | ||
} | ||
this->ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); | ||
} | ||
return *this; | ||
} | ||
|
||
iggy::crypto::SSLContext& iggy::crypto::SSLContext::operator=(SSLContext&& other) { | ||
if (this != &other) { | ||
if (this->ctx) { | ||
wolfSSL_CTX_free(this->ctx); | ||
} | ||
this->ctx = other.ctx; | ||
other.ctx = nullptr; | ||
} | ||
return *this; | ||
} | ||
|
||
void* iggy::crypto::SSLContext::getNativeHandle() const { | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#pragma once | ||
|
||
#include <wolfssl/options.h> | ||
#include <wolfssl/ssl.h> | ||
#include <filesystem> | ||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
#include "ada.h" | ||
|
||
namespace iggy { | ||
namespace crypto { | ||
|
||
enum CertificateFormat { PEM = 1, ASN1 = 2 }; | ||
|
||
enum RevocationMethod { CRL = 1, OCSP = 2 }; | ||
|
||
/** | ||
* @brief A mechanism for loading public key certificates: from file; database; or a secret vault. | ||
*/ | ||
class CertificateStore { | ||
private: | ||
iggy::crypto::CertificateFormat certificateFormat = iggy::crypto::CertificateFormat::PEM; | ||
|
||
public: | ||
virtual std::vector<uint8_t> getCertificate(std::string certPath) const = 0; | ||
virtual std::vector<uint8_t> getCertificateVerificationChain() const = 0; | ||
}; | ||
|
||
/** | ||
* @brief A certificate store that loads certificates from the local filesystem. | ||
*/ | ||
class LocalCertificateStore : CertificateStore { | ||
private: | ||
std::optional<std::filesystem::path> caCertChainPath; | ||
}; | ||
|
||
/** | ||
* @brief A mechanism for loading private keys: from file; database; or a secret vault. | ||
*/ | ||
class KeyStore { | ||
public: | ||
virtual std::vector<uint8_t> getPrivateKey(std::string keyPath) const = 0; | ||
}; | ||
|
||
/** | ||
* @brief A key store that loads private key materials from the local filesystem. | ||
*/ | ||
class LocalKeyStore : KeyStore { | ||
private: | ||
std::optional<std::filesystem::path> privateKeyPath; | ||
}; | ||
|
||
/** | ||
* @brief Object for managing PKI certificates and revocation methods. | ||
*/ | ||
class CertificateManager { | ||
private: | ||
std::string myCertificatePath; | ||
std::optional<std::string> trustedPeerCertificatePath; | ||
std::optional<std::filesystem::path> crlPath; | ||
std::optional<ada::url> crlUrl; | ||
std::optional<ada::url> ocspUrl; | ||
}; | ||
|
||
/** | ||
* @brief An SSL/TLS context for use in secure communication. | ||
*/ | ||
class SSLContext { | ||
private: | ||
WOLFSSL_CTX* ctx; | ||
iggy::crypto::CertificateManager certManager; | ||
std::optional<std::vector<std::string>> ciphers; | ||
|
||
public: | ||
SSLContext(); | ||
SSLContext(const SSLContext& other); | ||
SSLContext(SSLContext&& other); | ||
~SSLContext(); | ||
|
||
SSLContext& operator=(const SSLContext& other); | ||
SSLContext& operator=(SSLContext&& other); | ||
|
||
/// @brief Gets access to the underlying C SSL context handle. | ||
void* getNativeHandle() const; | ||
}; | ||
|
||
}; // namespace crypto | ||
}; // namespace iggy |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"ada-url", | ||
"catch2", | ||
"icu", | ||
"fmt", | ||
"libsodium", | ||
"libuv", | ||
"reproc", | ||
|