use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.
the class CarrierInfoManager method getCarrierInfoForImsiEncryption.
/**
* Returns Carrier specific information that will be used to encrypt the IMSI and IMPI.
* @param keyType whether the key is being used for WLAN or ePDG.
* @param mContext
* @return ImsiEncryptionInfo which contains the information, including the public key, to be
* used for encryption.
*/
public static ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType, Context mContext) {
String mcc = "";
String mnc = "";
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = telephonyManager.getNetworkOperator();
if (!TextUtils.isEmpty(networkOperator)) {
mcc = networkOperator.substring(0, 3);
mnc = networkOperator.substring(3);
Log.i(LOG_TAG, "using values for mnc, mcc: " + mnc + "," + mcc);
} else {
Log.e(LOG_TAG, "Invalid networkOperator: " + networkOperator);
return null;
}
Cursor findCursor = null;
try {
// In the current design, MVNOs are not supported. If we decide to support them,
// we'll need to add to this CL.
ContentResolver mContentResolver = mContext.getContentResolver();
String[] columns = { Telephony.CarrierColumns.PUBLIC_KEY, Telephony.CarrierColumns.EXPIRATION_TIME, Telephony.CarrierColumns.KEY_IDENTIFIER };
findCursor = mContentResolver.query(Telephony.CarrierColumns.CONTENT_URI, columns, "mcc=? and mnc=? and key_type=?", new String[] { mcc, mnc, String.valueOf(keyType) }, null);
if (findCursor == null || !findCursor.moveToFirst()) {
Log.d(LOG_TAG, "No rows found for keyType: " + keyType);
return null;
}
if (findCursor.getCount() > 1) {
Log.e(LOG_TAG, "More than 1 row found for the keyType: " + keyType);
}
byte[] carrier_key = findCursor.getBlob(0);
Date expirationTime = new Date(findCursor.getLong(1));
String keyIdentifier = findCursor.getString(2);
return new ImsiEncryptionInfo(mcc, mnc, keyType, keyIdentifier, carrier_key, expirationTime);
} catch (IllegalArgumentException e) {
Log.e(LOG_TAG, "Bad arguments:" + e);
} catch (Exception e) {
Log.e(LOG_TAG, "Query failed:" + e);
} finally {
if (findCursor != null) {
findCursor.close();
}
}
return null;
}
use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.
the class CarrierKeyDownloadManager method areCarrierKeysAbsentOrExpiring.
/**
* Checks whether is the keys are absent or close to expiration. Returns true, if either of
* those conditions are true.
* @return boolean returns true when keys are absent or close to expiration, else false.
*/
@VisibleForTesting
public boolean areCarrierKeysAbsentOrExpiring() {
for (int key_type : CARRIER_KEY_TYPES) {
if (!isKeyEnabled(key_type)) {
continue;
}
ImsiEncryptionInfo imsiEncryptionInfo = mPhone.getCarrierInfoForImsiEncryption(key_type);
if (imsiEncryptionInfo == null) {
Log.d(LOG_TAG, "Key not found for: " + key_type);
return true;
}
Date imsiDate = imsiEncryptionInfo.getExpirationTime();
long timeToExpire = imsiDate.getTime() - System.currentTimeMillis();
return (timeToExpire < START_RENEWAL_WINDOW_DAYS * DAY_IN_MILLIS) ? true : false;
}
return false;
}
use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.
the class CarrierKeyDownloadManager method getExpirationDate.
/**
* this method returns the date to be used to decide on when to start downloading the key.
* from the carrier.
*/
@VisibleForTesting
public long getExpirationDate() {
long minExpirationDate = Long.MAX_VALUE;
for (int key_type : CARRIER_KEY_TYPES) {
if (!isKeyEnabled(key_type)) {
continue;
}
ImsiEncryptionInfo imsiEncryptionInfo = mPhone.getCarrierInfoForImsiEncryption(key_type);
if (imsiEncryptionInfo != null && imsiEncryptionInfo.getExpirationTime() != null) {
if (minExpirationDate > imsiEncryptionInfo.getExpirationTime().getTime()) {
minExpirationDate = imsiEncryptionInfo.getExpirationTime().getTime();
}
}
}
// expiration.
if (minExpirationDate == Long.MAX_VALUE || (minExpirationDate < System.currentTimeMillis() + END_RENEWAL_WINDOW_DAYS * DAY_IN_MILLIS)) {
minExpirationDate = System.currentTimeMillis() + DAY_IN_MILLIS;
} else {
// We don't want all the phones to download the certs simultaneously, so
// we pick a random time during the download window to avoid this situation.
Random random = new Random();
int max = START_RENEWAL_WINDOW_DAYS * DAY_IN_MILLIS;
int min = END_RENEWAL_WINDOW_DAYS * DAY_IN_MILLIS;
int randomTime = random.nextInt(max - min) + min;
minExpirationDate = minExpirationDate - randomTime;
}
return minExpirationDate;
}
use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.
the class CarrierInfoManager method getCarrierInfoForImsiEncryption.
/**
* Returns Carrier specific information that will be used to encrypt the IMSI and IMPI.
* @param keyType whether the key is being used for WLAN or ePDG.
* @param context
* @return ImsiEncryptionInfo which contains the information, including the public key, to be
* used for encryption.
*/
public static ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType, Context context, String operatorNumeric) {
String mcc = "";
String mnc = "";
if (!TextUtils.isEmpty(operatorNumeric)) {
mcc = operatorNumeric.substring(0, 3);
mnc = operatorNumeric.substring(3);
Log.i(LOG_TAG, "using values for mnc, mcc: " + mnc + "," + mcc);
} else {
Log.e(LOG_TAG, "Invalid networkOperator: " + operatorNumeric);
return null;
}
Cursor findCursor = null;
try {
// In the current design, MVNOs are not supported. If we decide to support them,
// we'll need to add to this CL.
ContentResolver mContentResolver = context.getContentResolver();
String[] columns = { Telephony.CarrierColumns.PUBLIC_KEY, Telephony.CarrierColumns.EXPIRATION_TIME, Telephony.CarrierColumns.KEY_IDENTIFIER };
findCursor = mContentResolver.query(Telephony.CarrierColumns.CONTENT_URI, columns, "mcc=? and mnc=? and key_type=?", new String[] { mcc, mnc, String.valueOf(keyType) }, null);
if (findCursor == null || !findCursor.moveToFirst()) {
Log.d(LOG_TAG, "No rows found for keyType: " + keyType);
return null;
}
if (findCursor.getCount() > 1) {
Log.e(LOG_TAG, "More than 1 row found for the keyType: " + keyType);
}
byte[] carrier_key = findCursor.getBlob(0);
Date expirationTime = new Date(findCursor.getLong(1));
String keyIdentifier = findCursor.getString(2);
return new ImsiEncryptionInfo(mcc, mnc, keyType, keyIdentifier, carrier_key, expirationTime);
} catch (IllegalArgumentException e) {
Log.e(LOG_TAG, "Bad arguments:" + e);
} catch (Exception e) {
Log.e(LOG_TAG, "Query failed:" + e);
} finally {
if (findCursor != null) {
findCursor.close();
}
}
return null;
}
use of android.telephony.ImsiEncryptionInfo in project android_frameworks_opt_telephony by LineageOS.
the class ImsiEncryptionInfoTest method testParcel.
/**
* Tests the parceling/un-parceling of the object.
*/
@Test
@SmallTest
public void testParcel() {
Parcel p = Parcel.obtain();
p.setDataPosition(0);
mImsiEncryptionInfo.writeToParcel(p, 0);
p.setDataPosition(0);
ImsiEncryptionInfo nw = new ImsiEncryptionInfo(p);
assertEquals("310", mImsiEncryptionInfo.getMcc());
assertEquals("270", mImsiEncryptionInfo.getMnc());
assertEquals(TelephonyManager.KEY_TYPE_WLAN, mImsiEncryptionInfo.getKeyType());
assertEquals("key1=value", mImsiEncryptionInfo.getKeyIdentifier());
assertEquals(mPublicKey, mImsiEncryptionInfo.getPublicKey());
assertEquals(mDate, mImsiEncryptionInfo.getExpirationTime());
}
Aggregations