Search in sources :

Example 11 with SecurityProviderDiceEmulator

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

the class SecurityProviderDiceEmulatorTest method getterForAliasCertSucceeds.

// SRS_SecurityClientDiceEmulator_25_006: [ This method shall return Alias certificate generated by DICE ]
@Test
public void getterForAliasCertSucceeds() throws Exception {
    // arrange
    SecurityProviderDiceEmulator testSecurityClientDiceEmulator = new SecurityProviderDiceEmulator(TEST_ALIAS, TEST_SIGNER, TEST_ROOT);
    // act
    X509Certificate cert = testSecurityClientDiceEmulator.getClientCertificate();
    // assert
    assertNotNull(cert);
}
Also used : SecurityProviderDiceEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderDiceEmulator) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 12 with SecurityProviderDiceEmulator

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

the class ProvisioningX509CertGen method main.

public static void main(String[] args) {
    try {
        String aliasCertCnName, rootCertCnName, signerCertCnName;
        SecurityProviderDiceEmulator securityClient;
        Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
        System.out.println("Do you want to input common name : Y/N(use default)");
        String isCnName = scanner.next();
        if (isCnName.equalsIgnoreCase("Y")) {
            System.out.println("Input Client Cert commonName :");
            aliasCertCnName = scanner.next();
            System.out.println("Input Root Cert commonName :");
            rootCertCnName = scanner.next();
            System.out.println("Input Signer Cert commonName :");
            signerCertCnName = scanner.next();
            securityClient = new SecurityProviderDiceEmulator(aliasCertCnName, signerCertCnName, rootCertCnName);
        } else {
            securityClient = new SecurityProviderDiceEmulator();
        }
        System.out.println("Your registration Id is : " + securityClient.getRegistrationId());
        System.out.println("Client Cert");
        System.out.println(securityClient.getAliasCertPem());
        System.out.println("Client Cert Private Key");
        System.out.println(securityClient.getAliasCertPrivateKeyPem());
        System.out.println("Signer (Intermediate) Cert");
        System.out.println(securityClient.getSignerCertPem());
        System.out.println("Root Cert");
        System.out.println(securityClient.getRootCertPem());
        System.out.println("Do you want to input Verification Code Y/N");
        String isVerify = scanner.next();
        try {
            if (isVerify.equalsIgnoreCase("Y")) {
                System.out.println("Input Verification Code");
                scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
                {
                    String verificationCode = scanner.next();
                    if (verificationCode != null) {
                        System.out.println("Verification Cert");
                        System.out.println(securityClient.generateLeafCert(verificationCode));
                    }
                }
            }
        } catch (SecurityProviderException e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Shutting down...");
    }
}
Also used : Scanner(java.util.Scanner) SecurityProviderException(com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException) SecurityProviderDiceEmulator(com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderDiceEmulator) SecurityProviderException(com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)

Aggregations

SecurityProviderDiceEmulator (com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderDiceEmulator)12 Test (org.junit.Test)11 X509Certificate (java.security.cert.X509Certificate)2 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)1 Key (java.security.Key)1 Scanner (java.util.Scanner)1