Commit 6fcfb5a7 authored by Kenny Root's avatar Kenny Root
Browse files

Register Conscrypt as the AlgNameMapper source

Conscrypt was moved out of libcore, so the call directly to NativeCrypto
was removed as well. To break the dependency, introduce an interface
that Conscrypt registers as to answer algorithm name to OID mapping
queries and vice versa.

Bug: 10310296
Change-Id: I06de1501681d28afbc36de9c32e384dd32790a53
parent debfff83
/*
* Copyright 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.conscrypt;
import org.apache.harmony.security.utils.AlgNameMapperSource;
class OpenSSLMapper implements AlgNameMapperSource {
@Override
public String mapNameToOid(String algName) {
return NativeCrypto.OBJ_txt2nid_oid(algName);
}
@Override
public String mapOidToName(String oid) {
return NativeCrypto.OBJ_txt2nid_longName(oid);
}
}
......@@ -16,6 +16,8 @@
package org.conscrypt;
import org.apache.harmony.security.utils.AlgNameMapper;
import java.security.Provider;
/**
......@@ -33,6 +35,10 @@ public final class OpenSSLProvider extends Provider {
public static final String PROVIDER_NAME = "AndroidOpenSSL";
static {
AlgNameMapper.setSource(new OpenSSLMapper());
}
public OpenSSLProvider() {
super(PROVIDER_NAME, 1.0, "Android's OpenSSL-backed security provider");
......
......@@ -37,6 +37,7 @@ import org.apache.harmony.security.asn1.ObjectIdentifier;
* providers during initialization.
*/
public class AlgNameMapper {
private static AlgNameMapperSource source = null;
// Will search OID mappings for these services
private static final String[] serviceName = {
......@@ -113,7 +114,18 @@ public class AlgNameMapper {
*/
public static String map2OID(String algName) {
// alg2OidMap map contains upper case keys
return alg2OidMap.get(algName.toUpperCase(Locale.US));
String result = alg2OidMap.get(algName.toUpperCase(Locale.US));
if (result != null) {
return result;
}
// Check our external source.
AlgNameMapperSource s = source;
if (s != null) {
return s.mapNameToOid(algName);
}
return null;
}
/**
......@@ -124,11 +136,18 @@ public class AlgNameMapper {
*/
public static String map2AlgName(String oid) {
// oid2AlgMap map contains upper case values
final String algUC = oid2AlgMap.get(oid);
String algUC = oid2AlgMap.get(oid);
// if not null there is always map UC->Orig
if (algUC != null) {
return algAliasesMap.get(algUC);
}
// Check our external source.
AlgNameMapperSource s = source;
if (s != null) {
return s.mapOidToName(oid);
}
return null;
}
......@@ -204,4 +223,8 @@ public class AlgNameMapper {
? oid.substring(4)
: oid;
}
public static void setSource(AlgNameMapperSource source) {
AlgNameMapper.source = source;
}
}
/*
* Copyright 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.harmony.security.utils;
/**
* Provides a mapping source that the {@link AlgNameMapper} can query for
* mapping between algorithm names and OIDs.
*/
public interface AlgNameMapperSource {
public String mapNameToOid(String algName);
public String mapOidToName(String oid);
}
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