Search in sources :

Example 11 with InvalidAsn1DataException

use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testLongFormLength.

@SmallTest
@Test
public void testLongFormLength() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0xBF37).addChildAsBytes(0x5A, new byte[257]).build();
    assertEquals(266, node.getEncodedLength());
    assertEquals(261, node.getDataLength());
    assertEquals(257, node.getChild(0x5A).getDataLength());
    assertEquals("BF37820105", node.getHeadAsHex());
    byte[] expected = new byte[266];
    System.arraycopy(IccUtils.hexStringToBytes("BF378201055A820101"), 0, expected, 0, 9);
    byte[] actual = new byte[266];
    node.writeToBytes(actual, 0);
    assertArrayEquals(expected, actual);
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with InvalidAsn1DataException

use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testChildren.

@SmallTest
@Test
public void testChildren() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0x3F34).addChild(Asn1Node.newBuilder(0x35).addChild(Asn1Node.newBuilder(0x36))).addChild(Asn1Node.newBuilder(0x35)).addChild(Asn1Node.newBuilder(0x37)).build();
    assertEquals(0x3F34, node.getTag());
    assertEquals(3, node.getChildren().size());
    assertEquals(0x35, node.getChildren().get(0).getTag());
    assertEquals(0x35, node.getChildren().get(1).getTag());
    assertEquals(0x37, node.getChildren().get(2).getTag());
    assertEquals(2, node.getChildren(0x35).size());
    assertEquals(0x35, node.getChildren(0x35).get(0).getTag());
    assertEquals(0x35, node.getChildren(0x35).get(1).getTag());
    assertEquals(1, node.getChild(0x35).getChildren().size());
    assertEquals(0, node.getChildren().get(1).getChildren().size());
    assertEquals(0x36, node.getChild(0x35).getChildren().get(0).getTag());
    assertTrue(node.hasChild(0x35, 0x36));
    assertFalse(node.hasChild(0x38, 0x39));
    assertTrue(node.getChild(0x35).hasChild(0x36));
    assertFalse(node.getChild(0x35).hasChild(0x39));
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with InvalidAsn1DataException

use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.

the class EuiccCard method buildUiccAccessRule.

@Nullable
private static UiccAccessRule[] buildUiccAccessRule(List<Asn1Node> nodes) throws InvalidAsn1DataException, TagNotFoundException {
    if (nodes.isEmpty()) {
        return null;
    }
    int count = nodes.size();
    UiccAccessRule[] rules = new UiccAccessRule[count];
    for (int i = 0; i < count; i++) {
        Asn1Node node = nodes.get(i);
        Asn1Node refDoNode = node.getChild(Tags.TAG_REF_DO);
        byte[] signature = refDoNode.getChild(Tags.TAG_DEVICE_APP_ID_REF_DO).asBytes();
        String packageName = null;
        if (refDoNode.hasChild(Tags.TAG_PKG_REF_DO)) {
            packageName = refDoNode.getChild(Tags.TAG_PKG_REF_DO).asString();
        }
        long accessType = 0;
        if (node.hasChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO)) {
            Asn1Node permArDoNode = node.getChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO);
            accessType = permArDoNode.asRawLong();
        }
        rules[i] = new UiccAccessRule(signature, packageName, accessType);
    }
    return rules;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Nullable(android.annotation.Nullable)

Example 14 with InvalidAsn1DataException

use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.

the class EuiccSpecVersion method fromOpenChannelResponse.

/**
 * Parses the response of opening a logical channel to get spec version of the eUICC card.
 *
 * @return Parsed spec version. If any error is encountered, null will be returned.
 */
public static EuiccSpecVersion fromOpenChannelResponse(byte[] response) {
    Asn1Node node;
    try {
        Asn1Decoder decoder = new Asn1Decoder(response);
        if (!decoder.hasNextNode()) {
            return null;
        }
        node = decoder.nextNode();
    } catch (InvalidAsn1DataException e) {
        Rlog.e(LOG_TAG, "Cannot parse the select response of ISD-R.", e);
        return null;
    }
    try {
        byte[] versionType;
        if (node.getTag() == TAG_ISD_R_APP_TEMPLATE) {
            versionType = node.getChild(TAG_VERSION).asBytes();
        } else {
            versionType = node.getChild(TAG_ISD_R_APP_TEMPLATE, TAG_VERSION).asBytes();
        }
        if (versionType.length == 3) {
            return new EuiccSpecVersion(versionType);
        } else {
            Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
        }
    } catch (InvalidAsn1DataException | TagNotFoundException e) {
        Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
    }
    return null;
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) TagNotFoundException(com.android.internal.telephony.uicc.asn1.TagNotFoundException) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) InvalidAsn1DataException(com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)

Example 15 with InvalidAsn1DataException

use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.

the class EuiccCardTest method testAddDeviceCapability.

@Test
public void testAddDeviceCapability() throws InvalidAsn1DataException, TagNotFoundException {
    Asn1Node.Builder devCapsBuilder = Asn1Node.newBuilder(Tags.TAG_CTX_COMP_1);
    String devCapItem = "gsm,11";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    Asn1Node node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_0));
    Asn1Node child = node.getChild(Tags.TAG_CTX_0);
    assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
    devCapItem = "utran,11";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_1));
    child = node.getChild(Tags.TAG_CTX_1);
    assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
    devCapItem = "cdma1x,1";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_2));
    child = node.getChild(Tags.TAG_CTX_2);
    assertTrue(Arrays.equals(new byte[] { 1, 0, 0 }, child.asBytes()));
    devCapItem = "hrpd,1";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_3));
    child = node.getChild(Tags.TAG_CTX_3);
    assertTrue(Arrays.equals(new byte[] { 1, 0, 0 }, child.asBytes()));
    devCapItem = "ehrpd,12";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_4));
    child = node.getChild(Tags.TAG_CTX_4);
    assertTrue(Arrays.equals(new byte[] { 12, 0, 0 }, child.asBytes()));
    devCapItem = "eutran,11";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_5));
    child = node.getChild(Tags.TAG_CTX_5);
    assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
    devCapItem = "nfc,0";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_6));
    child = node.getChild(Tags.TAG_CTX_6);
    assertTrue(Arrays.equals(new byte[] { 0, 0, 0 }, child.asBytes()));
    devCapItem = "crl,0";
    mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
    node = devCapsBuilder.build();
    assertTrue(node.hasChild(Tags.TAG_CTX_7));
    child = node.getChild(Tags.TAG_CTX_7);
    assertTrue(Arrays.equals(new byte[] { 0, 0, 0 }, child.asBytes()));
    // Array length should not be 3.
    Asn1Node.Builder devCapsBuilder2 = Asn1Node.newBuilder(Tags.TAG_CTX_COMP_1);
    devCapItem = "gsm,1,1";
    mEuiccCard.addDeviceCapability(devCapsBuilder2, devCapItem);
    node = devCapsBuilder2.build();
    assertFalse(node.hasChild(Tags.TAG_CTX_0));
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

Aggregations

Asn1Node (com.android.internal.telephony.uicc.asn1.Asn1Node)23 Test (org.junit.Test)21 SmallTest (android.test.suitebuilder.annotation.SmallTest)20 Asn1Decoder (com.android.internal.telephony.uicc.asn1.Asn1Decoder)8 InvalidAsn1DataException (com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)3 TagNotFoundException (com.android.internal.telephony.uicc.asn1.TagNotFoundException)2 Nullable (android.annotation.Nullable)1 UiccAccessRule (android.telephony.UiccAccessRule)1 TelephonyTest (com.android.internal.telephony.TelephonyTest)1