Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
640caa0
Add SSL_set1_curve_list to NativeCrpto.
juergw Dec 8, 2025
618a736
Fix format.
juergw Dec 8, 2025
0dcb7ff
Fix format.
juergw Dec 8, 2025
a6932df
Merge branch 'google:master' into other
juergw Dec 10, 2025
2b1aab2
Use *Groups* instead of *Curves*.
juergw Dec 10, 2025
c3c7175
Fix format.
juergw Dec 10, 2025
07dfede
Remove more invalid test cases.
juergw Dec 10, 2025
758e20c
Fix format.
juergw Dec 10, 2025
cd91d21
Wrap SSL_set1_groups instead.
juergw Dec 10, 2025
9b6e909
Fix format.
juergw Dec 10, 2025
369b955
Fix format.
juergw Dec 10, 2025
b8f2a31
Remove empty line.
juergw Dec 10, 2025
301f16d
Remove unnecessary null check.
juergw Dec 10, 2025
8f10b65
Fix format.
juergw Dec 10, 2025
fc0b291
Add null check back.
juergw Dec 10, 2025
215a4be
Fix format.
juergw Dec 10, 2025
5d38a52
Comment out some code to debug.
juergw Dec 11, 2025
e307c40
Uncomment line.
juergw Dec 11, 2025
9a551ca
change
juergw Dec 11, 2025
bcf2bd8
Call _ro.get().
juergw Dec 11, 2025
51433ae
Type cast.
juergw Dec 11, 2025
cf3dc60
Fix format
juergw Dec 11, 2025
2c32442
Uncomment everthing.
juergw Dec 11, 2025
dd02bca
Add check that _ro is not null.
juergw Dec 11, 2025
3a77610
Fix typo.
juergw Dec 11, 2025
b9b88a9
Inline variables.
juergw Dec 11, 2025
8be461f
Use static_cast.
juergw Dec 11, 2025
c9c0d45
Fix format
juergw Dec 11, 2025
b7f4f20
Use reinterpret_cast.
juergw Dec 11, 2025
725248f
Create vector of int and copy jint values over.
juergw Dec 11, 2025
41fbc16
Add comment.
juergw Dec 11, 2025
3a1b260
fix format
juergw Dec 11, 2025
6ddd411
Use push-back.
juergw Dec 11, 2025
5b0e8d1
Use normal for loop.
juergw Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common/src/jni/main/cpp/conscrypt/native_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9861,6 +9861,39 @@ static jstring NativeCrypto_SSL_get_current_cipher(JNIEnv* env, jclass, jlong ss
return env->NewStringUTF(name);
}

static void NativeCrypto_SSL_set1_groups(JNIEnv* env, jclass, jlong sslAddress,
CONSCRYPT_UNUSED jobject sslHolder, jintArray groups) {
CHECK_ERROR_QUEUE_ON_RETURN;
SSL* ssl = to_SSL(env, sslAddress, /* throwIfNull= */ true);
JNI_TRACE("ssl=%p NativeCrypto_SSL_set1_groups groups=%p", ssl, groups);
if (ssl == nullptr) {
// to_SSL already called conscrypt::jniutil::throwNullPointerException
return;
}
if (groups == nullptr) {
conscrypt::jniutil::throwNullPointerException(env, "groups == null");
return;
}
ScopedIntArrayRO groups_ro(env, groups);
if (groups_ro.get() == nullptr) {
JNI_TRACE("ssl=%p NativeCrypto_SSL_set1_groups => threw exception", ssl);
conscrypt::jniutil::throwOutOfMemory(env, "Unable to allocate buffer for groups");
return;
}
std::vector<int> groups_vector;
groups_vector.reserve(groups_ro.size());
const jint* groups_ptr = groups_ro.get();
for (int i = 0; i < groups_ro.size(); i++) {
groups_vector.push_back(groups_ptr[i]);
}

if (!SSL_set1_groups(ssl, groups_vector.data(), groups_vector.size())) {
conscrypt::jniutil::throwSSLExceptionStr(env, "Error parsing groups");
ERR_clear_error();
return;
}
}

static jstring NativeCrypto_SSL_get_curve_name(JNIEnv* env, jclass, jlong sslAddress,
CONSCRYPT_UNUSED jobject sslHolder) {
CHECK_ERROR_QUEUE_ON_RETURN;
Expand Down Expand Up @@ -12497,6 +12530,7 @@ static JNINativeMethod sNativeCryptoMethods[] = {
CONSCRYPT_NATIVE_METHOD(SSL_get_servername, "(J" REF_SSL ")Ljava/lang/String;"),
CONSCRYPT_NATIVE_METHOD(SSL_do_handshake, "(J" REF_SSL FILE_DESCRIPTOR SSL_CALLBACKS "I)V"),
CONSCRYPT_NATIVE_METHOD(SSL_get_current_cipher, "(J" REF_SSL ")Ljava/lang/String;"),
CONSCRYPT_NATIVE_METHOD(SSL_set1_groups, "(J" REF_SSL "[I)V"),
CONSCRYPT_NATIVE_METHOD(SSL_get_curve_name, "(J" REF_SSL ")Ljava/lang/String;"),
CONSCRYPT_NATIVE_METHOD(SSL_get_version, "(J" REF_SSL ")Ljava/lang/String;"),
CONSCRYPT_NATIVE_METHOD(SSL_get0_peer_certificates, "(J" REF_SSL ")[[B"),
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/conscrypt/NativeCrypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,8 @@ static native void SSL_do_handshake(long ssl, NativeSsl ssl_holder, FileDescript

public static native String SSL_get_current_cipher(long ssl, NativeSsl ssl_holder);

public static native void SSL_set1_groups(long ssl, NativeSsl sslHolder, int[] groups);

public static native String SSL_get_curve_name(long ssl, NativeSsl sslHolder);

public static native String SSL_get_version(long ssl, NativeSsl ssl_holder);
Expand Down
8 changes: 8 additions & 0 deletions constants/src/gen/cpp/generate_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ int main(int /* argc */, char ** /* argv */) {
CONST(EVP_PKEY_ML_DSA_65);
CONST(EVP_PKEY_ML_DSA_87);

CONST(NID_X25519);
CONST(NID_X9_62_prime256v1);
CONST(NID_secp384r1);
CONST(NID_secp521r1);
CONST(NID_X25519MLKEM768);
CONST(NID_X25519Kyber768Draft00);
CONST(NID_ML_KEM_1024);

CONST(RSA_PKCS1_PADDING);
CONST(RSA_NO_PADDING);
CONST(RSA_PKCS1_OAEP_PADDING);
Expand Down
41 changes: 41 additions & 0 deletions openjdk/src/test/java/org/conscrypt/NativeCryptoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,47 @@ public void test_SSL_new() throws Exception {
NativeCrypto.SSL_CTX_free(c, null);
}

@Test
public void setGroupsList_validGroups_works() throws Exception {
long c = NativeCrypto.SSL_CTX_new();
long s = NativeCrypto.SSL_new(c, null);

NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_X25519});
NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_X9_62_prime256v1});
NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_secp384r1});
NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_secp521r1});
NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_X25519MLKEM768});
NativeCrypto.SSL_set1_groups(
s, null, new int[] {NativeConstants.NID_X25519Kyber768Draft00});
NativeCrypto.SSL_set1_groups(s, null, new int[] {NativeConstants.NID_ML_KEM_1024});

NativeCrypto.SSL_set1_groups(s, null,
new int[] {NativeConstants.NID_X25519, NativeConstants.NID_X9_62_prime256v1,
NativeConstants.NID_secp384r1, NativeConstants.NID_secp521r1,
NativeConstants.NID_X25519MLKEM768,
NativeConstants.NID_X25519Kyber768Draft00,
NativeConstants.NID_ML_KEM_1024});

NativeCrypto.SSL_free(s, null);
NativeCrypto.SSL_CTX_free(c, null);
}

@Test
public void setGroupsList_invalidInput_throws() throws Exception {
long c = NativeCrypto.SSL_CTX_new();
long s = NativeCrypto.SSL_new(c, null);

assertThrows(NullPointerException.class, () -> NativeCrypto.SSL_set1_groups(s, null, null));

assertThrows(SSLException.class,
()
-> NativeCrypto.SSL_set1_groups(
s, null, new int[] {NativeConstants.EVP_PKEY_RSA}));

NativeCrypto.SSL_free(s, null);
NativeCrypto.SSL_CTX_free(c, null);
}

@Test
public void setLocalCertsAndPrivateKey_withNullSSLShouldThrow() throws Exception {
assertThrows(NullPointerException.class,
Expand Down