Search in sources :

Example 6 with ImsiEncryptionInfo

use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.

the class CarrierKeyDownloadMgrTest method testParseJson3GppFormat.

/**
 * Checks if the JSON in 3GPP spec format is parsed correctly, and that WLAN is the key type.
 */
@Test
@SmallTest
public void testParseJson3GppFormat() {
    Pair<PublicKey, Long> keyInfo = null;
    try {
        keyInfo = mCarrierKeyDM.getKeyInformation(CERT.getBytes());
    } catch (Exception e) {
        fail(LOG_TAG + "exception creating public key");
    }
    ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo("310", "270", TelephonyManager.KEY_TYPE_WLAN, "key1=value", keyInfo.first, new Date(CERT_EXPIRATION));
    String mccMnc = "310:270";
    mCarrierKeyDM.parseJsonAndPersistKey(mJsonStr3GppSpec, mccMnc);
    verify(mPhone).setCarrierInfoForImsiEncryption((Matchers.refEq(imsiEncryptionInfo)));
}
Also used : ImsiEncryptionInfo(android.telephony.ImsiEncryptionInfo) PublicKey(java.security.PublicKey) Date(java.util.Date) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 7 with ImsiEncryptionInfo

use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.

the class CarrierKeyDownloadMgrTest method testExpirationDate1Day.

/* Checks if the expiration date is calculated correctly
     * In this case the expiration date should be the next day.
     */
@Test
@SmallTest
public void testExpirationDate1Day() {
    java.security.PublicKey publicKey = null;
    mCarrierKeyDM.mKeyAvailability = 3;
    SimpleDateFormat dt = new SimpleDateFormat("yyyy-mm-dd");
    Calendar cal = new GregorianCalendar();
    cal.add(Calendar.DATE, 6);
    Date date = cal.getTime();
    Calendar expectedCal = new GregorianCalendar();
    expectedCal.add(Calendar.DATE, 1);
    String dateExpected = dt.format(expectedCal.getTime());
    ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo("mcc", "mnc", 1, "keyIdentifier", publicKey, date);
    when(mPhone.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(imsiEncryptionInfo);
    Date expirationDate = new Date(mCarrierKeyDM.getExpirationDate());
    assertTrue(dt.format(expirationDate).equals(dateExpected));
}
Also used : ImsiEncryptionInfo(android.telephony.ImsiEncryptionInfo) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) PublicKey(java.security.PublicKey) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with ImsiEncryptionInfo

use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.

the class CarrierKeyDownloadMgrTest method testParseJsonPublicKey.

/**
 * Checks if the json is parse correctly.
 * Same as testParseJason, except that the test looks for the "public-key" field.
 */
@Test
@SmallTest
public void testParseJsonPublicKey() {
    Pair<PublicKey, Long> keyInfo = null;
    try {
        keyInfo = mCarrierKeyDM.getKeyInformation(CERT.getBytes());
    } catch (Exception e) {
        fail(LOG_TAG + "exception creating public key");
    }
    ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo("310", "270", 2, "key1=value", keyInfo.first, new Date(keyInfo.second));
    String mccMnc = "310:270";
    mCarrierKeyDM.parseJsonAndPersistKey(mJsonStr1, mccMnc);
    verify(mPhone, times(2)).setCarrierInfoForImsiEncryption((Matchers.refEq(imsiEncryptionInfo)));
}
Also used : ImsiEncryptionInfo(android.telephony.ImsiEncryptionInfo) PublicKey(java.security.PublicKey) Date(java.util.Date) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with ImsiEncryptionInfo

use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.

the class CarrierKeyDownloadMgrTest method testExpirationDate7Day.

/**
 * Checks if the expiration date is calculated correctly
 * In this case the expiration date should be within the window (7 to 21 days).
 */
@Test
@SmallTest
public void testExpirationDate7Day() {
    java.security.PublicKey publicKey = null;
    mCarrierKeyDM.mKeyAvailability = 3;
    SimpleDateFormat dt = new SimpleDateFormat("yyyy-mm-dd");
    Calendar cal = new GregorianCalendar();
    cal.add(Calendar.DATE, 30);
    Date date = cal.getTime();
    Calendar minExpirationCal = new GregorianCalendar();
    Calendar maxExpirationCal = new GregorianCalendar();
    minExpirationCal.add(Calendar.DATE, 23);
    maxExpirationCal.add(Calendar.DATE, 9);
    Date minExpirationDate = minExpirationCal.getTime();
    Date maxExpirationDate = maxExpirationCal.getTime();
    ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo("mcc", "mnc", 1, "keyIdentifier", publicKey, date);
    when(mPhone.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(imsiEncryptionInfo);
    Date expirationDate = new Date(mCarrierKeyDM.getExpirationDate());
    assertTrue(expirationDate.before(minExpirationDate));
    assertTrue(expirationDate.after(maxExpirationDate));
}
Also used : ImsiEncryptionInfo(android.telephony.ImsiEncryptionInfo) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) PublicKey(java.security.PublicKey) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with ImsiEncryptionInfo

use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.

the class CarrierKeyDownloadMgrTest method testParseJson.

/**
 * Checks if the json is parse correctly.
 * Verify that setCarrierInfoForImsiEncryption is called with the right params
 */
@Test
@SmallTest
public void testParseJson() {
    Pair<PublicKey, Long> keyInfo = null;
    try {
        keyInfo = mCarrierKeyDM.getKeyInformation(CERT.getBytes());
    } catch (Exception e) {
        fail(LOG_TAG + "exception creating public key");
    }
    ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo("310", "270", 2, "key1=value", keyInfo.first, new Date(keyInfo.second));
    String mccMnc = "310:270";
    mCarrierKeyDM.parseJsonAndPersistKey(mJsonStr, mccMnc);
    verify(mPhone, times(2)).setCarrierInfoForImsiEncryption((Matchers.refEq(imsiEncryptionInfo)));
}
Also used : ImsiEncryptionInfo(android.telephony.ImsiEncryptionInfo) PublicKey(java.security.PublicKey) Date(java.util.Date) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ImsiEncryptionInfo (android.telephony.ImsiEncryptionInfo)13 Date (java.util.Date)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Test (org.junit.Test)6 PublicKey (java.security.PublicKey)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)3 ContentResolver (android.content.ContentResolver)2 Cursor (android.database.Cursor)2 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 IRadio (android.hardware.radio.V1_0.IRadio)1 Parcel (android.os.Parcel)1 RemoteException (android.os.RemoteException)1 TelephonyManager (android.telephony.TelephonyManager)1 Random (java.util.Random)1 Before (org.junit.Before)1