dexter has uploaded this change for review. ( 
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, 36 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/onomondo-eim refs/changes/51/42951/1

diff --git a/src/esipa_asn1_handler.erl b/src/esipa_asn1_handler.erl
index 466461f..943c8a8 100644
--- a/src/esipa_asn1_handler.erl
+++ b/src/esipa_asn1_handler.erl
@@ -341,7 +341,9 @@
                         }}
                 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(
@@ -379,13 +381,9 @@
             [handle_asn1(Pid, {handleNotificationEsipa, {pendingNotification, 
PendingNotification}}) ||
                 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 1b8039f..d350116 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
@@ -24,6 +24,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:is_key(eimTransactionId, Map) of
@@ -98,3 +108,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 e88c58b..4a3d1a3 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,13 @@
     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.

--
To view, visit https://gerrit.osmocom.org/c/onomondo-eim/+/42951?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: onomondo-eim
Gerrit-Branch: master
Gerrit-Change-Id: Ie414eef7fd5c8928dd611503f4dd8d67322c0e80
Gerrit-Change-Number: 42951
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>

Reply via email to