本文整理汇总了Java中javax.net.ssl.SSLEngine.getUseClientMode方法的典型用法代码示例。如果您正苦于以下问题:Java SSLEngine.getUseClientMode方法的具体用法?Java SSLEngine.getUseClientMode怎么用?Java SSLEngine.getUseClientMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLEngine
的用法示例。
在下文中一共展示了SSLEngine.getUseClientMode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkBufferOverflowOnWrap
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
private void checkBufferOverflowOnWrap(SSLEngine engine)
throws SSLException {
String mode = engine.getUseClientMode() ? "client"
: "server";
System.out.println("================================================="
+ "===========");
System.out.println("Testing SSLEngine buffer overflow"
+ " on wrap by " + mode);
ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
//Making net buffer size less than required by 1 byte.
ByteBuffer net = ByteBuffer
.allocate(engine.getSession().getPacketBufferSize() - 1);
SSLEngineResult r = engine.wrap(app, net);
checkResult(r, SSLEngineResult.Status.BUFFER_OVERFLOW);
System.out.println("Passed");
}
示例2: checkBufferOverflowOnUnWrap
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
private void checkBufferOverflowOnUnWrap(SSLEngine wrappingEngine,
SSLEngine unwrappingEngine)
throws SSLException {
String wrapperMode = wrappingEngine.getUseClientMode() ? "client"
: "server";
String unwrapperMode = unwrappingEngine.getUseClientMode() ? "client"
: "server";
if (wrapperMode.equals(unwrapperMode)) {
throw new Error("Test error: both engines are in the same mode!");
}
System.out.println("================================================="
+ "===========");
System.out.println("Testing SSLEngine buffer overflow"
+ " on unwrap by " + unwrapperMode);
ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
ByteBuffer net = ByteBuffer
.allocate(wrappingEngine.getSession().getPacketBufferSize());
SSLEngineResult r = wrappingEngine.wrap(app, net);
checkResult(r, SSLEngineResult.Status.OK);
//Making app buffer size less than required by 1 byte.
app = ByteBuffer.allocate(MESSAGE.length() - 1);
net.flip();
r = unwrappingEngine.unwrap(net, app);
checkResult(r, SSLEngineResult.Status.BUFFER_OVERFLOW);
System.out.println("Passed");
}
示例3: produceHandshakePackets
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
@Override
boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
String side, List<DatagramPacket> packets) throws Exception {
boolean finished = super.produceHandshakePackets(
engine, socketAddr, side, packets);
if (needPacketDuplicate && (!(isClient ^ engine.getUseClientMode()))) {
DatagramPacket packet = getPacket(packets, handshakeType);
if (packet != null) {
needPacketDuplicate = false;
System.out.println("Duplicate the flight.");
List<DatagramPacket> duplicates = new ArrayList<>();
finished = super.produceHandshakePackets(
engine, socketAddr, side, duplicates);
packets.addAll(duplicates);
}
}
return finished;
}
示例4: produceHandshakePackets
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
@Override
boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
String side, List<DatagramPacket> packets) throws Exception {
boolean finished = super.produceHandshakePackets(
engine, socketAddr, side, packets);
if (needPacketLoss && (!(isClient ^ engine.getUseClientMode()))) {
DatagramPacket packet = getPacket(packets, handshakeType);
if (packet != null) {
needPacketLoss = false;
System.out.println("Loss a packet of handshake messahe");
packets.remove(packet);
}
}
return finished;
}
示例5: checkIncorrectAppDataUnwrap
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
private void checkIncorrectAppDataUnwrap(SSLEngine sendEngine,
SSLEngine recvEngine) throws SSLException {
String direction = sendEngine.getUseClientMode() ? "client"
: "server";
System.out.println("================================================="
+ "===========");
System.out.println("Testing DTLS incorrect app data packages unwrapping"
+ " by sending data from " + direction);
ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
ByteBuffer net = doWrap(sendEngine, direction, 0, app);
final Random RNG = RandomFactory.getRandom();
int randomPlace = RNG.nextInt(net.remaining());
net.array()[randomPlace] += 1;
app = ByteBuffer.allocate(recvEngine.getSession()
.getApplicationBufferSize());
recvEngine.unwrap(net, app);
app.flip();
int length = app.remaining();
System.out.println("Unwrapped " + length + " bytes.");
}
示例6: checkBufferUnderflowOnUnWrap
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
private void checkBufferUnderflowOnUnWrap(SSLEngine wrappingEngine,
SSLEngine unwrappingEngine)
throws SSLException {
String wrapperMode = wrappingEngine.getUseClientMode() ? "client"
: "server";
String unwrapperMode = unwrappingEngine.getUseClientMode() ? "client"
: "server";
if (wrapperMode.equals(unwrapperMode)) {
throw new Error("Test error: both engines are in the same mode!");
}
System.out.println("================================================="
+ "===========");
System.out.println("Testing SSLEngine buffer underflow"
+ " on unwrap by " + unwrapperMode);
ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
ByteBuffer net = ByteBuffer
.allocate(wrappingEngine.getSession().getPacketBufferSize());
SSLEngineResult r = wrappingEngine.wrap(app, net);
checkResult(r, SSLEngineResult.Status.OK);
app = ByteBuffer.allocate(unwrappingEngine.getSession()
.getApplicationBufferSize());
net.flip();
//Making net buffer size less than size of dtls message.
net.limit(net.limit() - 1);
r = unwrappingEngine.unwrap(net, app);
checkResult(r, SSLEngineResult.Status.BUFFER_UNDERFLOW);
System.out.println("Passed");
}
示例7: produceHandshakePackets
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
@Override
boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
String side, List<DatagramPacket> packets) throws Exception {
boolean finished = super.produceHandshakePackets(
engine, socketAddr, side, packets);
if (needPacketReorder && (!engine.getUseClientMode())) {
needPacketReorder = false;
Collections.reverse(packets);
}
return finished;
}
示例8: produceHandshakePackets
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
@Override
boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
String side, List<DatagramPacket> packets) throws Exception {
boolean finished = super.produceHandshakePackets(
engine, socketAddr, side, packets);
if (!needPacketLoss || (!engine.getUseClientMode())) {
return finished;
}
List<DatagramPacket> parts = new ArrayList<>();
int lostSeq = 2;
for (DatagramPacket packet : packets) {
lostSeq--;
if (lostSeq == 0) {
needPacketLoss = false;
// loss this packet
System.out.println("Loss a packet");
continue;
}
parts.add(packet);
}
packets.clear();
packets.addAll(parts);
return finished;
}
示例9: sendApplicationData
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
/**
* Routine to send application data from one SSLEngine to another.
*
* @param fromEngine - Sending engine.
* @param toEngine - Receiving engine.
* @return - Result of unwrap method of the receiving engine.
* @throws SSLException - thrown on engine errors.
*/
public static SSLEngineResult sendApplicationData(SSLEngine fromEngine,
SSLEngine toEngine)
throws SSLException {
String sender = null;
String reciever = null;
String excMsgSent = EXCHANGE_MSG_SENT;
if (fromEngine.getUseClientMode() && !toEngine.getUseClientMode()) {
sender = "Client";
reciever = "Server";
excMsgSent += " Client.";
} else if (toEngine.getUseClientMode() &&
!fromEngine.getUseClientMode()) {
sender = "Server";
reciever = "Client";
excMsgSent += " Server.";
} else {
throw new Error("Test issue: both engines are in the same mode");
}
System.out.println("=============================================");
System.out.println("Trying to send application data from " + sender
+ " to " + reciever);
ByteBuffer clientAppSent
= ByteBuffer.wrap(excMsgSent.getBytes());
net = doWrap(fromEngine, sender, 0, clientAppSent);
SSLEngineResult[] r = new SSLEngineResult[1];
ByteBuffer serverAppRecv = doUnWrap(toEngine, reciever, net, r);
byte[] serverAppRecvTrunc = Arrays.copyOf(serverAppRecv.array(),
serverAppRecv.limit());
String msgRecv = new String(serverAppRecvTrunc);
if (!msgRecv.equals(excMsgSent)) {
throw new AssertionError(sender + " to " + reciever
+ ": application data"
+ " has been altered while sending."
+ " Message sent: " + "\"" + excMsgSent + "\"."
+ " Message recieved: " + "\"" + msgRecv + "\".");
}
System.out.println("Successful sending application data from " + sender
+ " to " + reciever);
return r[0];
}
示例10: closeEngines
import javax.net.ssl.SSLEngine; //导入方法依赖的package包/类
/**
* Close engines by sending "close outbound" message from one SSLEngine to
* another.
*
* @param fromEngine - Sending engine.
* @param toEngine - Receiving engine.
* @throws SSLException - thrown on engine errors.
*/
public static void closeEngines(SSLEngine fromEngine,
SSLEngine toEngine) throws SSLException {
String from = null;
String to = null;
ByteBuffer app;
if (fromEngine.getUseClientMode() && !toEngine.getUseClientMode()) {
from = "Client";
to = "Server";
} else if (toEngine.getUseClientMode() &&
!fromEngine.getUseClientMode()) {
from = "Server";
to = "Client";
} else {
throw new Error("Both engines are in the same mode");
}
System.out.println("=============================================");
System.out.println(
"Trying to close engines from " + from + " to " + to);
// Sending close outbound request to peer
fromEngine.closeOutbound();
app = ByteBuffer.allocate(
fromEngine.getSession().getApplicationBufferSize());
net = doWrap(fromEngine, from, 0, app, SSLEngineResult.Status.CLOSED);
doUnWrap(toEngine, to, net, SSLEngineResult.Status.CLOSED);
app = ByteBuffer.allocate(
fromEngine.getSession().getApplicationBufferSize());
net = doWrap(toEngine, to, 0, app, SSLEngineResult.Status.CLOSED);
doUnWrap(fromEngine, from, net, SSLEngineResult.Status.CLOSED);
if (!toEngine.isInboundDone()) {
throw new AssertionError(from + " sent close request to " + to
+ ", but " + to + "did not close inbound.");
}
// Executing close inbound
fromEngine.closeInbound();
app = ByteBuffer.allocate(
fromEngine.getSession().getApplicationBufferSize());
net = doWrap(fromEngine, from, 0, app, SSLEngineResult.Status.CLOSED);
doUnWrap(toEngine, to, net, SSLEngineResult.Status.CLOSED);
if (!toEngine.isOutboundDone()) {
throw new AssertionError(from + "sent close request to " + to
+ ", but " + to + "did not close outbound.");
}
System.out.println("Successful closing from " + from + " to " + to);
}