1# 2# Copyright (C) 2010 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# 16LOCAL_PATH := $(call my-dir) 17 18# used for bouncycastle-hostdex where we want everything for testing 19all_bcprov_src_files := $(call all-java-files-under,bcprov/src/main/java) 20 21# used for bouncycastle for target where we want to be sure to use OpenSSLDigest 22android_bcprov_src_files := $(filter-out \ 23 bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactoryBouncyCastle.java, \ 24 $(all_bcprov_src_files)) 25 26# used for bouncycastle-host where we can't use OpenSSLDigest 27ri_bcprov_src_files := $(filter-out \ 28 bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactoryOpenSSL.java \ 29 bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java, \ 30 $(all_bcprov_src_files)) 31 32include $(CLEAR_VARS) 33LOCAL_MODULE := bouncycastle 34LOCAL_MODULE_TAGS := optional 35LOCAL_SRC_FILES := $(android_bcprov_src_files) 36LOCAL_JAVACFLAGS := -encoding UTF-8 37LOCAL_JAVA_LIBRARIES := conscrypt core 38LOCAL_NO_STANDARD_LIBRARIES := true 39LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt 40LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 41include $(BUILD_JAVA_LIBRARY) 42 43# non-jarjar version to build okhttp-tests 44include $(CLEAR_VARS) 45LOCAL_MODULE := bouncycastle-nojarjar 46LOCAL_MODULE_TAGS := optional 47LOCAL_SRC_FILES := $(android_bcprov_src_files) 48LOCAL_JAVACFLAGS := -encoding UTF-8 49LOCAL_JAVA_LIBRARIES := conscrypt core 50LOCAL_NO_STANDARD_LIBRARIES := true 51LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 52include $(BUILD_STATIC_JAVA_LIBRARY) 53 54# This is used to generate a list of what is unused so it can be removed when bouncycastle is updated. 55# Based on "Finding dead code" example in ProGuard manual at http://proguard.sourceforge.net/ 56.PHONY: bouncycastle-proguard-deadcode 57bouncycastle-proguard-deadcode: $(full_classes_compiled_jar) $(full_java_libs) 58 $(PROGUARD) \ 59 -injars $(full_classes_compiled_jar) \ 60 -libraryjars "$(call normalize-path-list,$(addsuffix (!org/bouncycastle/**.class,!com/android/org/conscrypt/OpenSSLMessageDigest.class),$(full_java_libs)))" \ 61 -dontoptimize \ 62 -dontobfuscate \ 63 -dontpreverify \ 64 -ignorewarnings \ 65 -printusage \ 66 -keep class org.bouncycastle.jce.provider.BouncyCastleProvider "{ public protected *; }" \ 67 -keep class org.bouncycastle.jce.provider.symmetric.AESMappings "{ public protected *; }" \ 68 -keep class org.bouncycastle.asn1.ASN1TaggedObject "{ public protected *; }" \ 69 -keep class org.bouncycastle.asn1.x509.CertificateList "{ public protected *; }" \ 70 -keep class org.bouncycastle.crypto.AsymmetricBlockCipher "{ public protected *; }" \ 71 -keep class org.bouncycastle.x509.ExtendedPKIXBuilderParameters "{ public protected *; }" \ 72 `(find $(LOCAL_PATH) -name '*.java' | xargs grep '"org.bouncycastle' | egrep ' (put|add)' | sed -e 's/");//' -e 's/.*"//'; \ 73 find $(LOCAL_PATH) -name '*.java' | xargs grep ' addHMACAlgorithm' | sed 's/"org.bouncycastle/\norg.bouncycastle/g' | grep ^org.bouncycastle | sed 's/".*//'; \ 74 find . -name '*.java' | xargs grep 'import org.bouncycastle' | grep -v /bouncycastle/ | sed -e 's/.*:import //' -e 's/;//') \ 75 | sed -e 's/^/-keep class /' -e 's/$$/ { public protected \*; } /' | sort | uniq` \ 76 -keepclassmembers "class * { \ 77 static final % *; \ 78 static final java.lang.String *; \ 79 }" \ 80 -keepclassmembers "class * implements java.io.Serializable { \ 81 private static final java.io.ObjectStreamField[] serialPersistentFields; \ 82 private void writeObject(java.io.ObjectOutputStream); \ 83 private void readObject(java.io.ObjectInputStream); \ 84 java.lang.Object writeReplace(); \ 85 java.lang.Object readResolve(); \ 86 }" \ 87 -keepclassmembers "interface org.bouncycastle.crypto.paddings.BlockCipherPadding { \ 88 abstract public java.lang.String getPaddingName(); \ 89 }" \ 90 -keepclassmembers "class * implements org.bouncycastle.crypto.paddings.BlockCipherPadding { \ 91 public java.lang.String getPaddingName(); \ 92 }" 93 94ifeq ($(WITH_HOST_DALVIK),true) 95 include $(CLEAR_VARS) 96 LOCAL_MODULE := bouncycastle-hostdex 97 LOCAL_MODULE_TAGS := optional 98 LOCAL_SRC_FILES := $(all_bcprov_src_files) 99 LOCAL_JAVACFLAGS := -encoding UTF-8 100 LOCAL_BUILD_HOST_DEX := true 101 LOCAL_MODULE_TAGS := optional 102 LOCAL_JAVA_LIBRARIES := conscrypt-hostdex 103 LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt 104 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 105 include $(BUILD_HOST_JAVA_LIBRARY) 106endif 107 108include $(CLEAR_VARS) 109LOCAL_MODULE := bouncycastle-host 110LOCAL_MODULE_TAGS := optional 111LOCAL_SRC_FILES := $(ri_bcprov_src_files) 112LOCAL_JAVACFLAGS := -encoding UTF-8 113LOCAL_MODULE_TAGS := optional 114LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 115include $(BUILD_HOST_JAVA_LIBRARY) 116 117include $(CLEAR_VARS) 118LOCAL_MODULE := bouncycastle-bcpkix-host 119LOCAL_MODULE_TAGS := optional 120LOCAL_SRC_FILES := $(call all-java-files-under,bcpkix/src/main/java) 121LOCAL_JAVACFLAGS := -encoding UTF-8 122LOCAL_MODULE_TAGS := optional 123LOCAL_JAVA_LIBRARIES := bouncycastle-host 124LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 125include $(BUILD_HOST_JAVA_LIBRARY) 126