Search in sources :

Example 1 with CMSEnvelopedDataParser

use of com.github.zhenwei.pkix.cms.CMSEnvelopedDataParser in project LinLong-Java by zhenwei1108.

the class SMimeParserListener method object.

public void object(MimeParserContext parserContext, Headers headers, InputStream inputStream) throws IOException {
    try {
        if (headers.getContentType().equals("application/pkcs7-signature") || headers.getContentType().equals("application/x-pkcs7-signature")) {
            Map<ASN1ObjectIdentifier, byte[]> hashes = new HashMap<ASN1ObjectIdentifier, byte[]>();
            for (int i = 0; i != digestCalculators.length; i++) {
                digestCalculators[i].getOutputStream().close();
                hashes.put(digestCalculators[i].getAlgorithmIdentifier().getAlgorithm(), digestCalculators[i].getDigest());
            }
            byte[] sigBlock = Streams.readAll(inputStream);
            CMSSignedData signedData = new CMSSignedData(hashes, sigBlock);
            signedData(parserContext, headers, signedData.getCertificates(), signedData.getCRLs(), signedData.getAttributeCertificates(), signedData.getSignerInfos());
        } else if (headers.getContentType().equals("application/pkcs7-mime") || headers.getContentType().equals("application/x-pkcs7-mime")) {
            CMSEnvelopedDataParser envelopedDataParser = new CMSEnvelopedDataParser(inputStream);
            envelopedData(parserContext, headers, envelopedDataParser.getOriginatorInfo(), envelopedDataParser.getRecipientInfos());
            envelopedDataParser.close();
        } else {
            content(parserContext, headers, inputStream);
        }
    } catch (CMSException e) {
        throw new MimeIOException("CMS failure: " + e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) CMSEnvelopedDataParser(com.github.zhenwei.pkix.cms.CMSEnvelopedDataParser) MimeIOException(com.github.zhenwei.pkix.mime.MimeIOException) CMSSignedData(com.github.zhenwei.pkix.cms.CMSSignedData) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) CMSException(com.github.zhenwei.pkix.cms.CMSException)

Aggregations

ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)1 CMSEnvelopedDataParser (com.github.zhenwei.pkix.cms.CMSEnvelopedDataParser)1 CMSException (com.github.zhenwei.pkix.cms.CMSException)1 CMSSignedData (com.github.zhenwei.pkix.cms.CMSSignedData)1 MimeIOException (com.github.zhenwei.pkix.mime.MimeIOException)1 HashMap (java.util.HashMap)1