Search in sources :

Example 1 with Pkcs11Lib

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"));
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Pkcs11Lib(software.amazon.awssdk.crt.io.Pkcs11Lib) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Test(org.junit.Test)

Example 2 with Pkcs11Lib

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);
    }
}
Also used : TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Pkcs11Lib(software.amazon.awssdk.crt.io.Pkcs11Lib) TlsContext(software.amazon.awssdk.crt.io.TlsContext) TlsContextPkcs11Options(software.amazon.awssdk.crt.io.TlsContextPkcs11Options) Test(org.junit.Test)

Example 3 with Pkcs11Lib

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(""));
}
Also used : Pkcs11Lib(software.amazon.awssdk.crt.io.Pkcs11Lib) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Pkcs11Lib (software.amazon.awssdk.crt.io.Pkcs11Lib)3 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)2 TlsContext (software.amazon.awssdk.crt.io.TlsContext)1 TlsContextOptions (software.amazon.awssdk.crt.io.TlsContextOptions)1 TlsContextPkcs11Options (software.amazon.awssdk.crt.io.TlsContextPkcs11Options)1