Skip to content

Commit 66dcb69

Browse files
committed
Project import generated by Copybara.
PiperOrigin-RevId: 885576965
1 parent 097b651 commit 66dcb69

80 files changed

Lines changed: 4318 additions & 1117 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 & 221 deletions
This file was deleted.
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) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <conscrypt/jni_init.h>
2+
#include <conscrypt/compatibility_close_monitor.h>
3+
#include <conscrypt/jniutil.h>
4+
#include <conscrypt/logging.h>
5+
#include <conscrypt/native_crypto.h>
6+
7+
namespace conscrypt {
8+
9+
jint JniInit(JavaVM* vm, void*, jint jni_version) {
10+
JNIEnv* env;
11+
if (vm->GetEnv(reinterpret_cast<void**>(&env), jni_version) != JNI_OK) {
12+
CONSCRYPT_LOG_ERROR("Could not get JNIEnv");
13+
return JNI_ERR;
14+
}
15+
16+
// Initialize the JNI constants.
17+
jniutil::init(vm, env);
18+
19+
// Register all of the native JNI methods.
20+
NativeCrypto::registerNativeMethods(env);
21+
22+
// Perform static initialization of the close monitor (if required on this platform).
23+
CompatibilityCloseMonitor::init();
24+
25+
return jni_version;
26+
}
27+
28+
} // namespace conscrypt

0 commit comments

Comments
 (0)