Search in sources :

Example 1 with MimeIOException

use of com.github.zhenwei.pkix.mime.MimeIOException 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)

Example 2 with MimeIOException

use of com.github.zhenwei.pkix.mime.MimeIOException in project LinLong-Java by zhenwei1108.

the class SMIMEEnvelopedWriter method getContentStream.

public OutputStream getContentStream() throws IOException {
    headers.dumpHeaders(mimeOut);
    mimeOut.write(Strings.toByteArray("\r\n"));
    try {
        OutputStream backing = mimeOut;
        if ("base64".equals(contentTransferEncoding)) {
            backing = new Base64OutputStream(backing);
        }
        OutputStream main = envGen.open(SMimeUtils.createUnclosable(backing), outEnc);
        return new ContentOutputStream(main, backing);
    } catch (CMSException e) {
        throw new MimeIOException(e.getMessage(), e);
    }
}
Also used : OutputStream(java.io.OutputStream) Base64OutputStream(com.github.zhenwei.pkix.mime.encoding.Base64OutputStream) Base64OutputStream(com.github.zhenwei.pkix.mime.encoding.Base64OutputStream) MimeIOException(com.github.zhenwei.pkix.mime.MimeIOException) CMSException(com.github.zhenwei.pkix.cms.CMSException)

Aggregations

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