本文整理匯總了Java中javax.net.ssl.SSLEngineResult.HandshakeStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLEngineResult.HandshakeStatus方法的具體用法?Java SSLEngineResult.HandshakeStatus怎麽用?Java SSLEngineResult.HandshakeStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.SSLEngineResult
的用法示例。
在下文中一共展示了SSLEngineResult.HandshakeStatus方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: tasks
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
* Executes all the tasks needed on the same thread.
* @return HandshakeStatus
*/
protected SSLEngineResult.HandshakeStatus tasks() {
Runnable r = null;
while ( (r = sslEngine.getDelegatedTask()) != null) {
r.run();
}
return sslEngine.getHandshakeStatus();
}
示例2: handleOutput
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
* Produce more handshake output. This is called in response to a
* call to {@link javax.net.ssl.SSLEngine#wrap}, when the handshake
* is still in progress.
*
* @param record The output record; the callee should put its output
* handshake message (or a part of it) in the argument's
* <code>fragment</code>, and should set the record length
* appropriately.
* @return An {@link SSLEngineResult} describing the result.
*/
public final HandshakeStatus handleOutput (ByteBuffer fragment)
throws SSLException
{
if (!tasks.isEmpty())
return HandshakeStatus.NEED_TASK;
int orig = fragment.position();
SSLEngineResult.HandshakeStatus status = implHandleOutput(fragment);
if (doHash())
{
if (Debug.DEBUG)
logger.logv(Component.SSL_HANDSHAKE, "hashing output:\n{0}",
Util.hexDump((ByteBuffer) fragment.duplicate().flip().position(orig), " >> "));
sha.update((ByteBuffer) fragment.duplicate().flip().position(orig));
md5.update((ByteBuffer) fragment.duplicate().flip().position(orig));
}
return status;
}
示例3: doTasks
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
* Do all the outstanding handshake tasks in the current Thread.
*/
private SSLEngineResult.HandshakeStatus doTasks() {
/*
* We could run this in a separate thread, but I don't see the need for
* this when used from SSLFilter. Use thread filters in MINA instead?
*/
Runnable runnable;
while ((runnable = sslEngine.getDelegatedTask()) != null) {
// TODO : we may have to use a thread pool here to improve the
// performances
runnable.run();
}
return sslEngine.getHandshakeStatus();
}
示例4: doTasks
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
public SSLEngineResult.HandshakeStatus doTasks() {
synchronized(this.engine){
Runnable runnable;
/*
* We could run this in a separate thread, but
* do in the current for now.
*/
while ((runnable = this.engine.getDelegatedTask()) != null) {
runnable.run();
}
return this.engine.getHandshakeStatus();
}
}
示例5: tasks
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
* Executes all the tasks needed on the same thread.
*
* @return HandshakeStatus
*/
protected SSLEngineResult.HandshakeStatus tasks() {
Runnable r = null;
while ((r = sslEngine.getDelegatedTask()) != null) {
r.run();
}
return sslEngine.getHandshakeStatus();
}
示例6: runDelegatedTasks
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private static void runDelegatedTasks(SSLEngine engine) {
Runnable runnable;
System.out.println("Running delegated tasks...");
while ((runnable = engine.getDelegatedTask()) != null) {
runnable.run();
}
SSLEngineResult.HandshakeStatus hs = engine.getHandshakeStatus();
if (hs == SSLEngineResult.HandshakeStatus.NEED_TASK) {
throw new Error("Handshake shouldn't need additional tasks.");
}
}
示例7: readPendingBytesFromBIO
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private SSLEngineResult readPendingBytesFromBIO(ByteBuffer dst, int bytesConsumed,
int bytesProduced, SSLEngineResult.HandshakeStatus status) throws SSLException {
try {
// Check to see if the engine wrote data into the network BIO
int pendingNet = pendingOutboundEncryptedBytes();
if (pendingNet > 0) {
// Do we have enough room in dst to write encrypted data?
int capacity = dst.remaining();
if (capacity < pendingNet) {
return new SSLEngineResult(BUFFER_OVERFLOW,
mayFinishHandshake(
status == FINISHED ? status : getHandshakeStatus(pendingNet)),
bytesConsumed, bytesProduced);
}
// Write the pending data from the network BIO into the dst buffer
int produced = readEncryptedData(dst, pendingNet);
if (produced <= 0) {
// We ignore BIO_* errors here as we use in memory BIO anyway and will do
// another SSL_* call later on in which we will produce an exception in
// case of an error
NativeCrypto.SSL_clear_error();
} else {
bytesProduced += produced;
pendingNet -= produced;
}
return new SSLEngineResult(getEngineStatus(),
mayFinishHandshake(
status == FINISHED ? status : getHandshakeStatus(pendingNet)),
bytesConsumed, bytesProduced);
}
return null;
} catch (Exception e) {
throw convertException(e);
}
}
示例8: mayFinishHandshake
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private SSLEngineResult.HandshakeStatus mayFinishHandshake(
SSLEngineResult.HandshakeStatus status) throws SSLException {
if (!handshakeFinished && status == NOT_HANDSHAKING) {
// If the status was NOT_HANDSHAKING and we not finished the handshake we need to call
// SSL_do_handshake() again
return handshake();
}
return status;
}
示例9: getHandshakeStatus
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
@Override
public synchronized SSLEngineResult.HandshakeStatus getHandshakeStatus() {
if (accepted == 0 || destroyed != 0) {
return SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING;
}
initSsl();
// Check if we are in the initial handshake phase
if (!handshakeFinished) {
// There is pending data in the network BIO -- call wrap
if (SSL.getInstance().pendingWrittenBytesInBIO(networkBIO) != 0) {
return SSLEngineResult.HandshakeStatus.NEED_WRAP;
}
// No pending data to be sent to the peer
// Check to see if we have finished handshaking
if (SSL.getInstance().isInInit(ssl) == 0) {
handshakeFinished();
return SSLEngineResult.HandshakeStatus.FINISHED;
}
// No pending data and still handshaking
// Must be waiting on the peer to send more data
return SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
}
// Check if we are in the shutdown phase
if (engineClosed) {
// Waiting to send the close_notify message
if (SSL.getInstance().pendingWrittenBytesInBIO(networkBIO) != 0) {
return SSLEngineResult.HandshakeStatus.NEED_WRAP;
}
// Must be waiting to receive the close_notify message
return SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
}
return SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING;
}
示例10: handshake
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private boolean handshake(final SelectionKey key) {
final SSLEngineResult.HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
logger.debug("Current handshake status: " + handshakeStatus);
if (!isHandshaking(handshakeStatus)) {
return true;
}
switch (handshakeStatus) {
case NEED_UNWRAP:
return receiveAndUnwrap(ByteBuffer.allocate(1024 * 1024)) && handshake(key);
case NEED_WRAP:
return wrapAndSend(key, ByteBuffer.allocate(0)) && handshake(key);
case NEED_TASK:
while (true) {
final Runnable task = engine.getDelegatedTask();
if (task == null) {
break;
}
task.run();
}
return handshake(key);
case FINISHED:
case NOT_HANDSHAKING:
default:
throw new AssertionError();
}
}
示例11: doHandshake
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
public static SSLEngineResult.HandshakeStatus doHandshake(SSLEngine tlsEngine,
ByteBuffer netDataBuf,
OutputStream out,
InputStream in){
try {
ByteBuffer empty;
/*Apparently on Android 4.4 (API_19) SSLEngine whines about BUFFER_OVERFLOW for this
buffer even though nothing ever gets written to it*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){
empty = ByteBuffer.allocate(0);
} else {
empty = ByteBuffer.allocate(tlsEngine.getSession().getApplicationBufferSize());
}
// ClientHello -> netDataBuf
tlsEngine.wrap(empty, netDataBuf);
netDataBuf.flip();
byte[] clientHello = new byte[netDataBuf.limit()];
netDataBuf.get(clientHello);
out.write(ConnectionHelper.intToByteArray(clientHello.length));
out.write(clientHello);
// netDataBuf <- ServerHello..ServerHelloDone
int serverHelloSize = ByteBuffer.wrap(ConnectionHelper.readAll(4, in)).getInt();
byte[] serverHello = ConnectionHelper.readAll(serverHelloSize, in);
netDataBuf.clear();
netDataBuf.put(serverHello);
netDataBuf.flip();
SSLEngineResult result = tlsEngine.unwrap(netDataBuf, empty);
while (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP){
result = tlsEngine.unwrap(netDataBuf, empty);
}
Runnable task = tlsEngine.getDelegatedTask();
while (task != null){
task.run();
task = tlsEngine.getDelegatedTask();
}
// [client]Certificate*..ClientKeyExchange..Finished -> netDataBuf
netDataBuf.clear();
result = tlsEngine.wrap(empty, netDataBuf);
while (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP){
result = tlsEngine.wrap(empty, netDataBuf);
}
netDataBuf.flip();
byte[] clientKeyExchange = new byte[netDataBuf.limit()];
netDataBuf.get(clientKeyExchange);
out.write(ConnectionHelper.intToByteArray(clientKeyExchange.length));
out.write(clientKeyExchange);
// netDataBuf <- ChangeCipherSpec..Finished
int serverChangeCipherSpecSize = ByteBuffer.wrap(ConnectionHelper.readAll(4, in)).getInt();
byte[] serverChangeCipherSpec = ConnectionHelper.readAll(serverChangeCipherSpecSize, in);
netDataBuf.clear();
netDataBuf.put(serverChangeCipherSpec);
netDataBuf.flip();
result = tlsEngine.unwrap(netDataBuf, empty);
while (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP){
result = tlsEngine.unwrap(netDataBuf, empty);
}
/*Apparently on Android 4.4 (API_19) with SSLEngine the latest call tlsEngine.unwrap(..)
that finishes the handshake returns NOT_HANDSHAKING instead of FINISHED as the result*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){
return result.getHandshakeStatus();
} else {
if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING){
return SSLEngineResult.HandshakeStatus.FINISHED;
} else if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.FINISHED) {
// just in case
return result.getHandshakeStatus();
} else {
return null;
}
}
} catch (IOException e){
return null;
}
}
示例12: doHandshake
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
* Does the handshake of the two specified engines according to the
* {@code mode} specified.
*
* @param clientEngine - Client SSLEngine.
* @param serverEngine - Server SSLEngine.
* @param maxPacketSize - Maximum packet size for MFLN of zero for no limit.
* @param mode - Handshake mode according to {@link HandshakeMode} enum.
* @param enableReplicatedPacks - Set {@code true} to enable replicated
* packet sending.
* @throws SSLException - thrown on engine errors.
*/
public static void doHandshake(SSLEngine clientEngine,
SSLEngine serverEngine, int maxPacketSize,
HandshakeMode mode,
boolean enableReplicatedPacks)
throws SSLException {
System.out.println("================================================="
+ "===========");
System.out.println("Starting handshake " + mode.name());
int loop = 0;
if (maxPacketSize < 0) {
throw new Error("Test issue: maxPacketSize is less than zero!");
}
SSLParameters params = clientEngine.getSSLParameters();
params.setMaximumPacketSize(maxPacketSize);
clientEngine.setSSLParameters(params);
params = serverEngine.getSSLParameters();
params.setMaximumPacketSize(maxPacketSize);
serverEngine.setSSLParameters(params);
SSLEngine firstEngine;
SSLEngine secondEngine;
switch (mode) {
case INITIAL_HANDSHAKE:
firstEngine = clientEngine;
secondEngine = serverEngine;
doUnwrapForNotHandshakingStatus = false;
clientEngine.beginHandshake();
serverEngine.beginHandshake();
break;
case REHANDSHAKE_BEGIN_CLIENT:
firstEngine = clientEngine;
secondEngine = serverEngine;
doUnwrapForNotHandshakingStatus = true;
clientEngine.beginHandshake();
break;
case REHANDSHAKE_BEGIN_SERVER:
firstEngine = serverEngine;
secondEngine = clientEngine;
doUnwrapForNotHandshakingStatus = true;
serverEngine.beginHandshake();
break;
default:
throw new Error("Test issue: unknown handshake mode");
}
endHandshakeLoop = false;
while (!endHandshakeLoop) {
if (++loop > MAX_HANDSHAKE_LOOPS) {
throw new Error("Too much loops for handshaking");
}
System.out.println("==============================================");
System.out.println("Handshake loop " + loop);
SSLEngineResult.HandshakeStatus clientHSStatus
= clientEngine.getHandshakeStatus();
SSLEngineResult.HandshakeStatus serverHSStatus
= serverEngine.getHandshakeStatus();
System.out.println("Client handshake status "
+ clientHSStatus.name());
System.out.println("Server handshake status "
+ serverHSStatus.name());
handshakeProcess(firstEngine, secondEngine, maxPacketSize,
enableReplicatedPacks);
handshakeProcess(secondEngine, firstEngine, maxPacketSize,
enableReplicatedPacks);
}
}
示例13: pendingStatus
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private static SSLEngineResult.HandshakeStatus pendingStatus(int pendingOutboundBytes) {
// Depending on if there is something left in the BIO we need to WRAP or UNWRAP
return pendingOutboundBytes > 0 ? NEED_WRAP : NEED_UNWRAP;
}
示例14: getHandshakeStatus
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private SSLEngineResult.HandshakeStatus getHandshakeStatus(int pending) {
// Check if we are in the initial handshake phase or shutdown phase
return !handshakeFinished ? pendingStatus(pending) : NOT_HANDSHAKING;
}
示例15: newResult
import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private SSLEngineResult newResult(int bytesConsumed, int bytesProduced,
SSLEngineResult.HandshakeStatus status) throws SSLException {
return new SSLEngineResult(getEngineStatus(),
mayFinishHandshake(status == FINISHED ? status : getHandshakeStatusInternal()),
bytesConsumed, bytesProduced);
}