mirror of
https://github.com/estkme-group/lpac
synced 2024-07-02 14:56:39 +02:00
new es10b_LoadBoundProfilePackage
This commit is contained in:
parent
6c92f9cf76
commit
7e79cd30bb
474
euicc/es10b.c
474
euicc/es10b.c
|
@ -13,9 +13,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asn1c/asn1/BoundProfilePackage.h"
|
||||
#include "asn1c/asn1/ProfileInstallationResult.h"
|
||||
|
||||
int es10b_PrepareDownload(struct euicc_ctx *ctx, char **b64_PrepareDownloadResponse, struct es10b_prepare_download_param *param)
|
||||
{
|
||||
int fret = 0;
|
||||
|
@ -103,7 +100,7 @@ int es10b_PrepareDownload(struct euicc_ctx *ctx, char **b64_PrepareDownloadRespo
|
|||
|
||||
if (derutils_convert_bin2long(n_ccRequiredFlag.value, n_ccRequiredFlag.length))
|
||||
{
|
||||
if (!param->confirmationCode || strlen(param->confirmationCode) == 0)
|
||||
if ((!param->confirmationCode) || (strlen(param->confirmationCode) == 0))
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
@ -184,274 +181,237 @@ exit:
|
|||
return fret;
|
||||
}
|
||||
|
||||
int es10b_LoadBoundProfilePackage(struct euicc_ctx *ctx, const char *b64_BoundProfilePackage)
|
||||
static int es10b_load_bound_profile_package_tx(struct euicc_ctx *ctx, struct es10b_load_bound_profile_package_result *result, const uint8_t *reqbuf, int reqbuf_len)
|
||||
{
|
||||
int fret = 0, ret;
|
||||
uint8_t *bpp_buf = NULL;
|
||||
int bpp_len;
|
||||
uint8_t prefix_len;
|
||||
asn_dec_rval_t asn1drval_bpp;
|
||||
BoundProfilePackage_t *bpp_asn1 = NULL;
|
||||
asn_enc_rval_t asn1erval;
|
||||
uint8_t *reqbuf = NULL;
|
||||
int reqlen;
|
||||
uint8_t *ptrtmp;
|
||||
struct
|
||||
{
|
||||
uint8_t *buf;
|
||||
int len;
|
||||
} apdus[64];
|
||||
int apdus_count = 0;
|
||||
ProfileInstallationResult_t *asn1resp = NULL;
|
||||
int fret = 0;
|
||||
uint8_t *respbuf = NULL;
|
||||
unsigned resplen;
|
||||
|
||||
bpp_buf = malloc(euicc_base64_decode_len(b64_BoundProfilePackage));
|
||||
if (!bpp_buf)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
if ((bpp_len = euicc_base64_decode(bpp_buf, b64_BoundProfilePackage)) < 0)
|
||||
result->bppCommandId = ES10B_BPP_COMMAND_ID_UNDEFINED;
|
||||
result->errorReason = ES10B_ERROR_REASON_UNDEFINED;
|
||||
|
||||
if (es10x_command(ctx, &respbuf, &resplen, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
asn1drval_bpp = ber_decode(NULL, &asn_DEF_BoundProfilePackage, (void **)&bpp_asn1, bpp_buf, bpp_len);
|
||||
if (asn1drval_bpp.code != RC_OK)
|
||||
if (resplen > 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
struct derutils_node tmpnode, n_finalResult;
|
||||
|
||||
ret = euicc_derutil_tag_find(&ptrtmp, bpp_buf, bpp_len, NULL, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
prefix_len = ptrtmp - bpp_buf;
|
||||
|
||||
asn1erval = der_encode(&asn_DEF_InitialiseSecureChannelRequest, (void **)&bpp_asn1->initialiseSecureChannelRequest, NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded + prefix_len;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
memcpy(reqbuf, bpp_buf, prefix_len);
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_InitialiseSecureChannelRequest, &bpp_asn1->initialiseSecureChannelRequest, reqbuf + prefix_len, reqlen - prefix_len);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded + prefix_len;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
|
||||
asn1erval = der_encode(&asn_DEF_SeqBoundProfilePackageTLV87, &bpp_asn1->firstSequenceOf87, NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_SeqBoundProfilePackageTLV87, &bpp_asn1->firstSequenceOf87, reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
|
||||
asn1erval = der_encode(&asn_DEF_SeqBoundProfilePackageTLV88, &bpp_asn1->sequenceOf88, NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_SeqBoundProfilePackageTLV88, &bpp_asn1->sequenceOf88, reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
ret = euicc_derutil_tag_find(&ptrtmp, reqbuf, reqlen, NULL, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = ptrtmp - reqbuf;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
|
||||
for (int i = 0; i < bpp_asn1->sequenceOf88.list.count; i++)
|
||||
{
|
||||
asn1erval = der_encode(&asn_DEF_BoundProfilePackageTLV88, bpp_asn1->sequenceOf88.list.array[i], NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xBF37, respbuf, resplen) < 0) // ProfileInstallationResult
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xBF27, tmpnode.value, tmpnode.length) < 0) // ProfileInstallationResultData
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_BoundProfilePackageTLV88, bpp_asn1->sequenceOf88.list.array[i], reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xA2, tmpnode.value, tmpnode.length) < 0) // finalResult
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
}
|
||||
|
||||
if (bpp_asn1->secondSequenceOf87)
|
||||
{
|
||||
asn1erval = der_encode(&asn_DEF_SeqSecondBoundProfilePackageTLV87, bpp_asn1->secondSequenceOf87, NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
if (derutils_unpack_first(&n_finalResult, tmpnode.value, tmpnode.length) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
|
||||
switch (n_finalResult.tag)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_SeqSecondBoundProfilePackageTLV87, bpp_asn1->secondSequenceOf87, reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
}
|
||||
|
||||
asn1erval = der_encode(&asn_DEF_SeqBoundProfilePackageTLV86, &bpp_asn1->sequenceOf86, NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_SeqBoundProfilePackageTLV86, &bpp_asn1->sequenceOf86, reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
ret = euicc_derutil_tag_find(&ptrtmp, reqbuf, reqlen, NULL, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = ptrtmp - reqbuf;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
|
||||
for (int i = 0; i < bpp_asn1->sequenceOf86.list.count; i++)
|
||||
{
|
||||
asn1erval = der_encode(&asn_DEF_BoundProfilePackageTLV86, bpp_asn1->sequenceOf86.list.array[i], NULL, NULL);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
reqbuf = malloc(reqlen);
|
||||
if (!reqlen)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
asn1erval = der_encode_to_buffer(&asn_DEF_BoundProfilePackageTLV86, bpp_asn1->sequenceOf86.list.array[i], reqbuf, reqlen);
|
||||
if (asn1erval.encoded == -1)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
reqlen = asn1erval.encoded;
|
||||
|
||||
apdus[apdus_count].buf = reqbuf;
|
||||
apdus[apdus_count].len = reqlen;
|
||||
apdus_count++;
|
||||
reqbuf = NULL;
|
||||
}
|
||||
|
||||
// for (int i = 0; i < apdus_count; i++)
|
||||
// {
|
||||
// printf("APDU[%d]: ", i);
|
||||
// for (int j = 0; j < apdus[i].len; j++)
|
||||
// {
|
||||
// printf("%02X", apdus[i].buf[j]);
|
||||
// }
|
||||
// printf("\n");
|
||||
// }
|
||||
|
||||
for (int i = 0; i < apdus_count; i++)
|
||||
{
|
||||
uint8_t *respbuf = NULL;
|
||||
unsigned resplen = 0;
|
||||
asn_dec_rval_t asn1drval;
|
||||
|
||||
ret = es10x_command(ctx, &respbuf, &resplen, apdus[i].buf, apdus[i].len);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
if (resplen > 0)
|
||||
{
|
||||
asn1drval = ber_decode(NULL, &asn_DEF_ProfileInstallationResult, (void **)&asn1resp, respbuf, resplen);
|
||||
free(respbuf);
|
||||
respbuf = NULL;
|
||||
resplen = 0;
|
||||
if (asn1drval.code != RC_OK)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
if (asn1resp->profileInstallationResultData.finalResult.present != ProfileInstallationResultData__finalResult_PR_successResult)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
case 0xA0: // SuccessResult
|
||||
break;
|
||||
|
||||
case 0xA1: // ErrorResult
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0x80, n_finalResult.value, n_finalResult.length) == 0) // bppCommandId
|
||||
{
|
||||
int bppCommandId;
|
||||
|
||||
bppCommandId = derutils_convert_bin2long(tmpnode.value, tmpnode.length);
|
||||
|
||||
switch (bppCommandId)
|
||||
{
|
||||
case ES10B_BPP_COMMAND_ID_INITIALISE_SECURE_CHANNEL:
|
||||
case ES10B_BPP_COMMAND_ID_CONFIGURE_ISDP:
|
||||
case ES10B_BPP_COMMAND_ID_STORE_METADATA:
|
||||
case ES10B_BPP_COMMAND_ID_STORE_METADATA2:
|
||||
case ES10B_BPP_COMMAND_ID_REPLACE_SESSION_KEYS:
|
||||
case ES10B_BPP_COMMAND_ID_LOAD_PROFILE_ELEMENTS:
|
||||
result->bppCommandId = bppCommandId;
|
||||
break;
|
||||
default:
|
||||
result->bppCommandId = ES10B_BPP_COMMAND_ID_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0x81, n_finalResult.value, n_finalResult.length) == 0) // errorReason
|
||||
{
|
||||
int errorReason;
|
||||
|
||||
errorReason = derutils_convert_bin2long(tmpnode.value, tmpnode.length);
|
||||
|
||||
switch (errorReason)
|
||||
{
|
||||
case ES10B_ERROR_REASON_INCORRECT_INPUT_VALUES:
|
||||
case ES10B_ERROR_REASON_INVALID_SIGNATURE:
|
||||
case ES10B_ERROR_REASON_INVALID_TRANSACTION_ID:
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_CRT_VALUES:
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_REMOTE_OPERATION_TYPE:
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS:
|
||||
case ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR:
|
||||
case ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_MISMATCH:
|
||||
case ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY:
|
||||
case ES10B_ERROR_REASON_PPR_NOT_ALLOWED:
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR:
|
||||
result->errorReason = errorReason;
|
||||
break;
|
||||
default:
|
||||
result->errorReason = ES10B_ERROR_REASON_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto err;
|
||||
default:
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
fret = 0;
|
||||
goto exit;
|
||||
|
||||
err:
|
||||
fret = -1;
|
||||
exit:
|
||||
free(respbuf);
|
||||
respbuf = NULL;
|
||||
return fret;
|
||||
}
|
||||
|
||||
int es10b_LoadBoundProfilePackage(struct euicc_ctx *ctx, struct es10b_load_bound_profile_package_result *result, const char *b64_BoundProfilePackage)
|
||||
{
|
||||
int fret = 0;
|
||||
|
||||
uint8_t *bpp = NULL;
|
||||
int bpp_len;
|
||||
|
||||
const uint8_t *reqbuf;
|
||||
int reqbuf_len;
|
||||
|
||||
struct derutils_node tmpnode, tmpchildnode, n_BoundProfilePackage;
|
||||
|
||||
bpp = malloc(euicc_base64_decode_len(b64_BoundProfilePackage));
|
||||
if (!bpp)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
if ((bpp_len = euicc_base64_decode(bpp, b64_BoundProfilePackage)) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&n_BoundProfilePackage, 0xBF36, bpp, bpp_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xBF23, n_BoundProfilePackage.value, n_BoundProfilePackage.length) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
reqbuf = n_BoundProfilePackage.self.ptr;
|
||||
reqbuf_len = tmpnode.self.ptr - n_BoundProfilePackage.self.ptr + tmpnode.self.length;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xA0, n_BoundProfilePackage.value, n_BoundProfilePackage.length) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
reqbuf = tmpnode.self.ptr;
|
||||
reqbuf_len = tmpnode.self.length;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xA1, n_BoundProfilePackage.value, n_BoundProfilePackage.length) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
reqbuf = tmpnode.self.ptr;
|
||||
reqbuf_len = tmpnode.value - tmpnode.self.ptr;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
tmpchildnode.self.ptr = tmpnode.value;
|
||||
tmpchildnode.self.length = 0;
|
||||
|
||||
while (derutils_unpack_next(&tmpchildnode, &tmpchildnode, tmpnode.value, tmpnode.length) == 0)
|
||||
{
|
||||
reqbuf = tmpchildnode.self.ptr;
|
||||
reqbuf_len = tmpchildnode.self.length;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xA2, n_BoundProfilePackage.value, n_BoundProfilePackage.length) == 0)
|
||||
{
|
||||
reqbuf = tmpnode.self.ptr;
|
||||
reqbuf_len = tmpnode.self.length;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (derutils_unpack_find_tag(&tmpnode, 0xA3, n_BoundProfilePackage.value, n_BoundProfilePackage.length) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
reqbuf = tmpnode.self.ptr;
|
||||
reqbuf_len = tmpnode.value - tmpnode.self.ptr;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
tmpchildnode.self.ptr = tmpnode.value;
|
||||
tmpchildnode.self.length = 0;
|
||||
|
||||
while (derutils_unpack_next(&tmpchildnode, &tmpchildnode, tmpnode.value, tmpnode.length) == 0)
|
||||
{
|
||||
reqbuf = tmpchildnode.self.ptr;
|
||||
reqbuf_len = tmpchildnode.self.length;
|
||||
|
||||
if (es10b_load_bound_profile_package_tx(ctx, result, reqbuf, reqbuf_len) < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
free(respbuf);
|
||||
respbuf = NULL;
|
||||
resplen = 0;
|
||||
}
|
||||
|
||||
goto exit;
|
||||
|
@ -459,14 +419,8 @@ int es10b_LoadBoundProfilePackage(struct euicc_ctx *ctx, const char *b64_BoundPr
|
|||
err:
|
||||
fret = -1;
|
||||
exit:
|
||||
free(bpp_buf);
|
||||
free(reqbuf);
|
||||
for (int i = 0; i < apdus_count; i++)
|
||||
{
|
||||
free(apdus[i].buf);
|
||||
}
|
||||
ASN_STRUCT_FREE(asn_DEF_BoundProfilePackage, bpp_asn1);
|
||||
ASN_STRUCT_FREE(asn_DEF_ProfileInstallationResult, asn1resp);
|
||||
free(bpp);
|
||||
bpp = NULL;
|
||||
return fret;
|
||||
}
|
||||
|
||||
|
@ -648,16 +602,10 @@ int es10b_ListNotification(struct euicc_ctx *ctx, struct es10b_notification_meta
|
|||
switch (tmpnode.value[1])
|
||||
{
|
||||
case ES10B_PROFILE_MANAGEMENT_OPERATION_INSTALL:
|
||||
p->profileManagementOperation = ES10B_PROFILE_MANAGEMENT_OPERATION_INSTALL;
|
||||
break;
|
||||
case ES10B_PROFILE_MANAGEMENT_OPERATION_ENABLE:
|
||||
p->profileManagementOperation = ES10B_PROFILE_MANAGEMENT_OPERATION_ENABLE;
|
||||
break;
|
||||
case ES10B_PROFILE_MANAGEMENT_OPERATION_DISABLE:
|
||||
p->profileManagementOperation = ES10B_PROFILE_MANAGEMENT_OPERATION_DISABLE;
|
||||
break;
|
||||
case ES10B_PROFILE_MANAGEMENT_OPERATION_DELETE:
|
||||
p->profileManagementOperation = ES10B_PROFILE_MANAGEMENT_OPERATION_DELETE;
|
||||
p->profileManagementOperation = tmpnode.value[1];
|
||||
break;
|
||||
default:
|
||||
p->profileManagementOperation = ES10B_PROFILE_MANAGEMENT_OPERATION_UNDEFINED;
|
||||
|
|
|
@ -12,6 +12,44 @@ enum es10b_profile_management_operation
|
|||
ES10B_PROFILE_MANAGEMENT_OPERATION_UNDEFINED = 0xFF,
|
||||
};
|
||||
|
||||
enum es10b_bpp_command_id
|
||||
{
|
||||
ES10B_BPP_COMMAND_ID_INITIALISE_SECURE_CHANNEL = 0,
|
||||
ES10B_BPP_COMMAND_ID_CONFIGURE_ISDP = 1,
|
||||
ES10B_BPP_COMMAND_ID_STORE_METADATA = 2,
|
||||
ES10B_BPP_COMMAND_ID_STORE_METADATA2 = 3,
|
||||
ES10B_BPP_COMMAND_ID_REPLACE_SESSION_KEYS = 4,
|
||||
ES10B_BPP_COMMAND_ID_LOAD_PROFILE_ELEMENTS = 5,
|
||||
ES10B_BPP_COMMAND_ID_UNDEFINED = 0xFF,
|
||||
};
|
||||
|
||||
enum es10b_error_reason
|
||||
{
|
||||
ES10B_ERROR_REASON_INCORRECT_INPUT_VALUES = 1,
|
||||
ES10B_ERROR_REASON_INVALID_SIGNATURE = 2,
|
||||
ES10B_ERROR_REASON_INVALID_TRANSACTION_ID = 3,
|
||||
ES10B_ERROR_REASON_UNSUPPORTED_CRT_VALUES = 4,
|
||||
ES10B_ERROR_REASON_UNSUPPORTED_REMOTE_OPERATION_TYPE = 5,
|
||||
ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS = 6,
|
||||
ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR = 7,
|
||||
ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR = 8,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC = 9,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE = 10,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION = 11,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR = 12,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_MISMATCH = 13,
|
||||
ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY = 14,
|
||||
ES10B_ERROR_REASON_PPR_NOT_ALLOWED = 15,
|
||||
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR = 127,
|
||||
ES10B_ERROR_REASON_UNDEFINED = 0xFF,
|
||||
};
|
||||
|
||||
struct es10b_load_bound_profile_package_result
|
||||
{
|
||||
enum es10b_bpp_command_id bppCommandId;
|
||||
enum es10b_error_reason errorReason;
|
||||
};
|
||||
|
||||
struct es10b_prepare_download_param
|
||||
{
|
||||
const char *b64_profileMetadata;
|
||||
|
@ -64,7 +102,7 @@ struct es10b_cancel_session_param
|
|||
};
|
||||
|
||||
int es10b_PrepareDownload(struct euicc_ctx *ctx, char **b64_PrepareDownloadResponse, struct es10b_prepare_download_param *param);
|
||||
int es10b_LoadBoundProfilePackage(struct euicc_ctx *ctx, const char *b64_BoundProfilePackage);
|
||||
int es10b_LoadBoundProfilePackage(struct euicc_ctx *ctx, struct es10b_load_bound_profile_package_result *result, const char *b64_BoundProfilePackage);
|
||||
int es10b_GetEUICCChallenge(struct euicc_ctx *ctx, char **b64_euiccChallenge);
|
||||
int es10b_GetEUICCInfo(struct euicc_ctx *ctx, char **b64_EUICCInfo1);
|
||||
int es10b_ListNotification(struct euicc_ctx *ctx, struct es10b_notification_metadata_list **notificationMetadataList);
|
||||
|
|
|
@ -25,6 +25,8 @@ int es10c_GetProfilesInfo(struct euicc_ctx *ctx, struct es10c_profile_info_list
|
|||
|
||||
struct es10c_profile_info_list *list_wptr;
|
||||
|
||||
int tmpint;
|
||||
|
||||
*profileInfoList = NULL;
|
||||
|
||||
reqlen = sizeof(ctx->apdu_request_buffer.body);
|
||||
|
@ -86,13 +88,12 @@ int es10c_GetProfilesInfo(struct euicc_ctx *ctx, struct es10c_profile_info_list
|
|||
euicc_hexutil_bin2hex(p->isdpAid, sizeof(p->isdpAid), tmpnode.value, tmpnode.length);
|
||||
break;
|
||||
case 0x9F70:
|
||||
switch (derutils_convert_bin2long(tmpnode.value, tmpnode.length))
|
||||
tmpint = derutils_convert_bin2long(tmpnode.value, tmpnode.length);
|
||||
switch (tmpint)
|
||||
{
|
||||
case ES10C_PROFILE_STATE_DISABLED:
|
||||
p->profileState = ES10C_PROFILE_STATE_DISABLED;
|
||||
break;
|
||||
case ES10C_PROFILE_STATE_ENABLED:
|
||||
p->profileState = ES10C_PROFILE_STATE_ENABLED;
|
||||
p->profileState = tmpint;
|
||||
break;
|
||||
default:
|
||||
p->profileState = ES10C_PROFILE_STATE_UNDEFINED;
|
||||
|
@ -124,13 +125,12 @@ int es10c_GetProfilesInfo(struct euicc_ctx *ctx, struct es10c_profile_info_list
|
|||
}
|
||||
break;
|
||||
case 0x93:
|
||||
switch (derutils_convert_bin2long(tmpnode.value, tmpnode.length))
|
||||
tmpint = derutils_convert_bin2long(tmpnode.value, tmpnode.length);
|
||||
switch (tmpint)
|
||||
{
|
||||
case ES10C_ICON_TYPE_JPEG:
|
||||
p->iconType = ES10C_ICON_TYPE_JPEG;
|
||||
break;
|
||||
case ES10C_ICON_TYPE_PNG:
|
||||
p->iconType = ES10C_ICON_TYPE_PNG;
|
||||
p->iconType = tmpint;
|
||||
break;
|
||||
default:
|
||||
p->iconType = ES10C_ICON_TYPE_UNDEFINED;
|
||||
|
@ -145,16 +145,13 @@ int es10c_GetProfilesInfo(struct euicc_ctx *ctx, struct es10c_profile_info_list
|
|||
}
|
||||
break;
|
||||
case 0x95:
|
||||
switch (derutils_convert_bin2long(tmpnode.value, tmpnode.length))
|
||||
tmpint = derutils_convert_bin2long(tmpnode.value, tmpnode.length);
|
||||
switch (tmpint)
|
||||
{
|
||||
case ES10C_PROFILE_CLASS_TEST:
|
||||
p->profileClass =ES10C_PROFILE_CLASS_TEST;
|
||||
break;
|
||||
case ES10C_PROFILE_CLASS_PROVISIONING:
|
||||
p->profileClass =ES10C_PROFILE_CLASS_PROVISIONING;
|
||||
break;
|
||||
case ES10C_PROFILE_CLASS_OPERATIONAL:
|
||||
p->profileClass = ES10C_PROFILE_CLASS_OPERATIONAL;
|
||||
p->profileClass = tmpint;
|
||||
break;
|
||||
default:
|
||||
p->profileClass = ES10C_PROFILE_CLASS_UNDEFINED;
|
||||
|
|
|
@ -274,9 +274,9 @@ int es9p_AuthenticateClient(struct es9p_ctx *ctx, struct es10b_prepare_download_
|
|||
{
|
||||
const char *ikey[] = {"transactionId", "authenticateServerResponse", NULL};
|
||||
const char *idata[] = {ctx->transactionId, b64_AuthenticateServerResponse, NULL};
|
||||
const char *okey[] = {"smdpSigned2", "smdpSignature2", "smdpCertificate", "profileMetadata", NULL};
|
||||
const char oobj[] = {0, 0, 0};
|
||||
void **optr[] = {(void **)&resp->b64_smdpSigned2, (void **)&resp->b64_smdpSignature2, (void **)&resp->b64_smdpSignature2, (void **)&resp->b64_profileMetadata, NULL};
|
||||
const char *okey[] = {"profileMetadata", "smdpSigned2", "smdpSignature2", "smdpCertificate", NULL};
|
||||
const char oobj[] = {0, 0, 0, 0};
|
||||
void **optr[] = {(void **)&resp->b64_profileMetadata, (void **)&resp->b64_smdpSigned2, (void **)&resp->b64_smdpSignature2, (void **)&resp->b64_smdpCertificate, NULL};
|
||||
|
||||
return es9p_trans_json(ctx, ctx->address, "/gsma/rsp2/es9plus/authenticateClient", ikey, idata, okey, oobj, optr);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ static int es10x_transmit_iter(struct euicc_ctx *ctx, struct apdu_request *req,
|
|||
} while (1);
|
||||
}
|
||||
|
||||
int es10x_command_buildrequest(struct euicc_ctx *ctx, struct apdu_request **request, uint8_t p1, uint8_t p2, uint8_t *der_req, unsigned req_len)
|
||||
int es10x_command_buildrequest(struct euicc_ctx *ctx, struct apdu_request **request, uint8_t p1, uint8_t p2, const uint8_t *der_req, unsigned req_len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -78,21 +78,21 @@ int es10x_command_buildrequest(struct euicc_ctx *ctx, struct apdu_request **requ
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int es10x_command_buildrequest_continue(struct euicc_ctx *ctx, uint8_t reqseq, struct apdu_request **request, uint8_t *der_req, unsigned req_len)
|
||||
static int es10x_command_buildrequest_continue(struct euicc_ctx *ctx, uint8_t reqseq, struct apdu_request **request, const uint8_t *der_req, unsigned req_len)
|
||||
{
|
||||
return es10x_command_buildrequest(ctx, request, 0x11, reqseq, der_req, req_len);
|
||||
}
|
||||
|
||||
static int es10x_command_buildrequest_last(struct euicc_ctx *ctx, uint8_t reqseq, struct apdu_request **request, uint8_t *der_req, unsigned req_len)
|
||||
static int es10x_command_buildrequest_last(struct euicc_ctx *ctx, uint8_t reqseq, struct apdu_request **request, const uint8_t *der_req, unsigned req_len)
|
||||
{
|
||||
return es10x_command_buildrequest(ctx, request, 0x91, reqseq, der_req, req_len);
|
||||
}
|
||||
|
||||
int es10x_command_iter(struct euicc_ctx *ctx, uint8_t *der_req, unsigned req_len, int (*callback)(struct apdu_response *response, void *userdata), void *userdata)
|
||||
int es10x_command_iter(struct euicc_ctx *ctx, const uint8_t *der_req, unsigned req_len, int (*callback)(struct apdu_response *response, void *userdata), void *userdata)
|
||||
{
|
||||
int ret, reqseq;
|
||||
struct apdu_request *req;
|
||||
uint8_t *req_ptr;
|
||||
const uint8_t *req_ptr;
|
||||
|
||||
reqseq = 0;
|
||||
req_ptr = der_req;
|
||||
|
@ -147,7 +147,7 @@ static int iter_es10x_command(struct apdu_response *response, void *userdata)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int es10x_command(struct euicc_ctx *ctx, uint8_t **resp, unsigned *resp_len, uint8_t *der_req, unsigned req_len)
|
||||
int es10x_command(struct euicc_ctx *ctx, uint8_t **resp, unsigned *resp_len, const uint8_t *der_req, unsigned req_len)
|
||||
{
|
||||
int ret = 0;
|
||||
struct userdata_es10x_command ud;
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
#include "euicc.h"
|
||||
#include "interface.private.h"
|
||||
|
||||
int es10x_command_iter(struct euicc_ctx *ctx, uint8_t *der_req, unsigned req_len, int (*callback)(struct apdu_response *response, void *userdata), void *userdata);
|
||||
int es10x_command(struct euicc_ctx *ctx, uint8_t **resp, unsigned *resp_len, uint8_t *der_req, unsigned req_len);
|
||||
int es10x_command_iter(struct euicc_ctx *ctx, const uint8_t *der_req, unsigned req_len, int (*callback)(struct apdu_response *response, void *userdata), void *userdata);
|
||||
int es10x_command(struct euicc_ctx *ctx, uint8_t **resp, unsigned *resp_len, const uint8_t *der_req, unsigned req_len);
|
||||
|
|
|
@ -65,3 +65,65 @@ const char *profilemanagementoperation2str(enum es10b_profile_management_operati
|
|||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char *bppcommandid2str(enum es10b_bpp_command_id value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case ES10B_BPP_COMMAND_ID_INITIALISE_SECURE_CHANNEL:
|
||||
return "initialise_secure_channel";
|
||||
case ES10B_BPP_COMMAND_ID_CONFIGURE_ISDP:
|
||||
return "configure_isdp";
|
||||
case ES10B_BPP_COMMAND_ID_STORE_METADATA:
|
||||
return "store_metadata";
|
||||
case ES10B_BPP_COMMAND_ID_STORE_METADATA2:
|
||||
return "store_metadata2";
|
||||
case ES10B_BPP_COMMAND_ID_REPLACE_SESSION_KEYS:
|
||||
return "replace_session_keys";
|
||||
case ES10B_BPP_COMMAND_ID_LOAD_PROFILE_ELEMENTS:
|
||||
return "load_profile_elements";
|
||||
case ES10B_BPP_COMMAND_ID_UNDEFINED:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char *errorreason2str(enum es10b_error_reason value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case ES10B_ERROR_REASON_INCORRECT_INPUT_VALUES:
|
||||
return "incorrect_input_values";
|
||||
case ES10B_ERROR_REASON_INVALID_SIGNATURE:
|
||||
return "invalid_signature";
|
||||
case ES10B_ERROR_REASON_INVALID_TRANSACTION_ID:
|
||||
return "invalid_transaction_id";
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_CRT_VALUES:
|
||||
return "unsupported_crt_values";
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_REMOTE_OPERATION_TYPE:
|
||||
return "unsupported_remote_operation_type";
|
||||
case ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS:
|
||||
return "unsupported_profile_class";
|
||||
case ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR:
|
||||
return "scp03t_structure_error";
|
||||
case ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR:
|
||||
return "scp03t_security_error";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC:
|
||||
return "install_failed_due_to_iccid_already_exists_on_euicc";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE:
|
||||
return "install_failed_due_to_insufficient_memory_for_profile";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION:
|
||||
return "install_failed_due_to_interruption";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR:
|
||||
return "install_failed_due_to_pe_processing_error";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_MISMATCH:
|
||||
return "install_failed_due_to_iccid_mismatch";
|
||||
case ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY:
|
||||
return "test_profile_install_failed_due_to_invalid_naa_key";
|
||||
case ES10B_ERROR_REASON_PPR_NOT_ALLOWED:
|
||||
return "ppr_not_allowed";
|
||||
case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR:
|
||||
return "install_failed_due_to_unknown_error";
|
||||
case ES10B_ERROR_REASON_UNDEFINED:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,3 +9,5 @@ const char *profilestate2str(enum es10c_profile_state value);
|
|||
const char *profileclass2str(enum es10c_profile_class value);
|
||||
const char *icontype2str(enum es10c_icon_type value);
|
||||
const char *profilemanagementoperation2str(enum es10b_profile_management_operation value);
|
||||
const char *bppcommandid2str(enum es10b_bpp_command_id value);
|
||||
const char *errorreason2str(enum es10b_error_reason value);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <euicc/es10a.h>
|
||||
#include <euicc/es10b.h>
|
||||
#include <euicc/es9p.h>
|
||||
#include <euicc/tostr.h>
|
||||
|
||||
static int applet_main(int argc, char **argv)
|
||||
{
|
||||
|
@ -34,6 +35,7 @@ static int applet_main(int argc, char **argv)
|
|||
char *b64_prepare_download_response = NULL;
|
||||
|
||||
char *b64_BoundProfilePackage = NULL;
|
||||
struct es10b_load_bound_profile_package_result es10b_LoadBoundProfilePackage_result = {0};
|
||||
|
||||
opt = getopt(argc, argv, opt_string);
|
||||
while (opt != -1)
|
||||
|
@ -151,9 +153,11 @@ static int applet_main(int argc, char **argv)
|
|||
}
|
||||
|
||||
jprint_progress("es10b_LoadBoundProfilePackage");
|
||||
if (es10b_LoadBoundProfilePackage(&euicc_ctx, b64_BoundProfilePackage))
|
||||
if (es10b_LoadBoundProfilePackage(&euicc_ctx, &es10b_LoadBoundProfilePackage_result, b64_BoundProfilePackage))
|
||||
{
|
||||
jprint_error("es10b_LoadBoundProfilePackage", NULL);
|
||||
char buffer[256];
|
||||
snprintf(buffer, sizeof(buffer), "%s,%s", bppcommandid2str(es10b_LoadBoundProfilePackage_result.bppCommandId), errorreason2str(es10b_LoadBoundProfilePackage_result.errorReason));
|
||||
jprint_error("es10b_LoadBoundProfilePackage", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue