use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class BCCryptoHelperTest method testSign_QuotedPrintable.
@Test
public void testSign_QuotedPrintable() throws Exception {
final MimeBodyPart aPart = new MimeBodyPart();
aPart.setText("Hello world", StandardCharsets.ISO_8859_1.name());
final MimeBodyPart aSigned = AS2Helper.getCryptoHelper().sign(aPart, (X509Certificate) PKE.getCertificate(), PKE.getPrivateKey(), ECryptoAlgorithmSign.DIGEST_SHA_256, false, false, false, EContentTransferEncoding.QUOTED_PRINTABLE);
assertNotNull(aSigned);
final String sBoundary = AS2HttpHelper.parseContentType(aSigned.getContentType()).getParameter("boundary");
assertNotNull(sBoundary);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
aSigned.writeTo(aBAOS);
final String sExpectedStart = "Content-Type: multipart/signed; protocol=\"application/pkcs7-signature\"; micalg=sha-256; \r\n" + "\tboundary=\"" + sBoundary + "\"\r\n" + "\r\n" + "--" + sBoundary + "\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Hello world\r\n" + "--" + sBoundary + "\r\n" + "Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Disposition: attachment; filename=\"smime.p7s\"\r\n" + "Content-Description: S/MIME Cryptographic Signature\r\n" + "\r\n" + "0=80=06=09*=86H=86=F7\r\n" + "=01=07=02=A0=800=80=02=01=011\r\n" + "0=0B=06=09`=86H=01e=03=04=02=010=80=06=09*=86H=86=F7\r\n" + "=01=07=01=00=001=82=02=A40=82=02=A0=02=01=010=81=C30=81=BA1#0!=06=09*=86H=\r\n" + "=86=F7\r\n" + "=01=09=01=16=14service@mendelson.de1=0B0=09=06=03U=04=06=13=02DE1=0F0\r\n" + "=06=03U=04=08=0C=06Berlin1=0F0\r\n" + "=06=03U=04=07=0C=06Berlin1\"0 =06=03U=04\r\n" + "=0C=19mendelson-e-commerce GmbH1!0=1F=06=03U=04=0B=0C=18Do not use in produ=\r\n" + "ction1=1D0=1B=06=03U=04=03=0C=14mendelson test key 3=02=04Z*[=1C0=0B=06=09`=\r\n" + "=86H=01e=03=04=02=01=A0=81=B40=18=06=09*=86H=86=F7\r\n" + "=01=09=031=0B=06=09*=86H=86=F7\r\n" + "=01=07=010=1C=06=09*=86H=86=F7\r\n" + "=01=09=051=0F=17\r\n";
final String sExpectedEnd = "\r\n" + "--" + sBoundary + "--\r\n";
final String sReal = aBAOS.getAsString(StandardCharsets.ISO_8859_1);
// assertEquals (sReal, sExpectedStart);
assertTrue(sReal.startsWith(sExpectedStart));
assertTrue(sReal.endsWith(sExpectedEnd));
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class BCCryptoHelperTest method testSign_Base64.
@Test
public void testSign_Base64() throws Exception {
final MimeBodyPart aPart = new MimeBodyPart();
aPart.setText("Hello world", StandardCharsets.ISO_8859_1.name());
final MimeBodyPart aSigned = AS2Helper.getCryptoHelper().sign(aPart, (X509Certificate) PKE.getCertificate(), PKE.getPrivateKey(), ECryptoAlgorithmSign.DIGEST_SHA_256, false, false, false, EContentTransferEncoding.BASE64);
assertNotNull(aSigned);
final String sBoundary = AS2HttpHelper.parseContentType(aSigned.getContentType()).getParameter("boundary");
assertNotNull(sBoundary);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
aSigned.writeTo(aBAOS);
final String sExpectedStart = "Content-Type: multipart/signed; protocol=\"application/pkcs7-signature\"; micalg=sha-256; \r\n" + "\tboundary=\"" + sBoundary + "\"\r\n" + "\r\n" + "--" + sBoundary + "\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Hello world\r\n" + "--" + sBoundary + "\r\n" + "Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-Disposition: attachment; filename=\"smime.p7s\"\r\n" + "Content-Description: S/MIME Cryptographic Signature\r\n" + "\r\n" + "MIAGCSqGSIb3DQEHAqCAMIACAQExDTALBglghkgBZQMEAgEwgAYJKoZIhvcNAQcBAAAxggKkMIIC\r\n" + "oAIBATCBwzCBujEjMCEGCSqGSIb3DQEJARYUc2VydmljZUBtZW5kZWxzb24uZGUxCzAJBgNVBAYT\r\n" + "AkRFMQ8wDQYDVQQIDAZCZXJsaW4xDzANBgNVBAcMBkJlcmxpbjEiMCAGA1UECgwZbWVuZGVsc29u\r\n" + "LWUtY29tbWVyY2UgR21iSDEhMB8GA1UECwwYRG8gbm90IHVzZSBpbiBwcm9kdWN0aW9uMR0wGwYD\r\n" + "VQQDDBRtZW5kZWxzb24gdGVzdCBrZXkgMwIEWipbHDALBglghkgBZQMEAgGggbQwGAYJKoZIhvcN\r\n";
final String sExpectedEnd = "\r\n" + "--" + sBoundary + "--\r\n";
final String sReal = aBAOS.getAsString(StandardCharsets.ISO_8859_1);
assertTrue(sReal.startsWith(sExpectedStart));
assertTrue(sReal.endsWith(sExpectedEnd));
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class BCCryptoHelperTest method testEncryptCTE_QuotedPrintable.
@Test
public void testEncryptCTE_QuotedPrintable() throws Exception {
final MimeBodyPart aPart = new MimeBodyPart();
aPart.setText("Hello world");
final MimeBodyPart aEncrypted = AS2Helper.getCryptoHelper().encrypt(aPart, CERT_ENCRYPT, ECryptoAlgorithmCrypt.CRYPT_3DES, EContentTransferEncoding.QUOTED_PRINTABLE);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
aEncrypted.writeTo(aBAOS);
final String sExpectedStart = "Content-Type: application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Disposition: attachment; filename=\"smime.p7m\"\r\n" + "Content-Description: S/MIME Encrypted Message\r\n" + "\r\n" + "0=80=06=09*=86H=86=F7\r\n" + "=01=07=03=A0=800=80=02=01=001=82=01=E00=82=01=DC=02=01=000=81=C30=81=BA1#0!=\r\n" + "=06=09*=86H=86=F7\r\n" + "=01=09=01=16=14service@mendelson.de1=0B0=09=06=03U=04=06=13=02DE1=0F0\r\n" + "=06=03U=04=08=0C=06Berlin1=0F0\r\n" + "=06=03U=04=07=0C=06Berlin1\"0 =06=03U=04\r\n" + "=0C=19mendelson-e-commerce GmbH1!0=1F=06=03U=04=0B=0C=18Do not use in produ=\r\n" + "ction1=1D0=1B=06=03U=04=03=0C=14mendelson test key 4=02=04Z*[=C80\r\n" + "=06=09*=86H=86=F7\r\n";
final String sReal = aBAOS.getAsString(StandardCharsets.ISO_8859_1);
// assertEquals (sReal, sExpectedStart);
assertTrue(sReal.startsWith(sExpectedStart));
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class BCCryptoHelperTest method testEncryptCTE_Binary.
@Test
public void testEncryptCTE_Binary() throws Exception {
final MimeBodyPart aPart = new MimeBodyPart();
aPart.setText("Hello world");
final MimeBodyPart aEncrypted = AS2Helper.getCryptoHelper().encrypt(aPart, CERT_ENCRYPT, ECryptoAlgorithmCrypt.CRYPT_3DES, EContentTransferEncoding.BINARY);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
aEncrypted.writeTo(aBAOS);
final String sExpectedStart = "Content-Type: application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-Disposition: attachment; filename=\"smime.p7m\"\r\n" + "Content-Description: S/MIME Encrypted Message\r\n" + "\r\n";
final String sReal = aBAOS.getAsString(StandardCharsets.ISO_8859_1);
assertTrue(sReal.startsWith(sExpectedStart));
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class HTTPHelper method sendSimpleHTTPResponse.
/**
* Send a simple HTTP response that only contains the HTTP status code and the
* respective descriptive text. An empty header map us used.
*
* @param aResponseHandler
* The response handler to be used.
* @param nResponseCode
* The HTTP response code to use.
* @throws IOException
* In case sending fails for whatever reason
*/
public static void sendSimpleHTTPResponse(@Nonnull final IAS2HttpResponseHandler aResponseHandler, @Nonnegative final int nResponseCode) throws IOException {
try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream()) {
final String sHTTPLine = Integer.toString(nResponseCode) + " " + CHttp.getHttpResponseMessage(nResponseCode) + CHttp.EOL;
aData.write(sHTTPLine.getBytes(CHttp.HTTP_CHARSET));
aResponseHandler.sendHttpResponse(nResponseCode, new HttpHeaderMap(), aData);
}
}
Aggregations