GenerationTests.java revision 6159
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
* @summary Basic unit tests for generating XML Signatures with JSR 105
* @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
* @author Sean Mullan
*/
/**
* Test that recreates merlin-xmldsig-twenty-three test vectors 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 KeySelector sks;
private static Key signingKey;
private static PublicKey validatingKey;
private static Certificate signingCert;
// private final static String DIR = ".";
private final static String STYLESHEET =
private final static String STYLESHEET_B64 =
setup();
}
dbf.setNamespaceAware(true);
// get key & self-signed certificate from keystore
// create common objects
("http://www.w3.org/2001/04/xmldsig-more#sha384", null);
("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", null);
("http://www.w3.org/2001/04/xmldsig-more#rsa-sha384", null);
("http://www.w3.org/2001/04/xmldsig-more#rsa-sha512", null);
httpUd = new HttpURIDereferencer();
}
static void test_create_signature_enveloped_dsa() throws Exception {
// create SignedInfo
// create XMLSignature
("http://example.org/envelope", "Envelope");
"xmlns", "http://example.org/envelope");
// StringWriter sw = new StringWriter();
// dumpDocument(doc, sw);
// System.out.println(sw.toString());
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
static void test_create_signature_enveloping_b64_dsa() throws Exception {
}
static void test_create_signature_enveloping_dsa() throws Exception {
}
static void test_create_signature_enveloping_sha256_dsa() throws Exception {
}
static void test_create_signature_enveloping_hmac_sha1_40()
throws Exception {
try {
} catch (Exception e) {
if (!(e instanceof XMLSignatureException)) {
throw e;
}
}
}
static void test_create_signature_enveloping_hmac_sha256()
throws Exception {
("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", null);
}
static void test_create_signature_enveloping_hmac_sha384()
throws Exception {
("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", null);
}
static void test_create_signature_enveloping_hmac_sha512()
throws Exception {
("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", null);
}
static void test_create_signature_enveloping_rsa() throws Exception {
}
static void test_create_signature_enveloping_sha384_rsa_sha256()
throws Exception {
}
static void test_create_signature_enveloping_sha512_rsa_sha384()
throws Exception {
}
static void test_create_signature_enveloping_sha512_rsa_sha512()
throws Exception {
}
static void test_create_signature_external_b64_dsa() throws Exception {
}
static void test_create_signature_external_dsa() throws Exception {
}
static void test_create_signature_keyname() throws Exception {
new X509KeySelector(ks), false);
}
static void test_create_signature_retrievalmethod_rawx509crt()
throws Exception {
"* Generating signature-retrievalmethod-rawx509crt.xml");
new X509KeySelector(ks), false);
}
static void test_create_signature_x509_crt_crl() throws Exception {
new X509KeySelector(ks), false);
}
static void test_create_signature_x509_crt() throws Exception {
new X509KeySelector(ks), false);
}
static void test_create_signature_x509_is() throws Exception {
new X509KeySelector(ks), false);
}
static void test_create_signature_x509_ski() throws Exception {
}
static void test_create_signature_x509_sn() throws Exception {
new X509KeySelector(ks), false);
}
static void test_create_signature_reference_dependency() throws Exception {
// create references
// create SignedInfo
// create objects
// Object 1
// Object 2
// create XMLSignature
// dumpDocument(doc, new PrintWriter(System.out));
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
static void test_create_signature_with_attr_in_no_namespace()
throws Exception
{
("* Generating signature-with-attr-in-no-namespace.xml");
// create references
// create SignedInfo
// create object-1
// add attribute with no namespace
// create XMLSignature
"signature", null);
// dumpDocument(doc, new PrintWriter(System.out));
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
static void test_create_signature() throws Exception {
// create references
// Reference 1
// Reference 2
// Reference 3
new XPathFilterParameterSpec("self::text()"))),
// Reference 4
+ " ancestor-or-self::dsig:SignedInfo " + "\n"
+ " and " + "\n"
+ " count(ancestor-or-self::dsig:Reference | " + "\n"
+ " here()/ancestor::dsig:Reference[1]) > " + "\n"
+ " count(ancestor-or-self::dsig:Reference) " + "\n"
+ " or " + "\n"
+ " count(ancestor-or-self::node() | " + "\n"
+ " id('notaries')) = " + "\n"
+ " count(ancestor-or-self::node()) " + "\n";
// Reference 5
// Reference 6
// Reference 7
// Reference 8
// Reference 9
// Reference 10
// Reference 11
transforms.clear();
// Reference 12
// Reference 13
// Reference 14
// Reference 15
// Reference 16
// Reference 17
null, "reference-1"));
// Reference 18
"reference-2"));
// create SignedInfo
// create keyinfo
"ancestor-or-self::dsig:X509Data",
// create objects
// Object 1
// Object 2
// Object 3
// Manifest
// Manifest Reference 1
// Manifest Reference 2
// Manifest Reference 3
+ "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n"
+ " xmlns='http://www.w3.org/TR/xhtml1/strict' \n"
+ " exclude-result-prefixes='foo' \n"
+ " version='1.0'>\n"
+ " <xsl:output encoding='UTF-8' \n"
+ " indent='no' \n"
+ " method='xml' />\n"
+ " <xsl:template match='/'>\n"
+ " <html>\n"
+ " <head>\n"
+ " <title>Notaries</title>\n"
+ " </head>\n"
+ " <body>\n"
+ " <table>\n"
+ " <tr>\n"
+ " <th>\n"
+ " <xsl:value-of select='@name' />\n"
+ " </th>\n"
+ " </tr>\n"
+ " </xsl:for-each>\n"
+ " </table>\n"
+ " </body>\n"
+ " </html>\n"
+ " </xsl:template>\n"
+ "</xsl:stylesheet>\n";
// SignatureProperties
"#signature", null);
// Object 4
// create XMLSignature
dbf.setNamespaceAware(true);
dbf.setValidating(false);
(new FileInputStream(ENVELOPE));
// StringWriter sw = new StringWriter();
// dumpDocument(envDoc, sw);
throw new Exception("Couldn't find signature Element");
}
"merlin-xmldsig-twenty-three" +
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
// trans.setOutputProperty(OutputKeys.INDENT, "yes");
}
private static void test_create_signature_external
// create reference
if (b64) {
} else {
}
// create SignedInfo
// create XMLSignature
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
private static void test_create_signature_enveloping
// create reference
if (b64) {
} else {
}
// create SignedInfo
// create Objects
// create XMLSignature
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
static void test_create_exc_signature() throws Exception {
// create reference 1
("#xpointer(id('to-be-signed'))",
// create reference 2
("#xpointer(id('to-be-signed'))",
// create reference 3
("#xpointer(id('to-be-signed'))",
// create reference 4
("#xpointer(id('to-be-signed'))",
// create SignedInfo
// create KeyInfo
// create Objects
// create XMLSignature
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
static void test_create_sign_spec() throws Exception {
// create reference 1
// create reference 2
// create SignedInfo
// create KeyInfo
// create XMLSignature
throw new Exception
("Unmarshalled signature is not equal to generated signature");
}
throw new Exception("Validation of generated signature failed");
}
}
"070662842167565771936588335128634396171789331656318483584455493822" +
"400811200853331373030669235424928346190274044631949560438023934623" +
"71310375123430985057160";
"013232376895198612407547930718267435757728527029623408872245156039" +
"757713029036368719146452186041204237350521785240337048752071462798" +
"273003935646236777459223";
"0857393771208094202104259627990318636601332086981";
"054216440574364751416096484883257051280474283943804743768346673007" +
"661082626139005426812890807137245973106730741193551360857959820973" +
"90670890367185141189796";
"0527140396812450214498055937934275626078768840117";
"010800185049102889923150759252557522305032794699952150943573164381" +
"936603255999071981574575044810461362008102247767482738822150129277" +
"490998033971789476107463";
"016116973584421969795445996229612671947635798429212816611707210835" +
"915586591340598683996088487065438751488342251960069575392056288063" +
"6800379454345804879553";
"909423744508062468450669519128736624058048856940468016843888594585" +
"322862378444314635412341974900625010364163960238734457710620107530" +
"573945081856371709138380902553309075505688814637544923038853658690" +
"857672483016239697038853418682988686871489963827000080098971762923" +
"833614557257607521";
"297021581096848810374110568017963075809477047466189822987258068867" +
"704855380407747867998863645890602646601140183818953428006646987710" +
"237008997971129772408397621801631622129297063463868593083106979716" +
"204903524890556839550490384015324575598723478554854070823335021842" +
"210112348400928769";
}
throws Exception {
new BigInteger(DSA_P),
new BigInteger(DSA_Q),
new BigInteger(DSA_G));
if (keysize == 512) {
new BigInteger(RSA_PUB));
} else {
new BigInteger(RSA_PUB));
}
}
}
throws Exception {
kspec = new DSAPrivateKeySpec
if (keysize == 512) {
kspec = new RSAPrivateKeySpec
} else {
new BigInteger(RSA_1024_PRIV));
}
}
return new SecretKey() {
public byte[] getEncoded() { return secret; }
};
}
/**
* This URIDereferencer returns locally cached copies of http content to
* avoid test failures due to network glitches, etc.
*/
private static class HttpURIDereferencer implements URIDereferencer {
private URIDereferencer defaultUd;
}
throws URIReferenceException {
try {
} catch (Exception e) { throw new URIReferenceException(e); }
}
// fallback on builtin deref
}
}
}