Search in sources :

Example 1 with CMSTypedStream

use of org.bouncycastle.cms.CMSTypedStream in project tika by apache.

the class Pkcs7Parser method parse.

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    try {
        DigestCalculatorProvider digestCalculatorProvider = new JcaDigestCalculatorProviderBuilder().setProvider("BC").build();
        CMSSignedDataParser parser = new CMSSignedDataParser(digestCalculatorProvider, new CloseShieldInputStream(stream));
        try {
            CMSTypedStream content = parser.getSignedContent();
            if (content == null) {
                throw new TikaException("cannot parse detached pkcs7 signature (no signed data to parse)");
            }
            try (InputStream input = content.getContentStream()) {
                Parser delegate = context.get(Parser.class, EmptyParser.INSTANCE);
                delegate.parse(input, handler, metadata, context);
            }
        } finally {
            parser.close();
        }
    } catch (OperatorCreationException e) {
        throw new TikaException("Unable to create DigestCalculatorProvider", e);
    } catch (CMSException e) {
        throw new TikaException("Unable to parse pkcs7 signed data", e);
    }
}
Also used : CMSSignedDataParser(org.bouncycastle.cms.CMSSignedDataParser) TikaException(org.apache.tika.exception.TikaException) DigestCalculatorProvider(org.bouncycastle.operator.DigestCalculatorProvider) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) InputStream(java.io.InputStream) JcaDigestCalculatorProviderBuilder(org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) CMSTypedStream(org.bouncycastle.cms.CMSTypedStream) Parser(org.apache.tika.parser.Parser) AbstractParser(org.apache.tika.parser.AbstractParser) CMSSignedDataParser(org.bouncycastle.cms.CMSSignedDataParser) EmptyParser(org.apache.tika.parser.EmptyParser) CMSException(org.bouncycastle.cms.CMSException)

Aggregations

InputStream (java.io.InputStream)1 CloseShieldInputStream (org.apache.commons.io.input.CloseShieldInputStream)1 TikaException (org.apache.tika.exception.TikaException)1 AbstractParser (org.apache.tika.parser.AbstractParser)1 EmptyParser (org.apache.tika.parser.EmptyParser)1 Parser (org.apache.tika.parser.Parser)1 CMSException (org.bouncycastle.cms.CMSException)1 CMSSignedDataParser (org.bouncycastle.cms.CMSSignedDataParser)1 CMSTypedStream (org.bouncycastle.cms.CMSTypedStream)1 DigestCalculatorProvider (org.bouncycastle.operator.DigestCalculatorProvider)1 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)1 JcaDigestCalculatorProviderBuilder (org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder)1