Skip to content
Open
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
1 change: 0 additions & 1 deletion src/test/java/ibm/jceplus/junit/TestMultithread.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class TestMultithread {
"ibm.jceplus.junit.openjceplus.multithread.TestAliases",
"ibm.jceplus.junit.openjceplus.multithread.TestDH",
"ibm.jceplus.junit.openjceplus.multithread.TestDSAKey",
"ibm.jceplus.junit.openjceplus.multithread.TestDSASignatureInteropSUN",
"ibm.jceplus.junit.openjceplus.multithread.TestECDH",
"ibm.jceplus.junit.openjceplus.multithread.TestECDHInteropSunEC",
"ibm.jceplus.junit.openjceplus.multithread.TestEdDSASignature",
Expand Down
1 change: 0 additions & 1 deletion src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class TestMultithreadFIPS {
"ibm.jceplus.junit.openjceplusfips.multithread.TestAliases",
"ibm.jceplus.junit.openjceplusfips.multithread.TestDH",
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSAKey",
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSASignatureInteropSUN",
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDH",
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDHInteropSunEC",
"ibm.jceplus.junit.openjceplusfips.multithread.TestHKDF",
Expand Down
1 change: 0 additions & 1 deletion src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
TestDSAKey.class,
TestDSASignature.class,
TestDSASignatureInteropBC.class,
TestDSASignatureInteropSUN.class,
TestECDH.class,
TestECDHInteropBC.class,
TestECDHInteropSunEC.class,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 9 additions & 1 deletion src/test/java/ibm/jceplus/junit/tests/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright IBM Corp. 2025
* Copyright IBM Corp. 2025, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
Expand Down Expand Up @@ -29,6 +29,14 @@ public void setProviderName(String providerName) {

public void setAndInsertProvider(TestProvider provider) throws Exception {
this.providerName = provider.getProviderName();
loadSupportedProvider(provider);
}

public void setAndInsertInteropProvider(TestProvider interopProvider) throws Exception {
loadSupportedProvider(interopProvider);
}

protected void loadSupportedProvider(TestProvider provider) throws Exception {
switch (provider) {
case BC:
loadProvider(TestProvider.BC);
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/ibm/jceplus/junit/tests/BaseTestInterop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright IBM Corp. 2023, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
* this code, including the "Classpath" Exception described therein.
*/

package ibm.jceplus.junit.tests;

public class BaseTestInterop extends BaseTest {

public String interopProviderName;
public String interopProviderName2;

/**
* Sets the provider name to interop with.
*
* @param providerName the provider name associated with this test case for use.
*/
public void setInteropProviderName(String providerName) {
this.interopProviderName = providerName;
}

/**
* Sets the interop provider name and loads the provider.
*
* @param interopProvider the provider to be used for interop.
*/
public void setAndInsertInteropProvider(TestProvider interopProvider) throws Exception {
this.interopProviderName = interopProvider.getProviderName();
loadSupportedProvider(interopProvider);
}

/**
* Gets the provider name that is to be used for interop.
*
* @return The provider name associated with the interop provider name.
*/
public String getInteropProviderName() {
return this.interopProviderName;
}

/**
* Sets the provider name to interop with.
*
* @param providerName the provider name associated with this test case for use.
*/
public void setInteropProviderName2(String providerName) {
this.interopProviderName2 = providerName;
}

/**
* Gets the provider name that is to be used for interop.
*
* @return The provider name associated with the interop provider name.
*/
public String getInteropProviderName2() {
return this.interopProviderName2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright IBM Corp. 2023, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
* this code, including the "Classpath" Exception described therein.
*/

package ibm.jceplus.junit.tests;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BaseTestSignatureInterop extends BaseTestInterop {

protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
PublicKey publicKey) throws Exception {
doSignVerify(sigAlgo, message, privateKey, publicKey, getProviderName(), getInteropProviderName());
doSignVerify(sigAlgo, message, privateKey, publicKey, getInteropProviderName(), getProviderName());
}


protected static void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
PublicKey publicKey, String signProvider, String verifyProvider) throws Exception {
Signature signing = Signature.getInstance(sigAlgo, signProvider);
signing.initSign(privateKey);
signing.update(message);
byte[] signedBytes = signing.sign();

Signature verifying = Signature.getInstance(sigAlgo, verifyProvider);
verifying.initVerify(publicKey);
verifying.update(message);

assertTrue(verifying.verify(signedBytes), "Signature verification failed");
}
}

29 changes: 28 additions & 1 deletion src/test/java/ibm/jceplus/junit/tests/TestArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public static Stream<Arguments> rsaMultithreadKeySizesAndProviders() {
return keySizesAndJCEPlusProviders(rsaKeySizes);
}

/**
* Generates combinations of OpenJCEPlus* providers with the SUN provider for interoperability testing.
*
* @return Stream of Arguments containing (JCEProviders, SUN) pairs
*/
public static Stream<Arguments> getOpenJCEPlusWithSUNInteropProvider() {
return getOpenJCEPlusWithInteropProviders(TestProvider.SUN);
}

/**
* Generates combinations of all key sizes and OpenJCEPlus* providers under test.
*
Expand Down Expand Up @@ -101,5 +110,23 @@ protected static Stream<TestProvider> getEnabledProviders() {
}
}
return enabledProviders.stream();
}
}

/**
* Generates combinations of OpenJCEPlus* providers with a specified interoperability provider for testing.
*
* @param interopProvider The interoperability provider to combine with OpenJCEPlus* providers
* @return Stream of Arguments containing (JCEProviders, interopProvider) pairs
*/
protected static Stream<Arguments> getOpenJCEPlusWithInteropProviders(TestProvider interopProvider) {
List<TestProvider> enabledProviders = getEnabledProviders().toList();

List<Arguments> arguments = new ArrayList<>();
for (TestProvider jceProvider : enabledProviders) {
arguments.add(Arguments.of(jceProvider, interopProvider));
}

return arguments.stream();
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright IBM Corp. 2023, 2024
* Copyright IBM Corp. 2023, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
* this code, including the "Classpath" Exception described therein.
*/

package ibm.jceplus.junit.base;
package ibm.jceplus.junit.tests;

import java.security.InvalidKeyException;
import java.security.InvalidParameterException;
Expand All @@ -21,16 +21,40 @@
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class BaseTestDSASignatureInterop extends BaseTestSignatureInterop {
@Tag(Tags.OPENJCEPLUS_NAME)
@Tag(Tags.OPENJCEPLUS_FIPS_NAME)
@Tag(Tags.OPENJCEPLUS_MULTITHREAD_NAME)
@Tag(Tags.OPENJCEPLUS_FIPS_MULTITHREAD_NAME)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ParameterizedClass
@MethodSource("ibm.jceplus.junit.tests.TestArguments#getOpenJCEPlusWithSUNInteropProvider")
public class TestDSASignatureInterop extends BaseTestSignatureInterop {

@Parameter(0)
TestProvider provider;

@Parameter(1)
TestProvider interopProvider;

static final byte[] origMsg = "this is the original message to be signed".getBytes();

@BeforeEach
public void setUp() throws Exception {
setAndInsertProvider(provider);
setAndInsertInteropProvider(interopProvider);
}

@Test
public void testSHA1withDSA_1024() throws Exception {
KeyPair keyPair = null;
Expand Down
Loading