Search in sources :

Example 6 with SecurityProviderX509

use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.

the class SecurityProviderX509Test method getSslContextThrowsIfX509TrustManagerNotFound.

// SRS_SecurityClientX509_25_004: [ This method shall throw SecurityProviderException if X509 Trust Manager is not found. ]
@Test(expected = SecurityProviderException.class)
public void getSslContextThrowsIfX509TrustManagerNotFound() throws SecurityProviderException, KeyManagementException, KeyStoreException {
    // arrange
    Collection<X509Certificate> certificates = new LinkedList<>();
    certificates.add(mockedX509Certificate);
    SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
    new NonStrictExpectations() {

        {
            mockedKeyManagerFactory.getKeyManagers();
            result = mockedX509KeyManager;
            mockedTrustManagerFactory.getTrustManagers();
            // not necessarily X509
            result = mockedTrustManager;
        }
    };
    // act
    securityClientX509Test.getSSLContext();
}
Also used : SecurityProviderX509(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with SecurityProviderX509

use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.

the class SecurityProviderX509Test method getSslContextThrowsOnNullPrivateKey.

@Test(expected = IllegalArgumentException.class)
public void getSslContextThrowsOnNullPrivateKey() throws SecurityProviderException, KeyManagementException, KeyStoreException {
    // arrange
    Collection<X509Certificate> certificates = new LinkedList<>();
    certificates.add(mockedX509Certificate);
    SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, null, certificates);
    // act
    securityClientX509Test.getSSLContext();
}
Also used : SecurityProviderX509(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 8 with SecurityProviderX509

use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.

the class SecurityProviderX509Test method getSslContextThrowsIfAnyOfTheUnderlyingAPIFails.

// SRS_SecurityClientX509_25_003: [ This method shall throw SecurityProviderException chained with the exception thrown from underlying API calls to SSL library. ]
@Test(expected = SecurityProviderException.class)
public void getSslContextThrowsIfAnyOfTheUnderlyingAPIFails() throws SecurityProviderException, KeyManagementException, KeyStoreException {
    // arrange
    Collection<X509Certificate> certificates = new LinkedList<>();
    certificates.add(mockedX509Certificate);
    SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
    new NonStrictExpectations() {

        {
            mockedKeyManagerFactory.getKeyManagers();
            result = mockedX509KeyManager;
            mockedTrustManagerFactory.getTrustManagers();
            result = mockedX509TrustManager;
            mockedSslContext.init((KeyManager[]) any, (TrustManager[]) any, (SecureRandom) any);
            result = new KeyManagementException();
        }
    };
    // act
    securityClientX509Test.getSSLContext();
}
Also used : SecurityProviderX509(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with SecurityProviderX509

use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.

the class SecurityProviderX509Test method getRegistrationIdSucceeds.

// SRS_SecurityClientX509_25_001: [ This method shall retrieve the commonName of the client certificate and return as registration Id. ]
@Test
public void getRegistrationIdSucceeds() throws SecurityProviderException {
    // arrange
    Collection<X509Certificate> certificates = new LinkedList<>();
    certificates.add(mockedX509Certificate);
    SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
    assertEquals(TEST_COMMON_NAME, securityClientX509Test.getRegistrationId());
}
Also used : SecurityProviderX509(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with SecurityProviderX509

use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.

the class SecurityProviderX509Test method getSslContextThrowsOnNullLeaf.

// SRS_SecurityClientX509_25_006: [ This method shall throw IllegalArgumentException if input parameters are null. ]
@Test(expected = IllegalArgumentException.class)
public void getSslContextThrowsOnNullLeaf() throws SecurityProviderException, KeyManagementException, KeyStoreException {
    // arrange
    Collection<X509Certificate> certificates = new LinkedList<>();
    certificates.add(mockedX509Certificate);
    SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, null, mockedKey, certificates);
    // act
    securityClientX509Test.getSSLContext();
}
Also used : SecurityProviderX509(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

SecurityProviderX509 (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509)10 Test (org.junit.Test)8 X509Certificate (java.security.cert.X509Certificate)7 LinkedList (java.util.LinkedList)7 ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)2 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)2 ProvisioningDeviceSecurityException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceSecurityException)1 RegistrationOperationStatusParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.RegistrationOperationStatusParser)1 SecurityProviderSymmetricKey (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey)1 SecurityProviderTpm (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm)1 IOException (java.io.IOException)1 SSLContext (javax.net.ssl.SSLContext)1