Skip to content

Commit

Permalink
[Source/cryptalgo/SecureSocketPort / Tests/unit/core] : Move 'IValida…
Browse files Browse the repository at this point in the history
…te' to 'CertificateStore'
  • Loading branch information
msieben committed Jan 8, 2025
1 parent cd54ba8 commit da99b1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Source/cryptalgo/SecureSocketPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,15 @@ int VerifyCallbackWrapper(int verifyStatus, X509_STORE_CTX* ctx)
X509* x509Cert = nullptr;
int exDataIndex = -1;
SSL* ssl = nullptr;
SecureSocketPort::IValidate* validator = nullptr;
CertificateStore::IValidate* validator = nullptr;

// Retrieve and call the registered callback

if ( ctx != nullptr
&& (exDataIndex = SSL_get_ex_data_X509_STORE_CTX_idx()) != -1
&& (ssl = static_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, exDataIndex))) != nullptr
&& (exDataIndex = ApplicationData::Instance().Index(static_cast<SSL*>(ssl))) != -1
&& (validator = static_cast<SecureSocketPort::IValidate*>(SSL_get_ex_data(ssl, exDataIndex))) != nullptr
&& (validator = static_cast<CertificateStore::IValidate*>(SSL_get_ex_data(ssl, exDataIndex))) != nullptr
&& (x509Cert = X509_STORE_CTX_get_current_cert(ctx)) != nullptr
) {
X509_up_ref(x509Cert);
Expand Down
19 changes: 9 additions & 10 deletions Source/cryptalgo/SecureSocketPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ namespace Crypto {

bool IsDefaultStore() const;

struct IValidate {
virtual ~IValidate() = default;

virtual bool Validate(const Certificate& certificate) const = 0;
};

protected:
operator const void* () const;

Expand All @@ -104,13 +110,6 @@ namespace Crypto {
};

class EXTERNAL SecureSocketPort : public Core::IResource {
public:
struct IValidate {
virtual ~IValidate() = default;

virtual bool Validate(const Certificate& certificate) const = 0;
};

private:
class EXTERNAL Handler : public Core::SocketPort {
private:
Expand Down Expand Up @@ -166,7 +165,7 @@ namespace Crypto {
void StateChange() override {
Update();
}
inline uint32_t Callback(IValidate* callback) {
inline uint32_t Callback(CertificateStore::IValidate* callback) {
uint32_t result = Core::ERROR_ILLEGAL_STATE;

Core::SocketPort::Lock();
Expand All @@ -193,7 +192,7 @@ namespace Crypto {
SecureSocketPort& _parent;
void* _context;
void* _ssl;
IValidate* _callback;
CertificateStore::IValidate* _callback;
mutable state _handShaking;
mutable Crypto::Certificate _certificate; // (PEM formatted ccertificate (chain)
mutable Crypto::Key _privateKey; // (PEM formatted) private key
Expand Down Expand Up @@ -278,7 +277,7 @@ namespace Crypto {
inline void Trigger() {
_handler.Trigger();
}
inline uint32_t Callback(IValidate* callback) {
inline uint32_t Callback(Crypto::CertificateStore::IValidate* callback) {
return (_handler.Callback(callback));
}
inline uint32_t Certificate(const Crypto::Certificate& certificate, const Crypto::Key& key) {
Expand Down
4 changes: 2 additions & 2 deletions Tests/unit/core/test_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace Core {
static constexpr char volatilePath[] = XSTR(VOLATILE_PATH);

// Validate client certificate
class Validator : public ::Thunder::Crypto::SecureSocketPort::IValidate {
class Validator : public ::Thunder::Crypto::CertificateStore::IValidate {
public:

Validator() = default;
Expand Down Expand Up @@ -539,7 +539,7 @@ namespace Core {
static constexpr char volatilePath[] = XSTR(VOLATILE_PATH);

// Validat eclient certificate
class Validator : public ::Thunder::Crypto::SecureSocketPort::IValidate {
class Validator : public ::Thunder::Crypto::CertificateStore::IValidate {
public:

Validator() = default;
Expand Down

0 comments on commit da99b1e

Please sign in to comment.