dexter has submitted this change. ( https://gerrit.osmocom.org/c/onomondo-eim/+/42951?usp=email )
Change subject: esipa_asn1_handler: use eimTransactionId for ipaEuiccDataResponse ......................................................................
esipa_asn1_handler: use eimTransactionId for ipaEuiccDataResponse
The ipaEuiccDataResponse does currently not use the eimTransactionId, which was added with SGP.32 V.1.2, let's make use of the eimTransactionId and move the handler functionality to a dedicated helper function in esipa_asn_handler_utils.
Change-Id: Ie414eef7fd5c8928dd611503f4dd8d67322c0e80 Related: SYS#8100 --- M src/esipa_asn1_handler.erl M src/esipa_asn1_handler_utils.erl M src/esipa_rest_utils.erl 3 files changed, 40 insertions(+), 13 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified dexter: Looks good to me, approved
diff --git a/src/esipa_asn1_handler.erl b/src/esipa_asn1_handler.erl index 8b9300a..867a326 100644 --- a/src/esipa_asn1_handler.erl +++ b/src/esipa_asn1_handler.erl @@ -341,7 +341,11 @@ }} end; {edr, Order} -> - IpaEuiccDataRequest = esipa_rest_utils:edr_order_to_ipaEuiccDataRequest(Order), + EimTransactionId = rand:bytes(16), + mnesia_db_work:bind(Pid, EimTransactionId), + IpaEuiccDataRequest = esipa_rest_utils:edr_order_to_ipaEuiccDataRequest( + Order, EimTransactionId + ), case IpaEuiccDataRequest of error -> ok = mnesia_db_work:finish( @@ -383,13 +387,9 @@ || PendingNotification <- NotificationList ]; {ipaEuiccDataResponse, IpaEuiccDataResponse} -> - % drive-by store the eUICC public key so that we can use it later to sign PSMOs or eCOs - {EidValue, _, _} = mnesia_db_work:pickup(Pid, none), - crypto_utils:store_euicc_pubkey_from_ipaEuiccDataResponse( - IpaEuiccDataResponse, EidValue - ), - Outcome = esipa_rest_utils:ipaEuiccDataResponse_to_outcome(IpaEuiccDataResponse), - ok = mnesia_db_work:finish(Pid, Outcome, EsipaReq); + ok = esipa_asn1_handler_utils:handle_ipaEuiccDataResponse( + Pid, IpaEuiccDataResponse, EsipaReq + ); {profileDownloadTriggerResult, _} -> % The profileDownloadTriggerResult is sent by the IPAd in case a profile was downloaded directly from an % RSP server, bypassing the eIM (see also SGP.32, section 3.2.3.1). This is a feature that this eIM does diff --git a/src/esipa_asn1_handler_utils.erl b/src/esipa_asn1_handler_utils.erl index 8ad9cb6..9db1f41 100644 --- a/src/esipa_asn1_handler_utils.erl +++ b/src/esipa_asn1_handler_utils.erl @@ -6,7 +6,7 @@
-module(esipa_asn1_handler_utils).
--export([handle_euiccPackageResult/3]). +-export([handle_euiccPackageResult/3, handle_ipaEuiccDataResponse/3]).
eimTransactionId_from_euiccPackageResult(EuiccPackageResult) -> case EuiccPackageResult of @@ -26,6 +26,16 @@ none end.
+eimTransactionId_from_ipaEuiccDataResponse(IpaEuiccDataResponse) -> + case IpaEuiccDataResponse of + {ipaEuiccData, IpaEuiccData} -> + maps:get(eimTransactionId, IpaEuiccData, none); + {ipaEuiccDataResponseError, IpaEuiccDataResponseError} -> + maps:get(eimTransactionId, IpaEuiccDataResponseError, none); + _ -> + none + end. + process_euiccPackageResult(Pid, EuiccPackageResult, Debuginfo, EimTransactionId) -> WorkBind = fun(Map) -> case maps:find(eimTransactionId, Map) of @@ -100,3 +110,16 @@ Pid, [{[{procedureError, euiccSignatureInvalid}]}], Debuginfo ) end. + +% Handle an IpaEuiccDataResponse, this includes everything from the handling of the work items in mnesia_db as well +% as the generation of an appropriate outcome for the REST API. In case IpaEuiccDataResponse contains an eUICC public +% key, we will automatically store it so that we can use it to check the signatures of PSMOs and eCOs. +handle_ipaEuiccDataResponse(Pid, IpaEuiccDataResponse, Debuginfo) -> + EimTransactionId = eimTransactionId_from_ipaEuiccDataResponse(IpaEuiccDataResponse), + {EidValue, _, _} = mnesia_db_work:pickup(Pid, EimTransactionId), + + % drive-by store the eUICC public key so that we can use it later to check the signatures of PSMOs or eCOs + crypto_utils:store_euicc_pubkey_from_ipaEuiccDataResponse(IpaEuiccDataResponse, EidValue), + + Outcome = esipa_rest_utils:ipaEuiccDataResponse_to_outcome(IpaEuiccDataResponse), + mnesia_db_work:finish(Pid, Outcome, Debuginfo). diff --git a/src/esipa_rest_utils.erl b/src/esipa_rest_utils.erl index 6a52f10..3b16492 100644 --- a/src/esipa_rest_utils.erl +++ b/src/esipa_rest_utils.erl @@ -12,7 +12,7 @@ euiccPackageResultDataSigned_to_outcome/1, profileInstallationResult_to_outcome/1, cancelSessionResponse_to_outcome/1, - edr_order_to_ipaEuiccDataRequest/1, + edr_order_to_ipaEuiccDataRequest/2, ipaEuiccDataResponse_to_outcome/1 ]).
@@ -510,11 +510,15 @@ end.
% Generate an ipaEuiccDataRequest from a eDR Order (JSON REST API) -edr_order_to_ipaEuiccDataRequest(Order) -> - % TODO: also add support for the two optional parameters SubjectKeyIdentifier and searchCriteria +edr_order_to_ipaEuiccDataRequest(Order, EimTransactionId) -> + % TODO: also add support for the two optional parameters euiccCiPKIdentifierToBeUsed, searchCriteriaNotification, + % and searchCriteriaEuiccPackageResult. case Order of {[{<<"edr">>, {[{<<"tagList">>, TagList}]}}]} -> - {ipaEuiccDataRequest, #{tagList => utils:hex_to_binary(TagList)}}; + {ipaEuiccDataRequest, #{ + tagList => utils:hex_to_binary(TagList), + eimTransactionId => EimTransactionId + }}; _ -> error end.