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