Skip to content

Commit 5f882ca

Browse files
committed
Project import generated by Copybara.
PiperOrigin-RevId: 884967932
1 parent 097b651 commit 5f882ca

78 files changed

Lines changed: 4283 additions & 933 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.

README.md

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,3 @@
1-
# Evolving Conscrypt's Open Source Approach
2-
3-
Hello Conscrypt Developers,
4-
5-
We're refining our **open source strategy for Conscrypt** to ensure its long-term health and sustainability. To optimize our development efforts and focus resources, we are making some changes to how Conscrypt is developed and how we handle contributions. The primary development of Conscrypt will now be done internally at Google. While we value community input, we will no longer be able to accept external contributions in the form of pull requests on the GitHub repository. This change allows us to better allocate resources to core development and ensure the project's long-term sustainability. To ensure transparency and continued access for the community, we will:
6-
7-
* **Continue Mirroring to GitHub:** All internal changes will be regularly mirrored to the public GitHub repository. Note that mirroring to GitHub might be paused for a short period of time during the transition to internal development.
8-
* **Maintain Bug Reporting Channels:** Please keep reporting bugs through GitHub Issues. For Android-specific bugs, the Android Issue Tracker is the place to go: [Report Bugs](https://source.android.com/docs/setup/contribute/report-bugs).
9-
10-
### What’s staying the same
11-
12-
The platform version of Conscrypt receives regular updates, including the latest features and security patches, through the Google Play system updates program (Project Mainline). This means that even devices running older Android versions can benefit from the most recent Conscrypt improvements without requiring a full OS update.
13-
14-
### What’s changing
15-
16-
As part of this shift, we will no longer be able to accept external pull requests on GitHub.
17-
18-
### What do you need to do
19-
20-
* Immediately, nothing.
21-
* For Android developers, we recommend leveraging the Conscrypt version built into the Android platform, which is also the default provider.
22-
23-
We appreciate the Conscrypt community and look forward to continuing to offer a secure and efficient security provider.
24-
25-
## Guidance for Android App Developers:
26-
27-
Most Android devices include Conscrypt as a core part of the platform's security providers. The Java Cryptography Architecture (JCA) framework allows for multiple security providers, and the system selects one when you request a cryptographic algorithm implementation (like Cipher, SSLContext, MessageDigest, etc.).
28-
29-
### Using the Platform Version (Recommended):
30-
31-
To use the platform-provided Conscrypt, you generally don't need to do anything specific. When requesting an algorithm, omit the provider name. The Android system will automatically select the highest-priority provider that offers the requested algorithm, which is typically the built-in Conscrypt.
32-
33-
*Example (Java):*
34-
35-
```java
36-
import javax.net.ssl.SSLContext;
37-
import java.security.Security;
38-
import java.security.Provider;
39-
40-
try {
41-
// Get an SSLContext instance using the default highest-priority provider
42-
SSLContext sslContext = SSLContext.getInstance("TLS");
43-
// Initialize and use sslContext
44-
45-
// Example: Listing providers to see what's available
46-
// Provider[] providers = Security.getProviders();
47-
// for (Provider provider : providers) {
48-
// System.out.println("Provider: " + provider.getName());
49-
// }
50-
} catch (NoSuchAlgorithmException e) {
51-
// Handle exception
52-
e.printStackTrace();
53-
}
54-
```
55-
56-
*Example (Kotlin):*
57-
58-
```kotlin
59-
import javax.net.ssl.SSLContext
60-
import java.security.Security
61-
import java.security.Provider
62-
63-
try {
64-
// Get an SSLContext instance using the default highest-priority provider
65-
val sslContext = SSLContext.getInstance("TLS")
66-
// Initialize and use sslContext
67-
68-
// Example: Listing providers to see what's available
69-
// val providers = Security.getProviders()
70-
// providers.forEach { provider ->
71-
// println("Provider: ${provider.name}")
72-
// }
73-
} catch (e: NoSuchAlgorithmException) {
74-
// Handle exception
75-
e.printStackTrace()
76-
}
77-
```
78-
79-
By *not* specifying a provider name in getInstance() calls, you rely on the Android system's default provider order, ensuring you use the up-to-date and maintained version of Conscrypt that is part of the Android platform.
80-
811
Conscrypt - A Java Security Provider
822
========================================
833

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)