use of java.security.spec.ECGenParameterSpec in project karaf by apache.
the class PublicKeyLoginModuleTest method testUnknownKeyEC.
@Test
public void testUnknownKeyEC() throws Exception {
Properties options = getLoginModuleOptions();
PublickeyLoginModule module = new PublickeyLoginModule();
Subject subject = new Subject();
String x = "2145382594999641569030545431803328907795332312211583318014254232969998637145";
String y = "52282205184471090919696434245736603165041352971927370430120381994413951213993";
KeyFactory keyFactory = KeyFactory.getInstance("EC");
AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
parameters.init(new ECGenParameterSpec("secp256r1"));
ECParameterSpec ecParameters = parameters.getParameterSpec(ECParameterSpec.class);
ECPoint pubPoint = new ECPoint(new BigInteger(x), new BigInteger(y));
KeySpec keySpec = new ECPublicKeySpec(pubPoint, ecParameters);
PublicKey publicKey = keyFactory.generatePublic(keySpec);
module.initialize(subject, new NamePubkeyCallbackHandler("ec", publicKey), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
try {
module.login();
fail("Failure expected on an unknown user");
} catch (FailedLoginException ex) {
// expected
}
}
Aggregations