use of com.helger.as2lib.crypto.ICryptoHelper in project as2-lib by phax.
the class ReadMDNFuncTest method testReadMDN02.
@Test
public void testReadMDN02() throws Exception {
String sPrefix = "mdn/4af6f84c-d882-4466-8e0c-305a7fbe37b3";
sPrefix = "mdn/20190925-david";
final IReadableResource aHeaderRes = new ClassPathResource(sPrefix + ".header");
assertTrue(aHeaderRes.exists());
final IReadableResource aPayloadRes = new ClassPathResource(sPrefix + ".payload");
assertTrue(aPayloadRes.exists());
final IReadableResource aCertRes = new ClassPathResource(sPrefix + ".pem");
assertTrue(aCertRes.exists());
final HttpHeaderMap aHeaders = new HttpHeaderMap();
try (NonBlockingBufferedReader aBR = new NonBlockingBufferedReader(aHeaderRes.getReader(StandardCharsets.ISO_8859_1))) {
String s;
while ((s = aBR.readLine()) != null) {
final int i = s.indexOf(':');
final String sName = s.substring(0, i).trim();
final String sValue = s.substring(i + 1).trim();
aHeaders.addHeader(sName, sValue);
}
}
if (false)
assertEquals("<MOKOsi42435716cf621589dnode1POP000046@sfgt1.unix.fina.hr>", aHeaders.getFirstHeaderValue("Message-ID"));
final X509Certificate aCert = CertificateHelper.convertStringToCertficateOrNull(StreamHelper.getAllBytesAsString(aCertRes, StandardCharsets.ISO_8859_1));
assertNotNull(aCert);
final AS2Message aMsg = new AS2Message();
// Create a MessageMDN and copy HTTP headers
final IMessageMDN aMDN = new AS2MessageMDN(aMsg);
aMDN.headers().addAllHeaders(aHeaders);
final MimeBodyPart aPart = new MimeBodyPart(AS2HttpHelper.getAsInternetHeaders(aMDN.headers()), StreamHelper.getAllBytes(aPayloadRes));
assertNotNull(aPart);
aMsg.getMDN().setData(aPart);
final ICryptoHelper aCryptoHelper = AS2Helper.getCryptoHelper();
assertTrue(aCryptoHelper.isSigned(aPart));
assertFalse(aCryptoHelper.isEncrypted(aPart));
assertFalse(aCryptoHelper.isCompressed(aPart.getContentType()));
final Consumer<X509Certificate> aCertHolder = null;
try (final AS2ResourceHelper aResHelper = new AS2ResourceHelper()) {
AS2Helper.parseMDN(aMsg, aCert, true, aCertHolder, aResHelper);
fail();
} catch (final CertificateExpiredException ex) {
// expected to fail
if (false)
ex.printStackTrace();
}
}
Aggregations