Skip to content

Commit

Permalink
feat: expose OpenSSL handles so that other code can create objects
Browse files Browse the repository at this point in the history
Previously X509HandleOpenSSL and KeyHandleOpenSSL were defined in
openssl_supplier.cpp this made it difficult to create Handles
from other OpenSSL code and use the methods in evse-security.

Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc committed Jun 6, 2024
1 parent 1ee9a96 commit f233237
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
36 changes: 36 additions & 0 deletions include/evse_security/detail/openssl/openssl_handles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once

#include <evse_security/crypto/interface/crypto_types.hpp>
#include <evse_security/detail/openssl/openssl_types.hpp>
#include <openssl/evp.h>
#include <openssl/x509.h>

namespace evse_security {

struct X509HandleOpenSSL : public X509Handle {
X509HandleOpenSSL(X509* certificate) : x509(certificate) {

Check notice on line 13 in include/evse_security/detail/openssl/openssl_handles.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/evse_security/detail/openssl/openssl_handles.hpp#L13

Struct 'X509HandleOpenSSL' has a constructor with 1 argument that is not explicit.
}

X509* get() {
return x509.get();
}

private:
X509_ptr x509;
};

struct KeyHandleOpenSSL : public KeyHandle {
KeyHandleOpenSSL(EVP_PKEY* key) : key(key) {

Check notice on line 25 in include/evse_security/detail/openssl/openssl_handles.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/evse_security/detail/openssl/openssl_handles.hpp#L25

Struct 'KeyHandleOpenSSL' has a constructor with 1 argument that is not explicit.
}

EVP_PKEY* get() {
return key.get();
}

private:
EVP_PKEY_ptr key;
};

} // namespace evse_security
25 changes: 1 addition & 24 deletions lib/evse_security/crypto/openssl/openssl_supplier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Pionix GmbH and Contributors to EVerest
#include <evse_security/crypto/openssl/openssl_supplier.hpp>

#include <evse_security/detail/openssl/openssl_handles.hpp>
#include <evse_security/detail/openssl/openssl_types.hpp>
#include <evse_security/utils/evse_filesystem.hpp>

Expand All @@ -26,30 +27,6 @@

namespace evse_security {

struct X509HandleOpenSSL : public X509Handle {
X509HandleOpenSSL(X509* certificate) : x509(certificate) {
}

X509* get() {
return x509.get();
}

private:
X509_ptr x509;
};

struct KeyHandleOpenSSL : public KeyHandle {
KeyHandleOpenSSL(EVP_PKEY* key) : key(key) {
}

EVP_PKEY* get() {
return key.get();
}

private:
EVP_PKEY_ptr key;
};

static X509* get(X509Handle* handle) {
if (X509HandleOpenSSL* ssl_handle = dynamic_cast<X509HandleOpenSSL*>(handle)) {
return ssl_handle->get();
Expand Down

0 comments on commit f233237

Please sign in to comment.