/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4635230 6283345 6303830 6824440 6867348 7094155 8038184 8038349 8046949
* 8046724 8079693 8177334 8205507 8210736
* @summary Basic unit tests for generating XML Signatures with JSR 105
* @modules java.base/sun.security.util
* java.base/sun.security.x509
* java.xml.crypto/org.jcp.xml.dsig.internal.dom
* jdk.httpserver/com.sun.net.httpserver
* @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
* X509KeySelector.java GenerationTests.java
* @run main/othervm/timeout=300 -Dsun.net.httpserver.nodelay=true GenerationTests
* @author Sean Mullan
*/
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.*;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509CRL;
import java.security.spec.KeySpec;
import java.security.spec.DSAPrivateKeySpec;
import java.security.spec.DSAPublicKeySpec;
import java.security.spec.ECField;
import java.security.spec.ECFieldFp;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
import java.security.spec.ECPrivateKeySpec;
import java.security.spec.ECPublicKeySpec;
import java.security.spec.EllipticCurve;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.*;
import java.util.stream.Stream;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.xml.XMLConstants;
import javax.xml.parsers.*;
import javax.xml.crypto.Data;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.OctetStreamData;
import javax.xml.crypto.URIDereferencer;
import javax.xml.crypto.URIReference;
import javax.xml.crypto.URIReferenceException;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dom.*;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
import javax.xml.crypto.dsig.keyinfo.*;
import javax.xml.crypto.dsig.spec.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
/**
* Test that recreates merlin-xmldsig-twenty-three test vectors (and more)
* but with different keys and X.509 data.
*/
public class GenerationTests {
private static XMLSignatureFactory fac;
private static KeyInfoFactory kifac;
private static DocumentBuilder db;
private static CanonicalizationMethod withoutComments;
private static SignatureMethod dsaSha1, dsaSha256,
rsaSha1, rsaSha224, rsaSha256, rsaSha384, rsaSha512,
ecdsaSha1, ecdsaSha224, ecdsaSha256, ecdsaSha384, ecdsaSha512,
hmacSha1, hmacSha224, hmacSha256, hmacSha384, hmacSha512,
rsaSha1mgf1, rsaSha224mgf1, rsaSha256mgf1, rsaSha384mgf1, rsaSha512mgf1;
private static DigestMethod sha1, sha224, sha256, sha384, sha512,
sha3_224, sha3_256, sha3_384, sha3_512;
private static KeyInfo dsa1024, dsa2048, rsa, rsa1024, rsa2048,
p256ki, p384ki, p521ki;
private static KeySelector kvks = new KeySelectors.KeyValueKeySelector();
private static KeySelector sks;
private static Key signingKey;
private static PublicKey validatingKey;
private static Certificate signingCert;
private static KeyStore ks;
private final static String DIR = System.getProperty("test.src", ".");
// private final static String DIR = ".";
private final static String DATA_DIR =
DIR + System.getProperty("file.separator") + "data";
private final static String KEYSTORE =
DATA_DIR + System.getProperty("file.separator") + "certs" +
System.getProperty("file.separator") + "test.jks";
private final static String CRL =
DATA_DIR + System.getProperty("file.separator") + "certs" +
System.getProperty("file.separator") + "crl";
private final static String ENVELOPE =
DATA_DIR + System.getProperty("file.separator") + "envelope.xml";
private static URIDereferencer httpUd = null;
private final static String STYLESHEET =
"http://www.w3.org/TR/xml-stylesheet";
private final static String STYLESHEET_B64 =
"http://www.w3.org/Signature/2002/04/xml-stylesheet.b64";
private final static String DSA_SHA256 =
"http://www.w3.org/2009/xmldsig11#dsa-sha256";
private static final String BOGUS = "bogus";
private static final String xslt = ""
+ "\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " Notaries\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " | \n"
+ "
\n"
+ " \n"
+ "
\n"
+ " \n"
+ " \n"
+ " \n"
+ "\n";
private static final String[] canonicalizationMethods = new String[] {
CanonicalizationMethod.EXCLUSIVE,
CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
CanonicalizationMethod.INCLUSIVE,
CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS
};
private static final String[] xml_transforms = new String[] {
Transform.XSLT,
Transform.XPATH,
Transform.XPATH2,
CanonicalizationMethod.EXCLUSIVE,
CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
CanonicalizationMethod.INCLUSIVE,
CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
};
private static final String[] non_xml_transforms = new String[] {
null, Transform.BASE64
};
// It will be too time consuming to test all combinations of
// all digest methods and signature methods. So we pick some
// majors one and only test a combination when a major method
// (either digest or signature) is included.
//
// * * *
// * * *
// * * *
// * * * * * * * * *
// * * * * * * * * *
// * * * * * * * * *
// * * *
// * * *
// * * *
private static List majorSignatureMethods = List.of(
SignatureMethod.DSA_SHA256,
SignatureMethod.RSA_SHA256,
SignatureMethod.ECDSA_SHA256,
SignatureMethod.HMAC_SHA256,
SignatureMethod.SHA256_RSA_MGF1);
private static final String[] allSignatureMethods
= Stream.of(SignatureMethod.class.getDeclaredFields())
.filter(f -> Modifier.isStatic(f.getModifiers()))
.map(f -> {
try {
return (String)f.get(null);
} catch (Exception e) {
throw new Error("should not happen");
}
})
.toArray(String[]::new);
private static final List majorDigestMethods = List.of(
DigestMethod.SHA1,
DigestMethod.SHA256,
DigestMethod.SHA3_256);
private static final String[] allDigestMethods
= Stream.of(DigestMethod.class.getDeclaredFields())
.filter(f -> Modifier.isStatic(f.getModifiers())
&& !f.getName().equals("RIPEMD160"))
.map(f -> {
try {
return (String)f.get(null);
} catch (Exception e) {
throw new Error("should not happen");
}
})
.toArray(String[]::new);
// As of JDK 11, the number of defined algorithms are...
static {
if (allSignatureMethods.length != 22
|| allDigestMethods.length != 9) {
System.out.println(Arrays.toString(allSignatureMethods));
System.out.println(Arrays.toString(allDigestMethods));
throw new AssertionError("Not all methods are counted");
}
}
private static enum Content {
Xml, Text, Base64, NotExisitng
}
private static enum KeyInfoType {
KeyValue, x509data, KeyName
}
// cached keys (for performance) used by test_create_detached_signature().
private static HashMap cachedKeys = new HashMap<>();
// Load cachedKeys persisted in a file to reproduce a failure.
// The keys are always saved to "cached-keys" but you can rename
// it to a different file name and load it here. Note: The keys will
// always be persisted so renaming is a good idea although the
// content might not change.
static {
String cacheFile = System.getProperty("use.cached.keys");
if (cacheFile != null) {
try (FileInputStream fis = new FileInputStream(cacheFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
cachedKeys = (HashMap) ois.readObject();
} catch (Exception e) {
throw new AssertionError("Cannot read " + cacheFile, e);
}
}
}
private static boolean result = true;
public static void main(String args[]) throws Exception {
setup();
test_create_signature_enveloped_dsa(1024);
test_create_signature_enveloped_dsa(2048);
test_create_signature_enveloping_b64_dsa();
test_create_signature_enveloping_dsa();
test_create_signature_enveloping_hmac_sha1_40();
test_create_signature_enveloping_hmac_sha256();
test_create_signature_enveloping_hmac_sha224();
test_create_signature_enveloping_hmac_sha384();
test_create_signature_enveloping_hmac_sha512();
test_create_signature_enveloping_rsa();
test_create_signature_enveloping_p256_sha1();
test_create_signature_enveloping_p256_sha224();
test_create_signature_enveloping_p256_sha256();
test_create_signature_enveloping_p256_sha384();
test_create_signature_enveloping_p256_sha512();
test_create_signature_enveloping_p384_sha1();
test_create_signature_enveloping_p521_sha1();
test_create_signature_external_b64_dsa();
test_create_signature_external_dsa();
test_create_signature_keyname();
test_create_signature_retrievalmethod_rawx509crt();
test_create_signature_x509_crt_crl();
test_create_signature_x509_crt();
test_create_signature_x509_is();
test_create_signature_x509_ski();
test_create_signature_x509_sn();
test_create_signature();
test_create_exc_signature();
test_create_sign_spec();
test_create_signature_enveloping_sha256_dsa();
test_create_signature_enveloping_sha384_rsa_sha256();
test_create_signature_enveloping_sha224_rsa_sha256();
test_create_signature_enveloping_sha3_224_rsa_sha256();
test_create_signature_enveloping_sha3_256_rsa_sha256();
test_create_signature_enveloping_sha3_384_rsa_sha256();
test_create_signature_enveloping_sha3_512_rsa_sha256();
test_create_signature_enveloping_sha512_rsa_sha384();
test_create_signature_enveloping_sha512_rsa_sha224();
test_create_signature_enveloping_sha512_rsa_sha512();
test_create_signature_enveloping_sha512_rsa_sha1_mgf1();
test_create_signature_enveloping_sha512_rsa_sha224_mgf1();
test_create_signature_enveloping_sha512_rsa_sha256_mgf1();
test_create_signature_enveloping_sha512_rsa_sha384_mgf1();
test_create_signature_enveloping_sha512_rsa_sha512_mgf1();
test_create_signature_reference_dependency();
test_create_signature_with_attr_in_no_namespace();
test_create_signature_with_empty_id();
// run tests for detached signatures with local http server
try (Http server = Http.startServer()) {
server.start();
System.out.println("\ntests for XML documents");
Arrays.stream(canonicalizationMethods).forEach(c ->
Arrays.stream(allSignatureMethods).forEach(s ->
Arrays.stream(allDigestMethods).forEach(d ->
Arrays.stream(xml_transforms).forEach(t ->
Arrays.stream(KeyInfoType.values()).forEach(k -> {
if (isMajor(s, d)) {
test_create_detached_signature(c, s, d, t, k,
Content.Xml, server.getPort(), false, null);
}
})))));
System.out.println("\ntests for text data with no transform");
Arrays.stream(canonicalizationMethods).forEach(c ->
Arrays.stream(allSignatureMethods).forEach(s ->
Arrays.stream(allDigestMethods).forEach(d ->
Arrays.stream(KeyInfoType.values()).forEach(k -> {
if (isMajor(s, d)) {
test_create_detached_signature(c, s, d, null, k,
Content.Text, server.getPort(), false, null);
}
}))));
System.out.println("\ntests for base64 data");
Arrays.stream(canonicalizationMethods).forEach(c ->
Arrays.stream(allSignatureMethods).forEach(s ->
Arrays.stream(allDigestMethods).forEach(d ->
Arrays.stream(non_xml_transforms).forEach(t ->
Arrays.stream(KeyInfoType.values()).forEach(k -> {
if (isMajor(s, d)) {
test_create_detached_signature(c, s, d, t, k,
Content.Base64, server.getPort(),
false, null);
}
})))));
// negative tests
System.out.println("\nunknown CanonicalizationMethod");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE + BOGUS,
SignatureMethod.DSA_SHA1,
DigestMethod.SHA1,
CanonicalizationMethod.INCLUSIVE,
KeyInfoType.KeyName,
Content.Xml,
server.getPort(),
true,
NoSuchAlgorithmException.class);
System.out.println("\nunknown SignatureMethod");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE,
SignatureMethod.DSA_SHA1 + BOGUS,
DigestMethod.SHA1,
CanonicalizationMethod.INCLUSIVE,
KeyInfoType.KeyName, Content.Xml,
server.getPort(),
true,
NoSuchAlgorithmException.class);
System.out.println("\nunknown DigestMethod");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE,
SignatureMethod.DSA_SHA1,
DigestMethod.SHA1 + BOGUS,
CanonicalizationMethod.INCLUSIVE,
KeyInfoType.KeyName, Content.Xml,
server.getPort(),
true,
NoSuchAlgorithmException.class);
System.out.println("\nunknown Transform");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE,
SignatureMethod.DSA_SHA1,
DigestMethod.SHA1,
CanonicalizationMethod.INCLUSIVE + BOGUS,
KeyInfoType.KeyName, Content.Xml,
server.getPort(),
true,
NoSuchAlgorithmException.class);
System.out.println("\nno source document");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE,
SignatureMethod.DSA_SHA1,
DigestMethod.SHA1,
CanonicalizationMethod.INCLUSIVE,
KeyInfoType.KeyName,
Content.NotExisitng,
server.getPort(),
true,
XMLSignatureException.class);
System.out.println("\nwrong transform for text data");
test_create_detached_signature(
CanonicalizationMethod.EXCLUSIVE,
SignatureMethod.DSA_SHA1,
DigestMethod.SHA1,
CanonicalizationMethod.INCLUSIVE,
KeyInfoType.KeyName,
Content.Text,
server.getPort(),
true,
XMLSignatureException.class);
}
// persist cached keys to a file.
try (FileOutputStream fos = new FileOutputStream("cached-keys", true);
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(cachedKeys);
}
if (!result) {
throw new RuntimeException("At least one test case failed");
}
}
// Do not test on all combinations.
private static boolean isMajor(String signatureMethod, String digestMethod) {
return majorDigestMethods.contains(digestMethod)
|| majorSignatureMethods.contains(signatureMethod);
}
private static void setup() throws Exception {
fac = XMLSignatureFactory.getInstance();
kifac = fac.getKeyInfoFactory();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
db = dbf.newDocumentBuilder();
// get key & self-signed certificate from keystore
FileInputStream fis = new FileInputStream(KEYSTORE);
ks = KeyStore.getInstance("JKS");
ks.load(fis, "changeit".toCharArray());
signingKey = ks.getKey("user", "changeit".toCharArray());
signingCert = ks.getCertificate("user");
validatingKey = signingCert.getPublicKey();
// create common objects
withoutComments = fac.newCanonicalizationMethod
(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec)null);
dsaSha1 = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
dsaSha256 = fac.newSignatureMethod(DSA_SHA256, null);
sha1 = fac.newDigestMethod(DigestMethod.SHA1, null);
sha224 = fac.newDigestMethod(DigestMethod.SHA224, null);
sha256 = fac.newDigestMethod(DigestMethod.SHA256, null);
sha384 = fac.newDigestMethod(DigestMethod.SHA384, null);
sha512 = fac.newDigestMethod(DigestMethod.SHA512, null);
sha3_224 = fac.newDigestMethod(DigestMethod.SHA3_224, null);
sha3_256 = fac.newDigestMethod(DigestMethod.SHA3_256, null);
sha3_384 = fac.newDigestMethod(DigestMethod.SHA3_384, null);
sha3_512 = fac.newDigestMethod(DigestMethod.SHA3_512, null);
dsa1024 = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(validatingKey)));
dsa2048 = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getPublicKey("DSA", 2048))));
rsa = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getPublicKey("RSA", 512))));
rsa1024 = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getPublicKey("RSA", 1024))));
rsa2048 = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getPublicKey("RSA", 2048))));
p256ki = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getECPublicKey("P256"))));
p384ki = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getECPublicKey("P384"))));
p521ki = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyValue(getECPublicKey("P521"))));
rsaSha1 = fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
rsaSha224 = fac.newSignatureMethod(SignatureMethod.RSA_SHA224, null);
rsaSha256 = fac.newSignatureMethod(SignatureMethod.RSA_SHA256, null);
rsaSha384 = fac.newSignatureMethod(SignatureMethod.RSA_SHA384, null);
rsaSha512 = fac.newSignatureMethod(SignatureMethod.RSA_SHA512, null);
rsaSha1mgf1 = fac.newSignatureMethod(SignatureMethod.SHA1_RSA_MGF1, null);
rsaSha224mgf1 = fac.newSignatureMethod(SignatureMethod.SHA224_RSA_MGF1, null);
rsaSha256mgf1 = fac.newSignatureMethod(SignatureMethod.SHA256_RSA_MGF1, null);
rsaSha384mgf1 = fac.newSignatureMethod(SignatureMethod.SHA384_RSA_MGF1, null);
rsaSha512mgf1 = fac.newSignatureMethod(SignatureMethod.SHA512_RSA_MGF1, null);
ecdsaSha1 = fac.newSignatureMethod(SignatureMethod.ECDSA_SHA1, null);
ecdsaSha224 = fac.newSignatureMethod(SignatureMethod.ECDSA_SHA224, null);
ecdsaSha256 = fac.newSignatureMethod(SignatureMethod.ECDSA_SHA256, null);
ecdsaSha384 = fac.newSignatureMethod(SignatureMethod.ECDSA_SHA384, null);
ecdsaSha512 = fac.newSignatureMethod(SignatureMethod.ECDSA_SHA512, null);
hmacSha1 = fac.newSignatureMethod(SignatureMethod.HMAC_SHA1, null);
hmacSha224 = fac.newSignatureMethod(SignatureMethod.HMAC_SHA224, null);
hmacSha256 = fac.newSignatureMethod(SignatureMethod.HMAC_SHA256, null);
hmacSha384 = fac.newSignatureMethod(SignatureMethod.HMAC_SHA384, null);
hmacSha512 = fac.newSignatureMethod(SignatureMethod.HMAC_SHA512, null);
sks = new KeySelectors.SecretKeySelector("secret".getBytes("ASCII"));
httpUd = new HttpURIDereferencer();
}
static void test_create_signature_enveloped_dsa(int size) throws Exception {
System.out.println("* Generating signature-enveloped-dsa-"
+ size + ".xml");
SignatureMethod sm = null;
KeyInfo ki = null;
Key privKey;
if (size == 1024) {
sm = dsaSha1;
ki = dsa1024;
privKey = signingKey;
} else if (size == 2048) {
sm = dsaSha256;
ki = dsa2048;
privKey = getPrivateKey("DSA", 2048);
} else throw new RuntimeException("unsupported keysize:" + size);
// create SignedInfo
SignedInfo si = fac.newSignedInfo
(withoutComments, sm, Collections.singletonList
(fac.newReference
("", sha1, Collections.singletonList
(fac.newTransform(Transform.ENVELOPED,
(TransformParameterSpec) null)),
null, null)));
// create XMLSignature
XMLSignature sig = fac.newXMLSignature(si, ki);
Document doc = db.newDocument();
Element envelope = doc.createElementNS
("http://example.org/envelope", "Envelope");
envelope.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
"xmlns", "http://example.org/envelope");
doc.appendChild(envelope);
DOMSignContext dsc = new DOMSignContext(privKey, envelope);
sig.sign(dsc);
// StringWriter sw = new StringWriter();
// dumpDocument(doc, sw);
// System.out.println(sw.toString());
DOMValidateContext dvc = new DOMValidateContext
(kvks, envelope.getFirstChild());
XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
if (sig.equals(sig2) == false) {
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
if (sig2.validate(dvc) == false) {
throw new Exception("Validation of generated signature failed");
}
System.out.println();
}
static void test_create_signature_enveloping_b64_dsa() throws Exception {
System.out.println("* Generating signature-enveloping-b64-dsa.xml");
test_create_signature_enveloping
(sha1, dsaSha1, dsa1024, signingKey, kvks, true);
System.out.println();
}
static void test_create_signature_enveloping_dsa() throws Exception {
System.out.println("* Generating signature-enveloping-dsa.xml");
test_create_signature_enveloping
(sha1, dsaSha1, dsa1024, signingKey, kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha256_dsa() throws Exception {
System.out.println("* Generating signature-enveloping-sha256-dsa.xml");
test_create_signature_enveloping
(sha256, dsaSha1, dsa1024, signingKey, kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_hmac_sha1_40()
throws Exception {
System.out.println("* Generating signature-enveloping-hmac-sha1-40.xml");
try {
test_create_signature_enveloping(sha1, hmacSha1, null,
getSecretKey("secret".getBytes("ASCII")), sks, false);
} catch (Exception e) {
if (!(e instanceof XMLSignatureException)) {
throw e;
}
}
System.out.println();
}
static void test_create_signature_enveloping_hmac_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-hmac-sha256.xml");
test_create_signature_enveloping(sha1, hmacSha256, null,
getSecretKey("secret".getBytes("ASCII")), sks, false);
System.out.println();
}
static void test_create_signature_enveloping_hmac_sha224()
throws Exception {
System.out.println("* Generating signature-enveloping-hmac-sha224.xml");
test_create_signature_enveloping(sha1, hmacSha224, null,
getSecretKey("secret".getBytes("ASCII")), sks, false);
System.out.println();
}
static void test_create_signature_enveloping_hmac_sha384()
throws Exception {
System.out.println("* Generating signature-enveloping-hmac-sha384.xml");
test_create_signature_enveloping(sha1, hmacSha384, null,
getSecretKey("secret".getBytes("ASCII")), sks, false);
System.out.println();
}
static void test_create_signature_enveloping_hmac_sha512()
throws Exception {
System.out.println("* Generating signature-enveloping-hmac-sha512.xml");
test_create_signature_enveloping(sha1, hmacSha512, null,
getSecretKey("secret".getBytes("ASCII")), sks, false);
System.out.println();
}
static void test_create_signature_enveloping_rsa() throws Exception {
System.out.println("* Generating signature-enveloping-rsa.xml");
test_create_signature_enveloping(sha1, rsaSha1, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha384_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha384-rsa_sha256.xml");
test_create_signature_enveloping(sha384, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha224_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha224-rsa_sha256.xml");
test_create_signature_enveloping(sha224, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha3_224_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha3_224-rsa_sha256.xml");
test_create_signature_enveloping(sha3_224, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha3_256_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha3_256-rsa_sha256.xml");
test_create_signature_enveloping(sha3_256, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha3_384_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha3_384-rsa_sha256.xml");
test_create_signature_enveloping(sha3_384, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha3_512_rsa_sha256()
throws Exception {
System.out.println("* Generating signature-enveloping-sha3_512-rsa_sha256.xml");
test_create_signature_enveloping(sha3_512, rsaSha256, rsa,
getPrivateKey("RSA", 512), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha384()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha384.xml");
test_create_signature_enveloping(sha512, rsaSha384, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha224()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha224.xml");
test_create_signature_enveloping(sha512, rsaSha224, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha512()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha512.xml");
test_create_signature_enveloping(sha512, rsaSha512, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha1_mgf1()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha1_mgf1.xml");
test_create_signature_enveloping(sha512, rsaSha1mgf1, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha224_mgf1()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha224_mgf1.xml");
test_create_signature_enveloping(sha512, rsaSha224mgf1, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha256_mgf1()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha256_mgf1.xml");
test_create_signature_enveloping(sha512, rsaSha256mgf1, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha384_mgf1()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha384_mgf1.xml");
test_create_signature_enveloping(sha512, rsaSha384mgf1, rsa1024,
getPrivateKey("RSA", 1024), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_sha512_rsa_sha512_mgf1()
throws Exception {
System.out.println("* Generating signature-enveloping-sha512-rsa_sha512_mgf1.xml");
test_create_signature_enveloping(sha512, rsaSha512mgf1, rsa2048,
getPrivateKey("RSA", 2048), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p256_sha1() throws Exception {
System.out.println("* Generating signature-enveloping-p256-sha1.xml");
test_create_signature_enveloping(sha1, ecdsaSha1, p256ki,
getECPrivateKey("P256"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p256_sha224() throws Exception {
System.out.println("* Generating signature-enveloping-p256-sha224.xml");
test_create_signature_enveloping(sha1, ecdsaSha224, p256ki,
getECPrivateKey("P256"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p256_sha256() throws Exception {
System.out.println("* Generating signature-enveloping-p256-sha256.xml");
test_create_signature_enveloping(sha1, ecdsaSha256, p256ki,
getECPrivateKey("P256"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p256_sha384() throws Exception {
System.out.println("* Generating signature-enveloping-p256-sha384.xml");
test_create_signature_enveloping(sha1, ecdsaSha384, p256ki,
getECPrivateKey("P256"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p256_sha512() throws Exception {
System.out.println("* Generating signature-enveloping-p256-sha512.xml");
test_create_signature_enveloping(sha1, ecdsaSha512, p256ki,
getECPrivateKey("P256"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p384_sha1() throws Exception {
System.out.println("* Generating signature-enveloping-p384-sha1.xml");
test_create_signature_enveloping(sha1, ecdsaSha1, p384ki,
getECPrivateKey("P384"), kvks, false);
System.out.println();
}
static void test_create_signature_enveloping_p521_sha1() throws Exception {
System.out.println("* Generating signature-enveloping-p521-sha1.xml");
test_create_signature_enveloping(sha1, ecdsaSha1, p521ki,
getECPrivateKey("P521"), kvks, false);
System.out.println();
}
static void test_create_signature_external_b64_dsa() throws Exception {
System.out.println("* Generating signature-external-b64-dsa.xml");
test_create_signature_external(dsaSha1, dsa1024, signingKey, kvks, true);
System.out.println();
}
static void test_create_signature_external_dsa() throws Exception {
System.out.println("* Generating signature-external-dsa.xml");
test_create_signature_external(dsaSha1, dsa1024, signingKey, kvks, false);
System.out.println();
}
static void test_create_signature_keyname() throws Exception {
System.out.println("* Generating signature-keyname.xml");
KeyInfo kn = kifac.newKeyInfo(Collections.singletonList
(kifac.newKeyName("user")));
test_create_signature_external(dsaSha1, kn, signingKey,
new X509KeySelector(ks), false);
System.out.println();
}
static void test_create_signature_retrievalmethod_rawx509crt()
throws Exception {
System.out.println(
"* Generating signature-retrievalmethod-rawx509crt.xml");
KeyInfo rm = kifac.newKeyInfo(Collections.singletonList
(kifac.newRetrievalMethod
("certs/user.crt", X509Data.RAW_X509_CERTIFICATE_TYPE, null)));
test_create_signature_external(dsaSha1, rm, signingKey,
new X509KeySelector(ks), false);
System.out.println();
}
static void test_create_signature_x509_crt_crl() throws Exception {
System.out.println("* Generating signature-x509-crt-crl.xml");
List