use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody in project qpid-broker-j by apache.
the class ConnectionTest method connectionSecureWithChallengeResponse.
@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecureWithChallengeResponse() throws Exception {
assumeThat(getBrokerAdmin().isSASLMechanismSupported(CRAM_MD5), is(true));
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
final Interaction interaction = transport.newInteraction();
final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(CRAM_MD5));
final ConnectionSecureBody secure = interaction.connection().startOkMechanism(CRAM_MD5).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
byte[] response = generateCramMD5ClientResponse(getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword(), secure.getChallenge());
final ConnectionTuneBody tune = interaction.connection().secureOk(response).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody in project qpid-broker-j by apache.
the class ConnectionTest method connectionSecure.
@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecure() throws Exception {
assumeThat(getBrokerAdmin().isSASLMechanismSupported(PLAIN), is(true));
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
final byte[] initialResponse = String.format("\0%s\0%s", getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword()).getBytes(StandardCharsets.US_ASCII);
final Interaction interaction = transport.newInteraction();
final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(PLAIN));
final ConnectionSecureBody secure = interaction.connection().startOkMechanism(PLAIN).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
assertThat(secure.getChallenge(), is(anyOf(nullValue(), equalTo(new byte[0]))));
final ConnectionTuneBody tune = interaction.connection().secureOk(initialResponse).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
}
}
Aggregations