Package org.apache.xml.security.c14n

Examples of org.apache.xml.security.c14n.Canonicalizer


          c14nMethodURI.equals("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments") ||
      c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#") ||
      c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#WithComments"))) {
        //The c14n is not a secure one and can rewrite the URIs or like that reparse the SignedInfo to be sure   
      try {
         Canonicalizer c14nizer =
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());

         this._c14nizedBytes =
            c14nizer.canonicalizeSubtree(this._constructionElement);
         javax.xml.parsers.DocumentBuilderFactory dbf =
            javax.xml.parsers.DocumentBuilderFactory.newInstance();

         dbf.setNamespaceAware(true);
View Full Code Here


           throws CanonicalizationException, InvalidCanonicalizerException,
                 XMLSecurityException {

      if ((this._c14nizedBytes == null)
              /*&& (this._state == ElementProxy.MODE_SIGN)*/) {
         Canonicalizer c14nizer =
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());

         this._c14nizedBytes =
            c14nizer.canonicalizeSubtree(this._constructionElement);
      }

      // make defensive copy
      byte[] output = new byte[this._c14nizedBytes.length];

View Full Code Here

   public void signInOctectStream(OutputStream os)           
       throws CanonicalizationException, InvalidCanonicalizerException,
     XMLSecurityException {

     if ((this._c14nizedBytes == null)) {
       Canonicalizer c14nizer =
          Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
       c14nizer.setWriter(os);
       String inclusiveNamespaces = this.getInclusiveNamespaces();

       if(inclusiveNamespaces == null)
        c14nizer.canonicalizeSubtree(this._constructionElement);
       else
        c14nizer.canonicalizeSubtree(this._constructionElement, inclusiveNamespaces);
    } else {
        try {
      os.write(this._c14nizedBytes);
    } catch (IOException e) {
      throw new RuntimeException(""+e);
View Full Code Here

            sig.addKeyInfo(cert);
            sig.addKeyInfo(cert.getPublicKey());
            sig.sign(privateKey);

            Canonicalizer c14n = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
            byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);

            InputSource is = new InputSource(new java.io.ByteArrayInputStream(canonicalMessage));
            DeserializationContextImpl dser = null;
            if (msgContext == null) {
                AxisClient tmpEngine = new AxisClient(new NullProvider());
View Full Code Here

            // The element to transform MUST be a SecurityTokenReference
            // element.
            //
            SecurityTokenReference secRef = new SecurityTokenReference(str);
           
            Canonicalizer canon = Canonicalizer.getInstance(canonAlgo);

            ByteArrayOutputStream bos = null;
            byte[] buf = null;
           
            //
            // Third and fourth step are performed by dereferenceSTR()
            //
            Object wsDocInfoObject = xc.getProperty(TRANSFORM_WS_DOC_INFO);
            WSDocInfo wsDocInfo = null;
            if (wsDocInfoObject instanceof WSDocInfo) {
                wsDocInfo = (WSDocInfo)wsDocInfoObject;
            }
            if (wsDocInfo == null && doDebug) {
                log.debug("STRTransform: no WSDocInfo found");
            }

            Document doc = str.getOwnerDocument();
            Element dereferencedToken =
                STRTransformUtil.dereferenceSTR(doc, secRef, wsDocInfo);
           
            if (dereferencedToken != null) {
                String type = dereferencedToken.getAttributeNS(null, "ValueType");
                if ((X509Security.X509_V3_TYPE.equals(type)
                    || PKIPathSecurity.getType().equals(type))) {
                    //
                    // Add the WSSE/WSU namespaces to the element for C14n
                    //
                    WSSecurityUtil.setNamespace(
                        dereferencedToken, WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX
                    );
                    WSSecurityUtil.setNamespace(
                        dereferencedToken, WSConstants.WSU_NS, WSConstants.WSU_PREFIX
                    );
                }
            }
           
            //
            // C14n with specified algorithm. According to WSS Specification.
            //
            buf = canon.canonicalizeSubtree(dereferencedToken, "#default");
            if (doDebug) {
                bos = new ByteArrayOutputStream(buf.length);
                bos.write(buf, 0, buf.length);
                log.debug("after c14n: " + bos.toString());
            }
View Full Code Here

                canonAlgo = canonElem.getAttribute("Algorithm");
                if (doDebug) {
                    log.debug("CanonAlgo: " + canonAlgo);
                }
            }
            Canonicalizer canon = Canonicalizer.getInstance(canonAlgo);

            ByteArrayOutputStream bos = null;
            byte[] buf = null;
            if (doDebug) {
                buf = input.getBytes();
                bos = new ByteArrayOutputStream(buf.length);
                bos.write(buf, 0, buf.length);
                log.debug("canon bos: " + bos.toString());
            }

            //
            // Get the input (node) to transform. Currently we support only an
            // Element as input format. If other formats are required we must
            // get it as bytes and probably reparse it into a DOM tree (How to
            // work with nodesets? how to select the right node from a nodeset?)
            //
            Element str = null;
            if (input.isElement()) {
                str = (Element) input.getSubNode();
            } else {
                throw new CanonicalizationException(
                    "Wrong input format - only element input supported"
                );
            }

            if (doDebug) {
                log.debug("STR: " + str.toString());
            }
            //
            // The element to transform MUST be a SecurityTokenReference
            // element.
            //
            SecurityTokenReference secRef = new SecurityTokenReference(str);
            //
            // Third and forth step are performed by derefenceSTR()
            //
            Element dereferencedToken = STRTransformUtil.dereferenceSTR(
                    thisDoc, secRef, wsDocInfo);
            //
            // C14n with specified algorithm. According to WSS Specification.
            //
            buf = canon.canonicalizeSubtree(dereferencedToken, "#default");
            if (doDebug) {
                bos = new ByteArrayOutputStream(buf.length);
                bos.write(buf, 0, buf.length);
                log.debug("after c14n: " + bos.toString());
            }
View Full Code Here

                canonAlgo = canonElem.getAttribute("Algorithm");
                if (doDebug) {
                    log.debug("CanonAlgo: " + canonAlgo);
                }
            }
            Canonicalizer canon = Canonicalizer.getInstance(canonAlgo);

            ByteArrayOutputStream bos = null;
            byte[] buf = null;
            if (doDebug) {
                buf = input.getBytes();
                bos = new ByteArrayOutputStream(buf.length);
                bos.write(buf, 0, buf.length);
                log.debug("canon bos: " + bos.toString());
            }

            /*
             * Get the input (node) to transform. Currently we support only an
             * Element as input format. If other formats are required we must
             * get it as bytes and probably reparse it into a DOM tree (How to
             * work with nodesets? how to select the right node from a nodeset?)
             */
            Element str = null;
            if (input.isElement()) {
                str = (Element) input.getSubNode();
            } else {
                throw (new CanonicalizationException(
                        "Wrong input format - only element input supported"));
            }

            if (doDebug) {
                log.debug("STR: " + str.toString());
            }
            /*
             * The element to transform MUST be a SecurityTokenReference
             * element.
             */
            SecurityTokenReference secRef = new SecurityTokenReference(str);
            /*
             * Third and forth step are performed by derefenceSTR()
             */
            Element dereferencedToken = dereferenceSTR(thisDoc, secRef);
            /*
             * C14n with specified algorithm. According to WSS Specification.
             */
            buf = canon.canonicalizeSubtree(dereferencedToken, "#default");
            if (doDebug) {
                bos = new ByteArrayOutputStream(buf.length);
                bos.write(buf, 0, buf.length);
                log.debug("after c14n: " + bos.toString());
            }
View Full Code Here

        DSNamespaceContext namespaceContext =
            new DSNamespaceContext(namespace);
        xPath.setNamespaceContext(namespaceContext);

        NodeList nodes = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
        Canonicalizer c14n =
            Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
        byte c14nBytes[] = c14n.canonicalizeXPathNodeSet(nodes);
        InputStream refStream = resolver.resolveEntity(null,
                                                       fileRef).getByteStream();
        byte refBytes[] = JavaUtils.getBytesFromStream(refStream);
        assertEquals(new String(refBytes),new String(c14nBytes));
    }
View Full Code Here

        DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
        Document doc = db.parse(new ByteArrayInputStream(inputStr.getBytes()));
        boolean weCatchedTheRelativeNS = false;

        try {
            Canonicalizer c14n =
                Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
            c14n.canonicalizeSubtree(doc);

        } catch (CanonicalizationException cex) {
            // if we reach this point - good.
            log.debug("We catched the C14nEx, that's good: " + cex.getMessage());
            weCatchedTheRelativeNS = true;
View Full Code Here

        ParserConfigurationException, CanonicalizationException,
        InvalidCanonicalizerException, TransformerException {
        String val =
            "<UTF16>The german &amp;auml (which is Unicode &amp;#xE4;):  &quot;&#xE4;&quot;</UTF16>";
        byte utf16[] = convertToUTF16(val.getBytes());
        Canonicalizer c14n =
            Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
        byte c14nBytes[] = c14n.canonicalize(utf16);
        org.xml.sax.EntityResolver resolver = new TestVectorResolver();
        InputStream refStream =
            resolver.resolveEntity(
                null, prefix + "/in/testTranslationFromUTF16toUTF8.xml").getByteStream();
        byte refBytes[] = JavaUtils.getBytesFromStream(refStream);
View Full Code Here

TOP

Related Classes of org.apache.xml.security.c14n.Canonicalizer

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.