Search in sources :

Example 1 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class PGPDataFormatTest method readSecretKey.

static PGPSecretKey readSecretKey() throws Exception {
    InputStream input = new ByteArrayInputStream(getSecKeyRing());
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input), new BcKeyFingerprintCalculator());
    @SuppressWarnings("rawtypes") Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
        @SuppressWarnings("rawtypes") Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext()) {
            PGPSecretKey key = (PGPSecretKey) keyIter.next();
            if (key.isSigningKey()) {
                return key;
            }
        }
    }
    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PGPSecretKey(org.bouncycastle.openpgp.PGPSecretKey) Iterator(java.util.Iterator) PGPSecretKeyRingCollection(org.bouncycastle.openpgp.PGPSecretKeyRingCollection) BcKeyFingerprintCalculator(org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing)

Example 2 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class AbstractPGPDataFormatTest method doRoundTripEncryptionTests.

protected void doRoundTripEncryptionTests(String endpoint) throws Exception {
    MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
    MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
    String payload = "Hi Alice, Be careful Eve is listening, signed Bob";
    Map<String, Object> headers = getHeaders();
    template.sendBodyAndHeaders(endpoint, payload, headers);
    template.sendBodyAndHeaders(endpoint, payload.getBytes(), headers);
    template.sendBodyAndHeaders(endpoint, new ByteArrayInputStream(payload.getBytes()), headers);
    assertMocksSatisfied(encrypted, unencrypted, payload);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class CryptoDataFormatTest method doRoundTripEncryptionTests.

private void doRoundTripEncryptionTests(String endpoint, Map<String, Object> headers) throws Exception {
    MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
    MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
    String payload = "Hi Alice, Be careful Eve is listening, signed Bob";
    template.sendBodyAndHeaders(endpoint, payload, headers);
    template.sendBodyAndHeaders(endpoint, payload.getBytes(), headers);
    template.sendBodyAndHeaders(endpoint, new ByteArrayInputStream(payload.getBytes()), headers);
    assertMocksSatisfied(encrypted, unencrypted, payload);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 4 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class DefaultCxfMessageMapperTest method setupCamelExchange.

private Exchange setupCamelExchange(String requestURI, String requestPath, HttpServletRequest request) {
    org.apache.camel.Message camelMessage = EasyMock.createMock(org.apache.camel.Message.class);
    Exchange camelExchange = EasyMock.createMock(Exchange.class);
    camelExchange.getProperty(CamelTransportConstants.CXF_EXCHANGE, org.apache.cxf.message.Exchange.class);
    EasyMock.expectLastCall().andReturn(new ExchangeImpl());
    camelExchange.hasOut();
    EasyMock.expectLastCall().andReturn(false);
    camelExchange.getIn();
    EasyMock.expectLastCall().andReturn(camelMessage).times(3);
    camelMessage.getHeaders();
    EasyMock.expectLastCall().andReturn(Collections.emptyMap()).times(2);
    camelMessage.getHeader(Exchange.CONTENT_TYPE, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader("Accept", String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.CHARSET_NAME, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.HTTP_URI, String.class);
    EasyMock.expectLastCall().andReturn(requestURI);
    camelMessage.getHeader(Exchange.HTTP_PATH, String.class);
    EasyMock.expectLastCall().andReturn(requestPath);
    camelMessage.getHeader(Exchange.HTTP_BASE_URI, String.class);
    EasyMock.expectLastCall().andReturn(requestPath);
    camelMessage.getHeader(Exchange.HTTP_METHOD, String.class);
    EasyMock.expectLastCall().andReturn("GET");
    camelMessage.getHeader(Exchange.HTTP_QUERY, String.class);
    EasyMock.expectLastCall().andReturn("");
    camelMessage.getHeader(Exchange.HTTP_SERVLET_REQUEST);
    EasyMock.expectLastCall().andReturn(request);
    camelMessage.getHeader(Exchange.HTTP_SERVLET_RESPONSE);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getBody(InputStream.class);
    EasyMock.expectLastCall().andReturn(new ByteArrayInputStream("".getBytes()));
    EasyMock.replay(camelExchange, camelMessage);
    return camelExchange;
}
Also used : Exchange(org.apache.camel.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 5 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class PGPDataFormatTest method createSignature.

private void createSignature(OutputStream out) throws Exception {
    PGPSecretKey pgpSec = readSecretKey();
    PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build("sdude".toCharArray()));
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(getProvider()));
    sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
    BCPGOutputStream bOut = new BCPGOutputStream(out);
    InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));
    int ch;
    while ((ch = fIn.read()) >= 0) {
        sGen.update((byte) ch);
    }
    fIn.close();
    sGen.generate().encode(bOut);
}
Also used : PGPSignatureGenerator(org.bouncycastle.openpgp.PGPSignatureGenerator) JcaPGPContentSignerBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PGPSecretKey(org.bouncycastle.openpgp.PGPSecretKey) BCPGOutputStream(org.bouncycastle.bcpg.BCPGOutputStream) PGPPrivateKey(org.bouncycastle.openpgp.PGPPrivateKey) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JcePBESecretKeyDecryptorBuilder(org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138