dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39656?usp=email )
Change subject: es9p_Types_JSON: add decoder/encoder functions for opposite direction ......................................................................
es9p_Types_JSON: add decoder/encoder functions for opposite direction
We currently only have ES9p encoder/decoder functions to emulate an ES9p server, however, we will need to emulate ES9p clients too
Change-Id: Ic7e3390bd09cc9e0c91ca90ac60cdde5d2ce1384 Related: SYS#7339 --- M library/euicc/es9p_Types_JSON.ttcn 1 file changed, 88 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/56/39656/1
diff --git a/library/euicc/es9p_Types_JSON.ttcn b/library/euicc/es9p_Types_JSON.ttcn index 79d5381..601ea8f 100644 --- a/library/euicc/es9p_Types_JSON.ttcn +++ b/library/euicc/es9p_Types_JSON.ttcn @@ -163,6 +163,94 @@ } } with { extension "prototype(fast)" }
+/* Converter function to encode an ASN.1 ES9+ request record to its JSON formatted ES9+ representation */ +function enc_RemoteProfileProvisioningRequest_to_JSON(in RemoteProfileProvisioningRequest asn1_pdu_dec, out charstring json_pdu_enc) { + var JSON_ES9p_RemoteProfileProvisioningRequest json_pdu; + + var charstring functionRequesterIdentifier := "TTCN3"; + var charstring functionCallIdentifier := "testsuite"; + + if (ispresent(asn1_pdu_dec.initiateAuthenticationRequest)) { + json_pdu.initiateAuthenticationRequest.header.functionRequesterIdentifier := functionRequesterIdentifier; + json_pdu.initiateAuthenticationRequest.header.functionCallIdentifier := functionCallIdentifier; + json_pdu.initiateAuthenticationRequest.euiccChallenge := encode_base64(asn1_pdu_dec.initiateAuthenticationRequest.euiccChallenge); + json_pdu.initiateAuthenticationRequest.smdpAddress := unichar2char(asn1_pdu_dec.initiateAuthenticationRequest.smdpAddress); + json_pdu.initiateAuthenticationRequest.euiccInfo1 := encode_base64(enc_EUICCInfo1(asn1_pdu_dec.initiateAuthenticationRequest.euiccInfo1)); + json_pdu_enc := oct2char(enc_JSON_ES9p_RemoteProfileProvisioningRequest(json_pdu)); + } else if (ispresent(asn1_pdu_dec.getBoundProfilePackageRequest)) { + json_pdu.getBoundProfilePackageRequest.header.functionRequesterIdentifier := functionRequesterIdentifier; + json_pdu.getBoundProfilePackageRequest.header.functionCallIdentifier := functionCallIdentifier; + json_pdu.getBoundProfilePackageRequest.transactionId := oct2str(asn1_pdu_dec.getBoundProfilePackageRequest.transactionId); + json_pdu.getBoundProfilePackageRequest.prepareDownloadResponse := + encode_base64(enc_PrepareDownloadResponse(asn1_pdu_dec.getBoundProfilePackageRequest.prepareDownloadResponse)); + json_pdu_enc := oct2char(enc_JSON_ES9p_RemoteProfileProvisioningRequest(json_pdu)); + } else if (ispresent(asn1_pdu_dec.authenticateClientRequest)) { + json_pdu.authenticateClientRequest.header.functionRequesterIdentifier := functionRequesterIdentifier; + json_pdu.authenticateClientRequest.header.functionCallIdentifier := functionCallIdentifier; + json_pdu.authenticateClientRequest.transactionId := oct2str(asn1_pdu_dec.authenticateClientRequest.transactionId); + json_pdu.authenticateClientRequest.authenticateServerResponse := + encode_base64(enc_AuthenticateServerResponse(asn1_pdu_dec.authenticateClientRequest.authenticateServerResponse)) + json_pdu_enc := oct2char(enc_JSON_ES9p_RemoteProfileProvisioningRequest(json_pdu)); + } else if (ispresent(asn1_pdu_dec.handleNotification)) { + json_pdu.handleNotification.header.functionRequesterIdentifier := functionRequesterIdentifier; + json_pdu.handleNotification.header.functionCallIdentifier := functionCallIdentifier; + json_pdu.handleNotification.pendingNotification := + encode_base64(enc_PendingNotification(asn1_pdu_dec.handleNotification.pendingNotification)) + json_pdu_enc := oct2char(enc_JSON_ES9p_RemoteProfileProvisioningRequest(json_pdu)); + } else if (ispresent(asn1_pdu_dec.cancelSessionRequestEs9)) { + json_pdu.cancelSessionRequestEs9.header.functionRequesterIdentifier := functionRequesterIdentifier; + json_pdu.cancelSessionRequestEs9.header.functionCallIdentifier := functionCallIdentifier; + json_pdu.cancelSessionRequestEs9.transactionId := oct2str(asn1_pdu_dec.cancelSessionRequestEs9.transactionId); + json_pdu.cancelSessionRequestEs9.cancelSessionResponse := + encode_base64(enc_CancelSessionResponse(asn1_pdu_dec.cancelSessionRequestEs9.cancelSessionResponse)) + json_pdu_enc := oct2char(enc_JSON_ES9p_RemoteProfileProvisioningRequest(json_pdu)); + } else { + setverdict(fail, "encoder path not implemented for JSON ES9+ message"); + } +} with { extension "prototype(fast)" } + +/* Converter function to decode a JSON formatted ES9+ response to its ASN.1 ES9+ record representation */ +function dec_RemoteProfileProvisioningResponse_from_JSON(in charstring json_pdu_enc, out RemoteProfileProvisioningResponse asn1_pdu_dec) { + var JSON_ES9p_RemoteProfileProvisioningResponse json_pdu; + json_pdu := dec_JSON_ES9p_RemoteProfileProvisioningResponse(char2oct(json_pdu_enc)); + + if (ispresent(json_pdu.initiateAuthenticationResponse)) { + if (not match(json_pdu.initiateAuthenticationResponse.header, ts_responseHeader)) { + setverdict(fail, "unsuccessful request"); + } + asn1_pdu_dec := valueof(ts_initiateAuthenticationResponse( + str2oct(json_pdu.initiateAuthenticationResponse.transactionId), + dec_ServerSigned1(decode_base64(json_pdu.initiateAuthenticationResponse.serverSigned1)), + decode_base64(json_pdu.initiateAuthenticationResponse.serverSignature1), + dec_SubjectKeyIdentifier(decode_base64(json_pdu.initiateAuthenticationResponse.euiccCiPKIdToBeUsed)), + dec_Certificate(decode_base64(json_pdu.initiateAuthenticationResponse.serverCertificate)))); + } else if (ispresent(json_pdu.getBoundProfilePackageResponse)) { + if (not match(json_pdu.getBoundProfilePackageResponse.header, ts_responseHeader)) { + setverdict(fail, "unsuccessful request"); + } + asn1_pdu_dec := valueof(ts_getBoundProfilePackageResponse( + str2oct(json_pdu.getBoundProfilePackageResponse.transactionId), + dec_BoundProfilePackage(decode_base64(json_pdu.getBoundProfilePackageResponse.boundProfilePackage)))); + } else if (ispresent(json_pdu.authenticateClientResponseEs9)) { + if (not match(json_pdu.authenticateClientResponseEs9.header, ts_responseHeader)) { + setverdict(fail, "unsuccessful request"); + } + asn1_pdu_dec := valueof(ts_authenticateClientResponseEs9( + str2oct(json_pdu.authenticateClientResponseEs9.transactionId), + dec_StoreMetadataRequest(decode_base64(json_pdu.authenticateClientResponseEs9.profileMetadata)), + dec_SmdpSigned2(decode_base64(json_pdu.authenticateClientResponseEs9.smdpSigned2)), + decode_base64(json_pdu.authenticateClientResponseEs9.smdpSignature2), + dec_Certificate(decode_base64(json_pdu.authenticateClientResponseEs9.smdpCertificate)))); + } else if (ispresent(json_pdu.emptyResponse)) { + if (not match(json_pdu.emptyResponse.header, ts_responseHeader)) { + setverdict(fail, "unsuccessful request"); + } + /* Empty response, do nothing? */ + } else { + setverdict(fail, "decoder path not implemented for JSON ES9+ message"); + } +} with { extension "prototype(fast)" } + /* Converter function to encode an ASN.1 ES9+ response record to its JSON formatted ES9+ representation */ function enc_RemoteProfileProvisioningResponse_to_JSON(in RemoteProfileProvisioningResponse asn1_pdu_dec, out charstring json_pdu_enc) { var JSON_ES9p_RemoteProfileProvisioningResponse json_pdu;