本文整理了Java中javax.net.ssl.SSLEngine.wrap()
方法的一些代码示例,展示了SSLEngine.wrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLEngine.wrap()
方法的具体详情如下:
包路径:javax.net.ssl.SSLEngine
类名称:SSLEngine
方法名:wrap
[英]Encodes the outgoing application data buffer into the network data buffer. If a handshake has not been started yet, it will automatically be started.
[中]将传出的应用程序数据缓冲区编码到网络数据缓冲区中。如果握手尚未开始,它将自动开始。
代码示例来源:origin: TooTallNate/Java-WebSocket
private synchronized ByteBuffer wrap( ByteBuffer b ) throws SSLException {
outCrypt.compact();
writeEngineResult = sslEngine.wrap( b, outCrypt );
outCrypt.flip();
return outCrypt;
}
代码示例来源:origin: TooTallNate/Java-WebSocket
@Override
public synchronized int write( ByteBuffer output ) throws IOException {
int num = 0;
while( output.hasRemaining() ) {
// The loop has a meaning for (outgoing) messages larger than 16KB.
// Every wrap call will remove 16KB from the original message and send it to the remote peer.
myNetData.clear();
SSLEngineResult result = engine.wrap( output, myNetData );
switch(result.getStatus()) {
case OK:
myNetData.flip();
while( myNetData.hasRemaining() ) {
num += socketChannel.write( myNetData );
}
break;
case BUFFER_OVERFLOW:
myNetData = enlargePacketBuffer( myNetData );
break;
case BUFFER_UNDERFLOW:
throw new SSLException( "Buffer underflow occured after a wrap. I don't think we should ever get here." );
case CLOSED:
closeConnection();
return 0;
default:
throw new IllegalStateException( "Invalid SSL status: " + result.getStatus() );
}
}
return num;
}
代码示例来源:origin: apache/nifi
private Status encryptAndWriteFully(final BufferStateManager src) throws IOException {
SSLEngineResult result = null;
final ByteBuffer buff = src.prepareForRead(0);
final ByteBuffer outBuff = streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
logger.trace("{} Encrypting {} bytes", this, buff.remaining());
while (buff.remaining() > 0) {
result = engine.wrap(buff, outBuff);
if (result.getStatus() == Status.OK) {
final ByteBuffer readableOutBuff = streamOutManager.prepareForRead(0);
writeFully(readableOutBuff);
streamOutManager.clear();
} else {
return result.getStatus();
}
}
return result.getStatus();
}
代码示例来源:origin: apache/kafka
/**
* Performs the WRAP function
* @param doWrite boolean
* @return SSLEngineResult
* @throws IOException
*/
private SSLEngineResult handshakeWrap(boolean doWrite) throws IOException {
log.trace("SSLHandshake handshakeWrap {}", channelId);
if (netWriteBuffer.hasRemaining())
throw new IllegalStateException("handshakeWrap called with netWriteBuffer not empty");
//this should never be called with a network buffer that contains data
//so we can clear it here.
netWriteBuffer.clear();
SSLEngineResult result = sslEngine.wrap(emptyBuf, netWriteBuffer);
//prepare the results to be written
netWriteBuffer.flip();
handshakeStatus = result.getHandshakeStatus();
if (result.getStatus() == SSLEngineResult.Status.OK &&
result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
handshakeStatus = runDelegatedTasks();
}
if (doWrite) flush(netWriteBuffer);
return result;
}
代码示例来源:origin: apache/activemq
plain = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
plain.clear();
engine.wrap(data, plain);
plain.flip();
} else {
plain = data;
engine.wrap(data, plain);
plain.flip();
代码示例来源:origin: redisson/redisson
SSLEngineResult result = engine.wrap(in0, out0);
in.skipBytes(result.bytesConsumed());
out.writerIndex(out.writerIndex() + result.bytesProduced());
switch (result.getStatus()) {
case BUFFER_OVERFLOW:
out.ensureWritable(engine.getSession().getPacketBufferSize());
代码示例来源:origin: apache/kafka
SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer);
if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) {
throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " +
wrapResult.getStatus() + ". Will not send close message to peer.");
netWriteBuffer.flip();
flush(netWriteBuffer);
代码示例来源:origin: rapidoid/rapidoid
result = sslDest.engine.wrap(src, tmpBuf);
} catch (SSLException e) {
throw U.rte(e);
tmpBuf.flip();
sslDest.dest.append(tmpBuf);
代码示例来源:origin: apache/nifi
final SSLEngineResult handshakeResult = engine.wrap(appDataOut, outboundBuffer);
if (handshakeResult.getStatus() != Status.CLOSED) {
throw new IOException("Invalid close state - will not send network data");
代码示例来源:origin: apache/kafka
switch (handshakeStatus) {
case NEED_WRAP:
handshakeResult = sslEngine.wrap(EMPTY_BUF, netBuffer);
switch (handshakeResult.getStatus()) {
case OK: break;
case BUFFER_OVERFLOW:
netBuffer.compact();
netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize());
netBuffer.flip();
break;
case BUFFER_UNDERFLOW:
case CLOSED:
default:
throw new SSLException("Unexpected handshake status: " + handshakeResult.getStatus());
if (peerEngine.netBuffer.position() == 0) // no data to unwrap, return to process peer
return;
peerEngine.netBuffer.flip(); // unwrap the data from peer
handshakeResult = sslEngine.unwrap(peerEngine.netBuffer, appBuffer);
peerEngine.netBuffer.compact();
handshakeStatus = handshakeResult.getHandshakeStatus();
switch (handshakeResult.getStatus()) {
case OK: break;
case BUFFER_OVERFLOW:
代码示例来源:origin: rapidoid/rapidoid
private synchronized void wrapOutput() {
if (!isClosed()) {
debug("- WRAP");
SSLEngineResult result;
try {
result = engine.wrap(new ByteBuffer[]{}, 0, 0, netOut);
} catch (SSLException e) {
throw U.rte(e);
}
debug("wrap: ", result);
debug("OUT " + netOut);
netOut.flip();
synchronized (conn.outgoing) {
conn.outgoing.append(netOut);
}
netOut.compact();
reactToResult(result);
}
}
代码示例来源:origin: wildfly/wildfly
SSLEngineResult result = engine.wrap(in0, out0);
in.skipBytes(result.bytesConsumed());
out.writerIndex(out.writerIndex() + result.bytesProduced());
switch (result.getStatus()) {
case BUFFER_OVERFLOW:
out.ensureWritable(engine.getSession().getPacketBufferSize());
代码示例来源:origin: apache/nifi
final SSLEngineResult result = sslEngine.wrap(plaintext, destinationBuffer);
switch (result.getStatus()) {
case OK:
destinationBuffer.flip();
return;
case CLOSED:
destinationBuffer.flip();
tempBuffer.put(destinationBuffer);
destinationBuffer = tempBuffer;
代码示例来源:origin: io.netty/netty
for (;;) {
synchronized (handshakeLock) {
result = engine.wrap(EMPTY_BUFFER, outNetBuf);
outNetBuf.flip();
ChannelBuffer msg =
ctx.getChannel().getConfig().getBufferFactory().getBuffer(outNetBuf.remaining());
代码示例来源:origin: apache/nifi
final SSLEngineResult wrapHelloResult = engine.wrap(appDataOut, outboundBuffer);
if (wrapHelloResult.getStatus() == Status.BUFFER_OVERFLOW) {
streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
continue;
if (wrapHelloResult.getStatus() != Status.OK) {
throw new SSLHandshakeException("Could not generate SSL Handshake information: SSLEngineResult: "
+ wrapHelloResult.toString());
logger.trace("{} Handshake response after unwrapping: {}", this, handshakeResponseResult);
if (handshakeResponseResult.getStatus() == Status.BUFFER_UNDERFLOW) {
final ByteBuffer writableDataIn = streamInManager.prepareForWrite(engine.getSession().getPacketBufferSize());
final int bytesRead = readData(writableDataIn);
代码示例来源:origin: apache/kafka
SSLEngineResult wrapResult = sslEngine.wrap(src, netWriteBuffer);
netWriteBuffer.flip();
if (wrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && wrapResult.getStatus() == Status.OK)
throw renegotiationException();
if (wrapResult.getStatus() == Status.OK) {
written = wrapResult.bytesConsumed();
flush(netWriteBuffer);
} else if (wrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
int currentNetWriteBufferSize = netWriteBufferSize();
netWriteBuffer.compact();
netWriteBuffer = Utils.ensureCapacity(netWriteBuffer, currentNetWriteBufferSize);
netWriteBuffer.flip();
if (netWriteBuffer.limit() >= currentNetWriteBufferSize)
throw new IllegalStateException("SSL BUFFER_OVERFLOW when available data size (" + netWriteBuffer.limit() + ") >= network buffer size (" + currentNetWriteBufferSize + ")");
代码示例来源:origin: ibinti/bugvm
private synchronized ByteBuffer wrap( ByteBuffer b ) throws SSLException {
outCrypt.compact();
writeEngineResult = sslEngine.wrap( b, outCrypt );
outCrypt.flip();
return outCrypt;
}
代码示例来源:origin: wildfly/wildfly
try {
synchronized (getWrapLock()) {
engine.wrap(EMPTY_BUFFER, sendBuffer.getResource());
doFlush();
if(res == 0 && result.getStatus() == SSLEngineResult.Status.BUFFER_UNDERFLOW) {
int old;
do {
代码示例来源:origin: apache/ignite
/**
* Writes close_notify message to the network output buffer.
*
* @throws SSLException If wrap failed or SSL engine does not get closed
* after wrap.
* @return {@code True} if <tt>close_notify</tt> message was encoded, {@code false} if outbound
* stream was already closed.
*/
boolean closeOutbound() throws SSLException {
assert isHeldByCurrentThread();
if (!sslEngine.isOutboundDone()) {
sslEngine.closeOutbound();
outNetBuf.clear();
SSLEngineResult res = sslEngine.wrap(handshakeBuf, outNetBuf);
if (res.getStatus() != CLOSED)
throw new SSLException("Incorrect SSL engine status after closeOutbound call [status=" +
res.getStatus() + ", handshakeStatus=" + res.getHandshakeStatus() + ", ses=" + ses + ']');
outNetBuf.flip();
return true;
}
return false;
}
代码示例来源:origin: org.java-websocket/Java-WebSocket
private synchronized ByteBuffer wrap( ByteBuffer b ) throws SSLException {
outCrypt.compact();
writeEngineResult = sslEngine.wrap( b, outCrypt );
outCrypt.flip();
return outCrypt;
}
内容来源于网络,如有侵权,请联系作者删除!