laforge submitted this change.

View Change

Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve
eim_cfg: insert eIM ESipa SSL CA-certificate into eIM configuration

The EimConfigurationData prvides a field to pin a CA-certificate that
allows the IPAd to validate the SSL certificate used on the ESipa
interface. If the ESipa SSL certificate is valid, the IPAd can be
sure that it is talking to the its trusted eIM and not to some
malicious entity.

Change-Id: I4f985902b5f9ad88075b16151d38dd5382f17668
Related: SYS#8287
---
M config/sys.config
M config/sys.dev.config
M src/crypto_utils.erl
M src/eim_cfg.erl
M src/onomondo_eim_app.erl
5 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/config/sys.config b/config/sys.config
index 6e8c2d2..8253e80 100644
--- a/config/sys.config
+++ b/config/sys.config
@@ -3,6 +3,7 @@
{esipa_ip, {127, 0, 0, 1}},
{esipa_port, 8000},
{esipa_ssl_disable, false},
+ {esipa_ssl_ca_cert, "sample_esipa_ssl_ca_cert_nist.crt"},
{esipa_ssl_cert, "sample_esipa_ssl_cert_nist.crt"},
{esipa_ssl_key, "sample_esipa_ssl_cert_nist.key"},
{rest_ip, {127, 0, 0, 1}},
diff --git a/config/sys.dev.config b/config/sys.dev.config
index 4e702f5..9a963f9 100644
--- a/config/sys.dev.config
+++ b/config/sys.dev.config
@@ -3,6 +3,7 @@
{esipa_ip, {127, 0, 0, 1}},
{esipa_port, 8000},
{esipa_ssl_disable, true},
+ {esipa_ssl_ca_cert, "sample_esipa_ssl_ca_cert_nist.crt"},
{esipa_ssl_cert, "sample_esipa_ssl_cert_nist.crt"},
{esipa_ssl_key, "sample_esipa_ssl_cert_nist.key"},
{rest_ip, {127, 0, 0, 1}},
diff --git a/src/crypto_utils.erl b/src/crypto_utils.erl
index ee7e6d3..b2bced5 100644
--- a/src/crypto_utils.erl
+++ b/src/crypto_utils.erl
@@ -12,7 +12,8 @@
verify_euiccPackageErrorSigned/2,
store_euicc_pubkey_from_authenticateResponseOk/2,
store_euicc_pubkey_from_ipaEuiccDataResponse/2,
- test_eim_certificate/0
+ test_eim_certificate/0,
+ test_esipa_ssl_certificate/0
]).

%Convert from DER encoded signature format to plain format (see also BSI TR03111 5.2.1)
@@ -355,3 +356,26 @@
true ->
ok
end.
+
+% Make sure the configured ESipa SSL certificate is valid against the provided CA certificate. This is to confirm that
+% the CA certificate, which is provided in the eIM configuration (REST API) matches to the sub certificate used on the
+% ESipa interface.
+test_esipa_ssl_certificate() ->
+ {ok, EsipaSslCaCertPath} = utils:get_env_priv_file_path(onomondo_eim, esipa_ssl_ca_cert),
+ {ok, EsipaSslCaCertPem} = file:read_file(EsipaSslCaCertPath),
+ [{'Certificate', EsipaSslCaCertBer, not_encrypted}] = public_key:pem_decode(EsipaSslCaCertPem),
+ {ok, EsipaSslCaCert} = 'PKIX1Explicit88':decode('Certificate', EsipaSslCaCertBer),
+
+ {ok, EsipaSslCertPath} = utils:get_env_priv_file_path(onomondo_eim, esipa_ssl_cert),
+ {ok, EsipaSslCertPem} = file:read_file(EsipaSslCertPath),
+ [{'Certificate', EsipaSslCertBer, not_encrypted}] = public_key:pem_decode(EsipaSslCertPem),
+ {ok, EsipaSslCert} = 'PKIX1Explicit88':decode('Certificate', EsipaSslCertBer),
+ Result = verify_cert(EsipaSslCaCert, EsipaSslCert),
+ case Result of
+ ok ->
+ ok;
+ _ ->
+ throw(
+ "eIM ESipa SSL certificate not valid against CA certificate, check certificates (sys.config)!~n"
+ )
+ end.
diff --git a/src/eim_cfg.erl b/src/eim_cfg.erl
index b4754d7..54cb278 100644
--- a/src/eim_cfg.erl
+++ b/src/eim_cfg.erl
@@ -37,6 +37,15 @@

EimCertSubjectPublicKeyInfo.

+% Load the trustedCertificateTls from the configured ESipa SSL certificate (see sys.config).
+get_trustedCertificateTls() ->
+ % Load ESipa SSL certificate and extract public key.
+ {ok, EimCertPath} = utils:get_env_priv_file_path(onomondo_eim, esipa_ssl_ca_cert),
+ {ok, EimCertPem} = file:read_file(EimCertPath),
+ [{'Certificate', EimCertBer, not_encrypted}] = public_key:pem_decode(EimCertPem),
+ {ok, EimCert} = 'PKIX1Explicit88':decode('Certificate', EimCertBer),
+ EimCert.
+
% Generate an encoded eIM configuration string, which can be used to program the eIM configuration into an eUICC,
% either via ES10b:AddInitialEim or ESep:addEim (eUICC package, eCO). The Format parameter selects how the output data
% shall be formatted. Two formats are possible: request: AddInitialEimRequest, single: EimConfigurationData
@@ -45,6 +54,7 @@
{ok, EimFqdn} = application:get_env(onomondo_eim, eim_fqdn),
EimCertSubjectPublicKeyInfo = get_eimPublicKey_from_eim_cert(),
{ok, CounterValue} = application:get_env(onomondo_eim, counter_value),
+ EsipaSslCaCert = get_trustedCertificateTls(),

% Generate eIM configuration
EimConfigurationData = #{
@@ -59,6 +69,8 @@
associationToken => -1,
% Mandatory
eimPublicKeyData => {eimPublicKey, EimCertSubjectPublicKeyInfo},
+ % Optional: Pin the ESipa SSL/TLS certificate of the eIM. The certificate is identified by its public key
+ trustedPublicKeyDataTls => {trustedCertificateTls, EsipaSslCaCert},
% This eIM implementation currently only supports ESipa via HTTPs where the only supported eIM Package
% transfer procedure is the eIM Package Retrieval procedure (see also SGP.32, section 3.1.1.1.
eimSupportedProtocol => [eimRetrieveHttps],
diff --git a/src/onomondo_eim_app.erl b/src/onomondo_eim_app.erl
index 227c938..acdfefb 100644
--- a/src/onomondo_eim_app.erl
+++ b/src/onomondo_eim_app.erl
@@ -107,6 +107,9 @@
% Ensure that the key material that is used for signing PSMOs and eCOs is correctly configured and valid.
crypto_utils:test_eim_certificate(),

+ % Ensure that the SSL/TLS certificate used on the ESipa interface is valid against its CA certificate
+ crypto_utils:test_esipa_ssl_certificate(),
+
% Startup database
ok = mnesia_db:init(),

To view, visit change 44062. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: onomondo-eim
Gerrit-Branch: master
Gerrit-Change-Id: I4f985902b5f9ad88075b16151d38dd5382f17668
Gerrit-Change-Number: 44062
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>