Package org.apache.xml.security.signature

Examples of org.apache.xml.security.signature.SignedInfo


    XMLSignature oSig = null;
    oSig = new XMLSignature(oSigElem, null);
   
    // Validate the signature content by checking the references
    String sFailedRef = null;
    SignedInfo oSignedInfo = oSig.getSignedInfo();
    if (oSignedInfo.getLength() != 1)
    {
      throw new XMLSecurityException(
          "Cannot verify the signature. Expected 1 reference, got " +
          oSignedInfo.getLength());
    }
   
    // make sure it references the correct element
    Reference oRef = oSignedInfo.item(0);
    String sURI = oRef.getURI();
    if (!sRef.equals(sURI))
    {
      throw new XMLSecurityException(
      "Cannot verify the signature. Reference URI did not match ID");


    XMLSignature oSig = null;
    oSig = new XMLSignature(oSigElem, null);
   
    // Validate the signature content by checking the references
    String sFailedRef = null;
    SignedInfo oSignedInfo = oSig.getSignedInfo();
    if (oSignedInfo.getLength() != 1)
    {
      throw new XMLSecurityException(
          "Cannot verify the signature. Expected 1 reference, got " +
          oSignedInfo.getLength());
    }
   
    // make sure it references the correct element
    Reference oRef = oSignedInfo.item(0);
    String sURI = oRef.getURI();
    if (!sRef.equals(sURI))
    {
      throw new XMLSecurityException(
      "Cannot verify the signature. Reference URI did not match ID");

        return result;
    }
   
    private void checkReferences(XMLSignature xmlSignature) throws Exception {
        SignedInfo signedInfo = xmlSignature.getSignedInfo();
        assertTrue(signedInfo.getLength() > 0);
        for (int i = 0; i < signedInfo.getLength(); i++) {
            Reference reference = signedInfo.item(i);
            assertNotNull(reference);
            ReferenceData referenceData = reference.getReferenceData();
            assertNotNull(referenceData);
           
            if (referenceData instanceof ReferenceNodeSetData) {

                /*
                     * Now dig into the Signature element to get the elements that
                     * this Signature covers. Build the QName of these Elements and
                     * return them to caller
                     */
                SignedInfo si = sig.getSignedInfo();
                int numReferences = si.getLength();
                Vector qvec = new Vector(numReferences);
                for (int i = 0; i < numReferences; i++) {
                    Reference siRef;
                    try {
                        siRef = si.item(i);
                    } catch (XMLSecurityException e3) {
                        throw new WSSecurityException(
                                WSSecurityException.FAILED_CHECK);
                    }
                    String uri = siRef.getURI();

                "IOException: Signature Element could not be read");
        }

        // Validate the signature content by checking the references
        String sFailedRef = null;
        SignedInfo oSignedInfo = oSig.getSignedInfo();
        if (oSignedInfo.getLength() != 1)
        {
            throw new XMLSecurityException(
                "Cannot verify the signature. Expected 1 reference, got " +
                oSignedInfo.getLength());
        }

        // make sure it references the correct element
        Reference oRef = oSignedInfo.item(0);
        String sURI = oRef.getURI();
        if (!sRef.equals(sURI))
        {
            throw new XMLSecurityException(
                "Cannot verify the signature. Reference URI did not match ID");

                              .createSecretKey(CreateCollectableSignature
                                 .passphrase.getBytes()))
                           ? "valid (good)"
                           : "invalid !!!!! (bad)"));

            SignedInfo s = signature.getSignedInfo();

            for (int j = 0; j < s.getSignedContentLength(); j++) {
               System.out.println("################ Signed Resource " + i + "/" + j
                                  + " ################");
               System.out.println(new String(s.getSignedContentItem(j)));
               System.out.println();
            }
         }
      } catch (Exception ex) {
         ex.printStackTrace();

      XMLUtils.outputDOMc14nWithComments(doc, f);
      f.close();
      System.out.println("Wrote signature to " + BaseURI);

      SignedInfo s = sig.getSignedInfo();
      for (int i=0; i<s.getLength(); i++) {
         Reference r = s.item(i);
         String fn = "merlin16_"+i+".html";
         System.out.println("Wrote Reference " + i + " to file " + fn);
         JavaUtils.writeBytesToFilename(fn, r.getHTMLRepresentation().getBytes());
      }

      XMLUtils.outputDOMc14nWithComments(doc, f);
      f.close();
      System.out.println("Wrote signature to " + BaseURI);

      SignedInfo s = sig.getSignedInfo();
      for (int i=0; i<s.getLength(); i++) {
         Reference r = s.item(i);
         String fn = "merlin16_"+i+".html";
         System.out.println("Wrote Reference " + i + " to file " + fn);
         JavaUtils.writeBytesToFilename(fn, r.getHTMLRepresentation().getBytes());
      }

                //
                // Now dig into the Signature element to get the elements that
                // this Signature covers. Build the QName of these Elements and
                // return them to caller
                //
                SignedInfo si = sig.getSignedInfo();
                int numReferences = si.getLength();
                for (int i = 0; i < numReferences; i++) {
                    Reference siRef;
                    try {
                        siRef = si.item(i);
                    } catch (XMLSecurityException e3) {
                        throw new WSSecurityException(
                            WSSecurityException.FAILED_CHECK, null, null, e3
                        );
                    }

        try {
            log.debug("Constructing Apache XMLSignature object");

            XMLSignature xmlSignature = new XMLSignature(signatureElement, "");

            SignedInfo signedInfo = xmlSignature.getSignedInfo();

            log.debug("Adding canonicalization and signing algorithms, and HMAC output length to Signature");
            signature.setCanonicalizationAlgorithm(signedInfo.getCanonicalizationMethodURI());
            signature.setSignatureAlgorithm(signedInfo.getSignatureMethodURI());
            signature.setHMACOutputLength(getHMACOutputLengthValue(signedInfo.getSignatureMethodElement()));

            org.apache.xml.security.keys.KeyInfo xmlSecKeyInfo = xmlSignature.getKeyInfo();
            if (xmlSecKeyInfo != null) {
                log.debug("Adding KeyInfo to Signature");
                Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(

TOP

Related Classes of org.apache.xml.security.signature.SignedInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.