Merge "[Secure Channel] Establish secure connection on sendMessage" into udc-dev

This commit is contained in:
Guojing Yuan
2023-05-11 21:02:15 +00:00
committed by Android (Google) Code Review

View File

@@ -67,25 +67,11 @@ class SecureTransport extends Transport implements SecureChannel.Callback {
mShouldProcessRequests = false; 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 @Override
protected void sendMessage(int message, int sequence, @NonNull byte[] data) protected void sendMessage(int message, int sequence, @NonNull byte[] data)
throws IOException { throws IOException {
establishSecureConnection();
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "Queueing message 0x" + Integer.toHexString(message) Slog.d(TAG, "Queueing message 0x" + Integer.toHexString(message)
+ " sequence " + sequence + " length " + data.length + " 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 @Override
public void onSecureConnection() { public void onSecureConnection() {
mShouldProcessRequests = true; mShouldProcessRequests = true;