List of usage examples for org.bouncycastle.cms CMSSignedDataParser close
public void close() throws IOException
From source file:org.apache.tika.parser.crypto.Pkcs7Parser.java
License:Apache License
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try {/*ww w . j av a2s . c om*/ 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); } }
From source file:org.cryptoworkshop.ximix.client.verify.LinkIndexVerifier.java
License:Apache License
/** * Return the number of messages that were on the board producing these commitments. * * @param fileList list of general transcript files. * @return number of messages on the board. * @throws TranscriptVerificationException if there is a mismatch in the file size. */// w w w . java 2s . co m public static int getAndCheckBoardSize(File[] fileList) throws TranscriptVerificationException { int boardSize = -1; for (File file : fileList) { int count = 0; try { CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), new BufferedInputStream(new FileInputStream(file))); ASN1InputStream aIn = new ASN1InputStream(cmsParser.getSignedContent().getContentStream()); while (aIn.readObject() != null) { count++; } if (boardSize == -1) { boardSize = count; } else if (count != boardSize) { throw new TranscriptVerificationException( "Size mismatch in commitment files: " + file.getPath()); } cmsParser.close(); } catch (Exception e) { throw new TranscriptVerificationException( "Size check failed on " + file.getPath() + ": " + e.getMessage(), e); } } return boardSize; }
From source file:org.cryptoworkshop.ximix.client.verify.test.VerifierTest.java
License:Apache License
private byte[] getSequence(byte[] init, MessageChooser chooser) throws Exception { CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), new ByteArrayInputStream(init)); ASN1InputStream aIn = new ASN1InputStream(cmsParser.getSignedContent().getContentStream()); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); CMSSignedDataStreamGenerator cmsGen = new CMSSignedDataStreamGenerator(); OutputStream outputStream = cmsGen.open(bOut, true); DEROutputStream dOut = new DEROutputStream(outputStream); ASN1Primitive obj;/*from w w w . j a va 2s .c o m*/ int count = 0; while ((obj = aIn.readObject()) != null) { if (chooser.chooseMessage(count++)) { dOut.writeObject(obj); } } dOut.close(); cmsParser.close(); outputStream.close(); return bOut.toByteArray(); }
From source file:org.cryptoworkshop.ximix.node.crypto.service.NodeShuffledBoardDecryptionService.java
License:Apache License
private Map createTranscriptMap(SignedDataVerifier verifier, File[] fileList) { final Map<Integer, File> transcripts = new TreeMap<>(); for (File file : fileList) { String name = file.getName(); int beginIndex = name.indexOf('.') + 1; int stepNumber = Integer.parseInt(name.substring(beginIndex, name.indexOf('.', beginIndex))); try {// ww w .ja va 2 s. co m CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), new BufferedInputStream(new FileInputStream(file))); if (verifier.signatureVerified(cmsParser)) { transcripts.put(stepNumber, file); } else { nodeContext.getEventNotifier().notify(EventNotifier.Level.ERROR, "Signature check failed: " + file.getPath()); } cmsParser.close(); } catch (Exception e) { nodeContext.getEventNotifier().notify(EventNotifier.Level.ERROR, "Signature check failed on " + file.getPath() + ": " + e.getMessage(), e); } } return transcripts; }