use of software.amazon.awssdk.crt.io.Pkcs11Lib in project aws-crt-java by awslabs.
the class Pkcs11LibTest method testPkcs11LibInitializeFinalizeBehavior.
@Test
public void testPkcs11LibInitializeFinalizeBehavior() {
assumeEnvironmentSetUpForPkcs11Tests();
// check that the behavior enum is passed to native.
// we expect OMIT behavior to cause failure here because no one else
// has called C_Initialize.
CrtRuntimeException crtException = null;
try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(TEST_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.OMIT)) {
} catch (Exception ex) {
crtException = (CrtRuntimeException) ex;
}
assertNotNull(crtException);
assertTrue(crtException.errorName.contains("CKR_CRYPTOKI_NOT_INITIALIZED"));
}
use of software.amazon.awssdk.crt.io.Pkcs11Lib in project aws-crt-java by awslabs.
the class TlsContextOptionsTest method testMtlsPkcs11.
@Test
public void testMtlsPkcs11() {
Assume.assumeTrue(System.getProperty("NETWORK_TESTS_DISABLED") == null);
Pkcs11LibTest.assumeEnvironmentSetUpForPkcs11Tests();
try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(Pkcs11LibTest.TEST_PKCS11_LIB);
TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib).withUserPin(Pkcs11LibTest.TEST_PKCS11_PIN).withTokenLabel(Pkcs11LibTest.TEST_PKCS11_TOKEN_LABEL).withPrivateKeyObjectLabel(Pkcs11LibTest.TEST_PKCS11_PKEY_LABEL).withCertificateFilePath(Pkcs11LibTest.TEST_PKCS11_CERT_FILE);
TlsContextOptions tlsOptions = TlsContextOptions.createWithMtlsPkcs11(pkcs11Options);
TlsContext tls = new TlsContext(tlsOptions)) {
} catch (CrtRuntimeException ex) {
// This is expected to fail on platforms where we don't yet support mTLS with PKCS#11
assertEquals("AWS_ERROR_UNIMPLEMENTED", ex.errorName);
}
}
use of software.amazon.awssdk.crt.io.Pkcs11Lib in project aws-crt-java by awslabs.
the class Pkcs11LibTest method testPkcs11LibException.
@Test
public void testPkcs11LibException() {
assumeEnvironmentSetUpForPkcs11Tests();
// check that errors during initialization bubble up as Exceptions
assertThrows(Exception.class, () -> new Pkcs11Lib(null));
assertThrows(Exception.class, () -> new Pkcs11Lib("obviously-invalid-path.so"));
assertThrows(Exception.class, () -> new Pkcs11Lib(""));
}
Aggregations