diff options
author | Brian Carlstrom <bdc@google.com> | 2012-09-17 16:04:47 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2012-09-19 14:26:13 -0700 |
commit | e6bf3e8dfa2804891a82075cb469b736321b4827 (patch) | |
tree | 8d78ebadb9c33191a0490537dbd50da4e6c85b49 /import_bouncycastle.sh | |
parent | 517da5b1cf8927b100e5e1d9df870854b09aa2ce (diff) | |
download | bouncycastle-e6bf3e8dfa2804891a82075cb469b736321b4827.tar.gz |
Make existing bouncycastle bcprov build on host and add host-only bcpkix build
- Move existing provider source to bcprov
- Added bcpkix host build to support built/tooks/signapk
sha1sum of sources:
- 10bfea344842fe8e065c80e399c93f8651dc87d8 bcprov-jdk15on-147.tar.gz
- 913828c7ae36e030508e97e07b3c213fb1db1e9c bcpkix-jdk15on-147.tar.gz
Bug: 7056297
Change-Id: Id4f957f300a39aa34b4c3c679b2312631d3f1639
Diffstat (limited to 'import_bouncycastle.sh')
-rwxr-xr-x | import_bouncycastle.sh | 191 |
1 files changed, 103 insertions, 88 deletions
diff --git a/import_bouncycastle.sh b/import_bouncycastle.sh index 297efeff..6d76099e 100755 --- a/import_bouncycastle.sh +++ b/import_bouncycastle.sh @@ -16,10 +16,11 @@ # # -# This script imports new versions of Bouncy Castle (http://bouncycastle.org) into the -# Android source tree. To run, (1) fetch the appropriate tarball from the Bouncy Castle repository, -# (2) check the checksum, and then (3) run: -# ./import_bouncycastle.sh bcprov-jdk*-*.tar.gz +# This script imports new versions of Bouncy Castle +# (http://bouncycastle.org) into the Android source tree. To run, (1) +# fetch the appropriate tarballs (bcprov and bcpkix) from the Bouncy +# Castle repository, (2) check the checksum, and then (3) run: +# ./import_bouncycastle.sh import bcprov-jdk*-*.tar.gz # # IMPORTANT: See README.android for additional details. @@ -61,156 +62,168 @@ function main() { die "Invalid bouncycastle.version; see README.android for more information" fi - BOUNCYCASTLE_DIR=bcprov-jdk$BOUNCYCASTLE_JDK-$BOUNCYCASTLE_VERSION - BOUNCYCASTLE_DIR_ORIG=$BOUNCYCASTLE_DIR.orig + BOUNCYCASTLE_BCPROV_DIR=bcprov-jdk$BOUNCYCASTLE_JDK-$BOUNCYCASTLE_VERSION + BOUNCYCASTLE_BCPROV_DIR_ORIG=$BOUNCYCASTLE_BCPROV_DIR.orig + + BOUNCYCASTLE_BCPKIX_DIR=bcpkix-jdk$BOUNCYCASTLE_JDK-$BOUNCYCASTLE_VERSION + BOUNCYCASTLE_BCPKIX_DIR_ORIG=$BOUNCYCASTLE_BCPKIX_DIR.orig if [ ! -f bouncycastle.config ]; then die "bouncycastle.config not found" fi source bouncycastle.config - if [ "$UNNEEDED_SOURCES" == "" -o "$NEEDED_SOURCES" == "" ]; then + if [ "$UNNEEDED_BCPROV_SOURCES" == "" -o "$NEEDED_BCPROV_SOURCES" == "" \ + -o "$UNNEEDED_BCPKIX_SOURCES" == "" -o "$NEEDED_BCPKIX_SOURCES" == "" ]; then die "Invalid bouncycastle.config; see README.android for more information" fi declare -r command=$1 shift || usage "No command specified. Try import, regenerate, or generate." if [ "$command" = "import" ]; then - declare -r tar=$1 + declare -r bcprov_tar=$1 shift || usage "No tar file specified." - import $tar + declare -r bcpkix_tar=`echo $bcprov_tar | sed s/bcprov/bcpkix/` + import $bcprov_tar $BOUNCYCASTLE_BCPROV_DIR $BOUNCYCASTLE_BCPROV_DIR_ORIG bcprov "$BOUNCYCASTLE_BCPROV_PATCHES" "$NEEDED_BCPROV_SOURCES" "$UNNEEDED_BCPROV_SOURCES" + import $bcpkix_tar $BOUNCYCASTLE_BCPKIX_DIR $BOUNCYCASTLE_BCPKIX_DIR_ORIG bcpkix "$BOUNCYCASTLE_BCPKIX_PATCHES" "$NEEDED_BCPKIX_SOURCES" "$UNNEEDED_BCPKIX_SOURCES" elif [ "$command" = "regenerate" ]; then declare -r patch=$1 shift || usage "No patch file specified." - [ -d $BOUNCYCASTLE_DIR ] || usage "$BOUNCYCASTLE_DIR not found, did you mean to use generate?" - [ -d $BOUNCYCASTLE_DIR_ORIG ] || usage "$BOUNCYCASTLE_DIR_ORIG not found, did you mean to use generate?" - regenerate $patch + if [[ $BOUNCYCASTLE_BCPROV_PATCHES == *$patch* ]]; then + [ -d $BOUNCYCASTLE_BCPROV_DIR ] || usage "$BOUNCYCASTLE_BCPROV_DIR not found, did you mean to use generate?" + [ -d $BOUNCYCASTLE_BCPROV_DIR_ORIG ] || usage "$BOUNCYCASTLE_BCPROV_DIR_ORIG not found, did you mean to use generate?" + regenerate $patch $BOUNCYCASTLE_BCPROV_DIR $BOUNCYCASTLE_BCPROV_DIR_ORIG + elif [[ $BOUNCYCASTLE_BCPKIX_PATCHES == *$patch* ]]; then + [ -d $BOUNCYCASTLE_BCPKIX_DIR ] || usage "$BOUNCYCASTLE_BCPROV_DIR not found, did you mean to use generate?" + [ -d $BOUNCYCASTLE_BCPKIX_DIR_ORIG ] || usage "$BOUNCYCASTLE_BCPKIX_DIR_ORIG not found, did you mean to use generate?" + regenerate $patch $BOUNCYCASTLE_BCPKIX_DIR $BOUNCYCASTLE_BCPKIX_DIR_ORIG + else + usage "Unknown patch file $patch specified" + fi elif [ "$command" = "generate" ]; then declare -r patch=$1 shift || usage "No patch file specified." - declare -r tar=$1 + declare -r bcprov_tar=$1 shift || usage "No tar file specified." - generate $patch $tar + declare -r bcpkix_tar=`echo $bcprov_tar | sed s/bcprov/bcpkix/` + if [[ $BOUNCYCASTLE_BCPROV_PATCHES == *$patch* ]]; then + generate $patch $bcprov_tar $BOUNCYCASTLE_BCPROV_DIR $BOUNCYCASTLE_BCPROV_DIR_ORIG bcprov "$BOUNCYCASTLE_BCPROV_PATCHES" "$NEEDED_BCPROV_SOURCES" "$UNNEEDED_BCPROV_SOURCES" + elif [[ $BOUNCYCASTLE_BCPKIX_PATCHES == *$patch* ]]; then + generate $patch $bcpkix_tar $BOUNCYCASTLE_BCPKIX_DIR $BOUNCYCASTLE_BCPKIX_DIR_ORIG bcpkix "$BOUNCYCASTLE_BCPKIX_PATCHES" "$NEEDED_BCPKIX_SOURCES" "$UNNEEDED_BCPKIX_SOURCES" + else + usage "Unknown patch file $patch specified" + fi else usage "Unknown command specified $command. Try import, regenerate, or generate." fi } function import() { - declare -r BOUNCYCASTLE_SOURCE=$1 + declare -r bouncycastle_source=$1 + declare -r bouncycastle_dir=$2 + declare -r bouncycastle_dir_orig=$3 + declare -r bouncycastle_out_dir=$4 + declare -r bouncycastle_patches=$5 + declare -r needed_sources=$6 + declare -r unneeded_sources=$7 - untar $BOUNCYCASTLE_SOURCE - applypatches + untar $bouncycastle_source $bouncycastle_dir $bouncycastle_dir_orig "$unneeded_sources" + applypatches $bouncycastle_dir "$bouncycastle_patches" "$unneeded_sources" - cd $BOUNCYCASTLE_DIR + cd $bouncycastle_dir sed 's/<p>/& <BR>/g' LICENSE.html | html2text -width 102 -nobs -ascii > ../NOTICE touch ../MODULE_LICENSE_BSD_LIKE cd .. - rm -r src - mkdir -p src/main/java/ - for i in $NEEDED_SOURCES; do + rm -r $bouncycastle_out_dir/src + mkdir -p $bouncycastle_out_dir/src/main/java/ + for i in $needed_sources; do echo "Updating $i" - mv $BOUNCYCASTLE_DIR/$i src/main/java/ + mv $bouncycastle_dir/$i $bouncycastle_out_dir/src/main/java/ done - # if [ $BOUNCYCASTLE_VERSION -ge 145 ]; then - # # move test directories from src/main/java to src/test/java - # for from in `find src/main/java -name test`; do - # to=`dirname $from | sed s,src/main/java/,src/test/java/,` - # echo "Moving $from to $to" - # mkdir -p $to - # mv $from $to - # done - # fi - - # # move stray test files from src/main/java to src/test/java - # if [ $BOUNCYCASTLE_VERSION -ge 137 ]; then - # mkdir -p src/test/java/org/bouncycastle/util/ - # echo "Moving src/main/java/org/bouncycastle/util tests" - # mv src/main/java/org/bouncycastle/util/*Test*.java src/test/java/org/bouncycastle/util/ - # fi - - cleantar + cleantar $bouncycastle_dir $bouncycastle_dir_orig } function regenerate() { declare -r patch=$1 + declare -r bouncycastle_dir=$2 + declare -r bouncycastle_dir_orig=$3 - generatepatch $patch + generatepatch $patch $bouncycastle_dir $bouncycastle_dir_orig } function generate() { declare -r patch=$1 - declare -r BOUNCYCASTLE_SOURCE=$2 - - untar $BOUNCYCASTLE_SOURCE - applypatches - - # # restore stray test files from src/test/java back to src/main/java - # if [ $BOUNCYCASTLE_VERSION -ge 137 ]; then - # echo "Restoring src/test/java/org/bouncycastle/util" - # mv src/test/java/org/bouncycastle/util/* src/main/java/org/bouncycastle/util/ - # fi - - # # restore test directories from src/test/java back to src/main/java - # if [ $BOUNCYCASTLE_VERSION -ge 145 ]; then - # for from in `find src/test/java -name test`; do - # to=`dirname $from | sed s,src/test/java/,src/main/java/,` - # echo "Restoring $from to $to" - # mkdir -p $to - # mv $from $to - # done - # fi - - for i in $NEEDED_SOURCES; do + declare -r bouncycastle_source=$2 + declare -r bouncycastle_dir=$3 + declare -r bouncycastle_dir_orig=$4 + declare -r bouncycastle_out_dir=$5 + declare -r bouncycastle_patches=$6 + declare -r needed_sources=$7 + declare -r unneeded_sources=$8 + + untar $bouncycastle_source $bouncycastle_dir $bouncycastle_dir_orig "$unneeded_sources" + applypatches $bouncycastle_dir "$bouncycastle_patches" "$unneeded_sources" + + for i in $needed_sources; do echo "Restoring $i" - rm -r $BOUNCYCASTLE_DIR/$i - cp -rf src/main/java/$i $BOUNCYCASTLE_DIR/$i + rm -r $bouncycastle_dir/$i + cp -rf $bouncycastle_out_dir/src/main/java/$i $bouncycastle_dir/$i done - generatepatch $patch - cleantar + generatepatch $patch $bouncycastle_dir $bouncycastle_dir_orig + cleantar $bouncycastle_dir $bouncycastle_dir_orig } function untar() { - declare -r BOUNCYCASTLE_SOURCE=$1 + declare -r bouncycastle_source=$1 + declare -r bouncycastle_dir=$2 + declare -r bouncycastle_dir_orig=$3 + declare -r unneeded_sources=$4 # Remove old source - cleantar + cleantar $bouncycastle_dir $bouncycastle_dir_orig # Process new source - tar -zxf $BOUNCYCASTLE_SOURCE - mv $BOUNCYCASTLE_DIR $BOUNCYCASTLE_DIR_ORIG - find $BOUNCYCASTLE_DIR_ORIG -type f -print0 | xargs -0 chmod a-w - (cd $BOUNCYCASTLE_DIR_ORIG && unzip -q src.zip) - tar -zxf $BOUNCYCASTLE_SOURCE - (cd $BOUNCYCASTLE_DIR && unzip -q src.zip) + tar -zxf $bouncycastle_source + mv $bouncycastle_dir $bouncycastle_dir_orig + find $bouncycastle_dir_orig -type f -print0 | xargs -0 chmod a-w + (cd $bouncycastle_dir_orig && unzip -q src.zip) + tar -zxf $bouncycastle_source + (cd $bouncycastle_dir && unzip -q src.zip) # Prune unnecessary sources - echo "Removing $UNNEEDED_SOURCES" - (cd $BOUNCYCASTLE_DIR_ORIG && rm -rf $UNNEEDED_SOURCES) - (cd $BOUNCYCASTLE_DIR && rm -r $UNNEEDED_SOURCES) + echo "Removing $unneeded_sources" + (cd $bouncycastle_dir_orig && rm -rf $unneeded_sources) + (cd $bouncycastle_dir && rm -r $unneeded_sources) } function cleantar() { - rm -rf $BOUNCYCASTLE_DIR_ORIG - rm -rf $BOUNCYCASTLE_DIR + declare -r bouncycastle_dir=$1 + declare -r bouncycastle_dir_orig=$2 + + rm -rf $bouncycastle_dir_orig + rm -rf $bouncycastle_dir } function applypatches () { - cd $BOUNCYCASTLE_DIR + declare -r bouncycastle_dir=$1 + declare -r bouncycastle_patches=$2 + declare -r unneeded_sources=$3 + + cd $bouncycastle_dir # Apply appropriate patches - for i in $BOUNCYCASTLE_PATCHES; do + for i in $bouncycastle_patches; do echo "Applying patch $i" - patch -p1 < ../patches/$i || die "Could not apply patches/$i. Fix source and run: $0 regenerate patches/$i" + patch -p1 < ../$i || die "Could not apply patches/$i. Fix source and run: $0 regenerate patches/$i" - # make sure no UNNEEDED_SOURCES got into the patch + # make sure no unneeded sources got into the patch problem=0 - for s in $UNNEEDED_SOURCES; do + for s in $unneeded_sources; do if [ -e $s ]; then echo Unneeded source $s restored by patch $i problem=1 @@ -229,13 +242,15 @@ function applypatches () { function generatepatch() { declare -r patch=$1 + declare -r bouncycastle_dir=$2 + declare -r bouncycastle_dir_orig=$3 # Cleanup stray files before generating patch - find $BOUNCYCASTLE_DIR -type f -name "*.orig" -print0 | xargs -0 rm -f - find $BOUNCYCASTLE_DIR -type f -name "*~" -print0 | xargs -0 rm -f + find $bouncycastle_dir -type f -name "*.orig" -print0 | xargs -0 rm -f + find $bouncycastle_dir -type f -name "*~" -print0 | xargs -0 rm -f rm -f $patch - LC_ALL=C TZ=UTC0 diff -Naur $BOUNCYCASTLE_DIR_ORIG $BOUNCYCASTLE_DIR >> $patch && die "ERROR: No diff for patch $path in file $i" + LC_ALL=C TZ=UTC0 diff -Naur $bouncycastle_dir_orig $bouncycastle_dir >> $patch && die "ERROR: No diff for patch $path in file $i" echo "Generated patch $patch" } |