本文整理汇总了Java中javax.net.ssl.SSLEngineResult.Status方法的典型用法代码示例。如果您正苦于以下问题:Java SSLEngineResult.Status方法的具体用法?Java SSLEngineResult.Status怎么用?Java SSLEngineResult.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLEngineResult
的用法示例。
在下文中一共展示了SSLEngineResult.Status方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkStatus
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* @param res
* @throws SSLException
*/
private void checkStatus(SSLEngineResult res) throws SSLException {
SSLEngineResult.Status status = res.getStatus();
/*
* The status may be:
* OK - Normal operation
* OVERFLOW - Should never happen since the application buffer is sized to hold the maximum
* packet size.
* UNDERFLOW - Need to read more data from the socket. It's normal.
* CLOSED - The other peer closed the socket. Also normal.
*/
if (status == SSLEngineResult.Status.BUFFER_OVERFLOW) {
throw new SSLException("SSLEngine error during decrypt: " + status + " inNetBuffer: " + inNetBuffer
+ "appBuffer: " + appBuffer);
}
}
示例2: doWrap
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Wraps data with the specified engine.
*
* @param engine - SSLEngine that wraps data.
* @param wrapper - Set wrapper id, e.g. "server" of "client".
* Used for logging only.
* @param maxPacketSize - Max packet size to check that MFLN extension
* works or zero for no check.
* @param app - Buffer with data to wrap.
* @param wantedStatus - Specifies expected result status of wrapping.
* @param result - Array which first element will be used to output
* wrap result object.
* @return - Buffer with wrapped data.
* @throws SSLException - thrown on engine errors.
*/
public static ByteBuffer doWrap(SSLEngine engine, String wrapper,
int maxPacketSize, ByteBuffer app,
SSLEngineResult.Status wantedStatus,
SSLEngineResult[] result)
throws SSLException {
ByteBuffer net = ByteBuffer.allocate(engine.getSession()
.getPacketBufferSize());
SSLEngineResult r = engine.wrap(app, net);
net.flip();
int length = net.remaining();
System.out.println(wrapper + " wrapped " + length + " bytes.");
System.out.println(wrapper + " handshake status is "
+ engine.getHandshakeStatus());
if (maxPacketSize < length && maxPacketSize != 0) {
throw new AssertionError("Handshake wrapped net buffer length "
+ length + " exceeds maximum packet size "
+ maxPacketSize);
}
checkResult(r, wantedStatus);
if (result != null && result.length > 0) {
result[0] = r;
}
return net;
}
示例3: doUnWrap
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Unwraps data with the specified engine.
*
* @param engine - SSLEngine that unwraps data.
* @param unwrapper - Set unwrapper id, e.g. "server" of "client".
* Used for logging only.
* @param net - Buffer with data to unwrap.
* @param wantedStatus - Specifies expected result status of wrapping.
* @param result - Array which first element will be used to output
* wrap result object.
* @return - Buffer with unwrapped data.
* @throws SSLException - thrown on engine errors.
*/
public static ByteBuffer doUnWrap(SSLEngine engine, String unwrapper,
ByteBuffer net, SSLEngineResult.Status wantedStatus,
SSLEngineResult[] result) throws SSLException {
ByteBuffer app = ByteBuffer.allocate(
engine.getSession().getApplicationBufferSize());
int length = net.remaining();
System.out.println(unwrapper + " unwrapping " + length + " bytes...");
SSLEngineResult r = engine.unwrap(net, app);
app.flip();
System.out.println(unwrapper + " handshake status is "
+ engine.getHandshakeStatus());
checkResult(r, wantedStatus);
if (result != null && result.length > 0) {
result[0] = r;
}
return app;
}
示例4: doWrap
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Wraps data with the specified engine.
*
* @param engine - SSLEngine that wraps data.
* @param wrapper - Set wrapper id, e.g. "server" of "client". Used for
* logging only.
* @param maxPacketSize - Max packet size to check that MFLN extension works
* or zero for no check.
* @param app - Buffer with data to wrap.
* @param wantedStatus - Specifies expected result status of wrapping.
* @param result - Array which first element will be used to output wrap
* result object.
* @return - Buffer with wrapped data.
* @throws SSLException - thrown on engine errors.
*/
public static ByteBuffer doWrap(SSLEngine engine, String wrapper,
int maxPacketSize, ByteBuffer app,
SSLEngineResult.Status wantedStatus,
SSLEngineResult[] result)
throws SSLException {
ByteBuffer net = ByteBuffer.allocate(engine.getSession()
.getPacketBufferSize());
SSLEngineResult r = engine.wrap(app, net);
net.flip();
int length = net.remaining();
System.out.println(wrapper + " wrapped " + length + " bytes.");
System.out.println(wrapper + " handshake status is "
+ engine.getHandshakeStatus());
if (maxPacketSize < length && maxPacketSize != 0) {
throw new AssertionError("Handshake wrapped net buffer length "
+ length + " exceeds maximum packet size "
+ maxPacketSize);
}
checkResult(r, wantedStatus);
if (result != null && result.length > 0) {
result[0] = r;
}
return net;
}
示例5: doUnWrap
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Unwraps data with the specified engine.
*
* @param engine - SSLEngine that unwraps data.
* @param unwrapper - Set unwrapper id, e.g. "server" of "client". Used for
* logging only.
* @param net - Buffer with data to unwrap.
* @param wantedStatus - Specifies expected result status of wrapping.
* @param result - Array which first element will be used to output wrap
* result object.
* @return - Buffer with unwrapped data.
* @throws SSLException - thrown on engine errors.
*/
public static ByteBuffer doUnWrap(SSLEngine engine, String unwrapper,
ByteBuffer net,
SSLEngineResult.Status wantedStatus,
SSLEngineResult[] result)
throws SSLException {
ByteBuffer app = ByteBuffer.allocate(engine.getSession()
.getApplicationBufferSize());
int length = net.remaining();
System.out.println(unwrapper + " unwrapping "
+ length + " bytes...");
SSLEngineResult r = engine.unwrap(net, app);
app.flip();
System.out.println(unwrapper + " handshake status is "
+ engine.getHandshakeStatus());
checkResult(r, wantedStatus);
if (result != null && result.length > 0) {
result[0] = r;
}
return app;
}
示例6: checkResult
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Checks that status of result {@code r} is {@code wantedStatus}.
*
* @param r - Result.
* @param wantedStatus - Wanted status of the result.
* @throws AssertionError - if status or {@code r} is not
* {@code wantedStatus}.
*/
public static void checkResult(SSLEngineResult r,
SSLEngineResult.Status wantedStatus) {
SSLEngineResult.Status rs = r.getStatus();
if (!rs.equals(wantedStatus)) {
throw new AssertionError("Unexpected status " + rs.name()
+ ", should be " + wantedStatus.name());
}
}
示例7: getEngineStatus
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private SSLEngineResult.Status getEngineStatus() {
switch (state) {
case STATE_CLOSED_INBOUND:
case STATE_CLOSED_OUTBOUND:
case STATE_CLOSED:
return CLOSED;
default:
return OK;
}
}
示例8: unwrapHandshake
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private SSLEngineResult.Status unwrapHandshake(NextFilter nextFilter) throws SSLException {
// Prepare the net data for reading.
if (inNetBuffer != null) {
inNetBuffer.flip();
}
if (inNetBuffer == null || !inNetBuffer.hasRemaining()) {
// Need more data.
return SSLEngineResult.Status.BUFFER_UNDERFLOW;
}
SSLEngineResult res = unwrap();
handshakeStatus = res.getHandshakeStatus();
checkStatus(res);
// If handshake finished, no data was produced, and the status is still
// ok, try to unwrap more
if (handshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED && res.getStatus() == SSLEngineResult.Status.OK
&& inNetBuffer.hasRemaining()) {
res = unwrap();
// prepare to be written again
if (inNetBuffer.hasRemaining()) {
inNetBuffer.compact();
} else {
inNetBuffer = null;
}
renegotiateIfNeeded(nextFilter, res);
} else {
// prepare to be written again
if (inNetBuffer.hasRemaining()) {
inNetBuffer.compact();
} else {
inNetBuffer = null;
}
}
return res.getStatus();
}
示例9: unwrap
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private byte[] unwrap(ByteBuffer[] encryptedBuffers, SSLEngine engine) throws IOException {
ByteArrayOutputStream cleartextStream = new ByteArrayOutputStream();
int decryptedBufferSize = 8192;
final ByteBuffer encryptedBuffer = combine(encryptedBuffers);
final ByteBuffer decryptedBuffer = bufferType.newBuffer(decryptedBufferSize);
while (encryptedBuffer.hasRemaining()) {
if (!decryptedBuffer.hasRemaining()) {
decryptedBuffer.clear();
}
int prevPos = decryptedBuffer.position();
SSLEngineResult unwrapResult = engine.unwrap(encryptedBuffer, decryptedBuffer);
SSLEngineResult.Status status = unwrapResult.getStatus();
switch (status) {
case BUFFER_OVERFLOW:
case OK: {
break;
}
default: { throw new RuntimeException("Unexpected SSLEngine status: " + status); }
}
int newPos = decryptedBuffer.position();
int bytesProduced = unwrapResult.bytesProduced();
assertEquals(bytesProduced, newPos - prevPos);
// Add any generated bytes to the output stream.
if (bytesProduced > 0 || status == Status.BUFFER_OVERFLOW) {
byte[] decryptedBytes = new byte[unwrapResult.bytesProduced()];
// Read the chunk that was just written to the output array.
int limit = decryptedBuffer.limit();
decryptedBuffer.limit(newPos);
decryptedBuffer.position(prevPos);
decryptedBuffer.get(decryptedBytes);
// Restore the position and limit.
decryptedBuffer.limit(limit);
// Write the decrypted bytes to the stream.
cleartextStream.write(decryptedBytes);
}
}
return cleartextStream.toByteArray();
}
示例10: getEngineStatus
import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private SSLEngineResult.Status getEngineStatus() {
return engineClosed ? SSLEngineResult.Status.CLOSED : SSLEngineResult.Status.OK;
}