forked from EVerest/everest-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TPM2 support for EvseV2G TLS server private key (EVerest#1021)
* feat: add TPM2 support for EvseV2G TLS server private key Note arbitrary sign/verify is not currently supported in the OpenSSL utility layer (openssl_util.cpp) TPM2 support requires -DUSING_TPM2 to cmake Signed-off-by: James Chapman <[email protected]> * fix: added comment to explain resetting the global provider settings Signed-off-by: James Chapman <[email protected]> --------- Signed-off-by: James Chapman <[email protected]>
- Loading branch information
Showing
10 changed files
with
266 additions
and
29 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
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
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,57 @@ | ||
#!/bin/sh | ||
|
||
base=. | ||
cfg=./openssl-pki.conf | ||
dir=tpm_pki | ||
|
||
[ ! -f "$cfg" ] && echo "missing openssl-pki.conf" && exit 1 | ||
|
||
generate() { | ||
local base=$1 | ||
local dir=$2 | ||
mkdir -p ${base}/${dir} | ||
|
||
local root_priv=${base}/${dir}/server_root_priv.pem | ||
local ca_priv=${base}/${dir}/server_ca_priv.pem | ||
local server_priv=${base}/${dir}/server_priv.pem | ||
|
||
local root_cert=${base}/${dir}/server_root_cert.pem | ||
local ca_cert=${base}/${dir}/server_ca_cert.pem | ||
local server_cert=${base}/${dir}/server_cert.pem | ||
local cert_path=${base}/${dir}/server_chain.pem | ||
|
||
local tpmA="-provider" | ||
local tpmB="tpm2" | ||
local propA="-propquery" | ||
local propB="?provider=tpm2" | ||
|
||
# generate keys | ||
for i in ${root_priv} ${ca_priv} ${server_priv} | ||
do | ||
openssl genpkey -config ${cfg} ${tpmA} ${tpmB} ${propA} ${propB} -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out $i | ||
done | ||
|
||
export OPENSSL_CONF=${cfg} | ||
# generate root cert | ||
echo "Generate root" | ||
openssl req ${tpmA} ${tpmB} -provider default ${propA} ${propB} \ | ||
-config ${cfg} -x509 -section req_server_root -extensions v3_server_root \ | ||
-key ${root_priv} -out ${root_cert} | ||
# generate ca cert | ||
echo "Generate ca" | ||
openssl req ${tpmA} ${tpmB} -provider default ${propA} ${propB} \ | ||
-config ${cfg} -x509 -section req_server_ca -extensions v3_server_ca \ | ||
-key ${ca_priv} -CA ${root_cert} \ | ||
-CAkey ${root_priv} -out ${ca_cert} | ||
# generate server cert | ||
echo "Generate server" | ||
openssl req ${tpmA} ${tpmB} -provider default ${propA} ${propB} \ | ||
-config ${cfg} -x509 -section req_server -extensions v3_server \ | ||
-key ${server_priv} -CA ${ca_cert} \ | ||
-CAkey ${ca_priv} -out ${server_cert} | ||
|
||
# create bundle | ||
cat ${server_cert} ${ca_cert} > ${cert_path} | ||
} | ||
|
||
generate $base $dir |
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
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,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Pionix GmbH and Contributors to EVerest | ||
|
||
#include "tls_connection_test.hpp" | ||
#include <openssl_util.hpp> | ||
|
||
#include <memory> | ||
#include <mutex> | ||
#include <poll.h> | ||
|
||
using namespace std::chrono_literals; | ||
|
||
namespace { | ||
using result_t = tls::Connection::result_t; | ||
using tls::status_request::ClientStatusRequestV2; | ||
|
||
constexpr auto server_root_CN = "00000000"; | ||
constexpr auto alt_server_root_CN = "11111111"; | ||
constexpr auto WAIT_FOR_SERVER_START_TIMEOUT = 50ms; | ||
|
||
// ---------------------------------------------------------------------------- | ||
// The tests | ||
|
||
TEST_F(TlsTestTpm, StartConnectDisconnect) { | ||
start(); | ||
connect(); | ||
// no status requested | ||
EXPECT_TRUE(is_set(flags_t::connected)); | ||
EXPECT_TRUE(is_reset(flags_t::status_request_cb)); | ||
EXPECT_TRUE(is_reset(flags_t::status_request)); | ||
EXPECT_TRUE(is_reset(flags_t::status_request_v2)); | ||
} | ||
|
||
} // namespace |
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
Oops, something went wrong.