Esempio n. 1
0
  protected void decompress(@Nonnull final IMessage aMsg) throws DispositionException {
    try {
      if (aMsg.getPartnership().isDisableDecompress()) {
        s_aLogger.info(
            "Message claims to be compressed but decompression is disabled"
                + aMsg.getLoggingText());
      } else {
        if (s_aLogger.isDebugEnabled()) s_aLogger.debug("Decompressing a compressed AS2 message");

        final SMIMECompressed aCompressed = new SMIMECompressed(aMsg.getData());
        // decompression step MimeBodyPart
        final MimeBodyPart aDecompressedPart =
            SMIMEUtil.toMimeBodyPart(aCompressed.getContent(new ZlibExpanderProvider()));
        // Update the message object
        aMsg.setData(aDecompressedPart);
        // Remember that message was decompressed
        aMsg.setAttribute(AS2Message.ATTRIBUTE_RECEIVED_COMPRESSED, Boolean.TRUE.toString());
        s_aLogger.info("Successfully decompressed incoming AS2 message" + aMsg.getLoggingText());
      }
    } catch (final Exception ex) {
      s_aLogger.error("Error decompressing received message", ex);
      throw new DispositionException(
          DispositionType.createError("unexpected-processing-error"),
          AbstractActiveNetModule.DISP_DECOMPRESSION_ERROR,
          ex);
    }
  }
Esempio n. 2
0
  public void testBasic() throws Exception {
    SMIMECompressedGenerator cgen = new SMIMECompressedGenerator();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    MimeBodyPart cbp = cgen.generate(msg, new ZlibCompressor());

    SMIMECompressed sc = new SMIMECompressed(cbp);

    msg.writeTo(bOut);

    assertTrue(Arrays.areEqual(bOut.toByteArray(), sc.getContent(new ZlibExpanderProvider())));
  }
Esempio n. 3
0
  /*
   * test compressing and uncompressing of a multipart-signed message.
   */
  public void testCompressedSHA1WithRSA() throws Exception {
    List certList = new ArrayList();

    certList.add(origCert);
    certList.add(signCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    caps.addCapability(SMIMECapability.dES_CBC);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider("BC")
            .setSignedAttributeGenerator(new AttributeTable(signedAttrs))
            .build("SHA1withRSA", origKP.getPrivate(), origCert));

    gen.addCertificates(certs);

    MimeMultipart smp = gen.generate(msg);

    MimeMessage bp2 = new MimeMessage((Session) null);

    bp2.setContent(smp);

    bp2.saveChanges();

    SMIMECompressedGenerator cgen = new SMIMECompressedGenerator();

    MimeBodyPart cbp = cgen.generate(bp2, new ZlibCompressor());

    SMIMECompressed cm = new SMIMECompressed(cbp);

    MimeMultipart mm =
        (MimeMultipart)
            SMIMEUtil.toMimeBodyPart(cm.getContent(new ZlibExpanderProvider())).getContent();

    SMIMESigned s = new SMIMESigned(mm);

    ByteArrayOutputStream _baos = new ByteArrayOutputStream();
    msg.writeTo(_baos);
    _baos.close();
    byte[] _msgBytes = _baos.toByteArray();
    _baos = new ByteArrayOutputStream();
    s.getContent().writeTo(_baos);
    _baos.close();
    byte[] _resBytes = _baos.toByteArray();

    assertEquals(true, Arrays.areEqual(_msgBytes, _resBytes));

    certs = s.getCertificates();

    SignerInformationStore signers = s.getSignerInfos();
    Collection c = signers.getSigners();
    Iterator it = c.iterator();

    while (it.hasNext()) {
      SignerInformation signer = (SignerInformation) it.next();
      Collection certCollection = certs.getMatches(signer.getSID());

      Iterator certIt = certCollection.iterator();
      X509CertificateHolder cert = (X509CertificateHolder) certIt.next();

      assertEquals(
          true,
          signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)));
    }
  }