/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.apache.xml.security.samples; import org.apache.xml.security.samples.SampleUtils; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.utils.Constants; import org.apache.xml.security.utils.XMLUtils; import org.apache.xml.security.utils.resolver.ResourceResolver; import org.apache.xpath.XPathAPI; import org.w3c.dom.Element; /** * * @author $Author: mullan $ */ public class ResolverUsageHTTP { /** * Method main * * @param unused * @throws Exception */ public static void main(String unused[]) throws Exception { ResourceResolver.registerAtStart( "org.apache.xml.security.samples.utils.resolver.OfflineResolver"); //J- // String currentSystemId = "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/signature.xml"; String currentSystemId = "file:/Y:/signature.xml"; // String refURI = "#N3"; String refURI = "#xpointer(id("id2"))"; // String refURI = "file:/Y:/jbproject/xmlsecurity/data/org.apache.xml.security/temp/id.xml#N3"; // String refURI = "http://www.nue.et-inf.uni-siegen.de/index.html#xpointer('id3')"; String inputStr = "" + "\n" + "" + "\n" + "]>" + "\n" + "" + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " 60NvZvtdTB+7UnlLp/H24p7h4bs=" + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " RJeREVHXdM5ysghhvpIYGJJaNQI=" + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " Hpg+6h1k1jYY5yr3TRzDZzw23CQ=" + "\n" // + " RJeREVHXdM5ysghhvpIYGJJaNQI=" + "\n" + " " + "\n" // + " " + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " self::text()" + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " RK9DKU4NnECPpNAb+QxMwTmSL+w=" + "\n" + " " + "\n" + " " + "\n" + " " + "\n" + " KTe1H5Hjp8hwahNFoUqHDuPJNNqhS1U3BBBH5/gByItNIwV18nMiLq4KunzFnOqD" + "\n" + " xzTuO0/T+wsoYC1xOEuCDxyIujNCaJfLh+rCi5THulnc8KSHHEoPQ+7fA1VjmO31" + "\n" + " 2iw1iENOi7m//wzKlIHuxZCJ5nvolT21PV6nSE4DHlA=" + "\n" + " " + "\n" + " " + "\n" + " Das N3 Element" + "\n" + " Das id2 Element" + "\n" + " " + "\n" + ""; //J+ javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(new java.io.ByteArrayInputStream(inputStr.getBytes())); Element context = SampleUtils.createDSctx(doc, "ds", Constants.SignatureSpecNS); Element dsElem = (Element) XPathAPI.selectSingleNode(doc, "//ds:Signature[1]", context); XMLSignature signature = new XMLSignature(dsElem, currentSystemId); // how can I reg my own keystore? boolean verify = signature.checkSignatureValue(signature.getKeyInfo().getPublicKey()); System.out.println("Signature " + (verify ? "Verification successful" : "Verification failed")); System.out.println("Canonicalized SignedInfo:"); System.out .println(new String(signature.getSignedInfo() .getCanonicalizedOctetStream())); /* Element signedInfoElem = (Element) XPathAPI.selectSingleNode(doc, "/doc/ds:Signature/ds:SignedInfo", context); SignedInfo si = new SignedInfo(signedInfoElem, currentSystemId); boolean useProxy = false; if (useProxy) { si.setResolverProperty("http.proxy.host", "www-cache.uni-siegen.de"); si.setResolverProperty("http.proxy.port", "3128"); } boolean verify = si.verify(); System.out.println(verify ? "Verification successful" : "Verification failed"); if (!verify) { for (int i=0; i