Package org.apache.xml.security.stax.impl.util

Examples of org.apache.xml.security.stax.impl.util.DigestOutputStream


        String digestAlgo = securePart.getDigestMethod();
        if (digestAlgo == null) {
            digestAlgo = getSecurityProperties().getSignatureDigestAlgorithm();
        }

        DigestOutputStream digestOutputStream = createMessageDigestOutputStream(digestAlgo);
        InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();

        SignaturePartDef signaturePartDef = new SignaturePartDef();
        signaturePartDef.setSecurePart(securePart);
        signaturePartDef.setSigRefId(externalReference);
        signaturePartDef.setExternalResource(true);
        signaturePartDef.setTransforms(securePart.getTransforms());
        signaturePartDef.setDigestAlgo(digestAlgo);

        try {
            if (securePart.getTransforms() != null) {
                signaturePartDef.setExcludeVisibleC14Nprefixes(true);
                Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);
                transformer.transform(inputStream);
                transformer.doFinal();
            } else {
                XMLSecurityUtils.copy(inputStream, digestOutputStream);
            }
            digestOutputStream.close();
        } catch (IOException e) {
            throw new XMLSecurityException(e);
        }

        String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
        if (logger.isDebugEnabled()) {
            logger.debug("Calculated Digest: " + calculatedDigest);
        }

        signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here


        } catch (NoSuchAlgorithmException e) {
            throw new XMLSecurityException(e);
        } catch (NoSuchProviderException e) {
            throw new XMLSecurityException(e);
        }
        return new DigestOutputStream(messageDigest);
    }
View Full Code Here

                signaturePartDef.setDigestAlgo(securePart.getDigestMethod());
                if (signaturePartDef.getDigestAlgo() == null) {
                    signaturePartDef.setDigestAlgo(getSecurityProperties().getSignatureDigestAlgorithm());
                }

                DigestOutputStream digestOutputStream = createMessageDigestOutputStream(signaturePartDef.getDigestAlgo());
                InputStream inputStream = attachment.getSourceStream();
                if (!inputStream.markSupported()) {
                    inputStream = new BufferedInputStream(inputStream);
                }
                inputStream.mark(Integer.MAX_VALUE); //we can process at maximum 2G with the standard jdk streams

                try {
                    Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);

                    Map<String, Object> transformerProperties = new HashMap<String, Object>(2);
                    transformerProperties.put(
                            AttachmentContentSignatureTransform.ATTACHMENT, attachment);
                    transformer.setProperties(transformerProperties);
                    transformer.transform(inputStream);
                    transformer.doFinal();

                    digestOutputStream.close();

                    //reset the inputStream to be able to reuse it
                    inputStream.reset();
                } catch (IOException e) {
                    throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                } catch (XMLStreamException e) {
                    throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                }

                String calculatedDigest = new String(Base64.encode(digestOutputStream.getDigestValue()));
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Calculated Digest: " + calculatedDigest);
                }

                signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here

            final SecurePart securePart = securePartEntry.getValue();
            final String externalReference = securePart.getExternalReference();
            if (externalReference != null) {
                ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(externalReference, outputProcessorChain.getDocumentContext().getBaseURI());

                DigestOutputStream digestOutputStream = createMessageDigestOutputStream(securePart.getDigestMethod());
                InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();

                SignaturePartDef signaturePartDef = new SignaturePartDef();
                signaturePartDef.setSecurePart(securePart);
                signaturePartDef.setSigRefId(externalReference);
                signaturePartDef.setExternalResource(true);
                signaturePartDef.setTransforms(securePart.getTransforms());
                String digestMethod = securePart.getDigestMethod();
                if (digestMethod == null) {
                    digestMethod = getSecurityProperties().getSignatureDigestAlgorithm();
                }
                signaturePartDef.setDigestAlgo(digestMethod);
                signaturePartDefs.add(signaturePartDef);

                try {
                    if (securePart.getTransforms() != null) {
                        signaturePartDef.setExcludeVisibleC14Nprefixes(true);
                        Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);
                        transformer.transform(inputStream);
                        transformer.doFinal();
                    } else {
                        XMLSecurityUtils.copy(inputStream, digestOutputStream);
                    }
                    digestOutputStream.close();
                } catch (IOException e) {
                    throw new XMLSecurityException(e);
                }

                String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
                if (logger.isDebugEnabled()) {
                    logger.debug("Calculated Digest: " + calculatedDigest);
                }

                signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here

        } catch (NoSuchAlgorithmException e) {
            throw new XMLSecurityException(e);
        } catch (NoSuchProviderException e) {
            throw new XMLSecurityException(e);
        }
        return new DigestOutputStream(messageDigest);
    }
View Full Code Here

    }

    private void verifyExternalReference(InputProcessorChain inputProcessorChain, ResourceResolver resourceResolver,
                                         ReferenceType referenceType) throws XMLSecurityException, XMLStreamException {

        DigestOutputStream digestOutputStream;
        OutputStream bufferedDigestOutputStream;
        Transformer transformer;

        InputStream inputStream = new BufferedInputStream(resourceResolver.getInputStreamFromExternalReference());
        try {
            digestOutputStream = createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
            bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(digestOutputStream);

            if (referenceType.getTransforms() != null) {
                transformer = buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain, null);
                transformer.transform(inputStream);
                bufferedDigestOutputStream.close();
            } else {
                XMLSecurityUtils.copy(inputStream, bufferedDigestOutputStream);
                bufferedDigestOutputStream.close();
            }
        } catch (IOException e) {
            throw new XMLSecurityException(e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                logger.warn("Could not close external resource input stream, ignored.");
            }
        }
        compareDigest(digestOutputStream.getDigestValue(), referenceType);
    }
View Full Code Here

            throw new XMLSecurityException(e);
        } catch (NoSuchProviderException e) {
            throw new XMLSecurityException(e);
        }

        return new DigestOutputStream(messageDigest);
    }
View Full Code Here

            }
            //todo workaround 2GB limit somehow?
            attachmentInputStream.mark(Integer.MAX_VALUE); //we can process at maximum 2G with the standard jdk streams

            try {
                DigestOutputStream digestOutputStream =
                        createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
                UnsynchronizedBufferedOutputStream bufferedDigestOutputStream =
                        new UnsynchronizedBufferedOutputStream(digestOutputStream);

                if (referenceType.getTransforms() != null) {
                    Transformer transformer =
                            buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain, null);
                    if (!(transformer instanceof AttachmentContentSignatureTransform)) {
                        throw new WSSecurityException(
                                WSSecurityException.ErrorCode.INVALID_SECURITY,
                                "empty", "First transform must be Attachment[Content|Complete]SignatureTransform"
                        );
                    }
                    Map<String, Object> transformerProperties = new HashMap<String, Object>(2);
                    transformerProperties.put(
                            AttachmentContentSignatureTransform.ATTACHMENT, attachment);
                    transformer.setProperties(transformerProperties);

                    transformer.transform(attachmentInputStream);

                    bufferedDigestOutputStream.close();
                } else {
                    XMLSecurityUtils.copy(attachmentInputStream, bufferedDigestOutputStream);
                    bufferedDigestOutputStream.close();
                }
                compareDigest(digestOutputStream.getDigestValue(), referenceType);

                //reset the inputStream to be able to reuse it
                attachmentInputStream.reset();

            } catch (IOException e) {
View Full Code Here

        String digestAlgo = securePart.getDigestMethod();
        if (digestAlgo == null) {
            digestAlgo = getSecurityProperties().getSignatureDigestAlgorithm();
        }

        DigestOutputStream digestOutputStream = createMessageDigestOutputStream(digestAlgo);
        InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();

        SignaturePartDef signaturePartDef = new SignaturePartDef();
        signaturePartDef.setSecurePart(securePart);
        signaturePartDef.setSigRefId(externalReference);
        signaturePartDef.setExternalResource(true);
        signaturePartDef.setTransforms(securePart.getTransforms());
        signaturePartDef.setDigestAlgo(digestAlgo);

        try {
            if (securePart.getTransforms() != null) {
                signaturePartDef.setExcludeVisibleC14Nprefixes(true);
                Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);
                transformer.transform(inputStream);
                transformer.doFinal();
            } else {
                XMLSecurityUtils.copy(inputStream, digestOutputStream);
            }
            digestOutputStream.close();
        } catch (IOException e) {
            throw new XMLSecurityException(e);
        }

        String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
        if (logger.isDebugEnabled()) {
            logger.debug("Calculated Digest: " + calculatedDigest);
        }

        signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here

        } catch (NoSuchAlgorithmException e) {
            throw new XMLSecurityException(e);
        } catch (NoSuchProviderException e) {
            throw new XMLSecurityException(e);
        }
        return new DigestOutputStream(messageDigest);
    }
View Full Code Here

TOP

Related Classes of org.apache.xml.security.stax.impl.util.DigestOutputStream

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.