com.sun.org.apache.xml.internal.security.Init Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.security.Init. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TruncateHMAC.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #2
Source File: TruncateHMAC.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #3
Source File: TruncateHMAC.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #4
Source File: TruncateHMAC.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #5
Source File: TruncateHMAC.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #6
Source File: TruncateHMAC.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #7
Source File: TruncateHMAC.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #8
Source File: TruncateHMAC.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #9
Source File: TruncateHMAC.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #10
Source File: TruncateHMAC.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #11
Source File: TruncateHMAC.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #12
Source File: TruncateHMAC.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #13
Source File: TruncateHMAC.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Init.init();
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false);
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false);
        // this one should pass
        validate("signature-enveloping-hmac-sha1.xml", true);
        generate_hmac_sha1_40();

        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected");
        }
    }
 
Example #14
Source File: DOMURIDereferencer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #15
Source File: DOMURIDereferencer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #16
Source File: DOMURIDereferencer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #17
Source File: DOMURIDereferencer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #18
Source File: Signer.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public Signer() {
if (!Init.isInitialized())
	Init.init();
  }
 
Example #19
Source File: SignatureVerifier.java    From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public SignatureVerifier() {
if (!Init.isInitialized())
	Init.init();
  }
 
Example #20
Source File: DOMURIDereferencer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #21
Source File: DOMURIDereferencer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #22
Source File: DOMURIDereferencer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #23
Source File: XMLSigner.java    From signer with GNU Lesser General Public License v3.0 4 votes vote down vote up
private byte[] getShaCanonizedValue(String Alg, Node xml) throws InvalidCanonicalizerException, NoSuchAlgorithmException, CanonicalizationException, ParserConfigurationException, IOException, SAXException {
	Init.init();
	Canonicalizer c14n = Canonicalizer.getInstance("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
	MessageDigest messageDigest = MessageDigest.getInstance(Alg);
	return messageDigest.digest(c14n.canonicalizeSubtree(xml));
}
 
Example #24
Source File: DOMURIDereferencer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #25
Source File: DOMURIDereferencer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #26
Source File: DOMURIDereferencer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #27
Source File: DOMURIDereferencer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #28
Source File: DOMURIDereferencer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #29
Source File: DOMURIDereferencer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private DOMURIDereferencer() {
    // need to call com.sun.org.apache.xml.internal.security.Init.init()
    // before calling any apache security code
    Init.init();
}
 
Example #30
Source File: XMLSigner.java    From signer with GNU Lesser General Public License v3.0 2 votes vote down vote up
public Document sign(String fileNameSource) throws Throwable{
	
	Init.init();
	
	Document doc = buildXML(fileNameSource);
					
	if(keyStore == null) {
		new Throwable("Keystore nula");
	}
	
	if(alias == null)
		alias = "";
	
	X509Certificate cert = (X509Certificate) this.keyStore.getCertificate(alias);
	PrivateKey myPrKey = (PrivateKey) keyStore.getKey (alias, null);
	
	int numSignatures = doc.getElementsByTagName("ds:Signature").getLength() - 1;
	
	Element sigTag = (Element) doc.getElementsByTagName("ds:Signature").item(numSignatures);
	
	Element objectTag = signedObject(cert, doc);
	
	Init.init();
	Canonicalizer c14n = Canonicalizer.getInstance(CanonicalizationMethod.EXCLUSIVE);
	
	byte[] canonicalized = null;
	
	if(sigPack != SignaturePack.DETACHED){
		canonicalized = c14n.canonicalizeSubtree(objectTag.getElementsByTagName("xades:SignedProperties").item(0)); 
	}else {
		canonicalized = null;
	}
	
	Element sigRefTag = createSignatureHashReference(doc, canonicalized);
	doc.getElementsByTagName("ds:SignedInfo").item(numSignatures).appendChild(sigRefTag);
	
	c14n = Canonicalizer.getInstance(CanonicalizationMethod.INCLUSIVE);
	byte[] dh = c14n.canonicalizeSubtree(doc.getElementsByTagName("ds:SignedInfo").item(numSignatures));
	
	Signature sig = Signature.getInstance("SHA256withRSA");
	sig.initSign(myPrKey);
	sig.update(dh);
	byte[] s = sig.sign();
	
	Element signValueTag = doc.createElementNS(XMLNS, "ds:SignatureValue");
	signValueTag.setAttribute("Id", "value-"+id);
	String hash = Base64.toBase64String(s);
	String result = splitString(hash);
	
	signValueTag.setTextContent(result);
	sigTag.appendChild(signValueTag);
	
	
	Element keyInfo = doc.createElementNS(XMLNS, "ds:KeyInfo");
	doc.getElementsByTagName("ds:Signature").item(numSignatures).appendChild(keyInfo);
	
	Element x509 = doc.createElementNS(XMLNS, "ds:X509Data");
	keyInfo.appendChild(x509);
			
	Element x509Certificate = doc.createElementNS(XMLNS, "ds:X509Certificate");
	x509Certificate.setTextContent(splitString(Base64.toBase64String(cert.getEncoded())));
	x509.appendChild(x509Certificate );
	
	sigTag.appendChild(objectTag);
	
	signedDocument = doc;
	
	return doc;
}