[Secure Channel] Establish secure connection on sendMessage
Bug: 281069627 Test: via the test app Change-Id: I9b51eadcfa636cdfb2943e0bea3c588db13cc530
This commit is contained in:
@@ -67,25 +67,11 @@ class SecureTransport extends Transport implements SecureChannel.Callback {
|
||||
mShouldProcessRequests = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<byte[]> requestForResponse(int message, byte[] data) {
|
||||
// Check if channel is secured and start securing
|
||||
if (!mShouldProcessRequests) {
|
||||
Slog.d(TAG, "Establishing secure connection.");
|
||||
try {
|
||||
mSecureChannel.establishSecureConnection();
|
||||
} catch (Exception e) {
|
||||
Slog.w(TAG, "Failed to initiate secure channel handshake.", e);
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
|
||||
return super.requestForResponse(message, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(int message, int sequence, @NonNull byte[] data)
|
||||
throws IOException {
|
||||
establishSecureConnection();
|
||||
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Queueing message 0x" + Integer.toHexString(message)
|
||||
+ " sequence " + sequence + " length " + data.length
|
||||
@@ -103,6 +89,19 @@ class SecureTransport extends Transport implements SecureChannel.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private void establishSecureConnection() {
|
||||
// Check if channel is secured and start securing
|
||||
if (!mShouldProcessRequests) {
|
||||
Slog.d(TAG, "Establishing secure connection.");
|
||||
try {
|
||||
mSecureChannel.establishSecureConnection();
|
||||
} catch (Exception e) {
|
||||
Slog.w(TAG, "Failed to initiate secure channel handshake.", e);
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSecureConnection() {
|
||||
mShouldProcessRequests = true;
|
||||
|
||||
Reference in New Issue
Block a user