Skip to content
Commits on Source (120)
bin
*.OBJ/
# CMake build directory
build/
# These files are automatically generated from their .in equivalents
org/mozilla/jss/util/jssver.h
......@@ -3,25 +3,46 @@
# All rights reserved.
# END COPYRIGHT BLOCK
language: java
services:
- docker
env:
- FEDORA=27
- FEDORA=28
stages:
- validate
- test
- extra
install:
- docker pull registry.fedoraproject.org/fedora:$FEDORA
- docker run
--name=container
--detach
-i
-v $(pwd):/root/jss
registry.fedoraproject.org/fedora:$FEDORA
- docker exec container dnf install -y dnf-plugins-core gcc make rpm-build
- docker exec container dnf copr -y enable ${JSS_4_5_REPO:-@pki/10.6}
- docker exec container dnf builddep -y --spec /root/jss/jss.spec.in
- docker exec container /root/jss/build.sh --with-timestamp --with-commit-id rpm
env:
- BASE_IMAGE="fedora_28"
- BASE_IMAGE="fedora_29"
script:
- docker exec container rpm -Uvh /root/build/jss/RPMS/*
- bash tools/run_container.sh "$BASE_IMAGE"
matrix:
fast_finish: true
include:
- stage: validate
env: BASE_IMAGE="stylecheck"
- stage: extra
env: BASE_IMAGE="pkcs11check"
- stage: extra
env: BASE_IMAGE="debian_jdk11"
- stage: extra
env: BASE_IMAGE="ubuntu_jdk8"
- stage: extra
env: BASE_IMAGE="fedora_29_jdk11"
- stage: extra
env: BASE_IMAGE="fedora_rawhide"
allow_failures:
- stage: extra
env: BASE_IMAGE="pkcs11check"
- stage: extra
env: BASE_IMAGE="debian_jdk11"
- stage: extra
env: BASE_IMAGE="ubuntu_jdk8"
- stage: extra
env: BASE_IMAGE="fedora_29_jdk11"
- stage: extra
env: BASE_IMAGE="fedora_rawhide"
# This is the CMakeLists.txt for the JSS Project.
project(jss)
# Required cmake version; set a 3.0.2 since that's the version of the
# documentation I referenced.
cmake_minimum_required(VERSION 3.0.2)
# Source our custom CMake modules; this includes NSS and NSPR modules from
# PKI and the JSSConfig and JSSCommon modules.
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Define optional variables and conditionals.
if (DEFINED CHECK_DEPRECATION)
set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint:deprecation")
endif()
# Build a debug build by default when no type is specified on the command line
if(NOT (DEFINED CMAKE_BUILD_TYPE))
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Find NSPR and NSS Libraries.
find_package(NSPR REQUIRED)
find_package(NSS REQUIRED)
# Find Java and JNI packages; this sets CMake wariables like
# Java_JAVAC_EXECUTABLE.
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
# Since we found Java, include UseJava to provide the find_jar function.
include(UseJava)
# Load JSSConfig module; this defines the jss_config() macro which defines
# JSS-specific configuration values.
include(JSSConfig)
# Load JSSCommon module; this defines the jss_build() macros which defines
# the JSS build procedure.
include(JSSCommon)
# Load JSSTests module; this defines the jss_tests() macro which defines the
# JSS test procedure.
include(JSSTests)
jss_config()
jss_build()
jss_tests()
#! gmake
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY). #
#######################################################################
include manifest.mn
#######################################################################
# (2) Include "global" configuration information. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/coreconf/config.mk
#######################################################################
# (3) Include "component" configuration information. (OPTIONAL) #
#######################################################################
#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
#######################################################################
#######################################################################
# (5) Execute "global" rules. (OPTIONAL) #
#######################################################################
# have to put this here, instead of in rules.mk, so that Java gets
# built first
all:: buildJava
test_jss: testJava
include $(CORE_DEPTH)/coreconf/rules.mk
#######################################################################
# (6) Execute "component" rules. (OPTIONAL) #
#######################################################################
#######################################################################
# (7) Execute "local" rules. (OPTIONAL). #
#######################################################################
include rules.mk
package:
$(MAKE) -C pkg publish
......@@ -10,271 +10,67 @@ JSS also provides a pure Java interface for ASN.1 types and BER/DER encoding.
* Website: http://www.dogtagpki.org/wiki/JSS
* Issues: https://pagure.io/jss/issues
* Archive: https://github.com/dogtagpki/jss-archive
* Javadocs: https://dogtagpki.github.io/jss
Build/Test Instructions
-----------------------
**NOTICE:** As of JSS version 4.5.1, the legacy build instructions will not
work; the build system has been completely replaced with CMake.
### 1. Prepare a work area
Dependencies
------------
(a) For upstream builds which checkout and utilize
the current NSPR and NSS source repositories:
This project has the following dependencies:
```
# mkdir sandbox
# cd sandbox
# hg clone https://hg.mozilla.org/projects/nspr
# hg clone https://hg.mozilla.org/projects/nss
# git clone git@github.com:dogtagpki/jss.git
# cd ..
```
- [NSPR](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR)
- [NSS](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS)
- A c and c++ compiler such as [gcc](ttps://gcc.gnu.org/)
- [zlib](https://zlib.net/)
- [OpenJDK 1.8.0](https://openjdk.java.net/)
- [CMake](https://cmake.org/)
- [Apache Commons Lang](https://commons.apache.org/proper/commons-lang/)
- [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/)
- [JavaEE JAXB](https://github.com/eclipse-ee4j/jaxb-ri)
- [SLF4J](https://www.slf4j.org/)
There is no need to clone every time. For additional builds,
simply use:
To install these dependencies on Fedora, execute the following:
```
# cd nspr
# hg pull -u -v
# cd ..
# cd nss
# hg pull -u -v
# cd ..
# cd jss
# git pull -v
# cd ..
````
sudo dnf install apache-commons-codec apache-commons-lang gcc-c++ \
java-devel jpackage-utils slf4j zlib-devel \
glassfish-jaxb-api nss-tools nss-devel cmake
(b) Alternatively, for upstream builds which use
the NSPR and NSS installed on the system:
To install these dependencies on Debian, execute the following:
```
# mkdir sandbox
# cd sandbox
# export USE_INSTALLED_NSPR=1
# export USE_INSTALLED_NSS=1
# export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
# export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
# export NSPR_INCLUDE_DIR=`/usr/bin/pkg-config --cflags-only-I nspr | sed 's/-I//'`
# export NSPR_LIB_DIR=`/usr/bin/pkg-config --libs-only-L nspr | sed 's/-L//'`
# export NSS_INCLUDE_DIR=`/usr/bin/pkg-config --cflags-only-I nss | sed 's/-I//'`
# export NSS_LIB_DIR=`/usr/bin/pkg-config --libs-only-L nss | sed 's/-L//'`
# export XCFLAGS="-g"
# hg clone https://hg.mozilla.org/projects/jss
# cd ..
```
sudo apt-get install build-essential libcommons-codec-java \
libcommons-lang-java libnss3-dev libslf4j-java \
openjdk-8-jdk pkg-config zlib1g-dev \
libjaxb-api-java libnss3-tools cmake zip unzip
There is no need to clone every time. For additional builds,
simply use:
```
# cd jss
# git pull -v
# cd ..
```
### 2. Prepare an interactive shell for building
```
# export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0_openjdk
# export USE_64=1
```
NOTE: JSS will now attempt to verify whether or not these two
environment variables have been set (JAVA_HOME is mandatory;
USE_64 is mandatory on 64-bit platforms when building 64-bit).
The following steps are optional, and left to the discretion of the user:
#### Normal vs. Optimized builds
By default, JSS will be built as a normal binaries.
To create an optimized build, set the following
environment variable:
```
# export BUILD_OPT=1
```
#### Beta vs. Non-Beta builds
Finally, by default, JSS is not built as a "beta" release (as
specified in 'org/mozilla/jss/util/jssver.h'):
```
#define JSS_BETA PR_FALSE
```
If a "beta" version of JSS is desired, reset this #define (as
specified in 'org/mozilla/jss/util/jssver.h') to:
```
#define JSS_BETA PR_TRUE
```
### 3. Build JSS
To build JSS, execute the following commands:
```
# cd sandbox/jss
# make clean all
# cd ../..
```
or you can run:
```
# script -c 'make clean all' typescript.build
```
NOTE: When build method (1)(a) is being utilized, if nss has not been
built, it will now automatically be built before jss; if nss has
already been built, only jss will be built/re-built.
### 4. Install JSS on the System (Optional)
If JSS already exists on the system, run something similar to the
following command(s):
```
# sudo mv /usr/lib/java/jss4.jar /usr/lib/java/jss4.jar.orig
```
If the platform is 32-bit Linux:
```
# sudo mv /usr/lib/jss/libjss4.so /usr/lib/jss/libjss4.so.orig
```
else if the platform is 64-bit Linux:
```
# sudo mv /usr/lib64/jss/libjss4.so /usr/lib64/jss/libjss4.so.orig
```
Then install the new JSS binaries:
```
# sudo cp sandbox/dist/xpclass.jar /usr/lib/java/jss4.jar
# sudo chown root:root /usr/lib/java/jss4.jar
# sudo chmod 644 /usr/lib/java/jss4.jar
# sudo cp sandbox/jss/lib/Linux*.OBJ/libjss4.so /usr/lib64/jss/libjss4.so
# sudo chown root:root /usr/lib64/jss/libjss4.so
# sudo chmod 755 /usr/lib64/jss/libjss4.so
```
### 5. Run JSS Tests (Optional, but only if build method (1)(a) was utilized)
If build method (1)(a) is being utilized, it is possible to run the built-in JSS tests:
```
# cd sandbox/jss
# make test_jss
# cd ../..
```
or you can run:
```
# script -c 'make test_jss' typescript.tests
```
NOTE: This command is currently only available on Linux and Macintosh
platforms when method (1)(a) has been utilized to build JSS
since the tests are dependent upon the work area as setup in
this method; currenty JSS must be built via 'make clean all' before
execution of this command (e.g. - build is separate from test).
### 6. Restoration of non-Test-Only Systems (Optional)
If step (4) above was run, and the system is being used for purposes
other than test, the user may wish to restore the original system JSS
by running the following commands:
```
# sudo mv /usr/lib/java/jss4.jar.orig /usr/lib/java/jss4.jar
```
If the platform is 32-bit Linux:
```
# sudo mv /usr/lib/jss/libjss4.so.orig /usr/lib/jss/libjss4.so
```
else if the platform is 64-bit Linux:
```
# sudo mv /usr/lib64/jss/libjss4.so.orig /usr/lib64/jss/libjss4.so
```
NOTE: For this procedure, no ownership or permission changes should
be necessary.
### 7. Tagging the Source Code for a Release
During development, several releases may be made. Consequently, it is
good practice to create a "regular tag" to the source code at these
various points in time using the following format:
```
# git tag -m "message" JSS_<major>_<minor>_<YYYYMMDD>
```
where:
* major = JSS Major Version Number
* minor = JSS Minor Version Number
* YYYY = 4-digit year (e. g. - 2017)
* MM = 2-digit month (e. g. - 01, ..., 12)
* DD = 2-digit day of the month (e. g. - 01, ..., 31)
For example:
```
# git rev-parse HEAD
b3e864205ff0...
# git tag -m "Added tag JSS_4_4_20170328 for changeset b3e864205ff0" JSS_4_4_20170328
```
At the appropriate time, a new major.minor version may be created. At this
time, it is important to create a maintenance branch for any future changes
to the previous major.minor version:
For example:
```
# git rev-parse HEAD
f00f00f00f00...
# git checkout -b JSS_4_4_BRANCH
```
Building
--------
### 8. Known Issues
To build JSS and make a best effort to detect environment variables:
Some of the known issues are:
git clone https://github.com/dogtagpki/jss
cd jss/build && cmake ..
make all check
* Mozilla Bug #1346410 - Load JSS libraries appropriately
Alternatively, to build a RPM distribution of JSS:
NOTE: This issue should not occur unless step (4) above was skipped.
git clone https://github.com/dogtagpki/jss
cd jss
./build.sh
Testing failures were found while working on Bug 1346410 when loading the
JSS libraries to meet requirements of certain operating systems. Our
investigation revealed that due to the nature of the changes made via this
patch and its interaction with the HMAC Tests (both non-FIPS and FIPS),
that a failure may be encountered on one or more of the HMAC algorithms
causing these two tests to fail. On 64-bit Linux, for example, the
workaround for this issue is to perform the following steps before
re-running the tests:
To view more detailed instructions for building JSS, please refer to
the build documentation: [`docs/building.md`](docs/building.md).
* Install the new JSS builds by executing step (4) above
* Execute the following commands:
```
# cd sandbox/jss
# make test_jss
```
Contributing
------------
NOTE: If the system is being used for purposes other than test, the user
may wish to restore the original JSS by executing step (6) above.
We welcome all contributions to JSS! If you're looking for help getting
started, check out our [documentation](docs/contributing.md), or if you
want to contact us, check out the following forums:
- The [pki-devel mailing list](https://www.redhat.com/mailman/listinfo/pki-devel).
- The `#dogtagpki` IRC channel on [Freenode](https://freenode.net/).
......@@ -7,10 +7,10 @@
NAME=jss
SCRIPT_PATH=`readlink -f "$0"`
SCRIPT_NAME=`basename "$SCRIPT_PATH"`
SCRIPT_PATH="$(readlink -f "$0")"
SCRIPT_NAME="$(basename "$SCRIPT_PATH")"
SRC_DIR=`dirname "$SCRIPT_PATH"`
SRC_DIR="$(dirname "$SCRIPT_PATH")"
WORK_DIR="$HOME/build/$NAME"
SOURCE_TAG=
......@@ -57,14 +57,14 @@ generate_rpm_sources() {
git -C "$SRC_DIR" \
archive \
--format=tar.gz \
--prefix $NAME-$VERSION${_PHASE}/ \
--prefix "$NAME-$VERSION${_PHASE}/" \
-o "$WORK_DIR/SOURCES/$TARBALL" \
$SOURCE_TAG
if [ "$SOURCE_TAG" != "HEAD" ] ; then
TAG_ID=`git -C "$SRC_DIR" rev-parse $SOURCE_TAG`
HEAD_ID=`git -C "$SRC_DIR" rev-parse HEAD`
TAG_ID="$(git -C "$SRC_DIR" rev-parse $SOURCE_TAG)"
HEAD_ID="$(git -C "$SRC_DIR" rev-parse HEAD)"
if [ "$TAG_ID" != "$HEAD_ID" ] ; then
generate_patch
......@@ -138,7 +138,7 @@ while getopts v-: arg ; do
case $OPTARG in
work-dir=?*)
WORK_DIR=`readlink -f "$LONG_OPTARG"`
WORK_DIR="$(readlink -f "$LONG_OPTARG")"
;;
source-tag=?*)
SOURCE_TAG="$LONG_OPTARG"
......@@ -211,13 +211,13 @@ if [ "$SPEC_TEMPLATE" = "" ] ; then
SPEC_TEMPLATE="$SRC_DIR/$NAME.spec"
fi
VERSION="`rpmspec -P "$SPEC_TEMPLATE" | grep "^Version:" | awk '{print $2;}'`"
VERSION="$(rpmspec -P "$SPEC_TEMPLATE" | grep "^Version:" | awk '{print $2;}')"
if [ "$DEBUG" = true ] ; then
echo "VERSION: $VERSION"
fi
RELEASE="`rpmspec -P "$SPEC_TEMPLATE" --undefine dist | grep "^Release:" | awk '{print $2;}'`"
RELEASE="$(rpmspec -P "$SPEC_TEMPLATE" --undefine dist | grep "^Release:" | awk '{print $2;}')"
if [ "$DEBUG" = true ] ; then
echo "RELEASE: $RELEASE"
......@@ -234,7 +234,7 @@ if [ "$DEBUG" = true ] ; then
fi
if [ "$WITH_TIMESTAMP" = true ] ; then
TIMESTAMP="`date +"%Y%m%d%H%M%S"`"
TIMESTAMP="$(date +"%Y%m%d%H%M%S")"
_TIMESTAMP=".$TIMESTAMP"
fi
......@@ -243,7 +243,7 @@ if [ "$DEBUG" = true ] ; then
fi
if [ "$WITH_COMMIT_ID" = true ]; then
COMMIT_ID="`git -C "$SRC_DIR" rev-parse --short=8 HEAD`"
COMMIT_ID="$(git -C "$SRC_DIR" rev-parse --short=8 HEAD)"
_COMMIT_ID=".$COMMIT_ID"
fi
......@@ -261,8 +261,8 @@ if [ "$VERBOSE" = true ] ; then
echo "Initializing $WORK_DIR"
fi
mkdir -p $WORK_DIR
cd $WORK_DIR
mkdir -p "$WORK_DIR"
cd "$WORK_DIR"
rm -rf BUILD
rm -rf RPMS
......@@ -283,7 +283,7 @@ mkdir SRPMS
generate_rpm_sources
echo "RPM sources:"
find "$WORK_DIR/SOURCES" -type f -printf " %p\n"
find "$WORK_DIR/SOURCES" -type f -printf " %p\\n"
if [ "$BUILD_TARGET" = "src" ] ; then
exit
......@@ -296,7 +296,7 @@ fi
generate_rpm_spec
echo "RPM spec:"
find "$WORK_DIR/SPECS" -type f -printf " %p\n"
find "$WORK_DIR/SPECS" -type f -printf " %p\\n"
if [ "$BUILD_TARGET" = "spec" ] ; then
exit
......@@ -324,7 +324,7 @@ if [ "$DIST" != "" ] ; then
fi
if [ "$DEBUG" = true ] ; then
echo "rpmbuild -bs ${OPTIONS[@]} $WORK_DIR/SPECS/$RPM_SPEC"
echo rpmbuild -bs "${OPTIONS[@]}" "$WORK_DIR/SPECS/$RPM_SPEC"
fi
# build SRPM with user-provided options
......@@ -337,7 +337,7 @@ if [ $rc != 0 ]; then
exit 1
fi
SRPM=`find "$WORK_DIR/SRPMS" -type f`
SRPM="$(find "$WORK_DIR/SRPMS" -type f)"
echo "SRPM package:"
echo " $SRPM"
......@@ -359,7 +359,7 @@ fi
OPTIONS+=(--define "_topdir ${WORK_DIR}")
if [ "$DEBUG" = true ] ; then
echo "rpmbuild --rebuild ${OPTIONS[@]} $SRPM"
echo rpmbuild --rebuild "${OPTIONS[@]}" "$SRPM"
fi
# rebuild RPM with hard-coded options in SRPM
......@@ -382,4 +382,4 @@ find "$WORK_DIR/RPMS" -mindepth 2 -type f -exec mv -i '{}' "$WORK_DIR/RPMS" ';'
find "$WORK_DIR/RPMS" -mindepth 1 -type d -delete
echo "RPM packages:"
find "$WORK_DIR/RPMS" -type f -printf " %p\n"
find "$WORK_DIR/RPMS" -type f -printf " %p\\n"
#use strict;
use Cwd qw(abs_path);
use File::Find;
use File::Compare;
use File::Basename;
use File::stat;
use File::Copy;
@excluded_sources = qw(
provider\.new/
org/mozilla/jss/provider/java/security/KeyFactorySpi1_4\.java
org/mozilla/jss/pkix/cert/X509Certificate\.java
samples/
);
@javah_classes = qw(
org.mozilla.jss.DatabaseCloser
org.mozilla.jss.CryptoManager
org.mozilla.jss.crypto.Algorithm
org.mozilla.jss.crypto.EncryptionAlgorithm
org.mozilla.jss.crypto.PQGParams
org.mozilla.jss.crypto.SecretDecoderRing
org.mozilla.jss.asn1.ASN1Util
org.mozilla.jss.pkcs11.CertProxy
org.mozilla.jss.pkcs11.CipherContextProxy
org.mozilla.jss.pkcs11.PK11Module
org.mozilla.jss.pkcs11.ModuleProxy
org.mozilla.jss.pkcs11.PK11Cert
org.mozilla.jss.pkcs11.PK11Cipher
org.mozilla.jss.pkcs11.PK11KeyWrapper
org.mozilla.jss.pkcs11.PK11MessageDigest
org.mozilla.jss.pkcs11.PK11PrivKey
org.mozilla.jss.pkcs11.PK11PubKey
org.mozilla.jss.pkcs11.PK11SymKey
org.mozilla.jss.pkcs11.PK11KeyPairGenerator
org.mozilla.jss.pkcs11.PK11SymmetricKeyDeriver
org.mozilla.jss.pkcs11.PK11KeyGenerator
org.mozilla.jss.pkcs11.PK11Token
org.mozilla.jss.pkcs11.PrivateKeyProxy
org.mozilla.jss.pkcs11.PublicKeyProxy
org.mozilla.jss.pkcs11.SymKeyProxy
org.mozilla.jss.pkcs11.KeyProxy
org.mozilla.jss.pkcs11.PK11Token
org.mozilla.jss.pkcs11.TokenProxy
org.mozilla.jss.pkcs11.PK11Signature
org.mozilla.jss.pkcs11.PK11Store
org.mozilla.jss.pkcs11.PK11KeyPairGenerator
org.mozilla.jss.pkcs11.SigContextProxy
org.mozilla.jss.pkcs11.PK11RSAPublicKey
org.mozilla.jss.pkcs11.PK11DSAPublicKey
org.mozilla.jss.pkcs11.PK11ECPublicKey
org.mozilla.jss.pkcs11.PK11SecureRandom
org.mozilla.jss.provider.java.security.JSSKeyStoreSpi
org.mozilla.jss.SecretDecoderRing.KeyManager
org.mozilla.jss.ssl.SSLSocket
org.mozilla.jss.ssl.SSLServerSocket
org.mozilla.jss.ssl.SocketBase
org.mozilla.jss.util.Password
);
@packages = qw(
org.mozilla.jss
org.mozilla.jss.asn1
org.mozilla.jss.crypto
org.mozilla.jss.pkcs7
org.mozilla.jss.pkcs10
org.mozilla.jss.pkcs11
org.mozilla.jss.pkcs12
org.mozilla.jss.pkix.primitive
org.mozilla.jss.pkix.cert
org.mozilla.jss.pkix.cmc
org.mozilla.jss.pkix.cmmf
org.mozilla.jss.pkix.cms
org.mozilla.jss.pkix.crmf
org.mozilla.jss.provider.java.security
org.mozilla.jss.provider.javax.crypto
org.mozilla.jss.SecretDecoderRing
org.mozilla.jss.ssl
org.mozilla.jss.tests
org.mozilla.jss.util
);
# setup environment
setup_env();
# setup variables
setup_vars(\@ARGV);
# run the command with its arguments
my $cmd = (shift || "build"); # first argument is command
grep { s/(.*)/"$1"/ } @ARGV; # enclose remaining arguments in quotes
my $args = join(",",@ARGV); # and comma-separate them
eval "$cmd($args)"; # now run the command
if( $@ ) {
die $@; # errors in eval will be put in $@
}
# END
sub grab_cmdline_vars {
my $argv = shift;
while( $$argv[0] =~ /(.+)=(.*)/ ) {
$cmdline_vars{$1} = $2;
shift @$argv;
}
}
sub dump_cmdline_vars {
print "Command variables:\n";
for(keys %cmdline_vars) {
print "$_=" . $cmdline_vars{$_} . "\n";
}
}
sub setup_env {
# check that JAVA_HOME environment variable has been set externally
$ENV{JAVA_HOME} or
die "\nMust specify JAVA_HOME environment variable!\n"
. "(e. g. - export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0_openjdk)"
. "\n\n";
print "JAVA_HOME=$ENV{'JAVA_HOME'}\n";
# check that USE_64 environment variable has been set externally
# for 64-bit architectures (when applicable)
$bitsize = `getconf LONG_BIT`;
if( $bitsize == 64 ) {
$ENV{USE_64} or
die "\nMust specify USE_64 environment variable!\n"
. "(e. g. - export USE_64=1)\n\n";
print "USE_64=$ENV{'USE_64'}\n";
}
}
sub setup_vars {
my $argv = shift;
grab_cmdline_vars($argv);
dump_cmdline_vars();
$jar = "$ENV{JAVA_HOME}/bin/jar";
$javac = "$ENV{JAVA_HOME}/bin/javac";
$javah = "$ENV{JAVA_HOME}/bin/javah";
$javadoc = "$ENV{JAVA_HOME}/bin/javadoc";
$dist_dir = abs_path($cmdline_vars{SOURCE_PREFIX});
$jce_jar = $ENV{JCE_JAR};
$class_release_dir = $cmdline_vars{SOURCE_RELEASE_PREFIX};
$class_dir = "$dist_dir/classes";
$class_jar = "$dist_dir/$cmdline_vars{XPCLASS_JAR}";
$class_release_dir .= "/$cmdline_vars{SOURCE_RELEASE_CLASSES_DIR}";
if( $ENV{BUILD_OPT} ) {
$javac_opt_flag = "-O";
} else {
$javac_opt_flag = "-g";
}
$jni_header_dir = "$dist_dir/private/jss/_jni";
if( $ENV{DEBIAN_BUILD} ) {
$jarFiles = "/usr/share/java/slf4j-api.jar:/usr/share/java/commons-codec.jar";
} else {
$jarFiles = "/usr/share/java/slf4j/slf4j-api.jar:/usr/share/java/commons-codec.jar";
}
$classpath = "-classpath $jarFiles:/usr/share/java/commons-lang.jar";
if( $jce_jar ) {
$classpath .= ":$jce_jar";
}
if( $ENV{CHECK_DEPRECATION} ) {
$javac_deprecation_flag = "-Xlint:deprecation";
} else {
$javac_deprecation_flag = "";
}
# retrieve present working directory
$jss_dir = `pwd`;
$jss_dir =~ chomp $jss_dir;
print "JSS directory: $jss_dir\n";
$work_dir = dirname($jss_dir);
print "Working directory: $work_dir\n";
# retrieve architecture
$arch = `uname -m`;
$arch =~ chomp $arch;
# retrieve operating system
$os = `uname`;
$os =~ chomp $os;
$jss_objdir = "$work_dir/dist/$cmdline_vars{JSS_OBJDIR_NAME}";
print "jss_objdir=$jss_objdir\n";
if( ( $ENV{USE_INSTALLED_NSPR} ) && ( $ENV{USE_INSTALLED_NSS} ) ) {
print "Using the NSPR and NSS installed on the system to build JSS.\n";
$nss_lib_dir = $ENV{NSS_LIB_DIR};
$nss_lib_dir =~ s/^\s+|\s+$//g; # trim spaces
} else {
# Verify existence of work area
if(( ! -d "$work_dir/nspr" ) ||
( ! -d "$work_dir/nss" ) ||
( ! -d "$jss_dir" )) {
my $workarea = "\nA work area must first be prepared; for example:\n\n"
. " mkdir sandbox\n"
. " cd sandbox\n"
. " hg clone https://hg.mozilla.org/projects/nspr\n"
. " hg clone https://hg.mozilla.org/projects/nss\n"
. " hg clone https://hg.mozilla.org/projects/jss\n"
. " cd ..\n\n";
die "$workarea";
}
# Build NSS if not already built
my $nss_latest_objdir = "$dist_dir/latest";
if( ! -e $nss_latest_objdir ) {
print("########################\n" .
"# BEGIN: Building NSS #\n" .
"########################\n");
print_do("cd $work_dir/nss;make clean nss_build_all;cd $jss_dir");
print("######################\n" .
"# END: Building NSS #\n" .
"######################\n");
}
$nss_objdir_name = `cat $nss_latest_objdir`;
chomp($nss_objdir_name);
$nss_bin_dir = "$dist_dir/$nss_objdir_name/bin";
$nss_lib_dir = "$dist_dir/$nss_objdir_name/lib";
$jss_objdir_name = $nss_objdir_name;
$jss_objdir_name =~ s/_cc//;
# create a JSS OBJDIR_NAME symlink to NSS OBJDIR_NAME
if( ! -l $jss_objdir ) {
my $cmd = "cd $work_dir/dist;"
. "ln -s $nss_objdir_name $jss_objdir_name;"
. "cd $jss_dir";
print_do($cmd);
}
}
print "nss_bin_dir=$nss_bin_dir\n";
print "nss_lib_dir=$nss_lib_dir\n";
$jss_lib_dir = "$jss_objdir/lib";
print "jss_lib_dir=$jss_lib_dir\n";
}
sub clean {
print_do("rm -rf $class_dir");
print_do("rm -f $class_jar");
print_do("rm -rf $jni_header_dir");
}
sub build {
#
# generate MANIFEST.MF file in dist dir
#
my $manifest_file = "$dist_dir/MANIFEST.MF";
print "Creating $manifest_file\n";
my $jss_revision = `grep JSS_VERSION org/mozilla/jss/util/jssver.h`;
chop($jss_revision);
$jss_revision = substr($jss_revision, 22, 3);
my $build_revision = $jss_revision;
$append = 0;
ensure_dir_exists($dist_dir);
if ($append) {
open(MYOUTFILE, ">$manifest_file"); #open for write, overwrite
} else {
open(MYOUTFILE, ">>$manifest_file"); #open for write, append
}
#*** Print freeform text, semicolon required ***
print MYOUTFILE <<"MyLabel";
Manifest-Version: 1.0
Name: org/mozilla/jss/
Specification-Title: Network Security Services for Java (JSS)
Specification-Version: $jss_revision
Specification-Vendor: Mozilla Foundation
Implementation-Title: org.mozilla.jss
Implementation-Version: $build_revision
Implementation-Vendor: Mozilla Foundation
MyLabel
#*** Close the file ***
close(MYOUTFILE);
#
# recursively find *.java
#
my %source_list;
find sub {
my $name = $File::Find::name;
if( $name =~ /\.java$/) {
$source_list{$File::Find::name} = 1;
}
}, ".";
#
# weed out files that are excluded or don't need to be updated
#
my $file;
foreach $file (keys %source_list) {
my $pattern;
foreach $pattern (@excluded_sources) {
if( $file =~ /$pattern/ ) {
delete $source_list{$file};
}
}
unless( java_source_needs_update( $file, $class_dir ) ){
delete $source_list{$file};
}
}
my @source_list = keys(%source_list);
#
# build the java sources
#
if( scalar(@source_list) > 0 ) {
ensure_dir_exists($class_dir);
print_do("$javac $javac_opt_flag $javac_deprecation_flag -sourcepath . -d $class_dir " .
"$classpath " . join(" ",@source_list));
print_do("sh -c 'cd $dist_dir/classes && $jar cvmf $dist_dir/MANIFEST.MF $dist_dir/xpclass.jar *'");
print "Exit status was " . ($?>>8) . "\n";
}
#
# create the JNI header files
#
ensure_dir_exists($jni_header_dir);
print_do("$javah -classpath $class_dir -d $jni_header_dir " .
(join " ", @javah_classes) );
}
sub print_do {
my $cmd = shift;
print "$cmd\n";
system($cmd);
my $exit_status = $?>>8;
$exit_status and die "Command failed ($exit_status)\n";
}
sub needs_update {
my $target = shift;
my @dependencies = @_;
my $target_mtime = (stat($target))[9];
my $dep;
foreach $dep( @dependencies ) {
my $dep_mtime = (stat($dep))[9];
if( $dep_mtime > $target_mtime ) {
return 1;
}
}
return 0;
}
# A quick-and-dirty way to guess whether a .java file needs to be rebuilt.
# We merely look for a .class file of the same name. This won't work if
# the source file's directory is different from its package, and it
# doesn't know about nested or inner classes.
# source_file: the relative path to the source file ("org/mozilla/jss/...")
# dest_dir: the directory where classes are output ("../../dist/classes")
# Returns 1 if the source file is newer than the class file, or the class file
# doesn't exist. Returns 0 if the class file is newer than the source file.
sub java_source_needs_update {
my $source_file = shift;
my $dest_dir = shift;
my $class_dir = "$dest_dir/" . dirname($source_file);
my $class_file = basename($source_file);
$class_file =~ s/\.java/.class/;
$class_file = $class_dir . "/" . $class_file;
if( -f $class_file ) {
my $class_stat = stat($class_file);
my $source_stat = stat($source_file);
if( $source_stat->mtime > $class_stat->mtime) {
# class file exists and is out of date
return 1;
} else {
#class file exists and is up to date
return 0;
}
} else {
# class file hasn't been generated yet.
return 1;
}
}
# Recursively makes the given directory. Dies at the first sign of trouble
sub ensure_dir_exists {
my $dir = shift;
my $parent = dirname($dir);
if( $parent ne $dir ) {
ensure_dir_exists($parent);
}
if( ! -d $dir ) {
mkdir($dir, 0777) or die "Failed to mkdir $dir: $!";
}
}
sub release {
# copy all class files into release directory
ensure_dir_exists("$class_release_dir");
print_do("cp -r $class_dir/* $class_release_dir");
}
sub javadoc {
my $html_header_opt;
if( $ENV{HTML_HEADER} ) {
$html_header_opt = "-header '$ENV{HTML_HEADER}'";
}
ensure_dir_exists("$dist_dir/jssdoc");
my $targets = join(" ", @packages);
print "$targets\n";
print_do("$javadoc -breakiterator $classpath -sourcepath . -d $dist_dir/jssdoc $html_header_opt $targets");
print_do("cp $dist_dir/jssdoc/index.html $dist_dir/jssdoc/index.html.bak");
print_do("cp $dist_dir/jssdoc/overview-summary.html $dist_dir/jssdoc/index.html");
}
sub test {
if( $os eq 'Linux' || $os eq 'Darwin' ) {
# Test JSS presuming that it has already been built
if(( -d $dist_dir ) &&
( -d $jss_objdir || -l $jss_objdir )) {
my $cmd = "cd $jss_dir/org/mozilla/jss/tests;"
. "perl all.pl dist \"$dist_dir\" \"$nss_bin_dir\" \"$nss_lib_dir\" \"$jss_lib_dir\";"
. "cd $jss_dir";
print("#######################\n" .
"# BEGIN: Testing JSS #\n" .
"#######################\n");
print_do($cmd);
print("#####################\n" .
"# END: Testing JSS #\n" .
"#####################\n");
} else {
die "JSS builds are not available at $jss_objdir.";
}
} else {
die "make test_jss is only available on Linux and MacOS platforms.";
}
}
# - Try to find NSPR
# Once done this will define
#
# NSPR_FOUND - system has NSPR
# NSPR_INCLUDE_DIRS - the NSPR include directory
# NSPR_LIBRARIES - Link these to use NSPR
# NSPR_DEFINITIONS - Compiler switches required for using NSPR
#
# Copyright (c) 2010 Andreas Schneider <asn@redhat.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (NSPR_LIBRARIES AND NSPR_INCLUDE_DIRS)
# in cache already
set(NSPR_FOUND TRUE)
else (NSPR_LIBRARIES AND NSPR_INCLUDE_DIRS)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_NSPR nspr)
endif (PKG_CONFIG_FOUND)
find_path(NSPR_INCLUDE_DIR
NAMES
nspr.h
PATHS
${_NSPR_INCLUDEDIR}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
PATH_SUFFIXES
nspr4
nspr
)
find_library(PLDS4_LIBRARY
NAMES
plds4
PATHS
${_NSPR_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
find_library(PLC4_LIBRARY
NAMES
plc4
PATHS
${_NSPR_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
find_library(NSPR4_LIBRARY
NAMES
nspr4
PATHS
${_NSPR_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
set(NSPR_INCLUDE_DIRS
${NSPR_INCLUDE_DIR}
)
if (PLDS4_LIBRARY)
set(NSPR_LIBRARIES
${NSPR_LIBRARIES}
${PLDS4_LIBRARY}
)
endif (PLDS4_LIBRARY)
if (PLC4_LIBRARY)
set(NSPR_LIBRARIES
${NSPR_LIBRARIES}
${PLC4_LIBRARY}
)
endif (PLC4_LIBRARY)
if (NSPR4_LIBRARY)
set(NSPR_LIBRARIES
${NSPR_LIBRARIES}
${NSPR4_LIBRARY}
)
endif (NSPR4_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NSPR DEFAULT_MSG NSPR_LIBRARIES NSPR_INCLUDE_DIRS)
# show the NSPR_INCLUDE_DIRS and NSPR_LIBRARIES variables only in the advanced view
mark_as_advanced(NSPR_INCLUDE_DIRS NSPR_LIBRARIES)
endif (NSPR_LIBRARIES AND NSPR_INCLUDE_DIRS)
# - Try to find NSS
# Once done this will define
#
# NSS_FOUND - system has NSS
# NSS_INCLUDE_DIRS - the NSS include directory
# NSS_LIBRARIES - Link these to use NSS
# NSS_DEFINITIONS - Compiler switches required for using NSS
#
# Copyright (c) 2010 Andreas Schneider <asn@redhat.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (NSS_LIBRARIES AND NSS_INCLUDE_DIRS)
# in cache already
set(NSS_FOUND TRUE)
else (NSS_LIBRARIES AND NSS_INCLUDE_DIRS)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_NSS nss)
endif (PKG_CONFIG_FOUND)
find_path(NSS_INCLUDE_DIR
NAMES
nss.h
PATHS
${_NSS_INCLUDEDIR}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
PATH_SUFFIXES
nss3
nss
)
find_library(SSL3_LIBRARY
NAMES
ssl3
PATHS
${_NSS_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
find_library(SMIME3_LIBRARY
NAMES
smime3
PATHS
${_NSS_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
find_library(NSS3_LIBRARY
NAMES
nss3
PATHS
${_NSS_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
find_library(NSSUTIL3_LIBRARY
NAMES
nssutil3
PATHS
${_NSS_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
set(NSS_INCLUDE_DIRS
${NSS_INCLUDE_DIR}
)
if (SSL3_LIBRARY)
set(NSS_LIBRARIES
${NSS_LIBRARIES}
${SSL3_LIBRARY}
)
endif (SSL3_LIBRARY)
if (SMIME3_LIBRARY)
set(NSS_LIBRARIES
${NSS_LIBRARIES}
${SMIME3_LIBRARY}
)
endif (SMIME3_LIBRARY)
if (NSS3_LIBRARY)
set(NSS_LIBRARIES
${NSS_LIBRARIES}
${NSS3_LIBRARY}
)
endif (NSS3_LIBRARY)
if (NSSUTIL3_LIBRARY)
set(NSS_LIBRARIES
${NSS_LIBRARIES}
${NSSUTIL3_LIBRARY}
)
endif (NSSUTIL3_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NSS DEFAULT_MSG NSS_LIBRARIES NSS_INCLUDE_DIRS)
# show the NSS_INCLUDE_DIRS and NSS_LIBRARIES variables only in the advanced view
mark_as_advanced(NSS_INCLUDE_DIRS NSS_LIBRARIES)
endif (NSS_LIBRARIES AND NSS_INCLUDE_DIRS)
# Core of JSS building
# Build JSS; high level flow
macro(jss_build)
# "set(..)" in CMake defines a globally-scoped variable (or more
# precisely, a variable that exists in all scopes _after_ this one)
# by default. These are three helpful globs of files for dependencies:
# all java, headers, and c source files. Note that org/*.java differs
# from the bash-style glob in that it matches all files which begin with
# "org" and end with ".java". This includes, e.g.,
# "org/mozilla/jss/CryptoManager.java". Because these globs are computed
# at cmake time (prior to the make step) incremental builds are not
# possible; each time the build directory should be removed and recreated
# prior to building again.
jss_build_globs()
# To build JSS, we need:
# 1. To build the Java files.
# 2. To copy the headers for compilation.
# 3. To build the library.
# 4. To build the jar.
# 5. To build the javadocs.
jss_build_java()
jss_build_includes()
jss_build_c()
jss_build_jars()
jss_build_javadocs()
endmacro()
macro(jss_build_globs)
file(GLOB_RECURSE _JAVA_SOURCES org/*.java)
foreach(_JAVA_SOURCE ${_JAVA_SOURCES})
if(${_JAVA_SOURCE} MATCHES "mozilla/jss/tests/")
list(APPEND JAVA_TEST_SOURCES "${_JAVA_SOURCE}")
else()
list(APPEND JAVA_SOURCES "${_JAVA_SOURCE}")
endif()
endforeach()
file(GLOB_RECURSE _C_HEADERS org/*.h)
foreach(_C_HEADER ${_C_HEADERS})
if(${_C_HEADER} MATCHES "mozilla/jss/tests/")
list(APPEND C_TEST_HEADERS "${_C_HEADER}")
else()
list(APPEND C_HEADERS "${_C_HEADER}")
endif()
endforeach()
file(GLOB_RECURSE _C_SOURCES org/*.c)
# We exclude any C files in the tests directory because they shouldn't
# contribute to our library. They should instead be built as part of the
# test suite and probably be built as stand alone binaries which link
# against libjss4.so (at most).
foreach(_C_SOURCE ${_C_SOURCES})
if(${_C_SOURCE} MATCHES "mozilla/jss/tests/")
list(APPEND C_TEST_SOURCES "${_C_SOURCE}")
else()
list(APPEND C_SOURCES "${_C_SOURCE}")
endif()
endforeach()
endmacro()
# Build all Java sources into classes and generate JNI headers
macro(jss_build_java)
# Create a fake, pseudo-target for generate_java -- we have to have some
# status for when the build finishes for the add_custom_target to depend
# on, but it also must be the last-thing created; thus, we touch
# ${JNI_OUTPUTS} after the javac command finishes.
set(JNI_OUTPUTS "${TARGETS_OUTPUT_DIR}/finished_generate_java")
set(TESTS_JNI_OUTPUTS "${TARGETS_OUTPUT_DIR}/finished_tests_generate_java")
# We frequently use the add_custom_command + add_custom_target wrapper due
# to a quirk of CMake. This is documented more extensively in the
# following links:
# https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/
# https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory
add_custom_command(
OUTPUT "${JNI_OUTPUTS}"
COMMAND ${Java_JAVAC_EXECUTABLE} ${JSS_JAVAC_FLAGS} -d ${CLASSES_OUTPUT_DIR} -h ${JNI_OUTPUT_DIR} ${JAVA_SOURCES}
COMMAND touch "${JNI_OUTPUTS}"
DEPENDS ${JAVA_SOURCES}
)
add_custom_command(
OUTPUT "${TESTS_JNI_OUTPUTS}"
COMMAND ${Java_JAVAC_EXECUTABLE} ${JSS_JAVAC_FLAGS} -d ${TESTS_CLASSES_OUTPUT_DIR} -h ${TESTS_JNI_OUTPUT_DIR} ${JAVA_TEST_SOURCES}
COMMAND touch "${TESTS_JNI_OUTPUTS}"
DEPENDS ${JAVA_TEST_SOURCES}
)
add_custom_target(
generate_java ALL
DEPENDS ${JNI_OUTPUTS} ${TESTS_JNI_OUTPUTS}
)
endmacro()
# "Build" all includes by copying them to a common directory
macro(jss_build_includes)
# Note that file(COPY ...) operations are performed at "CMake" run time,
# (equivalent to configure time), so CMake needs to be reconfigured every
# time a new header file is added. This is most easily done by removing
# the build directory and recreating it. This also applies to all other
# build steps as the globs are computed at configure time as well.
foreach(C_HEADER ${C_HEADERS})
file(COPY "${C_HEADER}" DESTINATION ${INCLUDE_OUTPUT_DIR})
endforeach()
foreach(C_TEST_HEADER ${C_TEST_HEADERS})
file(COPY "${C_TEST_HEADER}" DESTINATION ${TESTS_INCLUDE_OUTPUT_DIR})
endforeach()
add_custom_target(
generate_includes
)
endmacro()
# Compile a single C file
macro(jss_build_c_file C_FILE C_OUTPUT C_TARGET C_DIR)
# C files can be built in parallel. This macro builds each file wrapped in
# add_custom_command+add_custom_target so parallel builds work. Note that
# each build depends on generate_java and generate_includes to have
# finished, else many headers wouldn't exist.
add_custom_command(
OUTPUT "${C_OUTPUT}"
COMMAND ${CMAKE_C_COMPILER} -fPIC ${JSS_C_FLAGS} -o ${C_OUTPUT} -c ${C_FILE}
WORKING_DIRECTORY ${C_DIR}
DEPENDS ${C_FILE}
DEPENDS generate_java
DEPENDS generate_includes
)
add_custom_target(
"generate_c_${C_TARGET}"
DEPENDS "${C_OUTPUT}" ${C_HEADERS}
)
endmacro()
# Compile all C source files and build libjss library
macro(jss_build_c)
foreach(C_SOURCE ${C_SOURCES})
get_filename_component(C_TARGET ${C_SOURCE} NAME_WE)
get_filename_component(C_DIR ${C_SOURCE} DIRECTORY)
set(C_OUTPUT "${LIB_OUTPUT_DIR}/${C_TARGET}.o")
jss_build_c_file("${C_SOURCE}" "${C_OUTPUT}" "${C_TARGET}" "${C_DIR}")
list(APPEND C_OUTPUTS "${C_OUTPUT}")
endforeach()
# Combine all C targets here into a single pseudo-target for parallel
# builds.
add_custom_target(
generate_c ALL
DEPENDS ${C_OUTPUTS}
)
# We generate two libraries: build/lib/libjss.so and build/libjss.so:
# the former is for testing and is unversioned, so all symbols are public
# and can thus be tested; the latter is for releases and is versioned,
# limiting which symbols are made public. We only need to make the JNI
# symbols public as libjss.so should only be used from Java in conjunction
# with jss.jar.
add_custom_command(
OUTPUT "${JSS_SO_PATH}" "${JSS_TESTS_SO_PATH}"
COMMAND ${CMAKE_C_COMPILER} -o ${JSS_TESTS_SO_PATH} ${LIB_OUTPUT_DIR}/*.o ${JSS_LD_FLAGS} ${JSS_LIBRARY_FLAGS}
COMMAND ${CMAKE_C_COMPILER} -o ${JSS_SO_PATH} ${LIB_OUTPUT_DIR}/*.o ${JSS_LD_FLAGS} ${JSS_VERSION_SCRIPT} ${JSS_LIBRARY_FLAGS}
DEPENDS generate_c
)
# Add a target for anything depending on the library existing.
add_custom_target(
generate_so ALL
DEPENDS ${JSS_SO_PATH} ${JSS_TESTS_SO_PATH}
)
endmacro()
# Build the jar by combining the java classes from generate_java step
macro(jss_build_jars)
# Note that build/MANIFEST.MF is generated by JSSConfig.cmake's
# jss_config_version macro. Further, this doesn't yet build a reproducible
# JAR.
add_custom_command(
OUTPUT "${JSS_BUILD_JAR_PATH}"
COMMAND "${Java_JAR_EXECUTABLE}" cmf "${CMAKE_BINARY_DIR}/MANIFEST.MF" ${JSS_BUILD_JAR_PATH} org/*
WORKING_DIRECTORY "${CLASSES_OUTPUT_DIR}"
DEPENDS generate_java
)
add_custom_command(
OUTPUT "${JSS_TESTS_JAR_PATH}"
COMMAND "${Java_JAR_EXECUTABLE}" cmf "${CMAKE_BINARY_DIR}/MANIFEST.MF" ${JSS_TESTS_JAR_PATH} org/*
WORKING_DIRECTORY "${TESTS_CLASSES_OUTPUT_DIR}"
DEPENDS generate_java
)
add_custom_target(
generate_build_jar
DEPENDS "${JSS_BUILD_JAR_PATH}"
)
add_custom_command(
OUTPUT "${JSS_JAR_PATH}"
COMMAND "${PROJECT_SOURCE_DIR}/tools/reproducible_jar.sh" "${JSS_BUILD_JAR_PATH}" "${REPRODUCIBLE_TEMP_DIR}" "${JSS_JAR_PATH}"
DEPENDS generate_build_jar
)
add_custom_target(
generate_jar ALL
DEPENDS "${JSS_JAR_PATH}" "${JSS_TESTS_JAR_PATH}"
)
endmacro()
# Build javadocs from the source files
macro(jss_build_javadocs)
# Add another pseudo-target here as well -- javadocs create a lot of
# output, but anything which depends on the javadocs existing should
# depend on the javadoc target.
set(JAVADOCS_OUTPUTS "${TARGETS_OUTPUT_DIR}/finished_generate_javadocs")
add_custom_command(
OUTPUT ${JAVADOCS_OUTPUTS}
COMMAND "${Java_JAVADOC_EXECUTABLE}" -overview "${PROJECT_SOURCE_DIR}/tools/javadoc/overview.html" -windowtitle "${JSS_WINDOW_TITLE}" -notimestamp -breakiterator -classpath ${JAVAC_CLASSPATH} -sourcepath ${PROJECT_SOURCE_DIR} -d ${DOCS_OUTPUT_DIR} ${JSS_PACKAGES}
COMMAND touch "${JAVADOCS_OUTPUTS}"
DEPENDS ${JAVA_SOURCES}
)
add_custom_target(
javadoc
DEPENDS ${JAVADOCS_OUTPUTS}
)
# For compliance with GNU Make standard targets
add_custom_target(
html
DEPENDS javadoc
)
endmacro()
macro(jss_config)
# Set the current JSS release number. Arguments are:
# MAJOR MINOR PATCH BETA
# When BETA is zero, it isn't a beta release.
jss_config_version(4 5 1 0)
# Configure output directories
jss_config_outputs()
# Configure flags for compiling and linking
jss_config_cflags()
jss_config_ldflags()
# Configure java-related flags
jss_config_java()
endmacro()
macro(jss_config_version MAJOR MINOR PATCH BETA)
# This sets the JSS Version for use in CMake and propagates it to the
# necessary source locations. These are:
#
# org/mozilla/jss/util/jssver.h{.in,}
# lib/MANIFEST.MF.in -> build/MANIFEST.MF
#
# On a build, these automatically get generated with the correct versions
# included. Note that all "sets" are of global scope, so these variables
# can be used anywhere that is necessary. Some uses are for setting the
# version number in the library and jar file, etc.
# Define variables from passed arguments
set(JSS_VERSION_MAJOR "${MAJOR}")
set(JSS_VERSION_MINOR "${MINOR}")
set(JSS_VERSION_PATCH "${PATCH}")
set(JSS_VERSION_BETA "${BETA}")
set(JSS_VERSION "${JSS_VERSION_MAJOR}.${JSS_VERSION_MINOR}.${JSS_VERSION_PATCH}")
set(JSS_VERSION_MANIFEST "${JSS_VERSION_MAJOR}.${JSS_VERSION_MINOR}")
set(JSS_VERSION_STR "JSS_${JSS_VERSION_MAJOR}_${JSS_VERSION_MINOR}")
if(${PATCH} GREATER 0)
set(JSS_VERSION_MANIFEST "${JSS_VERSION_MANIFEST}.${JSS_VERSION_PATCH}")
set(JSS_VERSION_STR "${JSS_VERSION_STR}_${JSS_VERSION_PATCH}")
endif()
if(${BETA} GREATER 0)
set(JSS_VERSION "${JSS_VERSION} beta ${JSS_VERSION_BETA}")
set(JSS_VERSION_STR "${JSS_VERSION_STR}_b${JSS_VERSION_BETA}")
endif()
# Template files
configure_file(
"${PROJECT_SOURCE_DIR}/org/mozilla/jss/util/jssver.h.in"
"${PROJECT_SOURCE_DIR}/org/mozilla/jss/util/jssver.h"
)
configure_file(
"${PROJECT_SOURCE_DIR}/lib/MANIFEST.MF.in"
"${CMAKE_BINARY_DIR}/MANIFEST.MF"
)
endmacro()
macro(jss_config_outputs)
# Global variables representing various output files; note that these are
# created at the end of this macro.
set(CLASSES_OUTPUT_DIR "${CMAKE_BINARY_DIR}/classes/jss")
set(DOCS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/docs")
set(LIB_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib")
set(INCLUDE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/include/jss")
set(JNI_OUTPUT_DIR "${CMAKE_BINARY_DIR}/include/jss/_jni")
# This folder is for pseudo-locations for CMake targets
set(TARGETS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/.targets")
# These folders are for the NSS DBs created during testing
set(RESULTS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/results/tests")
set(RESULTS_FIPS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/results/fips")
# This is a temporary location for building the reproducible jar
set(REPRODUCIBLE_TEMP_DIR "${CMAKE_BINARY_DIR}/reproducible")
set(JSS_BUILD_JAR "staging.jar")
set(JSS_JAR "jss${JSS_VERSION_MAJOR}.jar")
set(JSS_SO "libjss${JSS_VERSION_MAJOR}.so")
set(JSS_BUILD_JAR_PATH "${CMAKE_BINARY_DIR}/${JSS_BUILD_JAR}")
set(JSS_JAR_PATH "${CMAKE_BINARY_DIR}/${JSS_JAR}")
set(JSS_SO_PATH "${CMAKE_BINARY_DIR}/${JSS_SO}")
# These options are for the test suite and mirror their non-tests
# counterparts. Note that JSS_TESTS_SO is the same as JSS_SO, but
# JSS_TESTS_SO_PATH differs -- one is "unversioned" and lacks a
# version script so we can test internal methods.
set(TESTS_CLASSES_OUTPUT_DIR "${CMAKE_BINARY_DIR}/classes/tests")
set(TESTS_INCLUDE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/include/tests")
set(TESTS_JNI_OUTPUT_DIR "${CMAKE_BINARY_DIR}/include/jss/_jni")
set(JSS_TESTS_JAR "tests-jss${JSS_VERSION_MAJOR}.jar")
set(JSS_TESTS_SO "${JSS_SO}")
set(JSS_TESTS_JAR_PATH "${CMAKE_BINARY_DIR}/${JSS_TESTS_JAR}")
set(JSS_TESTS_SO_PATH "${LIB_OUTPUT_DIR}/${JSS_TESTS_SO}")
# Create the *_OUTPUT_DIR locations.
file(MAKE_DIRECTORY "${CLASSES_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${DOCS_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${LIB_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${INCLUDE_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${JNI_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${TARGETS_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${TESTS_CLASSES_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${TESTS_INCLUDE_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${TESTS_JNI_OUTPUT_DIR}")
endmacro()
macro(jss_config_cflags)
# We check that the C compiler can handle each of the C flags below
include(CheckCCompilerFlag)
# This list of C flags was taken from the original build scripts for
# debug and release builds.
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
list(APPEND JSS_RAW_C_FLAGS "-Og")
list(APPEND JSS_RAW_C_FLAGS "-ggdb")
else()
list(APPEND JSS_RAW_C_FLAGS "-O2")
endif()
list(APPEND JSS_RAW_C_FLAGS "-Wall")
list(APPEND JSS_RAW_C_FLAGS "-Werror-implicit-function-declaration")
list(APPEND JSS_RAW_C_FLAGS "-Wno-switch")
list(APPEND JSS_RAW_C_FLAGS "-I${NSPR_INCLUDE_DIR}")
list(APPEND JSS_RAW_C_FLAGS "-I${NSS_INCLUDE_DIR}")
list(APPEND JSS_RAW_C_FLAGS "-I${INCLUDE_OUTPUT_DIR}")
foreach(JNI_INCLUDE_DIR ${JNI_INCLUDE_DIRS})
list(APPEND JSS_RAW_C_FLAGS "-I${JNI_INCLUDE_DIR}")
endforeach()
foreach(JSS_RAW_C_FLAG ${JSS_RAW_C_FLAGS})
# Validate that each of our desired CFLAGS is supported by the
# compiler, or well, at least the compiler doesn't immediately
# error on it. :)
check_c_compiler_flag(${JSS_RAW_C_FLAG} HAVE_C_FLAG)
if(${HAVE_C_FLAG})
list(APPEND JSS_C_FLAGS "${JSS_RAW_C_FLAG}")
endif()
endforeach()
# Handle passed-in C flags as well; assume they are valid.
separate_arguments(PASSED_C_FLAGS UNIX_COMMAND "${CMAKE_C_FLAGS}")
foreach(PASSED_C_FLAG ${PASSED_C_FLAGS})
list(APPEND JSS_C_FLAGS "${PASSED_C_FLAG}")
endforeach()
message(STATUS "JSS C FLAGS: ${JSS_C_FLAGS}")
endmacro()
macro(jss_config_ldflags)
# This list of C linker flags was taken from the original build scripts
# for debug and release builds. We lack a "check_c_linker_flag" macro,
# so no effort is made to validate these flags.
list(APPEND JSS_LD_FLAGS "-lsmime3")
list(APPEND JSS_LD_FLAGS "-lssl3")
list(APPEND JSS_LD_FLAGS "-lnss3")
list(APPEND JSS_LD_FLAGS "-lnssutil3")
list(APPEND JSS_LD_FLAGS "-lplc4")
list(APPEND JSS_LD_FLAGS "-lplds4")
list(APPEND JSS_LD_FLAGS "-lnspr4")
list(APPEND JSS_LD_FLAGS "-lpthread")
list(APPEND JSS_LD_FLAGS "-ldl")
# This set of flags is specific to building the libjss library.
list(APPEND JSS_LIBRARY_FLAGS "-shared")
list(APPEND JSS_LIBRARY_FLAGS "-Wl,-z,defs")
list(APPEND JSS_LIBRARY_FLAGS "-Wl,-soname")
list(APPEND JSS_LIBRARY_FLAGS "-Wl,${JSS_SO}")
set(JSS_VERSION_SCRIPT "-Wl,--version-script,${PROJECT_SOURCE_DIR}/lib/jss.map")
endmacro()
macro(jss_config_java)
# Find various JARs required by JSS build and test suite
find_jar(
SLF4J_API_JAR
NAMES api slf4j/api slf4j-api
)
find_jar(
CODEC_JAR
NAMES apache-commons-codec commons-codec
)
find_jar(
LANG_JAR
NAMES apache-commons-lang commons-lang
)
find_jar(
JAXB_JAR
NAMES jaxb-api
)
find_jar(
SLF4J_JDK14_JAR
NAMES jdk14 slf4j/jdk14 slf4j-jdk14
)
# Validate that we've found the required JARs
if(SLF4J_API_JAR STREQUAL "SLF4J_API_JAR-NOTFOUND")
message(FATAL_ERROR "Required dependency sfl4j-api.jar not found by find_jar!")
endif()
if(CODEC_JAR STREQUAL "CODEC_JAR-NOTFOUND")
message(FATAL_ERROR "Required dependency apache-commons-codec.jar not found by find_jar!")
endif()
if(LANG_JAR STREQUAL "LANG_JAR-NOTFOUND")
message(FATAL_ERROR "Required dependency apache-commons-lang.jar not found by find_jar!")
endif()
if(JAXB_JAR STREQUAL "JAXB_JAR-NOTFOUND")
message(FATAL_ERROR "Required dependency javaee-jaxb-api.jar not found by find_jar!")
endif()
if(SLF4J_JDK14_JAR STREQUAL "SLF4J_JDK14_JAR-NOTFOUND")
message(WARNING "Test dependency sfl4j-jdk14.jar not found by find_jar! Tests might not run properly.")
endif()
# Set class paths
set(JAVAC_CLASSPATH "${SLF4J_API_JAR}:${CODEC_JAR}:${LANG_JAR}:${JAXB_JAR}")
set(TEST_CLASSPATH "${JSS_JAR_PATH}:${JSS_TESTS_JAR_PATH}:${JAVAC_CLASSPATH}:${SLF4J_JDK14_JAR}")
list(APPEND JSS_JAVAC_FLAGS "-classpath")
list(APPEND JSS_JAVAC_FLAGS "${JAVAC_CLASSPATH}")
list(APPEND JSS_JAVAC_FLAGS "-sourcepath")
list(APPEND JSS_JAVAC_FLAGS "${PROJECT_SOURCE_DIR}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
list(APPEND JSS_JAVAC_FLAGS "-g")
else()
list(APPEND JSS_JAVAC_FLAGS "-O")
endif()
# Variables for javadoc building. Note that JSS_PACKAGES needs to be
# updated whenever a new package is created.
set(JSS_WINDOW_TITLE "JSS: Java Security Services")
set(JSS_PACKAGES "org.mozilla.jss;org.mozilla.jss.asn1;org.mozilla.jss.crypto;org.mozilla.jss.pkcs7;org.mozilla.jss.pkcs10;org.mozilla.jss.pkcs11;org.mozilla.jss.pkcs12;org.mozilla.jss.pkix.primitive;org.mozilla.jss.pkix.cert;org.mozilla.jss.pkix.cmc;org.mozilla.jss.pkix.cmmf;org.mozilla.jss.pkix.cms;org.mozilla.jss.pkix.crmf;org.mozilla.jss.provider.java.security;org.mozilla.jss.provider.javax.crypto;org.mozilla.jss.SecretDecoderRing;org.mozilla.jss.ssl;org.mozilla.jss.util")
set(JSS_BASE_PORT 2876)
math(EXPR JSS_TEST_PORT_CLIENTAUTH ${JSS_BASE_PORT}+0)
math(EXPR JSS_TEST_PORT_CLIENTAUTH_FIPS ${JSS_BASE_PORT}+1)
endmacro()
macro(jss_tests)
enable_testing()
# Common variables used as arguments to several tests
set(JSS_TEST_DIR "${PROJECT_SOURCE_DIR}/org/mozilla/jss/tests")
set(PASSWORD_FILE "${JSS_TEST_DIR}/passwords")
set(DB_PWD "m1oZilla")
jss_test_java(
NAME "Test_UTF-8_Converter"
COMMAND "org.mozilla.jss.tests.UTF8ConverterTest"
)
jss_test_java(
NAME "JSS_DER_Encoding_of_Enumeration_regression_test"
COMMAND "org.mozilla.jss.tests.EnumerationZeroTest"
)
jss_test_java(
NAME "JSS_Test_DER_Encoding_Functionality"
COMMAND "org.mozilla.jss.tests.DEROutputStreamTests"
)
jss_test_java(
NAME "JSS_Test_Empty_DER_Value"
COMMAND "org.mozilla.jss.tests.EmptyDerValue"
)
if ((${Java_VERSION_MAJOR} EQUAL 1) AND (${Java_VERSION_MINOR} LESS 9))
jss_test_java(
NAME "Test_PKCS11Constants.java_for_Sun_compatibility"
COMMAND "org.mozilla.jss.tests.TestPKCS11Constants"
)
endif()
# Rather than creating our results directories earlier in JSSConfig,
# create them here so that the test suite can be rerun multiple times.
jss_test_exec(
NAME "Clean_Setup_DBs"
COMMAND "cmake" "-E" "remove_directory" "${RESULTS_OUTPUT_DIR}"
)
jss_test_exec(
NAME "Create_Setup_DBs"
COMMAND "cmake" "-E" "make_directory" "${RESULTS_OUTPUT_DIR}"
DEPENDS "Clean_Setup_DBs"
)
jss_test_java(
NAME "Setup_DBs"
COMMAND "org.mozilla.jss.tests.SetupDBs" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Create_Setup_DBs"
)
# Various FIPS related tests depend on FIPS being enabled; since this
# affects the entire NSS DB, create a separate database for them.
jss_test_exec(
NAME "Clean_FIPS_Setup_DBs"
COMMAND "cmake" "-E" "remove_directory" "${RESULTS_FIPS_OUTPUT_DIR}"
)
jss_test_exec(
NAME "Create_FIPS_Setup_DBs"
COMMAND "cmake" "-E" "make_directory" "${RESULTS_FIPS_OUTPUT_DIR}"
DEPENDS "Clean_FIPS_Setup_DBs"
)
jss_test_java(
NAME "Setup_FIPS_DBs"
COMMAND "org.mozilla.jss.tests.SetupDBs" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Clean_FIPS_Setup_DBs"
)
jss_test_java(
NAME "Generate_known_RSA_cert_pair"
COMMAND "org.mozilla.jss.tests.GenerateTestCert" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}" "20" "localhost" "SHA-256/RSA" "CA_RSA" "Server_RSA" "Client_RSA"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Generate_known_ECDSA_cert_pair"
COMMAND "org.mozilla.jss.tests.GenerateTestCert" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}" "30" "localhost" "SHA-256/EC" "CA_ECDSA" "Server_ECDSA" "Client_ECDSA"
DEPENDS "Generate_known_RSA_cert_pair"
)
jss_test_java(
NAME "Generate_known_DSS_cert_pair"
COMMAND "org.mozilla.jss.tests.GenerateTestCert" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}" "40" "localhost" "SHA-1/DSA" "CA_DSS" "Server_DSS" "Client_DSS"
DEPENDS "Generate_known_ECDSA_cert_pair"
)
jss_test_exec(
NAME "Create_PKCS11_cert_to_PKCS12_rsa.pfx"
COMMAND "pk12util" "-o" "${RESULTS_OUTPUT_DIR}/rsa.pfx" "-n" "CA_RSA" "-d" "${RESULTS_OUTPUT_DIR}" "-K" "${DB_PWD}" "-W" "${DB_PWD}"
DEPENDS "Generate_known_RSA_cert_pair"
)
jss_test_exec(
NAME "Create_PKCS11_cert_to_PKCS12_ecdsa.pfx"
COMMAND "pk12util" "-o" "${RESULTS_OUTPUT_DIR}/ecdsa.pfx" "-n" "CA_ECDSA" "-d" "${RESULTS_OUTPUT_DIR}" "-K" "${DB_PWD}" "-W" "${DB_PWD}"
DEPENDS "Generate_known_ECDSA_cert_pair"
)
jss_test_exec(
NAME "Create_PKCS11_cert_to_PKCS12_dss.pfx"
COMMAND "pk12util" "-o" "${RESULTS_OUTPUT_DIR}/dss.pfx" "-n" "CA_DSS" "-d" "${RESULTS_OUTPUT_DIR}" "-K" "${DB_PWD}" "-W" "${DB_PWD}"
DEPENDS "Generate_known_DSS_cert_pair"
)
jss_test_java(
NAME "List_CA_certs"
COMMAND "org.mozilla.jss.tests.ListCACerts" "${RESULTS_OUTPUT_DIR}"
DEPENDS "Generate_known_DSS_cert_pair"
)
jss_test_java(
NAME "SSLClientAuth"
COMMAND "org.mozilla.jss.tests.SSLClientAuth" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}" "${JSS_TEST_PORT_CLIENTAUTH}" "50"
DEPENDS "List_CA_certs"
)
jss_test_java(
NAME "Key_Generation"
COMMAND "org.mozilla.jss.tests.TestKeyGen" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Key_Factory"
COMMAND "org.mozilla.jss.tests.KeyFactoryTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Digest"
COMMAND "org.mozilla.jss.tests.DigestTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "HMAC"
COMMAND "org.mozilla.jss.tests.HMACTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "HMAC_Unwrap"
COMMAND "org.mozilla.jss.tests.HmacTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "KeyWrapping"
COMMAND "org.mozilla.jss.tests.JCAKeyWrap" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Mozilla_JSS_JCA_Signature"
COMMAND "org.mozilla.jss.tests.JCASigTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Mozilla_JSS_NSS_Signature"
COMMAND "org.mozilla.jss.tests.SigTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "JSS_Signature_test"
COMMAND "org.mozilla.jss.tests.SigTest" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Secret_Decoder_Ring"
COMMAND "org.mozilla.jss.tests.TestSDR" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "List_cert_by_certnick"
COMMAND "org.mozilla.jss.tests.ListCerts" "${RESULTS_OUTPUT_DIR}" "Server_RSA"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Verify_cert_by_certnick"
COMMAND "org.mozilla.jss.tests.VerifyCert" "${RESULTS_OUTPUT_DIR}" "${PASSWORD_FILE}" "Server_RSA"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Secret_Key_Generation"
COMMAND "org.mozilla.jss.tests.SymKeyGen" "${RESULTS_OUTPUT_DIR}"
DEPENDS "Setup_DBs"
)
jss_test_java(
NAME "Mozilla_JSS_Secret_Key_Generation"
COMMAND "org.mozilla.jss.tests.JCASymKeyGen" "${RESULTS_OUTPUT_DIR}"
DEPENDS "Setup_DBs"
)
# FIPS-related tests
jss_test_java(
NAME "Enable_FipsMODE"
COMMAND "org.mozilla.jss.tests.FipsTest" "${RESULTS_FIPS_OUTPUT_DIR}" "enable"
DEPENDS "Setup_FIPS_DBs"
)
jss_test_java(
NAME "check_FipsMODE"
COMMAND "org.mozilla.jss.tests.FipsTest" "${RESULTS_FIPS_OUTPUT_DIR}" "chkfips"
DEPENDS "Enable_FipsMODE"
)
jss_test_java(
NAME "SSLClientAuth_FIPSMODE"
COMMAND "org.mozilla.jss.tests.SSLClientAuth" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}" "${JSS_TEST_PORT_CLIENTAUTH_FIPS}" "60"
DEPENDS "Enable_FipsMODE"
)
jss_test_java(
NAME "HMAC_FIPSMODE"
COMMAND "org.mozilla.jss.tests.HMACTest" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Enable_FipsMODE"
)
jss_test_java(
NAME "KeyWrapping_FIPSMODE"
COMMAND "org.mozilla.jss.tests.JCAKeyWrap" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Enable_FipsMODE"
)
jss_test_java(
NAME "Mozilla_JSS_JCA_Signature_FIPSMODE"
COMMAND "org.mozilla.jss.tests.JCASigTest" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Enable_FipsMODE"
)
jss_test_java(
NAME "JSS_Signature_test_FipsMODE"
COMMAND "org.mozilla.jss.tests.SigTest" "${RESULTS_FIPS_OUTPUT_DIR}" "${PASSWORD_FILE}"
DEPENDS "Enable_FipsMODE"
)
# Since we need to disable FIPS mode _after_ all FIPS-mode tests have
# run, we have to add a strict dependency from Disable_FipsMODE onto all
# FIPS-related checks.
jss_test_java(
NAME "Disable_FipsMODE"
COMMAND "org.mozilla.jss.tests.FipsTest" "${RESULTS_FIPS_OUTPUT_DIR}" "disable"
DEPENDS "check_FipsMODE" "SSLClientAuth_FIPSMODE" "HMAC_FIPSMODE" "KeyWrapping_FIPSMODE" "Mozilla_JSS_JCA_Signature_FIPSMODE" "JSS_Signature_test_FipsMODE"
)
# For compliance with several
add_custom_target(
check
DEPENDS test
)
endmacro()
function(jss_test_java)
set(TEST_FLAGS "NAME")
set(TEST_ARGS "COMMAND" "DEPENDS")
cmake_parse_arguments(TEST_JAVA "" "${TEST_FLAGS}" "${TEST_ARGS}" ${ARGN})
list(APPEND EXEC_COMMAND "${Java_JAVA_EXECUTABLE}")
list(APPEND EXEC_COMMAND "-classpath")
list(APPEND EXEC_COMMAND "${TEST_CLASSPATH}")
list(APPEND EXEC_COMMAND "-ea")
set(EXEC_COMMAND "${EXEC_COMMAND};${TEST_JAVA_COMMAND}")
if(TEST_JAVA_DEPENDS)
jss_test_exec(
NAME "${TEST_JAVA_NAME}"
COMMAND "${EXEC_COMMAND}"
DEPENDS ${TEST_JAVA_DEPENDS}
LIBRARY "java"
)
else()
jss_test_exec(
NAME "${TEST_JAVA_NAME}"
COMMAND "${EXEC_COMMAND}"
LIBRARY "java"
)
endif()
endfunction()
macro(jss_test_exec)
# Usage:
#
# jss_test_exec(
# NAME TEST_NAME
# COMMAND TEST_COMMAND
# [DEPENDS [TEST_DEPENDS TEST_DEPENDS...]]
#
# Note that TEST_COMMAND can be a list by quoting the list:
#
# jss_test_exec("NAME" "ARG1" "ARG2" "...")
set(TEST_FLAGS "NAME" "LIBRARY")
set(TEST_ARGS "COMMAND" "DEPENDS")
cmake_parse_arguments(TEST_EXEC "" "${TEST_FLAGS}" "${TEST_ARGS}" ${ARGN})
add_test(
NAME "${TEST_EXEC_NAME}"
COMMAND ${TEST_EXEC_COMMAND}
)
# If we are calling a java program, use the versioned library to ensure
# that any new JNI calls are made visible.
if(TEST_EXEC_LIBRARY AND (TEST_EXEC_LIBRARY STREQUAL "java"))
set_tests_properties(
"${TEST_EXEC_NAME}"
PROPERTIES ENVIRONMENT
"LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}"
)
else()
set_tests_properties(
"${TEST_EXEC_NAME}"
PROPERTIES ENVIRONMENT
"LD_LIBRARY_PATH=${LIB_OUTPUT_DIR}"
)
endif()
if(TEST_EXEC_DEPENDS)
set_tests_properties(
"${TEST_EXEC_NAME}"
PROPERTIES DEPENDS
"${TEST_EXEC_DEPENDS}"
)
endif()
endmacro()
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Configuration information unique to the "sectools" component
#
#######################################################################
# Local "sectools" component library link options #
#######################################################################
include $(CORE_DEPTH)//config/linkage.mk
#######################################################################
# Local "sectools" component STATIC system library names #
#######################################################################
include $(CORE_DEPTH)/config/static.mk
#######################################################################
# Local "sectools" component DYNAMIC system library names #
#######################################################################
include $(CORE_DEPTH)/config/dynamic.mk
# Stricter semantic checking for SunOS compiler. This catches calling
# undeclared functions, a major headache during debugging.
ifeq ($(OS_ARCH), SunOS)
OS_CFLAGS += -v
endif
ifeq ($(OS_ARCH), WINNT)
LINK_DLL += -LIBPATH:$(SOURCE_LIB_DIR)
LINK_DLL += -LIBPATH:$(JAVA_HOME)/$(JAVA_LIBDIR)
LINK_DLL += $(foreach file,$(LD_LIBS),-DEFAULTLIB:"$(notdir $(file))")
endif
CFLAGS += -I$(JAVA_HOME)/include
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#######################################################################
# Initialize DYNAMIC system library names on some platforms #
#######################################################################
#
# AIX platforms
#
ifeq ($(OS_ARCH),AIX)
ifeq ($(OS_RELEASE),4.1)
DLLSYSTEM += -lsvld -lC_r -lC -lpthreads -lc_r -lm /usr/lib/libc.a
else
DLLSYSTEM += -ldl -lC_r -lC -lpthreads -lc_r -lm /usr/lib/libc.a
endif
endif
#
# HP/UX platforms
#
ifeq ($(OS_ARCH),HP-UX)
ifeq ($(USE_PTHREADS), 1)
DLLSYSTEM += -lpthread
endif
ifeq ($(PTHREADS_USER), 1)
DLLSYSTEM += -lpthread
endif
ifeq ($(OS_RELEASE),A.09.03)
DLLSYSTEM += -ldld -L/lib/pa1.1 -lm
else
DLLSYSTEM += -ldld -lm -lc
endif
endif
#
# IRIX platforms
#
ifeq ($(OS_ARCH), IRIX)
ifeq ($(USE_PTHREADS), 1)
DLLSYSTEM += -lpthread
endif
endif
#
# Linux platforms
#
ifeq ($(OS_ARCH), Linux)
DLLSYSTEM += -ldl -lpthread -lm
endif
#
# NCR platforms
#
ifeq ($(OS_ARCH), NCR)
DLLSYSTEM += -lsocket -ldl -lnsl -lc
endif
#
# OSF 1 platforms
#
ifeq ($(OS_ARCH),OSF1)
ifneq ($(OS_RELEASE),V2.0)
DLLSYSTEM += -lc_r
endif
ifeq ($(USE_PTHREADS), 1)
DLLSYSTEM += -lpthread -lrt
endif
ifeq ($(USE_IPV6), 1)
DLLSYSTEM += -lip6
endif
endif
#
# SCO platforms
#
ifeq ($(OS_ARCH), SCO_SV)
DLLSYSTEM += -lsocket -ldl -lnsl -lc
endif
#
# Solaris platforms
#
ifeq ($(OS_ARCH), SunOS)
ifneq ($(OS_RELEASE), 4.1.3_U1)
DLLSYSTEM += -lthread -lposix4 -lsocket -lnsl -lintl -ldl
endif
endif
#
# UNIXWARE platforms
#
ifeq ($(OS_ARCH), UNIXWARE)
DLLSYSTEM += -lsocket
endif
#
# Windows platforms
#
ifeq ($(OS_ARCH),WINNT)
ifneq ($(OS_TARGET),WIN16)
DLLSYSTEM += wsock32.lib winmm.lib
endif
endif
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#######################################################################
# Adjust variables for component library linkage on some platforms #
#######################################################################
#
# AIX platforms
#
ifeq ($(OS_ARCH),AIX)
LDOPTS += -blibpath:.:$(PWD)/$(SOURCE_LIB_DIR):/usr/lib/threads:/usr/lpp/xlC/lib:/usr/lib:/lib
endif
#
# HP/UX platforms
#
ifeq ($(OS_ARCH), HP-UX)
LDOPTS += -Wl,+s,+b,$(PWD)/$(SOURCE_LIB_DIR)
endif
#
# IRIX platforms
#
ifeq ($(OS_ARCH), IRIX)
LDOPTS += -rpath $(PWD)/$(SOURCE_LIB_DIR)
endif
#
# OSF 1 platforms
#
ifeq ($(OS_ARCH), OSF1)
LDOPTS += -rpath $(PWD)/$(SOURCE_LIB_DIR) -lpthread
endif
#
# Solaris platforms
# NOTE: Disable optimization on SunOS4.1.3
#
ifeq ($(OS_ARCH), SunOS)
ifneq ($(OS_RELEASE), 4.1.3_U1)
ifdef NS_USE_GCC
LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(SOURCE_LIB_DIR)
else
LDOPTS += -R $(PWD)/$(SOURCE_LIB_DIR)
endif
else
OPTIMIZER =
endif
endif
#
# Windows platforms
#
ifeq ($(OS_ARCH), WINNT)
LDOPTS += -NOLOGO -DEBUG -DEBUGTYPE:CV -INCREMENTAL:NO
endif
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#######################################################################
### ###
### R U L E S O F E N G A G E M E N T ###
### ###
#######################################################################
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#######################################################################
# Initialize STATIC system library names on some platforms #
#######################################################################
#
# AIX platforms
#
ifeq ($(OS_ARCH),AIX)
ifeq ($(OS_RELEASE),4.1)
LIBSYSTEM += /lib/libsvld.a /lib/libC_r.a /lib/libC.a /lib/libpthreads.a /lib/libc_r.a /lib/libm.a /lib/libc.a
else
LIBSYSTEM += -ldl /lib/libC_r.a /lib/libC.a /lib/libpthreads.a /lib/libc_r.a /lib/libm.a /lib/libc.a
endif
endif
#
# HP/UX platforms
#
ifeq ($(OS_ARCH),HP-UX)
ifeq ($(USE_PTHREADS), 1)
LIBSYSTEM += -lpthread
endif
ifeq ($(PTHREADS_USER), 1)
LIBSYSTEM += -lpthread
endif
ifeq ($(OS_RELEASE),A.09.03)
LIBSYSTEM += -ldld -L/lib/pa1.1 -lm
else
LIBSYSTEM += -ldld -lm -lc
endif
endif
#
# Linux platforms
#
ifeq ($(OS_ARCH), Linux)
LIBSYSTEM += -ldl
endif
#
# IRIX platforms
#
ifeq ($(OS_ARCH), IRIX)
ifeq ($(USE_PTHREADS), 1)
LIBSYSTEM += -lpthread
endif
endif
#
# OSF 1 platforms
#
ifeq ($(OS_ARCH),OSF1)
ifneq ($(OS_RELEASE),V2.0)
LIBSYSTEM += -lc_r
endif
ifeq ($(USE_PTHREADS), 1)
LIBSYSTEM += -lpthread -lrt
endif
ifeq ($(USE_IPV6), 1)
LIBSYSTEM += -lip6
endif
endif
#
# Solaris platforms
#
ifeq ($(OS_ARCH), SunOS)
ifneq ($(OS_RELEASE), 4.1.3_U1)
ifeq ($(OS_RELEASE), 5.5.1_i86pc)
LIBSYSTEM += -lsocket -lnsl -lintl -ldl
else
ifeq ($(OS_RELEASE), 5.6_i86pc)
LIBSYSTEM += -lsocket -lnsl -lintl -ldl
else
LIBSYSTEM += -lthread -lposix4 /lib/libsocket.a /lib/libnsl.a /lib/libintl.a -ldl
endif
endif
endif
endif
#
# UNIXWARE platforms
#
ifeq ($(OS_ARCH), UNIXWARE)
LIBSYSTEM += -lsocket
endif
#
# Windows platforms
#
ifeq ($(OS_ARCH),WINNT)
ifneq ($(OS_TARGET),WIN16)
LIBSYSTEM += wsock32.lib winmm.lib
endif
endif
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Config stuff for AIX.
include $(CORE_DEPTH)/coreconf/UNIX.mk
#
# There are two implementation strategies available on AIX:
# pthreads, and pthreads-user. The default is pthreads.
# In both strategies, we need to use pthread_user.c, instead of
# aix.c. The fact that aix.c is never used is somewhat strange.
#
# So we need to do the following:
# - Default (PTHREADS_USER not defined in the environment or on
# the command line):
# Set PTHREADS_USER=1, USE_PTHREADS=1
# - PTHREADS_USER=1 set in the environment or on the command line:
# Do nothing.
#
ifeq ($(PTHREADS_USER),1)
USE_PTHREADS = # just to be safe
IMPL_STRATEGY = _PTH_USER
else
USE_PTHREADS = 1
PTHREADS_USER = 1
endif
DEFAULT_COMPILER = xlc_r
CC = xlc_r
CCC = xlC_r
CPU_ARCH = rs6000
RANLIB = ranlib
OS_CFLAGS = -DAIX -DSYSV
OS_LIBS += -blibpath:/usr/lib:/lib -lc -lm
DSO_LDOPTS = -brtl -bnortllib -bM:SRE -bnoentry
MKSHLIB = $(LD) $(DSO_LDOPTS) -blibpath:/usr/lib:/lib -lc -lm
AIX_WRAP = $(DIST)/lib/aixwrap.o
AIX_TMP = $(OBJDIR)/_aix_tmp.o
ifdef MAPFILE
DSO_LDOPTS += -bexport:$(MAPFILE)
else
DSO_LDOPTS += -bexpall
endif
PROCESS_MAP_FILE = grep -v ';+' $< | grep -v ';-' | \
sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' > $@
ifdef BUILD_OPT
OPTIMIZER += -qmaxmem=-1
endif
ifeq ($(USE_64), 1)
OS_CFLAGS += -DAIX_64BIT
OBJECT_MODE=64
export OBJECT_MODE
endif
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
include $(CORE_DEPTH)/coreconf/Linux.mk