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)));
}
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));
}
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)));
}
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));
}
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)));
}
Aggregations