📄 sestsconnectionimpl.java
字号:
{
reportFailed(e);
if (e instanceof MessageException)
throw (MessageException)e;
else
throw new MessageException("Receive failed", e);
}
}
protected void setupBlockCrypto()
throws MessageException
{
if (!failed)
{
if (block_crypto == 1)
return;
try
{
byte shared_secret[] = sts_engine.getSharedSecret();
SecretKeySpec secret_key_spec1 = new SecretKeySpec(shared_secret, 0, 16, "AES");
SecretKeySpec secret_key_spec2 = new SecretKeySpec(shared_secret, 8, 16, "AES");
java.security.spec.AlgorithmParameterSpec param_spec1 = new IvParameterSpec(AES_IV1);
java.security.spec.AlgorithmParameterSpec param_spec2 = new IvParameterSpec(AES_IV2);
Cipher cipher1 = Cipher.getInstance("AES/CBC/PKCS5Padding");
Cipher cipher2 = Cipher.getInstance("AES/CBC/PKCS5Padding");
if (connection.isIncoming())
{
cipher1.init(1, secret_key_spec1, param_spec1);
cipher2.init(2, secret_key_spec2, param_spec2);
incoming_cipher = cipher2;
outgoing_cipher = cipher1;
} else
{
cipher1.init(2, secret_key_spec1, param_spec1);
cipher2.init(1, secret_key_spec2, param_spec2);
incoming_cipher = cipher1;
outgoing_cipher = cipher2;
}
}
catch (Throwable e)
{
throw new MessageException("Failed to setup block encryption", e);
}
}
}
protected void cryptoComplete()
throws MessageException
{
crypto_complete.releaseForever();
}
public void send(PooledByteBuffer message)
throws MessageException
{
if (failed)
throw new MessageException("Connection failed");
try
{
if (crypto_complete.isReleasedForever())
sendContent(message);
else
synchronized (this)
{
if (pending_message == null)
pending_message = message;
}
crypto_complete.reserve();
boolean send_it = false;
synchronized (this)
{
if (pending_message == message)
{
pending_message = null;
send_it = true;
}
}
if (send_it)
sendContent(message);
}
catch (Throwable e)
{
setFailed();
if (e instanceof MessageException)
throw (MessageException)e;
else
throw new MessageException("Send failed", e);
}
}
protected void sendContent(PooledByteBuffer message)
throws MessageException
{
if (outgoing_cipher != null)
{
try
{
byte plain[] = message.toByteArray();
byte enc[] = outgoing_cipher.doFinal(plain);
PooledByteBuffer temp = new PooledByteBufferImpl(enc);
try
{
connection.send(temp);
message.returnToPool();
}
catch (Throwable e)
{
temp.returnToPool();
throw e;
}
}
catch (Throwable e)
{
throw new MessageException("Failed to encrypt data", e);
}
} else
{
if (block_crypto != 1)
{
connection.close();
throw new MessageException("Crypto isn't setup");
}
connection.send(message);
}
}
protected void receiveContent(PooledByteBuffer message)
throws MessageException
{
boolean buffer_handled = false;
if (incoming_cipher != null)
try
{
byte enc[] = message.toByteArray();
byte plain[] = incoming_cipher.doFinal(enc);
PooledByteBuffer temp = new PooledByteBufferImpl(plain);
message.returnToPool();
buffer_handled = true;
message = temp;
}
catch (Throwable e)
{
throw new MessageException("Failed to decrypt data", e);
}
else
if (block_crypto != 1)
throw new MessageException("Crypto isn't setup");
List listeners_ref = listeners.getList();
MessageException last_error = null;
for (int i = 0; i < listeners_ref.size();)
{
PooledByteBuffer message_to_deliver;
if (i == 0)
message_to_deliver = message;
else
message_to_deliver = new PooledByteBufferImpl(message.toByteArray());
try
{
((GenericMessageConnectionListener)listeners_ref.get(i)).receive(this, message_to_deliver);
if (message_to_deliver == message)
buffer_handled = true;
continue;
}
catch (Throwable e)
{
message_to_deliver.returnToPool();
if (message_to_deliver == message)
buffer_handled = true;
if (e instanceof MessageException)
last_error = (MessageException)e;
else
last_error = new MessageException("Failed to process message", e);
i++;
}
}
if (last_error != null)
throw last_error;
if (!buffer_handled)
message.returnToPool();
break MISSING_BLOCK_LABEL_252;
Exception exception;
exception;
if (!buffer_handled)
message.returnToPool();
throw exception;
}
public void close()
throws MessageException
{
synchronized (connections)
{
connections.remove(this);
}
connection.close();
}
protected void reportConnected()
{
(new AEThread2("SESTSConnection:connected", true) {
final SESTSConnectionImpl this$0;
public void run()
{
List listeners_ref = listeners.getList();
for (int i = 0; i < listeners_ref.size(); i++)
try
{
((GenericMessageConnectionListener)listeners_ref.get(i)).connected(SESTSConnectionImpl.this);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
{
this$0 = SESTSConnectionImpl.this;
super(x0, x1);
}
}).start();
}
protected void reportFailed(Throwable error)
{
setFailed();
(new AEThread2(true, error) {
final Throwable val$error;
final SESTSConnectionImpl this$0;
public void run()
{
List listeners_ref = listeners.getList();
for (int i = 0; i < listeners_ref.size(); i++)
try
{
((GenericMessageConnectionListener)listeners_ref.get(i)).failed(SESTSConnectionImpl.this, error);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
try
{
close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
break MISSING_BLOCK_LABEL_100;
Exception exception;
exception;
try
{
close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
throw exception;
}
{
this$0 = SESTSConnectionImpl.this;
error = throwable;
super(x0, x1);
}
}).start();
}
public void addListener(GenericMessageConnectionListener listener)
{
listeners.add(listener);
}
public void removeListener(GenericMessageConnectionListener listener)
{
listeners.remove(listener);
}
static
{
LOGID = LogIDs.NWMAN;
SimpleTimer.addPeriodicEvent("SESTSConnectionTimer", 15000L, new TimerEventPerformer() {
public void perform(TimerEvent event)
{
List to_close = new ArrayList();
synchronized (SESTSConnectionImpl.connections)
{
for (int i = 0; i < SESTSConnectionImpl.connections.size(); i++)
{
SESTSConnectionImpl connection = (SESTSConnectionImpl)SESTSConnectionImpl.connections.get(i);
if (connection.crypto_complete.isReleasedForever())
continue;
long now = SystemTime.getCurrentTime();
if (connection.create_time > now)
{
connection.create_time = now;
continue;
}
int time_allowed = connection.getConnectMethodCount() * 60000;
if (now - connection.create_time > (long)time_allowed)
to_close.add(connection);
}
}
for (int i = 0; i < to_close.size(); i++)
((SESTSConnectionImpl)to_close.get(i)).reportFailed(new Exception("Timeout during crypto setup"));
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -