Search in sources :

Example 1 with X509ThumbprintParser

use of com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser in project azure-iot-sdk-java by Azure.

the class X509ThumbprintParserTest method testGettersAndSetters.

// Tests_SRS_X509ThumbprintParser_34_001: [This method shall return the value of primaryThumbprint]
// Tests_SRS_X509ThumbprintParser_34_003: [This method shall set the value of primaryThumbprint to the provided value.]
// Tests_SRS_X509ThumbprintParser_34_004: [This method shall return the value of secondaryThumbprint]
// Tests_SRS_X509ThumbprintParser_34_006: [This method shall set the value of secondaryThumbprint to the provided value.]
@Test
public void testGettersAndSetters() {
    // arrange
    X509ThumbprintParser parser = new X509ThumbprintParser();
    // act
    parser.setPrimaryThumbprint(SAMPLE_THUMBPRINT1);
    parser.setSecondaryThumbprint(SAMPLE_THUMBPRINT2);
    // assert
    assertEquals(SAMPLE_THUMBPRINT1, parser.getPrimaryThumbprintFinal());
    assertEquals(SAMPLE_THUMBPRINT2, parser.getSecondaryThumbprintFinal());
}
Also used : X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) Test(org.junit.Test)

Example 2 with X509ThumbprintParser

use of com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser in project azure-iot-sdk-java by Azure.

the class X509ThumbprintParserTest method testFromThumbprints.

// Tests_SRS_X509ThumbprintParser_34_008: [The parser shall create and return an instance of a X509ThumbprintParser object that holds the provided primary and secondary thumbprints.]
@Test
public void testFromThumbprints() {
    // act
    X509ThumbprintParser parser = new X509ThumbprintParser(SAMPLE_THUMBPRINT1, SAMPLE_THUMBPRINT2);
    // assert
    String actualPrimaryThumbprint = Deencapsulation.getField(parser, "primaryThumbprint");
    String actualSecondaryThumbprint = Deencapsulation.getField(parser, "secondaryThumbprint");
    assertEquals(SAMPLE_THUMBPRINT1, actualPrimaryThumbprint);
    assertEquals(SAMPLE_THUMBPRINT2, actualSecondaryThumbprint);
}
Also used : X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) Test(org.junit.Test)

Example 3 with X509ThumbprintParser

use of com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser in project azure-iot-sdk-java by Azure.

the class AuthenticationParserTest method testThumbprintParserProperty.

// Tests_SRS_AUTHENTICATION_PARSER_34_004: [This method shall return the value of this object's thumbprint.]
// Tests_SRS_AUTHENTICATION_PARSER_34_005: [This method shall set the value of this object's thumbprint equal to the provided value.]
@Test
public void testThumbprintParserProperty() {
    // arrange
    AuthenticationParser parser = new AuthenticationParser();
    X509ThumbprintParser thumbprintParser = new X509ThumbprintParser();
    thumbprintParser.setPrimaryThumbprint("1234");
    thumbprintParser.setSecondaryThumbprint("5678");
    // act
    parser.setThumbprint(thumbprintParser);
    // assert
    assertEquals(thumbprintParser, parser.getThumbprint());
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) Test(org.junit.Test)

Example 4 with X509ThumbprintParser

use of com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser in project azure-iot-sdk-java by Azure.

the class Tools method addModules.

private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
    if (modules == null) {
        throw new IllegalArgumentException("modules cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Module module : modules) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(module.getDeviceId());
        exportImportDevice.setModuleId(module.getId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (module.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Module(com.microsoft.azure.sdk.iot.service.Module) URL(java.net.URL)

Example 5 with X509ThumbprintParser

use of com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser in project azure-iot-sdk-java by Azure.

the class Tools method addDevices.

private static void addDevices(Iterable<Device> devices, String connectionString) throws IOException, IotHubException {
    if (devices == null) {
        throw new IllegalArgumentException("devices cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Device device : devices) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(device.getDeviceId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (device.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(device.getSymmetricKey().getPrimaryKey(), device.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(device.getPrimaryThumbprint(), device.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Device(com.microsoft.azure.sdk.iot.service.Device) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL)

Aggregations

X509ThumbprintParser (com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser)7 Test (org.junit.Test)5 AuthenticationParser (com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser)3 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)2 SymmetricKeyParser (com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Device (com.microsoft.azure.sdk.iot.service.Device)1 Module (com.microsoft.azure.sdk.iot.service.Module)1