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
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ TEST_JAVA_DIR := ${TOPDIR}/src/test/java
TEST_JAVA_SRCS := $(wildcard $(addsuffix /*.java, $(TEST_JAVA_DIR)))
TEST_NAT_SRCS := $(wildcard $(addsuffix /*.c, $(TEST_JAVA_DIR)/native))
TESTOBJS := $(patsubst $(TEST_JAVA_DIR)/native/%.c, $(TEST_BIN)/%.o, $(TEST_NAT_SRCS))
TESTLIB := $(BUILD)/test/bin/libsigtest.so

LIBPATH := $(BUILD)/bin:${TOPDIR}/build/test/bin

Expand Down Expand Up @@ -79,9 +78,6 @@ $(BUILD)/test/bin/%.o: $(TEST_JAVA_DIR)/native/%.c
$(SOLIB): $(OBJS)
@cc ${LDFLAGS} -o $@ $^ -L/usr/local/lib64 -lcrypto -lssl

$(TESTLIB): $(TESTOBJS)
@cc -shared -fPIC -Wl,-soname,libsigtest.so -o $@ $^ -L/usr/local/lib64 -L$(BUILD)/bin -lcrypto -lssl -ljssl

$(TEST_BIN)/%: $(TEST_C_DIR)/%.c
@cc $(TEST_CFLAGS) -o $@ $< -ljssl -lcrypto

Expand All @@ -90,7 +86,7 @@ gen-code:

solib: $(BUILD)/bin $(SOLIB)

test-solib: $(BUILD)/test/bin $(TESTLIB) $(TEST_C_OBJS)
test-solib: $(BUILD)/test/bin $(TEST_C_OBJS)
@LD_LIBRARY_PATH=$(BUILD)/bin:$(BUILD)/test LIBPATH=${LIBPATH} src/test/runner.py

clean:
Expand Down
90 changes: 34 additions & 56 deletions src/test/java/SignatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
import com.canonical.openssl.key.OpenSSLKey;
import com.canonical.openssl.key.OpenSSLPublicKey;
import com.canonical.openssl.key.OpenSSLPrivateKey;
import com.canonical.openssl.key.KeyConverter;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.util.Arrays;
import java.nio.ByteBuffer;
import java.security.spec.AlgorithmParameterSpec;
import java.security.AlgorithmParameters;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
Expand All @@ -39,9 +42,6 @@
import static org.junit.Assert.assertFalse;

public class SignatureTest {
static {
System.loadLibrary("sigtest");
}

static String message = "Apollo is one of the Olympian deities in classical "
+ "Greek and Roman religion and Greek and Roman mythology. Apollo "
Expand All @@ -56,11 +56,10 @@ public class SignatureTest {

@Test
public void testRSABasic() throws Exception {
RSAKeyPairGenerator gen = new RSAKeyPairGenerator();
gen.generateKeyPair();

PublicKey publicKey = gen.pubKey;
PrivateKey privateKey = gen.privKey;
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand All @@ -77,8 +76,11 @@ public void testRSABasic() throws Exception {

@Test
public void testRSAwithMultipleUpdates() throws Exception {
PublicKey publicKey = new RSAPublicKey("src/test/keys/rsa16384-pub.pem");
PrivateKey privateKey = new RSAPrivateKey("src/test/keys/rsa16384-priv.pem");
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
gen.initialize(4096);
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand All @@ -99,11 +101,10 @@ public void testRSAwithMultipleUpdates() throws Exception {

@Test
public void testRSAsingleByteUpdates() throws Exception {
RSAKeyPairGenerator gen = new RSAKeyPairGenerator();
gen.generateKeyPair();

PublicKey publicKey = gen.pubKey;
PrivateKey privateKey = gen.privKey;
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand All @@ -123,8 +124,11 @@ public void testRSAsingleByteUpdates() throws Exception {

@Test
public void testRSAmultipleByteBufferUpdates() throws Exception {
PublicKey publicKey = new RSAPublicKey("src/test/keys/rsa8192-pub.pem");
PrivateKey privateKey = new RSAPrivateKey("src/test/keys/rsa8192-priv.pem");
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
gen.initialize(8192);
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand All @@ -141,8 +145,11 @@ public void testRSAmultipleByteBufferUpdates() throws Exception {

@Test
public void testRSAsignNonzeroOffset() throws Exception {
PublicKey publicKey = new RSAPublicKey("src/test/keys/rsa4096-pub.pem");
PrivateKey privateKey = new RSAPrivateKey("src/test/keys/rsa4096-priv.pem");
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
gen.initialize(4096);
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

byte[] sigBytes = new byte[612];
Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
Expand All @@ -160,11 +167,10 @@ public void testRSAsignNonzeroOffset() throws Exception {

@Test
public void testRSAtamperedSignature() throws Exception {
RSAKeyPairGenerator gen = new RSAKeyPairGenerator();
gen.generateKeyPair();

PublicKey publicKey = gen.pubKey;
PrivateKey privateKey = gen.privKey;
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand All @@ -187,11 +193,11 @@ public void testRSAtamperedSignature() throws Exception {

@Test
public void testRSAtamperedContent() throws Exception {
RSAKeyPairGenerator gen = new RSAKeyPairGenerator();
gen.generateKeyPair();
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
KeyPair kp = gen.generateKeyPair();
PublicKey publicKey = new RSAPublicKey(KeyConverter.publicKeyToEVPKey(kp.getPublic()));
PrivateKey privateKey = new RSAPrivateKey(KeyConverter.privateKeyToEVPKey(kp.getPrivate()));

PublicKey publicKey = gen.pubKey;
PrivateKey privateKey = gen.privKey;

Signature signer = Signature.getInstance("RSAwithSHA256", "OpenSSLFIPSProvider");
signer.initSign(privateKey);
Expand Down Expand Up @@ -238,15 +244,9 @@ public RSAPublicKey(long nativeKey) {
this.nativeKey = nativeKey;
}

public RSAPublicKey(String filename) {
this.nativeKey = readPubKeyFromPem0(filename);
}

public long getNativeKeyHandle() {
return nativeKey;
}

native long readPubKeyFromPem0(String filename);
}

class RSAPrivateKey extends TestKey implements OpenSSLPrivateKey {
Expand All @@ -256,29 +256,7 @@ public RSAPrivateKey(long nativeKey) {
this.nativeKey = nativeKey;
}

public RSAPrivateKey(String filename) {
this.nativeKey = readPrivKeyFromPem0(filename);
}

public long getNativeKeyHandle() {
return nativeKey;
}

native long readPrivKeyFromPem0(String filename);
}

class RSAKeyPairGenerator {
long nativePrivKey = 0;
long nativePubKey = 0;

RSAPrivateKey privKey;
RSAPublicKey pubKey;

public void generateKeyPair() {
generateKeyPair0();
privKey = new RSAPrivateKey(nativePrivKey);
pubKey = new RSAPublicKey(nativePubKey);
}

private native void generateKeyPair0();
}
77 changes: 0 additions & 77 deletions src/test/java/native/RSAKeyPairGenerator.c

This file was deleted.

37 changes: 0 additions & 37 deletions src/test/java/native/RSAKeyPairGenerator.h

This file was deleted.

35 changes: 0 additions & 35 deletions src/test/java/native/RSAPrivateKey.c

This file was deleted.

37 changes: 0 additions & 37 deletions src/test/java/native/RSAPrivateKey.h

This file was deleted.

Loading