1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package libcore.java.security; 18 19 import java.security.Provider; 20 import java.security.Security; 21 import java.util.HashSet; 22 import java.util.Locale; 23 import java.util.Set; 24 import java.util.SortedSet; 25 import java.util.TreeSet; 26 27 /** 28 * Prints a list of all algorithms (including aliases) that overlap between Conscrypt and 29 * Bouncy Castle. Intended to be run via vogar. 30 * <p> 31 * {@code vogar libcore/tools/crypto/src/java/libcore/java/security/ProviderOverlap.java} 32 */ 33 public class ProviderOverlap { 34 main(String[] argv)35 public static void main(String[] argv) throws Exception { 36 Set<String> conscrypt = getAlgorithms(Security.getProvider("AndroidOpenSSL")); 37 Set<String> bc = getAlgorithms(Security.getProvider("BC")); 38 SortedSet<String> overlap = new TreeSet<>(conscrypt); 39 overlap.retainAll(bc); 40 for (String s : overlap) { 41 System.out.println(s); 42 } 43 } 44 getAlgorithms(Provider p)45 private static Set<String> getAlgorithms(Provider p) { 46 Set<String> result = new HashSet<>(); 47 for (Object keyObj : p.keySet()) { 48 String key = (String) keyObj; 49 if (key.contains(" ")) { 50 // These are implementation properties like "Provider.id name" 51 continue; 52 } 53 if (key.startsWith("Alg.Alias.")) { 54 // This is an alias, strip its prefix 55 key = key.substring("Alg.Alias.".length()); 56 } 57 result.add(key.toUpperCase(Locale.US)); 58 } 59 return result; 60 } 61 }