Skip to content

Commit b7e6501

Browse files
authored
Throw SSLException in SSL_set1_ech_config_list (#1405)
Prior to this change, NativeCrypto.SSL_set1_ech_config_list would throw a OpenSSLX509CertificateFactory.ParsingException. Since the config list is not directly linked to that exception, use the more generic SSLException instead. Update the Java declaration to explicitly throws this exception. NativeCrypto.SSL_ech_accepted was found to raise a similar exception. Simply return false.
1 parent f5a96c9 commit b7e6501

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11857,7 +11857,7 @@ static jboolean NativeCrypto_SSL_set1_ech_config_list(JNIEnv* env, jclass, jlong
1185711857
int ret = SSL_set1_ech_config_list(ssl, reinterpret_cast<const uint8_t*>(configBytes.get()),
1185811858
configBytes.size());
1185911859
if (!ret) {
11860-
conscrypt::jniutil::throwParsingException(env, "Error parsing ECH config");
11860+
conscrypt::jniutil::throwSSLExceptionStr(env, "Error parsing ECH config");
1186111861
ERR_clear_error();
1186211862
JNI_TRACE("ssl=%p NativeCrypto_SSL_set1_ech_config_list(%p) => threw exception", ssl,
1186311863
configJavaBytes);
@@ -11955,8 +11955,6 @@ static jboolean NativeCrypto_SSL_ech_accepted(JNIEnv* env, jclass, jlong ssl_add
1195511955
JNI_TRACE("ssl=%p NativeCrypto_SSL_ech_accepted", ssl);
1195611956

1195711957
if (!SSL_ech_accepted(ssl)) {
11958-
conscrypt::jniutil::throwParsingException(env, "Invalid ECH config list");
11959-
ERR_clear_error();
1196011958
JNI_TRACE("ssl=%p NativeCrypto_SSL_ech_accepted => threw exception", ssl);
1196111959
return JNI_FALSE;
1196211960
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,8 @@ static native byte[] Scrypt_generate_key(
16271627

16281628
static native void SSL_set_enable_ech_grease(long ssl, NativeSsl ssl_holder, boolean enable);
16291629

1630-
static native boolean SSL_set1_ech_config_list(
1631-
long ssl, NativeSsl ssl_holder, byte[] echConfig);
1630+
static native boolean SSL_set1_ech_config_list(long ssl, NativeSsl ssl_holder, byte[] echConfig)
1631+
throws SSLException;
16321632

16331633
static native String SSL_get0_ech_name_override(long ssl, NativeSsl ssl_holder);
16341634

openjdk/src/test/java/org/conscrypt/NativeCryptoTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ public void test_SSL_set1_ech_invalid_config_list() throws Exception {
632632
byte[] badConfigList = {
633633
0x00, 0x05, (byte) 0xfe, 0x0d, (byte) 0xff, (byte) 0xff, (byte) 0xff};
634634
boolean set = false;
635-
assertThrows(ParsingException.class,
635+
assertThrows(SSLException.class,
636636
() -> NativeCrypto.SSL_set1_ech_config_list(s, null, badConfigList));
637637
NativeCrypto.SSL_free(s, null);
638638
NativeCrypto.SSL_CTX_free(c, null);
@@ -663,8 +663,7 @@ public void test_SSL_ech_accepted() throws Exception {
663663
long c = NativeCrypto.SSL_CTX_new();
664664
long s = NativeCrypto.SSL_new(c, null);
665665

666-
assertThrows(
667-
ParsingException.class, () -> assertFalse(NativeCrypto.SSL_ech_accepted(s, null)));
666+
assertFalse(NativeCrypto.SSL_ech_accepted(s, null));
668667

669668
NativeCrypto.SSL_free(s, null);
670669
NativeCrypto.SSL_CTX_free(c, null);

0 commit comments

Comments
 (0)