Skip to content

Commit 94d538a

Browse files
committed
Project import generated by Copybara.
PiperOrigin-RevId: 885622312
1 parent 097b651 commit 94d538a

77 files changed

Lines changed: 4278 additions & 853 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.
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: 6 additions & 54 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;
@@ -859,59 +861,8 @@ static boolean supportsX509ExtendedTrustManager() {
859861
return Build.VERSION.SDK_INT > 23;
860862
}
861863

862-
/**
863-
* Check if SCT verification is required for a given hostname.
864-
*
865-
* SCT Verification is enabled using {@code Security} properties.
866-
* The "conscrypt.ct.enable" property must be true, as well as a per domain property.
867-
* The reverse notation of the domain name, prefixed with "conscrypt.ct.enforce."
868-
* is used as the property name.
869-
* Basic globbing is also supported.
870-
*
871-
* For example, for the domain foo.bar.com, the following properties will be
872-
* looked up, in order of precedence.
873-
* - conscrypt.ct.enforce.com.bar.foo
874-
* - conscrypt.ct.enforce.com.bar.*
875-
* - conscrypt.ct.enforce.com.*
876-
* - conscrypt.ct.enforce.*
877-
*/
878-
public static boolean isCTVerificationRequired(String hostname) {
879-
if (hostname == null) {
880-
return false;
881-
}
882-
// TODO: Use the platform version on platforms that support it
883-
884-
String property = Security.getProperty("conscrypt.ct.enable");
885-
if (property == null || !Boolean.parseBoolean(property)) {
886-
return false;
887-
}
888-
889-
List<String> parts = Arrays.asList(hostname.split("\\."));
890-
Collections.reverse(parts);
891-
892-
boolean enable = false;
893-
String propertyName = "conscrypt.ct.enforce";
894-
// The loop keeps going on even once we've found a match
895-
// This allows for finer grained settings on subdomains
896-
for (String part : parts) {
897-
property = Security.getProperty(propertyName + ".*");
898-
if (property != null) {
899-
enable = Boolean.parseBoolean(property);
900-
}
901-
902-
propertyName = propertyName + "." + part;
903-
}
904-
905-
property = Security.getProperty(propertyName);
906-
if (property != null) {
907-
enable = Boolean.parseBoolean(property);
908-
}
909-
return enable;
910-
}
911-
912-
public static CertificateTransparencyVerificationReason reasonCTVerificationRequired(
913-
String hostname) {
914-
return CertificateTransparencyVerificationReason.UNKNOWN;
864+
static SSLException wrapInvalidEchDataException(SSLException e) {
865+
return e;
915866
}
916867

917868
static boolean supportsConscryptCertStore() {
@@ -940,7 +891,8 @@ static CertBlocklist newDefaultBlocklist() {
940891
return null;
941892
}
942893

943-
static CertificateTransparency newDefaultCertificateTransparency() {
894+
static CertificateTransparency newDefaultCertificateTransparency(
895+
Supplier<NetworkSecurityPolicy> policySupplier) {
944896
return null;
945897
}
946898

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ void CompatibilityCloseMonitor::init() {
4343
return;
4444
}
4545
#ifdef CONSCRYPT_UNBUNDLED
46-
// Only attempt to initialise the legacy C++ API if the C API symbols were not found.
46+
// Only attempt to initialise the legacy C++ API if the C API symbols were not
47+
// found.
4748
lib = dlopen("libjavacore.so", RTLD_NOW);
4849
if (lib != nullptr) {
4950
if (asyncCloseMonitorCreate == nullptr) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ jint libconscrypt_JNI_OnLoad(JavaVM* vm, void*) {
4141
// Register all of the native JNI methods.
4242
NativeCrypto::registerNativeMethods(env);
4343

44-
// Perform static initialization of the close monitor (if required on this platform).
44+
// Perform static initialization of the close monitor (if required on this
45+
// platform).
4546
CompatibilityCloseMonitor::init();
4647
return CONSCRYPT_JNI_VERSION;
4748
}
4849

4950
#ifdef STATIC_LIB
5051

51-
// A version of OnLoad called when the Conscrypt library has been statically linked to the JVM (For
52-
// Java >= 1.8). The manner in which the library is statically linked is implementation specific.
52+
// A version of OnLoad called when the Conscrypt library has been statically
53+
// linked to the JVM (For Java >= 1.8). The manner in which the library is
54+
// statically linked is implementation specific.
5355
//
5456
// See http://openjdk.java.net/jeps/178
5557
CONSCRYPT_PUBLIC jint JNI_OnLoad_conscrypt(JavaVM* vm, void* reserved) {

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ void init(JavaVM* vm, JNIEnv* env) {
9393
openSslInputStreamClass = getGlobalRefToClass(
9494
env, TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/OpenSSLBIOInputStream");
9595
sslHandshakeCallbacksClass = getGlobalRefToClass(
96-
env, TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/NativeCrypto$SSLHandshakeCallbacks");
96+
env,
97+
TO_STRING(
98+
JNI_JARJAR_PREFIX) "org/conscrypt/"
99+
"NativeCrypto$SSLHandshakeCallbacks");
97100

98101
nativeRef_address = getFieldRef(env, nativeRefClass, "address", "J");
99102
#if defined(ANDROID) && !defined(CONSCRYPT_OPENJDK)
@@ -119,7 +122,7 @@ void init(JavaVM* vm, JNIEnv* env) {
119122
sslHandshakeCallbacks_clientCertificateRequested = getMethodRef(
120123
env, sslHandshakeCallbacksClass, "clientCertificateRequested", "([B[I[[B)V");
121124
sslHandshakeCallbacks_serverCertificateRequested =
122-
getMethodRef(env, sslHandshakeCallbacksClass, "serverCertificateRequested", "()V");
125+
getMethodRef(env, sslHandshakeCallbacksClass, "serverCertificateRequested", "([I)V");
123126
sslHandshakeCallbacks_clientPSKKeyRequested = getMethodRef(
124127
env, sslHandshakeCallbacksClass, "clientPSKKeyRequested", "(Ljava/lang/String;[B[B)I");
125128
sslHandshakeCallbacks_serverPSKKeyRequested =
@@ -178,8 +181,8 @@ int jniGetFDFromFileDescriptor(JNIEnv* env, jobject fileDescriptor) {
178181
}
179182

180183
extern bool isDirectByteBufferInstance(JNIEnv* env, jobject buffer) {
181-
// Some versions of ART do not check the buffer validity when handling GetDirectBufferAddress()
182-
// and GetDirectBufferCapacity().
184+
// Some versions of ART do not check the buffer validity when handling
185+
// GetDirectBufferAddress() and GetDirectBufferCapacity().
183186
if (buffer == nullptr) {
184187
return false;
185188
}
@@ -191,7 +194,8 @@ extern bool isDirectByteBufferInstance(JNIEnv* env, jobject buffer) {
191194

192195
bool isGetByteArrayElementsLikelyToReturnACopy(size_t size) {
193196
#if defined(ANDROID) && !defined(CONSCRYPT_OPENJDK)
194-
// ART's GetByteArrayElements creates copies only for arrays smaller than 12 kB.
197+
// ART's GetByteArrayElements creates copies only for arrays smaller than 12
198+
// kB.
195199
return size <= 12 * 1024;
196200
#else
197201
(void)size;
@@ -447,8 +451,9 @@ void throwExceptionFromBoringSSLError(JNIEnv* env, CONSCRYPT_UNUSED const char*
447451
return;
448452
}
449453

450-
// If there's an error from BoringSSL it may have been caused by an exception in Java code, so
451-
// ensure there isn't a pending exception before we throw a new one.
454+
// If there's an error from BoringSSL it may have been caused by an exception
455+
// in Java code, so ensure there isn't a pending exception before we throw a
456+
// new one.
452457
if (!env->ExceptionCheck()) {
453458
char message[256];
454459
ERR_error_string_n(error, message, sizeof(message));

0 commit comments

Comments
 (0)