use of io.churchkey.Skip in project churchkey by tomitribe.
the class BeginPrivateKeyEcTest method encode.
/**
* Oakley-EC2N-3 and Oakley-EC2N-4 are ignored because
* they have no OID according to OpenSSL
*/
@Test
@Skip({ "Oakley-EC2N-3", "Oakley-EC2N-4" })
public void encode() throws Exception {
// Read the key
final byte[] bytes = resource.bytes("private.pkcs8." + openSslCurveName + "." + "oid" + ".pem");
final Key expected = EcKeys.decode(bytes);
// Write it back out to a PEM file
final byte[] encoded = expected.encode(Key.Format.PEM);
// Read it back from the PEM file
final Key actual = Keys.decode(encoded);
// Assert what we read is identical
final ECPrivateKey expectedKey = (ECPrivateKey) expected.getKey();
final ECPrivateKey actualKey = (ECPrivateKey) actual.getKey();
assertEquals(Hex.toString(expectedKey.getS().toByteArray()), Hex.toString(actualKey.getS().toByteArray()));
ECParameterSpecs.equals(expectedKey.getParams(), actualKey.getParams());
}
use of io.churchkey.Skip in project churchkey by tomitribe.
the class BeginPrivateKeyEcTest method verify.
@Skip("wap-wsg-idm-ecid-wtls7")
public void verify() throws Exception {
// Read the key
final Key key = EcKeys.decode(resource.bytes("private.pkcs8." + openSslCurveName + "." + "params" + ".pem"));
final byte[] sig = resource.bytes("private.pkcs8." + openSslCurveName + "." + "params" + ".sig");
final byte[] data = resource.bytes("data.txt");
final Signature instance = Signature.getInstance("SHA256withECDSA");
instance.initVerify((PublicKey) key.getPublicKey().getKey());
instance.update(data);
try {
assertTrue(instance.verify(Base64.getDecoder().decode(new String(sig).trim())));
} catch (SignatureException e) {
throw new AssertionError(openSslCurveName, e);
}
}
use of io.churchkey.Skip in project churchkey by tomitribe.
the class BeginPrivateKeyEcTest method roundTrip.
/**
* Verify that what we are able to encode/decode the key
* and get the same result as the key we first encoded
*/
@Test
@Skip({ "Oakley-EC2N-3", "Oakley-EC2N-4" })
public void roundTrip() throws IOException {
final Key read = EcKeys.decode(resource.bytes("private.pkcs8." + openSslCurveName + ".oid.pem"));
final byte[] encode = read.encode(Key.Format.PEM);
final Key written = Keys.decode(encode);
KeyAsserts.assertEcPrivateKey((ECPrivateKey) read.getKey(), (ECPrivateKey) written.getKey());
}
use of io.churchkey.Skip in project churchkey by tomitribe.
the class OpenSslEcCurvesTest method oid.
/**
* Oakley-EC2N-3 and Oakley-EC2N-4 are ignored because
* they have no OID according to OpenSSL
*/
@Test
@Skip({ "Oakley-EC2N-3", "Oakley-EC2N-4" })
public void oid() throws Exception {
final byte[] bytes = resource.bytes(openSslCurveName + "-oid.pem");
final Oid oid = (Oid) BeginEcParameters.decode(bytes);
final Curve actual = Curve.resolve(oid);
assertNotNull("OID could not be resolved " + oid, actual);
if (!curve.equals(actual) && !curve.getAliases().contains(actual) && !actual.getAliases().contains(curve)) {
fail("Expected: " + curve + ", found: " + actual);
}
}
use of io.churchkey.Skip in project churchkey by tomitribe.
the class BeginPrivateKeyEcTest method sign.
@Skip("wap-wsg-idm-ecid-wtls7")
public void sign() throws Exception {
// Read the key
final Key key = EcKeys.decode(resource.bytes("private.pkcs8." + openSslCurveName + "." + "params" + ".pem"));
final byte[] sig = resource.bytes("private.pkcs8." + openSslCurveName + "." + "params" + ".sig");
final byte[] data = resource.bytes("data.txt");
final Signature instance = Signature.getInstance("SHA256withECDSA");
instance.initSign((PrivateKey) key.getKey());
instance.update(data);
final byte[] sign = instance.sign();
assertEquals(new String(sig).trim(), Base64.getEncoder().encodeToString(sign));
}
Aggregations