Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Use the [os-maven-plugin](https://github.com/trustin/os-maven-plugin) to add the
<dependency>
<groupId>org.conscrypt</groupId>
<artifactId>conscrypt-openjdk</artifactId>
<version>2.7.0</version>
<version>2.8.0</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
```
Expand All @@ -173,7 +173,7 @@ buildscript {
apply plugin: "com.google.osdetector"

dependencies {
compile 'org.conscrypt:conscrypt-openjdk:2.7.0:' + osdetector.classifier
compile 'org.conscrypt:conscrypt-openjdk:2.8.0:' + osdetector.classifier
}
```

Expand All @@ -191,14 +191,14 @@ To depend on the uber jar, simply use the `conscrypt-openjdk-uber` artifacts.
<dependency>
<groupId>org.conscrypt</groupId>
<artifactId>conscrypt-openjdk-uber</artifactId>
<version>2.6.3</version>
<version>2.8.0</version>
</dependency>
```

##### Gradle
```gradle
dependencies {
compile 'org.conscrypt:conscrypt-openjdk-uber:2.7.0'
compile 'org.conscrypt:conscrypt-openjdk-uber:2.8.0'
}
```

Expand All @@ -211,7 +211,7 @@ arm64-v8a.

```gradle
dependencies {
implementation 'org.conscrypt:conscrypt-android:2.7.0'
implementation 'org.conscrypt:conscrypt-android:2.8.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ description = 'Conscrypt is an alternate Java Security Provider that uses Boring

subprojects {
// Keep this in `subprojects` for scripts and ease of use. Migrate to properties later.
version = "2.8.0"
version = "2.8-SNAPSHOT"
}
70 changes: 39 additions & 31 deletions common/src/jni/main/cpp/conscrypt/native_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <conscrypt/netutil.h>
#include <conscrypt/scoped_ssl_bio.h>
#include <conscrypt/ssl_error.h>
#include <conscrypt/trace.h>
#include <jni.h>
#include <limits.h>
#include <nativehelper/scoped_primitive_array.h>
#include <nativehelper/scoped_utf_chars.h>
Expand All @@ -39,6 +41,7 @@
#include <openssl/cmac.h>
#include <openssl/crypto.h>
#include <openssl/curve25519.h>
#include <openssl/digest.h>
#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/evp.h>
Expand All @@ -48,13 +51,15 @@
#include <openssl/mlkem.h>
#include <openssl/pkcs7.h>
#include <openssl/pkcs8.h>
#include <openssl/pool.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
#include <openssl/slhdsa.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <openssl/xwing.h>

#include <cstdint>
#include <limits>
#include <optional>
#include <string>
Expand All @@ -65,7 +70,6 @@ using conscrypt::AppData;
using conscrypt::BioInputStream;
using conscrypt::BioOutputStream;
using conscrypt::BioStream;
using conscrypt::CompatibilityCloseMonitor;
using conscrypt::NativeCrypto;
using conscrypt::SslError;

Expand Down Expand Up @@ -156,6 +160,22 @@ static T* fromContextObject(JNIEnv* env, jobject contextObject) {
return ref;
}

namespace {

template <typename T>
jobject createNativeRef(JNIEnv* env, jclass clazz, jmethodID ctor, bssl::UniquePtr<T> obj) {
if (obj == nullptr) {
return nullptr;
}
jobject ref = env->NewObject(clazz, ctor, reinterpret_cast<jlong>(obj.get()));
if (ref != nullptr) {
OWNERSHIP_TRANSFERRED(obj);
}
return ref;
}

} // namespace

/**
* Converts a Java byte[] two's complement to an OpenSSL BIGNUM. Returns a
* non-null BIGNUM on success. If the return value is nullptr, there is a
Expand Down Expand Up @@ -4413,11 +4433,9 @@ static jint NativeCrypto_EVP_MD_size(JNIEnv* env, jclass, jlong evpMdRef) {
return result;
}

static jlong evpDigestSignVerifyInit(JNIEnv* env,
int (*init_func)(EVP_MD_CTX*, EVP_PKEY_CTX**, const EVP_MD*,
ENGINE*, EVP_PKEY*),
const char* jniName, jobject evpMdCtxRef, jlong evpMdRef,
jobject pkeyRef) {
template <typename InitFunc>
static jlong evpDigestSignVerifyInit(JNIEnv* env, InitFunc init_func, const char* jniName,
jobject evpMdCtxRef, jlong evpMdRef, jobject pkeyRef) {
EVP_MD_CTX* mdCtx = fromContextObject<EVP_MD_CTX>(env, evpMdCtxRef);
if (mdCtx == nullptr) {
JNI_TRACE("%s => mdCtx == null", jniName);
Expand Down Expand Up @@ -6038,16 +6056,17 @@ static jobject NativeCrypto_EVP_HPKE_CTX_setup_base_mode_recipient(
infoLen = optionalInfo->size();
}

ScopedByteArrayRO enc(env, encArray);
if (enc.get() == nullptr) {
return nullptr;
}

bssl::UniquePtr<EVP_HPKE_CTX> ctx(EVP_HPKE_CTX_new());
if (ctx == nullptr) {
conscrypt::jniutil::throwOutOfMemory(env, "Unable to allocate EVP_HPKE_CTX");
ERR_clear_error();
return nullptr;
}
ScopedByteArrayRO enc(env, encArray);
if (enc.get() == nullptr) {
return nullptr;
}
if (!EVP_HPKE_CTX_setup_recipient(
/* ctx= */ ctx.get(),
/* key= */ key.get(),
Expand All @@ -6061,15 +6080,8 @@ static jobject NativeCrypto_EVP_HPKE_CTX_setup_base_mode_recipient(
return nullptr;
}

ScopedLocalRef<jobject> ctxObject(
env, env->NewObject(conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor,
reinterpret_cast<jlong>(ctx.get())));
if (ctxObject.get() == nullptr) {
return nullptr;
}
ctx.release();
return ctxObject.release();
return createNativeRef(env, conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor, std::move(ctx));
}

static jobjectArray NativeCrypto_EVP_HPKE_CTX_setup_base_mode_sender(JNIEnv* env, jclass,
Expand Down Expand Up @@ -6160,15 +6172,13 @@ static jobjectArray NativeCrypto_EVP_HPKE_CTX_setup_base_mode_sender(JNIEnv* env
return {};
}
ScopedLocalRef<jobject> ctxObject(
env, env->NewObject(conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor,
reinterpret_cast<jlong>(ctx.get())));
env, createNativeRef(env, conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor, std::move(ctx)));
if (ctxObject.get() == nullptr) {
return {};
}
ctx.release();
env->SetObjectArrayElement(result.get(), 0, ctxObject.release());
env->SetObjectArrayElement(result.get(), 1, encArray.release());
env->SetObjectArrayElement(result.get(), 0, ctxObject.get());
env->SetObjectArrayElement(result.get(), 1, encArray.get());

return result.release();
}
Expand Down Expand Up @@ -6268,16 +6278,14 @@ static jobjectArray NativeCrypto_EVP_HPKE_CTX_setup_base_mode_sender_with_seed_f
}

ScopedLocalRef<jobject> ctxObject(
env, env->NewObject(conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor,
reinterpret_cast<jlong>(ctx.get())));
env, createNativeRef(env, conscrypt::jniutil::nativeRefHpkeCtxClass,
conscrypt::jniutil::nativeRefHpkeCtxClass_constructor, std::move(ctx)));
if (ctxObject.get() == nullptr) {
return nullptr;
}
ctx.release();

env->SetObjectArrayElement(result.get(), 0, ctxObject.release());
env->SetObjectArrayElement(result.get(), 1, encArray.release());
env->SetObjectArrayElement(result.get(), 0, ctxObject.get());
env->SetObjectArrayElement(result.get(), 1, encArray.get());

return result.release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.conscrypt;

import java.nio.ByteBuffer;
import java.security.PrivateKey;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
Expand All @@ -30,6 +29,8 @@
abstract class AbstractConscryptEngine extends SSLEngine {
abstract void setBufferAllocator(BufferAllocator bufferAllocator);

abstract String getGroupName();

/**
* Returns the maximum overhead, in bytes, of sealing a record with SSL.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.SocketChannel;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -515,7 +514,7 @@ public String toString() {

public abstract void setNamedGroups(String[] namedGroups);

abstract String getCurveNameForTesting();
abstract String getGroupName();

/**
* Returns the hostname that was supplied during socket creation. No DNS resolution is
Expand Down
17 changes: 16 additions & 1 deletion common/src/main/java/org/conscrypt/Conscrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.security.KeyManagementException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.cert.X509Certificate;
import java.util.Properties;
Expand Down Expand Up @@ -381,6 +380,22 @@ public static void setNamedGroups(SSLSocket socket, String[] namedGroups) {
toConscrypt(socket).setNamedGroups(namedGroups);
}

/**
* Returns the name of the curve or named group used during the TLS handshake, or {@code null}
* if the handshake has not completed.
*/
public static String getGroupName(SSLSocket socket) {
return toConscrypt(socket).getGroupName();
}

/**
* Returns the name of the curve or named group used during the TLS handshake, or {@code null}
* if the handshake has not completed.
*/
public static String getGroupName(SSLEngine engine) {
return toConscrypt(engine).getGroupName();
}

/**
* This method enables Server Name Indication (SNI) and overrides the hostname supplied
* during socket creation. If the hostname is not a valid SNI hostname, the SNI extension
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/org/conscrypt/ConscryptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ public void setNamedGroups(String[] namedGroups) {
sslParameters.setNamedGroups(namedGroups);
}

String getCurveNameForTesting() {
return ssl.getCurveNameForTesting();
@Override
String getGroupName() {
return ssl.getGroupName();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/conscrypt/ConscryptEngineSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ public final void setNamedGroups(String[] namedGroups) {
}

@Override
public final String getCurveNameForTesting() {
return engine.getCurveNameForTesting();
public final String getGroupName() {
return engine.getGroupName();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion common/src/main/java/org/conscrypt/Java8EngineWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.conscrypt.Preconditions.checkNotNull;

import java.nio.ByteBuffer;
import java.security.PrivateKey;
import java.util.List;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -72,6 +71,11 @@ void setBufferAllocator(BufferAllocator bufferAllocator) {
delegate.setBufferAllocator(bufferAllocator);
}

@Override
String getGroupName() {
return delegate.getGroupName();
}

@Override
int maxSealOverhead() {
return delegate.maxSealOverhead();
Expand Down
4 changes: 1 addition & 3 deletions common/src/main/java/org/conscrypt/NativeSsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.conscrypt.SSLParametersImpl.PSKCallbacks;
import org.conscrypt.metrics.TlsEncryptedClientHelloHandshake;

import java.io.FileDescriptor;
import java.io.IOException;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
Expand Down Expand Up @@ -145,7 +143,7 @@ String getCipherSuite() {
}
}

String getCurveNameForTesting() {
String getGroupName() {
lock.readLock().lock();
try {
return isClosed() ? null : NativeCrypto.SSL_get_curve_name(ssl, this);
Expand Down
9 changes: 4 additions & 5 deletions common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.Locale;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
Expand Down Expand Up @@ -86,9 +87,7 @@ public abstract class OpenSSLAeadCipher extends OpenSSLCipher {
*/
int tagLengthInBytes;

protected OpenSSLAeadCipher() {
super(Padding.NOPADDING);
}
protected OpenSSLAeadCipher() {}

private void checkInitialization() {
if (mustInitialize) {
Expand Down Expand Up @@ -432,8 +431,8 @@ int doFinalInternal(byte[] input, int inputOffset, int inputLen, byte[] output,
}

@Override
void checkSupportedPadding(Padding padding) throws NoSuchPaddingException {
if (padding != Padding.NOPADDING) {
protected void engineSetPadding(String paddingStr) throws NoSuchPaddingException {
if (!paddingStr.toUpperCase(Locale.US).equals("NOPADDING")) {
throw new NoSuchPaddingException("Must be NoPadding for AEAD ciphers");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ String getBaseCipherName() {
}

@Override
int getCipherBlockSize() {
protected int engineGetBlockSize() {
return AES_BLOCK_SIZE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ String getBaseCipherName() {
}

@Override
int getCipherBlockSize() {
protected int engineGetBlockSize() {
return 0;
}

Expand Down
Loading
Loading