Skip to content

Commit a079f47

Browse files
committed
Project import generated by Copybara.
PiperOrigin-RevId: 858143213
1 parent d6bbf71 commit a079f47

90 files changed

Lines changed: 2349 additions & 866 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

android/lint.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
<issue id="Assert">
2929
<ignore path="**/common/src/main/java/org/conscrypt/OpenSSLCipherChaCha20.java" />
3030
</issue>
31+
32+
<!-- Workaround for "Unexpected failure during lint analysis". -->
33+
<issue id="LintError">
34+
<ignore regexp=".*module-info\.class.*"/>
35+
</issue>
36+
3137
</lint>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2025 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+
import org.conscrypt.metrics.CertificateTransparencyVerificationReason;
20+
21+
/**
22+
* A default NetworkSecurityPolicy for unbundled Android.
23+
*/
24+
@Internal
25+
public class ConscryptNetworkSecurityPolicy implements NetworkSecurityPolicy {
26+
public static ConscryptNetworkSecurityPolicy getDefault() {
27+
return new ConscryptNetworkSecurityPolicy();
28+
}
29+
30+
@Override
31+
public boolean isCertificateTransparencyVerificationRequired(String hostname) {
32+
return false;
33+
}
34+
35+
@Override
36+
public CertificateTransparencyVerificationReason getCertificateTransparencyVerificationReason(
37+
String hostname) {
38+
return CertificateTransparencyVerificationReason.UNKNOWN;
39+
}
40+
41+
@Override
42+
public DomainEncryptionMode getDomainEncryptionMode(String hostname) {
43+
return DomainEncryptionMode.UNKNOWN;
44+
}
45+
}

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

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@
5959
import java.util.Collection;
6060
import java.util.Collections;
6161
import java.util.List;
62+
import java.util.function.Supplier;
6263

6364
import javax.net.ssl.SNIHostName;
6465
import javax.net.ssl.SNIMatcher;
6566
import javax.net.ssl.SNIServerName;
6667
import javax.net.ssl.SSLEngine;
68+
import javax.net.ssl.SSLException;
6769
import javax.net.ssl.SSLParameters;
6870
import javax.net.ssl.SSLSession;
6971
import javax.net.ssl.SSLSocketFactory;
@@ -257,7 +259,8 @@ private static void setSSLParametersOnImpl(SSLParameters params, SSLParametersIm
257259
try {
258260
Method getNamedGroupsMethod = params.getClass().getMethod("getNamedGroups");
259261
impl.setNamedGroups((String[]) getNamedGroupsMethod.invoke(params));
260-
} catch (NoSuchMethodException | IllegalArgumentException e) {
262+
} catch (NoSuchMethodException | IllegalArgumentException
263+
| IllegalAccessException | InvocationTargetException e) {
261264
// Do nothing.
262265
}
263266
}
@@ -334,7 +337,8 @@ private static void getSSLParametersFromImpl(SSLParameters params, SSLParameters
334337
Method setNamedGroupsMethod =
335338
params.getClass().getMethod("setNamedGroups", String[].class);
336339
setNamedGroupsMethod.invoke(params, (Object) impl.getNamedGroups());
337-
} catch (NoSuchMethodException | IllegalArgumentException e) {
340+
} catch (NoSuchMethodException | IllegalArgumentException
341+
| IllegalAccessException | InvocationTargetException e) {
338342
// Do nothing.
339343
}
340344
}
@@ -839,59 +843,8 @@ static boolean supportsX509ExtendedTrustManager() {
839843
return Build.VERSION.SDK_INT > 23;
840844
}
841845

842-
/**
843-
* Check if SCT verification is required for a given hostname.
844-
*
845-
* SCT Verification is enabled using {@code Security} properties.
846-
* The "conscrypt.ct.enable" property must be true, as well as a per domain property.
847-
* The reverse notation of the domain name, prefixed with "conscrypt.ct.enforce."
848-
* is used as the property name.
849-
* Basic globbing is also supported.
850-
*
851-
* For example, for the domain foo.bar.com, the following properties will be
852-
* looked up, in order of precedence.
853-
* - conscrypt.ct.enforce.com.bar.foo
854-
* - conscrypt.ct.enforce.com.bar.*
855-
* - conscrypt.ct.enforce.com.*
856-
* - conscrypt.ct.enforce.*
857-
*/
858-
public static boolean isCTVerificationRequired(String hostname) {
859-
if (hostname == null) {
860-
return false;
861-
}
862-
// TODO: Use the platform version on platforms that support it
863-
864-
String property = Security.getProperty("conscrypt.ct.enable");
865-
if (property == null || !Boolean.parseBoolean(property)) {
866-
return false;
867-
}
868-
869-
List<String> parts = Arrays.asList(hostname.split("\\."));
870-
Collections.reverse(parts);
871-
872-
boolean enable = false;
873-
String propertyName = "conscrypt.ct.enforce";
874-
// The loop keeps going on even once we've found a match
875-
// This allows for finer grained settings on subdomains
876-
for (String part : parts) {
877-
property = Security.getProperty(propertyName + ".*");
878-
if (property != null) {
879-
enable = Boolean.parseBoolean(property);
880-
}
881-
882-
propertyName = propertyName + "." + part;
883-
}
884-
885-
property = Security.getProperty(propertyName);
886-
if (property != null) {
887-
enable = Boolean.parseBoolean(property);
888-
}
889-
return enable;
890-
}
891-
892-
public static CertificateTransparencyVerificationReason reasonCTVerificationRequired(
893-
String hostname) {
894-
return CertificateTransparencyVerificationReason.UNKNOWN;
846+
static SSLException wrapInvalidEchDataException(SSLException e) {
847+
return e;
895848
}
896849

897850
static boolean supportsConscryptCertStore() {
@@ -920,7 +873,8 @@ static CertBlocklist newDefaultBlocklist() {
920873
return null;
921874
}
922875

923-
static CertificateTransparency newDefaultCertificateTransparency() {
876+
static CertificateTransparency newDefaultCertificateTransparency(
877+
Supplier<NetworkSecurityPolicy> policySupplier) {
924878
return null;
925879
}
926880

common/src/jni/main/cpp/conscrypt/jniutil.cc

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,34 @@ void init(JavaVM* vm, JNIEnv* env) {
116116
sslHandshakeCallbacks_verifyCertificateChain =
117117
getMethodRef(env, sslHandshakeCallbacksClass, "verifyCertificateChain", "([[BLjava/lang/String;)V");
118118
sslHandshakeCallbacks_onSSLStateChange =
119-
getMethodRef(env, sslHandshakeCallbacksClass, "onSSLStateChange", "(II)V");
120-
sslHandshakeCallbacks_clientCertificateRequested =
121-
getMethodRef(env, sslHandshakeCallbacksClass, "clientCertificateRequested", "([B[I[[B)V");
119+
getMethodRef(env, sslHandshakeCallbacksClass, "onSSLStateChange", "(II)V");
120+
sslHandshakeCallbacks_clientCertificateRequested = getMethodRef(
121+
env, sslHandshakeCallbacksClass, "clientCertificateRequested", "([B[I[[B)V");
122122
sslHandshakeCallbacks_serverCertificateRequested =
123-
getMethodRef(env, sslHandshakeCallbacksClass, "serverCertificateRequested", "()V");
124-
sslHandshakeCallbacks_clientPSKKeyRequested =
125-
getMethodRef(env, sslHandshakeCallbacksClass, "clientPSKKeyRequested", "(Ljava/lang/String;[B[B)I");
123+
getMethodRef(env, sslHandshakeCallbacksClass, "serverCertificateRequested", "()V");
124+
sslHandshakeCallbacks_clientPSKKeyRequested = getMethodRef(
125+
env, sslHandshakeCallbacksClass, "clientPSKKeyRequested", "(Ljava/lang/String;[B[B)I");
126126
sslHandshakeCallbacks_serverPSKKeyRequested =
127-
getMethodRef(env, sslHandshakeCallbacksClass, "serverPSKKeyRequested", "(Ljava/lang/String;Ljava/lang/String;[B)I");
127+
getMethodRef(env, sslHandshakeCallbacksClass, "serverPSKKeyRequested",
128+
"(Ljava/lang/String;Ljava/lang/String;[B)I");
128129
sslHandshakeCallbacks_onNewSessionEstablished =
129-
getMethodRef(env, sslHandshakeCallbacksClass, "onNewSessionEstablished", "(J)V");
130+
getMethodRef(env, sslHandshakeCallbacksClass, "onNewSessionEstablished", "(J)V");
130131
sslHandshakeCallbacks_serverSessionRequested =
131-
getMethodRef(env, sslHandshakeCallbacksClass, "serverSessionRequested", "([B)J");
132+
getMethodRef(env, sslHandshakeCallbacksClass, "serverSessionRequested", "([B)J");
132133
sslHandshakeCallbacks_selectApplicationProtocol =
133-
getMethodRef(env, sslHandshakeCallbacksClass, "selectApplicationProtocol", "([B)I");
134-
cryptoUpcallsClass_rawSignMethod = env->GetStaticMethodID(cryptoUpcallsClass,
135-
"ecSignDigestWithPrivateKey",
136-
"(Ljava/security/PrivateKey;[B)[B");
134+
getMethodRef(env, sslHandshakeCallbacksClass, "selectApplicationProtocol", "([B)I");
135+
cryptoUpcallsClass_rawSignMethod = env->GetStaticMethodID(
136+
cryptoUpcallsClass, "ecSignDigestWithPrivateKey", "(Ljava/security/PrivateKey;[B)[B");
137137
if (cryptoUpcallsClass_rawSignMethod == nullptr) {
138138
env->FatalError("Could not find ecSignDigestWithPrivateKey");
139139
}
140-
cryptoUpcallsClass_rsaSignMethod = env->GetStaticMethodID(cryptoUpcallsClass,
141-
"rsaSignDigestWithPrivateKey",
142-
"(Ljava/security/PrivateKey;I[B)[B");
140+
cryptoUpcallsClass_rsaSignMethod = env->GetStaticMethodID(
141+
cryptoUpcallsClass, "rsaSignDigestWithPrivateKey", "(Ljava/security/PrivateKey;I[B)[B");
143142
if (cryptoUpcallsClass_rsaSignMethod == nullptr) {
144143
env->FatalError("Could not find rsaSignDigestWithPrivateKey");
145144
}
146-
cryptoUpcallsClass_rsaDecryptMethod = env->GetStaticMethodID(cryptoUpcallsClass,
147-
"rsaDecryptWithPrivateKey",
148-
"(Ljava/security/PrivateKey;I[B)[B");
145+
cryptoUpcallsClass_rsaDecryptMethod = env->GetStaticMethodID(
146+
cryptoUpcallsClass, "rsaDecryptWithPrivateKey", "(Ljava/security/PrivateKey;I[B)[B");
149147
if (cryptoUpcallsClass_rsaDecryptMethod == nullptr) {
150148
env->FatalError("Could not find rsaDecryptWithPrivateKey");
151149
}

common/src/jni/main/cpp/conscrypt/native_crypto.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include <type_traits>
5959
#include <vector>
6060

61+
#include "jni.h"
62+
6163
using conscrypt::AppData;
6264
using conscrypt::BioInputStream;
6365
using conscrypt::BioOutputStream;
@@ -543,8 +545,7 @@ static jbyteArray ecSignDigestWithPrivateKey(JNIEnv* env, jobject privateKey, co
543545

544546
return reinterpret_cast<jbyteArray>(env->CallStaticObjectMethod(
545547
conscrypt::jniutil::cryptoUpcallsClass,
546-
conscrypt::jniutil::cryptoUpcallsClass_rawSignMethod,
547-
privateKey, messageArray.get()));
548+
conscrypt::jniutil::cryptoUpcallsClass_rawSignMethod, privateKey, messageArray.get()));
548549
}
549550

550551
static jbyteArray rsaSignDigestWithPrivateKey(JNIEnv* env, jobject privateKey, jint padding,
@@ -571,10 +572,9 @@ static jbyteArray rsaSignDigestWithPrivateKey(JNIEnv* env, jobject privateKey, j
571572
}
572573

573574
return reinterpret_cast<jbyteArray>(
574-
env->CallStaticObjectMethod(
575-
conscrypt::jniutil::cryptoUpcallsClass,
576-
conscrypt::jniutil::cryptoUpcallsClass_rsaSignMethod,
577-
privateKey, padding, messageArray.get()));
575+
env->CallStaticObjectMethod(conscrypt::jniutil::cryptoUpcallsClass,
576+
conscrypt::jniutil::cryptoUpcallsClass_rsaSignMethod,
577+
privateKey, padding, messageArray.get()));
578578
}
579579

580580
// rsaDecryptWithPrivateKey uses privateKey to decrypt |ciphertext_len| bytes
@@ -605,10 +605,9 @@ static jbyteArray rsaDecryptWithPrivateKey(JNIEnv* env, jobject privateKey, jint
605605
}
606606

607607
return reinterpret_cast<jbyteArray>(
608-
env->CallStaticObjectMethod(
609-
conscrypt::jniutil::cryptoUpcallsClass,
610-
conscrypt::jniutil::cryptoUpcallsClass_rsaDecryptMethod,
611-
privateKey, padding, ciphertextArray.get()));
608+
env->CallStaticObjectMethod(conscrypt::jniutil::cryptoUpcallsClass,
609+
conscrypt::jniutil::cryptoUpcallsClass_rsaDecryptMethod,
610+
privateKey, padding, ciphertextArray.get()));
612611
}
613612

614613
// *********************************************
@@ -8101,7 +8100,7 @@ static void info_callback(const SSL* ssl, int type, int value) {
81018100

81028101
JNI_TRACE("ssl=%p info_callback calling onSSLStateChange", ssl);
81038102
env->CallVoidMethod(sslHandshakeCallbacks,
8104-
conscrypt::jniutil::sslHandshakeCallbacks_onSSLStateChange, type, value);
8103+
conscrypt::jniutil::sslHandshakeCallbacks_onSSLStateChange, type, value);
81058104

81068105
if (env->ExceptionCheck()) {
81078106
JNI_TRACE("ssl=%p info_callback exception", ssl);
@@ -8422,8 +8421,7 @@ static SSL_SESSION* server_session_requested_callback(SSL* ssl, const uint8_t* i
84228421
return ssl_session_ptr;
84238422
}
84248423

8425-
static jint NativeCrypto_EVP_has_aes_hardware(JNIEnv* env, jclass) {
8426-
CHECK_ERROR_QUEUE_ON_RETURN;
8424+
static jint NativeCrypto_EVP_has_aes_hardware(CRITICAL_JNI_PARAMS) {
84278425
int ret = 0;
84288426
ret = EVP_has_aes_hardware();
84298427
JNI_TRACE("EVP_has_aes_hardware => %d", ret);
@@ -10715,9 +10713,8 @@ static jlong NativeCrypto_SSL_get_timeout(JNIEnv* env, jclass, jlong ssl_address
1071510713
return result;
1071610714
}
1071710715

10718-
static jint NativeCrypto_SSL_get_signature_algorithm_key_type(JNIEnv* env, jclass,
10716+
static jint NativeCrypto_SSL_get_signature_algorithm_key_type(CRITICAL_JNI_PARAMS_COMMA
1071910717
jint signatureAlg) {
10720-
CHECK_ERROR_QUEUE_ON_RETURN;
1072110718
return SSL_get_signature_algorithm_key_type(signatureAlg);
1072210719
}
1072310720

@@ -11190,7 +11187,7 @@ static jint NativeCrypto_SSL_get_error(JNIEnv* env, jclass, jlong ssl_address,
1119011187
return SSL_get_error(ssl, ret);
1119111188
}
1119211189

11193-
static void NativeCrypto_SSL_clear_error(JNIEnv*, jclass) {
11190+
static void NativeCrypto_SSL_clear_error(CRITICAL_JNI_PARAMS) {
1119411191
ERR_clear_error();
1119511192
}
1119611193

common/src/jni/main/include/conscrypt/jniutil.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
namespace conscrypt {
2828
namespace jniutil {
2929

30+
#ifdef __ANDROID__
31+
#define CRITICAL_JNI_PARAMS
32+
#define CRITICAL_JNI_PARAMS_COMMA
33+
#else
34+
#define CRITICAL_JNI_PARAMS JNIEnv*, jclass
35+
#define CRITICAL_JNI_PARAMS_COMMA JNIEnv*, jclass,
36+
#endif
37+
3038
extern JavaVM* gJavaVM;
3139
extern jclass cryptoUpcallsClass;
3240
extern jclass openSslInputStreamClass;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public abstract SSLEngineResult wrap(
134134
*/
135135
abstract void setUseSessionTickets(boolean useSessionTickets);
136136

137+
/**
138+
* This method sets the ECH config data to be used in the TLS handshake.
139+
*
140+
* @param echConfigList the ECH config data to be used in the TLS handshake
141+
*/
142+
abstract void setEchConfigList(byte[] echConfigList);
143+
137144
/**
138145
* Sets the list of ALPN protocols.
139146
*

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,13 @@ private boolean isDelegating() {
626626
*/
627627
abstract void setUseSessionTickets(boolean useSessionTickets);
628628

629+
/**
630+
* This method sets the ECH config data to be used in the TLS handshake.
631+
*
632+
* @param echConfigList the ECH config data to be used in the TLS handshake
633+
*/
634+
abstract void setEchConfigList(byte[] echConfigList);
635+
629636
/**
630637
* Enables/disables TLS Channel ID for this server socket.
631638
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private ArrayUtils() {}
2929
* Checks that the range described by {@code offset} and {@code count}
3030
* doesn't exceed {@code arrayLength}.
3131
*/
32-
static void checkOffsetAndCount(int arrayLength, int offset, int count) {
32+
public static void checkOffsetAndCount(int arrayLength, int offset, int count) {
3333
if ((offset | count) < 0 || offset > arrayLength || arrayLength - offset < count) {
3434
throw new ArrayIndexOutOfBoundsException("length=" + arrayLength + "; regionStart="
3535
+ offset + "; regionLength=" + count);

0 commit comments

Comments
 (0)