Skip to content

Commit d4dab99

Browse files
Conscrypt Teammiguelaranda0
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 855621833
1 parent 6152118 commit d4dab99

File tree

21 files changed

+578
-232
lines changed

21 files changed

+578
-232
lines changed

android/proguard-rules.pro

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.conscrypt;
18+
19+
/**
20+
* Stub class for logging statistics events.
21+
*/
22+
public class ConscryptStatsLog {
23+
public static final int TLS_HANDSHAKE_REPORTED = 0;
24+
25+
public static void write(int code, boolean arg1, int arg2, int arg3, int arg4) {}
26+
}

android/src/main/java/org/conscrypt/Platform.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ private static void setSSLParametersOnImpl(SSLParameters params, SSLParametersIm
255255
Method m_getUseCipherSuitesOrder = params.getClass().getMethod("getUseCipherSuitesOrder");
256256
impl.setUseCipherSuitesOrder((boolean) m_getUseCipherSuitesOrder.invoke(params));
257257

258-
Method getNamedGroupsMethod = params.getClass().getMethod("getNamedGroups");
259-
impl.setNamedGroups((String[]) getNamedGroupsMethod.invoke(params));
258+
try {
259+
Method getNamedGroupsMethod = params.getClass().getMethod("getNamedGroups");
260+
impl.setNamedGroups((String[]) getNamedGroupsMethod.invoke(params));
261+
} catch (NoSuchMethodException | IllegalArgumentException e) {
262+
// Do nothing.
263+
}
260264
}
261265

262266
public static void setSSLParameters(
@@ -327,8 +331,12 @@ private static void getSSLParametersFromImpl(SSLParameters params, SSLParameters
327331
params.getClass().getMethod("setUseCipherSuitesOrder", boolean.class);
328332
m_setUseCipherSuitesOrder.invoke(params, impl.getUseCipherSuitesOrder());
329333

330-
Method setNamedGroupsMethod = params.getClass().getMethod("setNamedGroups", String[].class);
331-
setNamedGroupsMethod.invoke(params, (Object[]) impl.getNamedGroups());
334+
try {
335+
Method setNamedGroupsMethod = params.getClass().getMethod("setNamedGroups", String[].class);
336+
setNamedGroupsMethod.invoke(params, (Object) impl.getNamedGroups());
337+
} catch (NoSuchMethodException | IllegalArgumentException e) {
338+
// Do nothing.
339+
}
332340
}
333341

334342
public static void getSSLParameters(

common/src/main/java/org/conscrypt/ConscryptEngine.java

Lines changed: 218 additions & 143 deletions
Large diffs are not rendered by default.

common/src/main/java/org/conscrypt/ConscryptEngineSocket.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ public final void setWantClientAuth(boolean want) {
511511
@Override
512512
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
513513
public final void close() throws IOException {
514-
// TODO: Close SSL sockets using a background thread so they close gracefully.
515-
516514
if (stateLock == null) {
517515
// Constructor failed, e.g. superclass constructor called close()
518516
return;
@@ -544,6 +542,9 @@ public final void close() throws IOException {
544542
if (in != null) {
545543
in.release();
546544
}
545+
if (out != null) {
546+
out.release();
547+
}
547548
}
548549
}
549550
}
@@ -625,7 +626,7 @@ private void waitForHandshake() throws IOException {
625626

626627
private void drainOutgoingQueue() {
627628
try {
628-
while (engine.pendingOutboundEncryptedBytes() > 0) {
629+
while (engine.pendingOutboundEncryptedBytes() > 0 && out != null) {
629630
out.writeInternal(EMPTY_BUFFER);
630631
// Always flush handshake frames immediately.
631632
out.flushInternal();
@@ -661,10 +662,18 @@ private final class SSLOutputStream extends OutputStream {
661662
private final Object writeLock = new Object();
662663
private final ByteBuffer target;
663664
private final int targetArrayOffset;
665+
private final AllocatedBuffer allocatedTargetBuffer;
664666
private OutputStream socketOutputStream;
665667

666668
SSLOutputStream() {
667-
target = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
669+
if (bufferAllocator != null) {
670+
allocatedTargetBuffer = bufferAllocator.allocateHeapBuffer(
671+
engine.getSession().getPacketBufferSize());
672+
target = allocatedTargetBuffer.nioBuffer();
673+
} else {
674+
allocatedTargetBuffer = null;
675+
target = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
676+
}
668677
targetArrayOffset = target.arrayOffset();
669678
}
670679

@@ -673,6 +682,14 @@ public void close() throws IOException {
673682
ConscryptEngineSocket.this.close();
674683
}
675684

685+
void release() {
686+
synchronized (writeLock) {
687+
if (allocatedTargetBuffer != null) {
688+
allocatedTargetBuffer.release();
689+
}
690+
}
691+
}
692+
676693
@Override
677694
public void write(int b) throws IOException {
678695
waitForHandshake();
@@ -770,6 +787,7 @@ private final class SSLInputStream extends InputStream {
770787
private final ByteBuffer fromSocket;
771788
private final int fromSocketArrayOffset;
772789
private final AllocatedBuffer allocatedBuffer;
790+
private final AllocatedBuffer allocatedSocketBuffer;
773791
private InputStream socketInputStream;
774792

775793
SSLInputStream() {
@@ -783,7 +801,15 @@ private final class SSLInputStream extends InputStream {
783801
}
784802
// Initially fromEngine.remaining() == 0.
785803
fromEngine.flip();
786-
fromSocket = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
804+
805+
if (bufferAllocator != null) {
806+
allocatedSocketBuffer = bufferAllocator.allocateHeapBuffer(
807+
engine.getSession().getPacketBufferSize());
808+
fromSocket = allocatedSocketBuffer.nioBuffer();
809+
} else {
810+
allocatedSocketBuffer = null;
811+
fromSocket = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
812+
}
787813
fromSocketArrayOffset = fromSocket.arrayOffset();
788814
}
789815

@@ -797,6 +823,9 @@ void release() {
797823
if (allocatedBuffer != null) {
798824
allocatedBuffer.release();
799825
}
826+
if (allocatedSocketBuffer != null) {
827+
allocatedSocketBuffer.release();
828+
}
800829
}
801830
}
802831

common/src/test/java/org/conscrypt/HostnameVerifierTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import javax.net.ssl.SSLPeerUnverifiedException;
3232
import javax.net.ssl.SSLSession;
3333
import javax.security.auth.x500.X500Principal;
34-
import org.junit.Ignore;
34+
// g3-add: import org.junit.Ignore;
3535
import org.junit.Test;
3636
import org.junit.runner.RunWith;
3737
import org.junit.runners.Parameterized;

common/src/test/java/org/conscrypt/java/security/MessageDigestTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ private static Map<String, byte[]> getExpectations(String algorithm) throws Exce
169169
TestUtils.decodeHex(
170170
"a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6"
171171
+ "15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"));
172-
putExpectation("SHAKE128-256", INPUT_EMPTY,
173-
TestUtils.decodeHex(
174-
"7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26"));
175-
putExpectation("SHAKE256-512", INPUT_EMPTY,
176-
TestUtils.decodeHex(
177-
"46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f"
178-
+ "d75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be"));
172+
putExpectation("SHAKE128-256",
173+
INPUT_EMPTY,
174+
TestUtils.decodeHex(
175+
"7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26"));
176+
putExpectation("SHAKE256-512",
177+
INPUT_EMPTY,
178+
TestUtils.decodeHex(
179+
"46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f"
180+
+ "d75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be"));
179181

180182
// Regression test for a SHA-1 problem with inputs larger than 256 MiB. http://b/4501620
181183
// In mid-2013 this takes 3 minutes even on the host, so let's not run it on devices.

common/src/test/java/org/conscrypt/javax/crypto/XdhKeyFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.conscrypt.OpenSSLX25519PublicKey;
3131
import org.conscrypt.TestUtils;
3232
import org.conscrypt.XdhKeySpec;
33-
import org.junit.Ignore;
33+
// g3-add: import org.junit.Ignore;
3434
import org.junit.Test;
3535
import org.junit.runner.RunWith;
3636
import org.junit.runners.JUnit4;

common/src/test/java/org/conscrypt/javax/net/ssl/HttpsURLConnectionTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public void failedUrlConnect() throws Exception {
122122
Future<Void> future = executor.submit(server.run(op));
123123

124124
HttpsURLConnection connection = server.tlsConnection("/file");
125-
// g3-add: broken HTTPS hostname verification
125+
// google3-added: broken HTTPS hostname verification: b/266061083
126+
connection.setHostnameVerifier(new FakeHostnameVerifier());
126127
int response = connection.getResponseCode();
127128
assertEquals(404, response);
128129

@@ -138,7 +139,8 @@ public void successfulUrlConnect() throws Exception {
138139
Future<Void> future = executor.submit(server.run(op));
139140

140141
HttpsURLConnection connection = server.tlsConnection("/file");
141-
// g3-add: broken HTTPS hostname verification
142+
// google3-added: broken HTTPS hostname verification: b/266061083
143+
connection.setHostnameVerifier(new FakeHostnameVerifier());
142144
int response = connection.getResponseCode();
143145
assertEquals(200, response);
144146

@@ -193,7 +195,14 @@ public void urlConnectTimeout() throws Exception {
193195
}
194196
return null;
195197
});
196-
future.get(2 * timeoutMillis, TimeUnit.MILLISECONDS);
198+
try {
199+
future.get(2 * timeoutMillis, TimeUnit.MILLISECONDS);
200+
} catch (ExecutionException e) {
201+
// google3 changed, DO NOT UPSTREAM: Currently no way to reliably generate a connection
202+
// timeout on Forge, so just skip this test if we get a SocketException for now.
203+
assumeFalse(e.getCause() instanceof SocketException);
204+
throw e.getCause();
205+
}
197206
}
198207

199208
@Test

common/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketVersionCompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import org.conscrypt.tlswire.record.TlsRecord;
5353
import org.junit.After;
5454
import org.junit.Before;
55-
import org.junit.Ignore;
55+
// g3-add: import org.junit.Ignore;
5656
import org.junit.Test;
5757
import org.junit.runner.RunWith;
5858
import org.junit.runners.Parameterized;

0 commit comments

Comments
 (0)