public boolean verify(PublicKey publicKey) throws Exception { SMIMESigned signed = new SMIMESigned(body); SignerInformationStore signers = signed.getSignerInfos(); SignerInformation signer = (SignerInformation) signers.getSigners().iterator().next(); return (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(publicKey))); }
SMIMESigned signed; if (obj instanceof MimeMultipart) { signed = new SMIMESigned((MimeMultipart) message.getContent()); } else if (obj instanceof SMIMESigned) { signed = (SMIMESigned) obj; } else if (obj instanceof byte[]) { signed = new SMIMESigned(message); } else { signed = null;
private SignedMessage(MimeMessage message) throws IOException, OxalisAs2Exception { try { // Verify content type if (!message.isMimeType("multipart/signed")) throw new OxalisAs2Exception("Received content is not 'multipart/signed'."); micalg = extractMicalg(message); // Extract headers //noinspection unchecked // headers = Collections.list((Enumeration<Header>) message.getAllHeaders()); // Create MimeMultitype mimeMultipart = (MimeMultipart) message.getContent(); // Extracting signature signature = ByteStreams.toByteArray(mimeMultipart.getBodyPart(1).getInputStream()); // Create signed message smimeSigned = new SMIMESigned(mimeMultipart); } catch (CMSException | MessagingException e) { throw new OxalisAs2Exception("Unable to parse received content.", e); } }
private SignedMessage(MimeMessage message) throws IOException, OxalisAs2Exception { try { // Verify content type if (!message.isMimeType("multipart/signed")) throw new OxalisAs2Exception("Received content is not 'multipart/signed'."); micalg = extractMicalg(message); // Extract headers //noinspection unchecked // headers = Collections.list((Enumeration<Header>) message.getAllHeaders()); // Create MimeMultitype mimeMultipart = (MimeMultipart) message.getContent(); // Extracting signature signature = ByteStreams.toByteArray(mimeMultipart.getBodyPart(1).getInputStream()); // Create signed message smimeSigned = new SMIMESigned(mimeMultipart); } catch (CMSException | MessagingException e) { throw new OxalisAs2Exception("Unable to parse received content.", e); } }
/** * Get the internal SMIMESigned message * * @return the SMIMESigned message instance * @throws PackageException */ public SMIMESigned getSMIMESignedMessage() throws PackageException { if (smimeSignedMessage == null && message != null) { // smimeSignedMessage is not 'null' if the message is signed and already decrypted final String notASignedMessage = "The Content-Type is '" + CONTENT_TYPE_MULTIPART_SIGNED + "' but could not create SMIMESigned message"; try { if (message.isMimeType(CONTENT_TYPE_MULTIPART_SIGNED)) { smimeSignedMessage = new SMIMESigned((MimeMultipart) message.getContent()); } } catch (MessagingException me) { throw new PackageException("Could not get message details", me); } catch (CMSException e) { throw new PackageException(notASignedMessage, e); } catch (IOException e) { throw new PackageException(notASignedMessage, e); } } return smimeSignedMessage; }
SMIMESigned signedPart = new SMIMESigned(mainParts);
.contains(CONTENT_TYPE_MULTIPART_SIGNED)) { signedMessage = new SMIMESigned(multipartContent); } else if (content instanceof BASE64DecoderStream) { signedMessage = new SMIMESigned(decryptedMsg); // will throw exception if not signed