|
| 1 | +#include "es10b_ex.h" |
| 2 | + |
| 3 | +#include "base64.h" |
| 4 | +#include "derutil.h" |
| 5 | + |
| 6 | +#include <stdlib.h> |
| 7 | + |
| 8 | +int es10b_parse_pending_notification(const struct es10b_pending_notification *notification, |
| 9 | + struct es10b_load_bound_profile_package_result *result) { |
| 10 | + int fret = 0; |
| 11 | + const int buf_len = euicc_base64_decode_len(notification->b64_PendingNotification); |
| 12 | + uint8_t *buf = calloc(sizeof(uint8_t *), buf_len); |
| 13 | + if (euicc_base64_decode(buf, notification->b64_PendingNotification) < 0) { |
| 14 | + goto err; |
| 15 | + } |
| 16 | + if (es10b_parse_handle_notification(buf, buf_len, result) < 0) { |
| 17 | + goto err; |
| 18 | + } |
| 19 | + goto exit; |
| 20 | +err: |
| 21 | + fret = -1; |
| 22 | +exit: |
| 23 | + free(buf); |
| 24 | + buf = NULL; |
| 25 | + return fret; |
| 26 | +} |
| 27 | + |
| 28 | +int es10b_parse_handle_notification(const uint8_t *buf, const unsigned int buf_len, |
| 29 | + struct es10b_load_bound_profile_package_result *result) { |
| 30 | + struct euicc_derutil_node tmpnode, n_notificationMetadata, n_sequenceNumber, n_finalResult; |
| 31 | + |
| 32 | + if (euicc_derutil_unpack_find_tag(&tmpnode, 0xBF37, buf, buf_len) < 0) { |
| 33 | + goto err; // ProfileInstallationResult |
| 34 | + } |
| 35 | + |
| 36 | + if (euicc_derutil_unpack_find_tag(&tmpnode, 0xBF27, tmpnode.value, tmpnode.length) < 0) { |
| 37 | + goto err; // ProfileInstallationResultData |
| 38 | + } |
| 39 | + |
| 40 | + if (euicc_derutil_unpack_find_tag(&n_notificationMetadata, 0xBF2F, tmpnode.value, tmpnode.length) < 0) { |
| 41 | + goto err; // NotificationMetadata |
| 42 | + } |
| 43 | + |
| 44 | + if (euicc_derutil_unpack_find_tag(&tmpnode, 0xA2, tmpnode.value, tmpnode.length) < 0) { |
| 45 | + goto err; // finalResult |
| 46 | + } |
| 47 | + |
| 48 | + if (euicc_derutil_unpack_first(&n_finalResult, tmpnode.value, tmpnode.length) < 0) { |
| 49 | + goto err; |
| 50 | + } |
| 51 | + |
| 52 | + if (euicc_derutil_unpack_find_tag(&n_sequenceNumber, 0x80, n_notificationMetadata.value, |
| 53 | + n_notificationMetadata.length) |
| 54 | + == 0) { |
| 55 | + result->seqNumber = euicc_derutil_convert_bin2long(n_sequenceNumber.value, n_sequenceNumber.length); |
| 56 | + } |
| 57 | + |
| 58 | + switch (n_finalResult.tag) { |
| 59 | + case 0xA0: // SuccessResult |
| 60 | + break; |
| 61 | + case 0xA1: // ErrorResult |
| 62 | + tmpnode.self.ptr = n_finalResult.value; |
| 63 | + tmpnode.self.length = 0; |
| 64 | + while (euicc_derutil_unpack_next(&tmpnode, &tmpnode, n_finalResult.value, n_finalResult.length) == 0) { |
| 65 | + long tmpint; |
| 66 | + switch (tmpnode.tag) { |
| 67 | + case 0x80: |
| 68 | + tmpint = euicc_derutil_convert_bin2long(tmpnode.value, tmpnode.length); |
| 69 | + switch (tmpint) { |
| 70 | + case ES10B_BPP_COMMAND_ID_INITIALISE_SECURE_CHANNEL: |
| 71 | + case ES10B_BPP_COMMAND_ID_CONFIGURE_ISDP: |
| 72 | + case ES10B_BPP_COMMAND_ID_STORE_METADATA: |
| 73 | + case ES10B_BPP_COMMAND_ID_STORE_METADATA2: |
| 74 | + case ES10B_BPP_COMMAND_ID_REPLACE_SESSION_KEYS: |
| 75 | + case ES10B_BPP_COMMAND_ID_LOAD_PROFILE_ELEMENTS: |
| 76 | + result->bppCommandId = tmpint; |
| 77 | + break; |
| 78 | + default: |
| 79 | + result->bppCommandId = ES10B_BPP_COMMAND_ID_UNDEFINED; |
| 80 | + break; |
| 81 | + } |
| 82 | + break; |
| 83 | + case 0x81: |
| 84 | + tmpint = euicc_derutil_convert_bin2long(tmpnode.value, tmpnode.length); |
| 85 | + switch (tmpint) { |
| 86 | + case ES10B_ERROR_REASON_INCORRECT_INPUT_VALUES: |
| 87 | + case ES10B_ERROR_REASON_INVALID_SIGNATURE: |
| 88 | + case ES10B_ERROR_REASON_INVALID_TRANSACTION_ID: |
| 89 | + case ES10B_ERROR_REASON_UNSUPPORTED_CRT_VALUES: |
| 90 | + case ES10B_ERROR_REASON_UNSUPPORTED_REMOTE_OPERATION_TYPE: |
| 91 | + case ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS: |
| 92 | + case ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR: |
| 93 | + case ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR: |
| 94 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC: |
| 95 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE: |
| 96 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION: |
| 97 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR: |
| 98 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_DATA_MISMATCH: |
| 99 | + case ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY: |
| 100 | + case ES10B_ERROR_REASON_PPR_NOT_ALLOWED: |
| 101 | + case ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR: |
| 102 | + result->errorReason = tmpint; |
| 103 | + break; |
| 104 | + default: |
| 105 | + result->errorReason = ES10B_ERROR_REASON_UNDEFINED; |
| 106 | + break; |
| 107 | + } |
| 108 | + break; |
| 109 | + default: |
| 110 | + break; |
| 111 | + } |
| 112 | + } |
| 113 | + goto err; |
| 114 | + default: // Unexpected tag |
| 115 | + goto err; |
| 116 | + } |
| 117 | + return 0; |
| 118 | +err: |
| 119 | + result->seqNumber = -1; |
| 120 | + result->bppCommandId = ES10B_BPP_COMMAND_ID_UNDEFINED; |
| 121 | + result->errorReason = ES10B_ERROR_REASON_UNDEFINED; |
| 122 | + return -1; |
| 123 | +} |
0 commit comments