Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRYPTO-162 openSslCipher support engine #164

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a8d85a2
CRYPTO-162 openSslCipher support engine
Jun 13, 2022
297754d
Bump maven-antrun-plugin from 3.0.0 to 3.1.0 (#158)
dependabot[bot] Jun 9, 2022
b40914b
Bump maven-antrun-plugin from 3.0.0 to 3.1.0 #158
garydgregory Jun 9, 2022
af87e3c
Bump jmh.version from 1.34 to 1.35 (#157)
dependabot[bot] Jun 9, 2022
8248d8b
Bump jmh.version from 1.34 to 1.35 #157
garydgregory Jun 9, 2022
8c2d8be
Bump github/codeql-action from 1 to 2 (#159)
dependabot[bot] Jun 9, 2022
51b2d34
Bump github/codeql-action from 1 to 2 #159
garydgregory Jun 9, 2022
8b755a2
Bump commons-parent from 52 to 53
garydgregory Jun 9, 2022
1135f9c
Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0 (#160)
dependabot[bot] Jun 9, 2022
f23e9b9
Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0 #160
garydgregory Jun 9, 2022
bea5e9c
Clean up.
garydgregory Jun 9, 2022
718da27
Bump commons.javadoc.version from 3.3.2 to 3.4.0
garydgregory Jun 9, 2022
b01dcfa
Remove redundant entry
garydgregory Jun 9, 2022
b37dcad
Bump commons.surefire.version from 3.0.0-M5 to 3.0.0-M7
garydgregory Jun 9, 2022
ef5676f
Add Ubuntu build to GitHub
garydgregory Jun 9, 2022
f5e1735
CRYPTO-160: Improve quality for methods, that JavaCryptoRandom inheri…
jochenw Jun 10, 2022
a3753fb
Undoing accidental white space changes.
jochenw Jun 10, 2022
5a284ce
Typo
sebbASF Jun 12, 2022
df7def7
Looks like Windows has yet to be tried
sebbASF Jun 12, 2022
95627da
Don't trigger on changes to maven GH action
sebbASF Jun 12, 2022
a31ddd3
Trying to fix Windows build
sebbASF Jun 12, 2022
89e771f
Allow to continue
sebbASF Jun 12, 2022
c179da9
Duh! Wrong OS
sebbASF Jun 12, 2022
b0b25d9
Wromg command for Windows
sebbASF Jun 12, 2022
9b9bc76
Try c:
sebbASF Jun 12, 2022
314bd06
Alternative find
sebbASF Jun 12, 2022
30efaf8
Windows wants "
sebbASF Jun 12, 2022
792c554
Keep trying
sebbASF Jun 12, 2022
4c6c075
Again
sebbASF Jun 12, 2022
6fbce07
Again
sebbASF Jun 12, 2022
be8e308
Restore main build; hive off Windows
sebbASF Jun 12, 2022
42f516b
Dummy change to trigger GH builds
sebbASF Jun 13, 2022
c37174d
Keep looking for the openssl header files
sebbASF Jun 13, 2022
503502c
Trigger ourselves
sebbASF Jun 13, 2022
7773275
Need quotes
sebbASF Jun 13, 2022
2cb5416
Start with C
sebbASF Jun 13, 2022
369ce93
Looks like we need to set OPENSSL_HOME
sebbASF Jun 13, 2022
b3a8873
Find is slow
sebbASF Jun 13, 2022
2c98dd7
Wrong syntax for PowerShell
sebbASF Jun 13, 2022
6cb2d8e
Try setting in script
sebbASF Jun 13, 2022
9387f89
Let's see if Windows can join the other builds
sebbASF Jun 13, 2022
ab95d75
No longer needed
sebbASF Jun 13, 2022
0058f49
Revert "No longer needed"
wenwj0 Jun 14, 2022
b4703fd
Revert "Let's see if Windows can join the other builds"
wenwj0 Jun 14, 2022
6c9b241
Revert "Try setting in script"
wenwj0 Jun 14, 2022
5f99cfe
Revert "Wrong syntax for PowerShell"
wenwj0 Jun 14, 2022
8554c66
Revert "Find is slow"
wenwj0 Jun 14, 2022
b492c01
Revert "Looks like we need to set OPENSSL_HOME"
wenwj0 Jun 14, 2022
6f184c5
Revert "Start with C"
wenwj0 Jun 14, 2022
e691fc8
Revert "Need quotes"
wenwj0 Jun 14, 2022
1439355
Revert "Trigger ourselves"
wenwj0 Jun 14, 2022
236ce38
Revert "Keep looking for the openssl header files"
wenwj0 Jun 14, 2022
f73ae7b
Revert "Dummy change to trigger GH builds"
wenwj0 Jun 14, 2022
21977b1
Revert "Restore main build; hive off Windows"
wenwj0 Jun 14, 2022
f3e1f21
Revert "Again"
wenwj0 Jun 14, 2022
1745963
Revert "Again"
wenwj0 Jun 14, 2022
7f0cf96
Revert "Keep trying"
wenwj0 Jun 14, 2022
3517616
Revert "Windows wants ""
wenwj0 Jun 14, 2022
2401e5d
Revert "Alternative find"
wenwj0 Jun 14, 2022
b2da633
Revert "Try c:"
wenwj0 Jun 14, 2022
833ea32
Revert "Wromg command for Windows"
wenwj0 Jun 14, 2022
e1cffa6
Revert "Duh! Wrong OS"
wenwj0 Jun 14, 2022
e8222a0
Revert "Allow to continue"
wenwj0 Jun 14, 2022
b16affc
Revert "Trying to fix Windows build"
wenwj0 Jun 14, 2022
432391b
Revert "Don't trigger on changes to maven GH action"
wenwj0 Jun 14, 2022
36e8328
Revert "Looks like Windows has yet to be tried"
wenwj0 Jun 14, 2022
e3c9141
Revert "Typo"
wenwj0 Jun 14, 2022
2255d24
Revert "Undoing accidental white space changes."
wenwj0 Jun 14, 2022
cec8f2d
Revert "CRYPTO-160: Improve quality for methods, that JavaCryptoRando…
wenwj0 Jun 14, 2022
2e3ebd3
Revert "Add Ubuntu build to GitHub"
wenwj0 Jun 14, 2022
b0051eb
Revert "Bump commons.surefire.version from 3.0.0-M5 to 3.0.0-M7"
wenwj0 Jun 14, 2022
f82a98c
Revert "Remove redundant entry"
wenwj0 Jun 14, 2022
413a2ab
Revert "Bump commons.javadoc.version from 3.3.2 to 3.4.0"
wenwj0 Jun 14, 2022
081cec1
Revert "Clean up."
wenwj0 Jun 14, 2022
4885764
Revert "Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0 #160"
wenwj0 Jun 14, 2022
95865aa
Revert "Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0 (#160)"
wenwj0 Jun 14, 2022
ff5b35d
Revert "Bump commons-parent from 52 to 53"
wenwj0 Jun 14, 2022
2293a8a
Revert "Bump github/codeql-action from 1 to 2 #159"
wenwj0 Jun 14, 2022
969348d
Revert "Bump github/codeql-action from 1 to 2 (#159)"
wenwj0 Jun 14, 2022
a9fa454
Revert "Bump jmh.version from 1.34 to 1.35 #157"
wenwj0 Jun 14, 2022
d4b742e
Revert "Bump jmh.version from 1.34 to 1.35 (#157)"
wenwj0 Jun 14, 2022
0daecdc
Revert "Bump maven-antrun-plugin from 3.0.0 to 3.1.0 #158"
wenwj0 Jun 14, 2022
e6d9293
Revert "Bump maven-antrun-plugin from 3.0.0 to 3.1.0 (#158)"
wenwj0 Jun 14, 2022
e7f9416
Merge pull request #4 from apache/master
wenwj0 Jun 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class CryptoCipherFactory {
*/
public static final String JCE_PROVIDER_KEY = Crypto.CONF_PREFIX
+ "cipher.jce.provider";

public static final String CIPHER_ENGINE_KEY = Crypto.CONF_PREFIX
+ "cipher.engine";

/**
* The configuration key of the CryptoCipher implementation class.
* <p>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,7 @@ protected void finalize() throws Throwable {
clean();
}

public void engineSetDefaultCiphers(String engineId){
opensslBlockCipher.engineSetDefaultCiphers(engineId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public OpenSslCipher(final Properties props, final String transformation) // NOP
}

openSslEngine = OpenSsl.getInstance(transformation);

String engineId = props.getProperty(CryptoCipherFactory.CIPHER_ENGINE_KEY);
if(engineId != null && !engineId.isEmpty()) {
openSslEngine.engineSetDefaultCiphers(engineId);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ public void updateAAD(final byte[] aad) {
"The underlying Cipher implementation "
+ "does not support this method");
}

@Override
public void engineSetDefaultCiphers(String engineId) {
OpenSslNative.engineSetDefaultCiphers(engineId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ abstract int doFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferExce

abstract void updateAAD(byte[] aad);

abstract void engineSetDefaultCiphers(String engineId);

public void clean() {
if (context != 0) {
OpenSslNative.clean(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ public void updateAAD(final byte[] aad) {
}
}

@Override
public void engineSetDefaultCiphers(String engineId) {
OpenSslNative.engineSetDefaultCiphers(engineId);
}

private void processAAD() {
if (aadBuffer != null && aadBuffer.size() > 0) {
OpenSslNative.updateByteArray(context, aadBuffer.toByteArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,6 @@ public native static int doFinalByteArray(long context, byte[] output,
* @param context The cipher context address
*/
public native static void clean(long context);

public native static void engineSetDefaultCiphers(String engineId);
}
39 changes: 39 additions & 0 deletions src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ static EVP_CIPHER * (*dlsym_EVP_aes_128_cbc)(void);
static EVP_CIPHER * (*dlsym_EVP_aes_256_gcm)(void);
static EVP_CIPHER * (*dlsym_EVP_aes_192_gcm)(void);
static EVP_CIPHER * (*dlsym_EVP_aes_128_gcm)(void);
static ENGINE * (*dlsym_ENGINE_by_id) (const char *);
static int (*dlsym_ENGINE_init) (ENGINE *);
static int (*dlsym_ENGINE_finish) (ENGINE *);
static int (*dlsym_ENGINE_free) (ENGINE *);
static int (*dlsym_ENGINE_set_default_ciphers) (ENGINE *);
#endif

#ifdef WINDOWS
Expand Down Expand Up @@ -181,6 +186,11 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
LOAD_DYNAMIC_SYMBOL(dlsym_EVP_CipherInit_ex, env, openssl, "EVP_CipherInit_ex");
LOAD_DYNAMIC_SYMBOL(dlsym_EVP_CipherUpdate, env, openssl, "EVP_CipherUpdate");
LOAD_DYNAMIC_SYMBOL(dlsym_EVP_CipherFinal_ex, env, openssl, "EVP_CipherFinal_ex");
LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_by_id, env, openssl, "ENGINE_by_id");
LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_init, env, openssl, "ENGINE_init");
LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_finish, env, openssl, "ENGINE_finish");
LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_free, env, openssl, "ENGINE_free");
LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_set_default_ciphers, env, openssl, "ENGINE_set_default_ciphers");
#endif

#ifdef WINDOWS
Expand Down Expand Up @@ -688,6 +698,35 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_clean
free_context_wrapper(wrapper);
}

JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_engineSetDefaultCiphers
(JNIEnv *env, jclass clazz, jstring engineId)
{
const char* eId = (*env)->GetStringUTFChars(env, engineId, 0);
ENGINE *e = dlsym_ENGINE_by_id(eId);

if (!e) {
char msg[64] = {0};
snprintf(msg, sizeof(msg), "Not found engine: %s", eId);
THROW(env, "java/lang/InternalError", msg);
return;
}
(*env)->ReleaseStringUTFChars(env, engineId, eId);

if (dlsym_ENGINE_init(e) != 1) {
dlsym_ENGINE_free(e);
THROW(env, "java/lang/InternalError", "Error in ENGINE_init.");
return;
}

if (dlsym_ENGINE_set_default_ciphers(e) != 1) {
THROW(env, "java/lang/InternalError", "Error in ENGINE_set_default_ciphers.");
return;
}
dlsym_ENGINE_finish(e);
dlsym_ENGINE_free(e);
return;
}

static int check_update_max_output_len(EVP_CTX_Wrapper *wrapper, int input_len, int max_output_len)
{
if (dlsym_EVP_CIPHER_CTX_test_flags(wrapper->ctx, EVP_CIPH_NO_PADDING) == EVP_CIPH_NO_PADDING) {
Expand Down