laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
es9p_client: make asn.1 encoder/decoder functions more flexible

The encoder and decoder functions we currently use have the spec
name hardcoded in the function body. Let's change the functions
so that we have the spec name as a parameter for more flexibility

Related: SYS#8100
Change-Id: Idfb280d3863998dd0387c65c478d9c765eadf106
---
M src/es9p_client.erl
1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/src/es9p_client.erl b/src/es9p_client.erl
index 9bf3856..ac89456 100644
--- a/src/es9p_client.erl
+++ b/src/es9p_client.erl
@@ -157,17 +157,14 @@
{ok, 503, ""}
end.

-% encode RSP ASN.1 data of given type + base64-encode it
-rsp_enc_asn1_b64(TypeName, Data) ->
- {ok, Bin} = 'RSPDefinitions':encode(TypeName, Data),
+% encode ASN.1 data of given type + base64-encode it
+enc_asn1_b64(SpecName, TypeName, Data) ->
+ {ok, Bin} = SpecName:encode(TypeName, Data),
base64:encode(Bin).

-% base64-decode and RSP ASN.1 decode data of given type
-rsp_dec_b64_asn1(TypeName, Data) ->
- {ok, Dec} = 'RSPDefinitions':decode(TypeName, base64:decode(Data)),
- Dec.
-pki_dec_b64_asn1(TypeName, Data) ->
- {ok, Dec} = 'PKIX1Explicit88':decode(TypeName, base64:decode(Data)),
+% base64-decode and ASN.1 decode data of given type
+dec_asn1_b64(SpecName, TypeName, Data) ->
+ {ok, Dec} = SpecName:decode(TypeName, base64:decode(Data)),
Dec.

% convert from RemoteProfileProvisioningRequest to weird ASN.1-base64-in-JSON
@@ -182,7 +179,9 @@
Json = #{
<<"euiccChallenge">> => base64:encode(maps:get(euiccChallenge, InitAuthReq)),
<<"smdpAddress">> => maps:get(smdpAddress, InitAuthReq),
- <<"euiccInfo1">> => rsp_enc_asn1_b64('EUICCInfo1', maps:get(euiccInfo1, InitAuthReq))
+ <<"euiccInfo1">> => enc_asn1_b64(
+ 'RSPDefinitions', 'EUICCInfo1', maps:get(euiccInfo1, InitAuthReq)
+ )
},

{ok, _HtppStatus, JsonResp} = make_req_json(BaseUrl, "initiateAuthentication", Json),
@@ -195,14 +194,17 @@
} ->
R = #{
transactionId => utils:hex_to_binary(maps:get(<<"transactionId">>, JsonResp)),
- serverSigned1 => rsp_dec_b64_asn1(
- 'ServerSigned1', maps:get(<<"serverSigned1">>, JsonResp)
+ serverSigned1 => dec_asn1_b64(
+ 'RSPDefinitions',
+ 'ServerSigned1',
+ maps:get(<<"serverSigned1">>, JsonResp)
),
serverSignature1 => base64:decode(maps:get(<<"serverSignature1">>, JsonResp)),
euiccCiPKIdToBeUsed => base64:decode(
maps:get(<<"euiccCiPKIdToBeUsed">>, JsonResp)
),
- serverCertificate => pki_dec_b64_asn1(
+ serverCertificate => dec_asn1_b64(
+ 'PKIX1Explicit88',
'Certificate',
maps:get(
<<"serverCertificate">>,
@@ -222,7 +224,8 @@
request_json({authenticateClientRequest, AuthClientReq}, BaseUrl) ->
Json = #{
<<"transactionId">> => utils:binary_to_hex(maps:get(transactionId, AuthClientReq)),
- <<"authenticateServerResponse">> => rsp_enc_asn1_b64(
+ <<"authenticateServerResponse">> => enc_asn1_b64(
+ 'RSPDefinitions',
'AuthenticateServerResponse',
maps:get(authenticateServerResponse, AuthClientReq)
)
@@ -237,18 +240,22 @@
} ->
R = #{
transactionId => utils:hex_to_binary(maps:get(<<"transactionId">>, JsonResp)),
- profileMetaData => rsp_dec_b64_asn1(
+ profileMetaData => dec_asn1_b64(
+ 'RSPDefinitions',
'StoreMetadataRequest',
maps:get(
<<"profileMetadata">>,
JsonResp
)
),
- smdpSigned2 => rsp_dec_b64_asn1(
- 'SmdpSigned2', maps:get(<<"smdpSigned2">>, JsonResp)
+ smdpSigned2 => dec_asn1_b64(
+ 'RSPDefinitions',
+ 'SmdpSigned2',
+ maps:get(<<"smdpSigned2">>, JsonResp)
),
smdpSignature2 => base64:decode(maps:get(<<"smdpSignature2">>, JsonResp)),
- smdpCertificate => pki_dec_b64_asn1(
+ smdpCertificate => dec_asn1_b64(
+ 'PKIX1Explicit88',
'Certificate',
maps:get(<<"smdpCertificate">>, JsonResp)
)
@@ -263,7 +270,8 @@
request_json({getBoundProfilePackageRequest, GetBppReq}, BaseUrl) ->
Json = #{
<<"transactionId">> => utils:binary_to_hex(maps:get(transactionId, GetBppReq)),
- <<"prepareDownloadResponse">> => rsp_enc_asn1_b64(
+ <<"prepareDownloadResponse">> => enc_asn1_b64(
+ 'RSPDefinitions',
'PrepareDownloadResponse',
maps:get(prepareDownloadResponse, GetBppReq)
)
@@ -278,7 +286,8 @@
} ->
R = #{
transactionId => utils:hex_to_binary(maps:get(<<"transactionId">>, JsonResp)),
- boundProfilePackage => rsp_dec_b64_asn1(
+ boundProfilePackage => dec_asn1_b64(
+ 'RSPDefinitions',
'BoundProfilePackage',
maps:get(<<"boundProfilePackage">>, JsonResp)
)
@@ -293,7 +302,8 @@
request_json({cancelSessionRequestEs9, CancelSessReq}, BaseUrl) ->
Json = #{
<<"transactionId">> => utils:binary_to_hex(maps:get(transactionId, CancelSessReq)),
- <<"cancelSessionResponse">> => rsp_enc_asn1_b64(
+ <<"cancelSessionResponse">> => enc_asn1_b64(
+ 'RSPDefinitions',
'CancelSessionResponse',
maps:get(cancelSessionResponse, CancelSessReq)
)
@@ -316,7 +326,8 @@
% GSMA SGP.22, section 6.5.2.9 and section 6.6.2.4
request_json({handleNotification, HandleNotifReq}, BaseUrl) ->
Json = #{
- <<"pendingNotification">> => rsp_enc_asn1_b64(
+ <<"pendingNotification">> => enc_asn1_b64(
+ 'RSPDefinitions',
'PendingNotification',
maps:get(pendingNotification, HandleNotifReq)
)

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

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