Commit 6243428c authored by Kenny Root's avatar Kenny Root
Browse files

Make sure AlgNameMapper has the latest name version

In the current design, if AlgNameMapper's class initialization is run
too early, the data will be incomplete. This change uses the Services's
cache versioning system to check when it should update its internal
cache ensuring it's never out of date.

Bug: 10666722
Change-Id: I0549ebb8fa1b5b3a8af71ceb179d5d217bdbdf59
parent 41a439b8
......@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.harmony.security.asn1.ObjectIdentifier;
import org.apache.harmony.security.fortress.Services;
/**
* Provides Algorithm Name to OID and OID to Algorithm Name mappings. Some known
......@@ -39,6 +40,8 @@ import org.apache.harmony.security.asn1.ObjectIdentifier;
public class AlgNameMapper {
private static AlgNameMapperSource source = null;
private static volatile int cacheVersion = -1;
// Will search OID mappings for these services
private static final String[] serviceName = {
"Cipher",
......@@ -90,22 +93,29 @@ public class AlgNameMapper {
// map upper case alg name to its original name
algAliasesMap.put(algUC, element[1]);
}
//
// Now search providers for mappings like
// Alg.Alias.<service>.<OID-INTS-DOT-SEPARATED>=<alg-name>
// or
// Alg.Alias.<service>.OID.<OID-INTS-DOT-SEPARATED>=<alg-name>
//
Provider[] pl = Security.getProviders();
for (Provider element : pl) {
selectEntries(element);
}
}
// No instances
private AlgNameMapper() {
}
private static synchronized void checkCacheVersion() {
int newCacheVersion = Services.getCacheVersion();
if (newCacheVersion != cacheVersion) {
//
// Now search providers for mappings like
// Alg.Alias.<service>.<OID-INTS-DOT-SEPARATED>=<alg-name>
// or
// Alg.Alias.<service>.OID.<OID-INTS-DOT-SEPARATED>=<alg-name>
//
Provider[] pl = Security.getProviders();
for (Provider element : pl) {
selectEntries(element);
}
cacheVersion = newCacheVersion;
}
}
/**
* Returns OID for algName
*
......@@ -113,6 +123,8 @@ public class AlgNameMapper {
* @return OID as String
*/
public static String map2OID(String algName) {
checkCacheVersion();
// alg2OidMap map contains upper case keys
String result = alg2OidMap.get(algName.toUpperCase(Locale.US));
if (result != null) {
......@@ -135,6 +147,8 @@ public class AlgNameMapper {
* @return algorithm name
*/
public static String map2AlgName(String oid) {
checkCacheVersion();
// oid2AlgMap map contains upper case values
String algUC = oid2AlgMap.get(oid);
// if not null there is always map UC->Orig
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment