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
32# These cannot build in the PDK, because the PDK requires all libraries
33# compile against SDK versions. LOCAL_NO_STANDARD_LIBRARIES conflicts with
34# this requirement.
35ifneq ($(TARGET_BUILD_PDK),true)
36
37    include $(CLEAR_VARS)
38    LOCAL_MODULE := bouncycastle
39    LOCAL_MODULE_TAGS := optional
40    LOCAL_SRC_FILES := $(android_bcprov_src_files)
41    LOCAL_JAVA_LIBRARIES := core-libart conscrypt
42    LOCAL_NO_STANDARD_LIBRARIES := true
43    LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
44    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
45    include $(BUILD_JAVA_LIBRARY)
46
47    # non-jarjar version to build okhttp-tests
48    include $(CLEAR_VARS)
49    LOCAL_MODULE := bouncycastle-nojarjar
50    LOCAL_MODULE_TAGS := optional
51    LOCAL_SRC_FILES := $(android_bcprov_src_files)
52    LOCAL_JAVA_LIBRARIES := core-libart conscrypt
53    LOCAL_NO_STANDARD_LIBRARIES := true
54    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
55    include $(BUILD_STATIC_JAVA_LIBRARY)
56
57    # unbundled bouncycastle jar
58    include $(CLEAR_VARS)
59    LOCAL_MODULE := bouncycastle-unbundled
60    LOCAL_MODULE_TAGS := optional
61    LOCAL_SDK_VERSION := 9
62    LOCAL_SRC_FILES := $(ri_bcprov_src_files)
63    LOCAL_MODULE_TAGS := optional
64    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
65    include $(BUILD_STATIC_JAVA_LIBRARY)
66endif # TARGET_BUILD_PDK != true
67
68# This is used to generate a list of what is unused so it can be removed when bouncycastle is updated.
69# Based on "Finding dead code" example in ProGuard manual at http://proguard.sourceforge.net/
70.PHONY: bouncycastle-proguard-deadcode
71bouncycastle-proguard-deadcode: $(full_classes_compiled_jar) $(full_java_libs)
72	$(PROGUARD) \
73		-injars $(full_classes_compiled_jar) \
74		-libraryjars "$(call normalize-path-list,$(addsuffix (!org/bouncycastle/**.class,!com/android/org/conscrypt/OpenSSLMessageDigest.class),$(full_java_libs)))" \
75		-dontoptimize \
76		-dontobfuscate \
77		-dontpreverify \
78		-ignorewarnings \
79		-printusage \
80		-keep class org.bouncycastle.jce.provider.BouncyCastleProvider "{ public protected *; }" \
81		-keep class org.bouncycastle.jce.provider.symmetric.AESMappings "{ public protected *; }" \
82		-keep class org.bouncycastle.asn1.ASN1TaggedObject "{ public protected *; }" \
83		-keep class org.bouncycastle.asn1.x509.CertificateList "{ public protected *; }" \
84		-keep class org.bouncycastle.crypto.AsymmetricBlockCipher "{ public protected *; }" \
85		-keep class org.bouncycastle.x509.ExtendedPKIXBuilderParameters "{ public protected *; }" \
86		`(find $(LOCAL_PATH) -name '*.java' | xargs grep '"org.bouncycastle' | egrep '  (put|add)' | sed -e 's/");//' -e 's/.*"//'; \
87		  find $(LOCAL_PATH) -name '*.java' | xargs grep '  addHMACAlgorithm' | sed 's/"org.bouncycastle/\norg.bouncycastle/g' | grep ^org.bouncycastle | sed 's/".*//'; \
88                  find . -name '*.java' | xargs grep 'import org.bouncycastle' | grep -v /bouncycastle/ | sed -e 's/.*:import //' -e 's/;//') \
89		  | sed -e 's/^/-keep class /' -e 's/$$/ { public protected \*; } /' | sort | uniq` \
90		-keepclassmembers "class * { \
91		    static final %                *; \
92		    static final java.lang.String *; \
93		}" \
94		-keepclassmembers "class * implements java.io.Serializable { \
95		    private static final java.io.ObjectStreamField[] serialPersistentFields; \
96		    private void writeObject(java.io.ObjectOutputStream); \
97		    private void readObject(java.io.ObjectInputStream); \
98		    java.lang.Object writeReplace(); \
99		    java.lang.Object readResolve(); \
100		}" \
101		-keepclassmembers "interface org.bouncycastle.crypto.paddings.BlockCipherPadding { \
102		    abstract public java.lang.String getPaddingName(); \
103		}" \
104		-keepclassmembers "class * implements org.bouncycastle.crypto.paddings.BlockCipherPadding { \
105		    public java.lang.String getPaddingName(); \
106		}"
107
108# Conscrypt isn't built in the PDK or on non-linux OSes, so this cannot be built
109# because it has a dependency on conscrypt-hostdex.
110ifneq ($(TARGET_BUILD_PDK),true)
111  ifeq ($(HOST_OS),linux)
112    include $(CLEAR_VARS)
113    LOCAL_MODULE := bouncycastle-hostdex
114    LOCAL_MODULE_TAGS := optional
115    LOCAL_SRC_FILES := $(all_bcprov_src_files)
116    LOCAL_MODULE_TAGS := optional
117    LOCAL_JAVA_LIBRARIES := conscrypt-hostdex
118    LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
119    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
120    include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
121  endif  # ($(HOST_OS),linux)
122endif
123
124include $(CLEAR_VARS)
125LOCAL_MODULE := bouncycastle-host
126LOCAL_MODULE_TAGS := optional
127LOCAL_SRC_FILES := $(ri_bcprov_src_files)
128LOCAL_MODULE_TAGS := optional
129LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
130include $(BUILD_HOST_JAVA_LIBRARY)
131
132include $(CLEAR_VARS)
133LOCAL_MODULE := bouncycastle-bcpkix-host
134LOCAL_MODULE_TAGS := optional
135LOCAL_SRC_FILES := $(call all-java-files-under,bcpkix/src/main/java)
136LOCAL_MODULE_TAGS := optional
137LOCAL_JAVA_LIBRARIES := bouncycastle-host
138LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
139include $(BUILD_HOST_JAVA_LIBRARY)
140