Search in sources :

Example 1 with Handshakers

use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.

the class AltsTsiTest method verifyHandshakePeer.

@Test
public void verifyHandshakePeer() throws Exception {
    Handshakers handshakers = newHandshakers();
    TsiTest.performHandshake(TsiTest.getDefaultTransportBufferSize(), handshakers);
    TsiPeer clientPeer = handshakers.getClient().extractPeer();
    assertEquals(1, clientPeer.getProperties().size());
    assertEquals(MockAltsHandshakerResp.getTestPeerAccount(), clientPeer.getProperty("service_account").getValue());
    TsiPeer serverPeer = handshakers.getServer().extractPeer();
    assertEquals(1, serverPeer.getProperties().size());
    assertEquals(MockAltsHandshakerResp.getTestPeerAccount(), serverPeer.getProperty("service_account").getValue());
}
Also used : Handshakers(io.grpc.alts.internal.TsiTest.Handshakers) Test(org.junit.Test)

Example 2 with Handshakers

use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.

the class AltsTsiTest method newHandshakers.

private Handshakers newHandshakers() {
    NoopChannelLogger channelLogger = new NoopChannelLogger();
    TsiHandshaker clientHandshaker = new AltsTsiHandshaker(true, client, channelLogger);
    TsiHandshaker serverHandshaker = new AltsTsiHandshaker(false, server, channelLogger);
    return new Handshakers(clientHandshaker, serverHandshaker);
}
Also used : NoopChannelLogger(io.grpc.internal.TestUtils.NoopChannelLogger) Handshakers(io.grpc.alts.internal.TsiTest.Handshakers)

Example 3 with Handshakers

use of io.grpc.alts.internal.TsiTest.Handshakers in project grpc-java by grpc.

the class FakeTsiTest method handshakeStateOrderTest.

@Test
public void handshakeStateOrderTest() {
    try {
        Handshakers handshakers = newHandshakers();
        TsiHandshaker clientHandshaker = handshakers.getClient();
        TsiHandshaker serverHandshaker = handshakers.getServer();
        byte[] transportBufferBytes = new byte[TsiTest.getDefaultTransportBufferSize()];
        ByteBuffer transportBuffer = ByteBuffer.wrap(transportBufferBytes);
        // Start off with an empty buffer
        ((Buffer) transportBuffer).limit(0);
        ((Buffer) transportBuffer).clear();
        clientHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertEquals(FakeTsiHandshaker.State.CLIENT_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
        serverHandshaker.processBytesFromPeer(transportBuffer);
        assertFalse(transportBuffer.hasRemaining());
        // client shouldn't offer any more bytes
        ((Buffer) transportBuffer).clear();
        clientHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertFalse(transportBuffer.hasRemaining());
        ((Buffer) transportBuffer).clear();
        serverHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertEquals(FakeTsiHandshaker.State.SERVER_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
        clientHandshaker.processBytesFromPeer(transportBuffer);
        assertFalse(transportBuffer.hasRemaining());
        // server shouldn't offer any more bytes
        ((Buffer) transportBuffer).clear();
        serverHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertFalse(transportBuffer.hasRemaining());
        ((Buffer) transportBuffer).clear();
        clientHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertEquals(FakeTsiHandshaker.State.CLIENT_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
        serverHandshaker.processBytesFromPeer(transportBuffer);
        assertFalse(transportBuffer.hasRemaining());
        // client shouldn't offer any more bytes
        ((Buffer) transportBuffer).clear();
        clientHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertFalse(transportBuffer.hasRemaining());
        ((Buffer) transportBuffer).clear();
        serverHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertEquals(FakeTsiHandshaker.State.SERVER_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim());
        clientHandshaker.processBytesFromPeer(transportBuffer);
        assertFalse(transportBuffer.hasRemaining());
        // server shouldn't offer any more bytes
        ((Buffer) transportBuffer).clear();
        serverHandshaker.getBytesToSendToPeer(transportBuffer);
        ((Buffer) transportBuffer).flip();
        assertFalse(transportBuffer.hasRemaining());
    } catch (GeneralSecurityException e) {
        throw new AssertionError(e);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(java.nio.Buffer) GeneralSecurityException(java.security.GeneralSecurityException) Handshakers(io.grpc.alts.internal.TsiTest.Handshakers) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Handshakers (io.grpc.alts.internal.TsiTest.Handshakers)3 Test (org.junit.Test)2 NoopChannelLogger (io.grpc.internal.TestUtils.NoopChannelLogger)1 Buffer (java.nio.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 GeneralSecurityException (java.security.GeneralSecurityException)1