Skip to content

Commit

Permalink
Added OpenSSL compatibility for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
cartertinney authored and Azure IoT Builder committed Mar 19, 2018
1 parent 20a39e7 commit 4482798
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ compileAsC99()

set(prov_sc_bulk_operation_sample_c_files
prov_sc_bulk_operation_sample.c
../../../certs/certs.c
)

set (prov_sc_bulk_operation_sample_h_files
Expand All @@ -25,5 +26,14 @@ add_executable(prov_sc_bulk_operation_sample ${prov_sc_bulk_operation_sample_c_f
target_link_libraries(prov_sc_bulk_operation_sample
provisioning_service_client)

if(${use_openssl})
add_definitions(-DUSE_OPENSSL)
if (WIN32)
target_link_libraries(prov_sc_bulk_operation_sample $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)
file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
endif()

linkSharedUtil(prov_sc_bulk_operation_sample)
linkUHTTP(prov_sc_bulk_operation_sample)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@

#include "azure_c_shared_utility/platform.h"

#include "../../../certs/certs.h"

#include "provisioning_service_client.h"

static bool g_use_trace = true;

#ifdef USE_OPENSSL
static bool g_use_certificate = true;
#else
static bool g_use_certificate = false;
#endif //USE_OPENSSL

int main()
{
int result = 0;
Expand All @@ -24,7 +34,14 @@ int main()
PROVISIONING_SERVICE_CLIENT_HANDLE prov_sc = prov_sc_create_from_connection_string(connectionString);

/* ---Optionally set connection options---*/
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
if (g_use_trace)
{
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
}
if (g_use_certificate)
{
prov_sc_set_certificate(prov_sc, certificates);
}

/* ---Build the array of individual enrollments to run bulk operations on--- */
ATTESTATION_MECHANISM_HANDLE am1 = attestationMechanism_createWithTpm(endorsementKey, NULL);
Expand Down Expand Up @@ -66,6 +83,7 @@ int main()

/* ---Destroy the provisioning service client handle--- */
prov_sc_destroy(prov_sc);
platform_deinit();

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

This is a quick tutorial with the steps to create and delete Individual Enrollmens with Bulk Operations on the Microsoft Azure IoT Hub Device Provisioning Service using the C SDK.
This is a quick tutorial with the steps to create and delete Individual Enrollments with Bulk Operations on the Microsoft Azure IoT Hub Device Provisioning Service using the C SDK.

## References

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ compileAsC99()

set(prov_sc_enrollment_group_sample_c_files
prov_sc_enrollment_group_sample.c
../../../certs/certs.c
)

set (prov_sc_enrollment_group_sample_h_files
Expand All @@ -25,5 +26,14 @@ add_executable(prov_sc_enrollment_group_sample ${prov_sc_enrollment_group_sample
target_link_libraries(prov_sc_enrollment_group_sample
provisioning_service_client)

if(${use_openssl})
add_definitions(-DUSE_OPENSSL)
if (WIN32)
target_link_libraries(prov_sc_enrollment_group_sample $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)
file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
endif()

linkSharedUtil(prov_sc_enrollment_group_sample)
linkUHTTP(prov_sc_enrollment_group_sample)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@

#include "azure_c_shared_utility/platform.h"

#include "../../../certs/certs.h"

#include "provisioning_service_client.h"

static bool g_use_trace = true;

#ifdef USE_OPENSSL
static bool g_use_certificate = true;
#else
static bool g_use_certificate = false;
#endif //USE_OPENSSL

int main()
{
int result = 0;
Expand Down Expand Up @@ -37,8 +47,14 @@ int main()
prov_sc = prov_sc_create_from_connection_string(connectionString);

/* ---Optionally set connection options--- */
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
//Other options can also be set here - refer to the APIs
if (g_use_trace)
{
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
}
if (g_use_certificate)
{
prov_sc_set_certificate(prov_sc, certificates);
}

/* ---Create an Enrollment Group structure--- */
printf("Creating an Enrollment Group structure...\n");
Expand Down Expand Up @@ -81,6 +97,7 @@ int main()
/* ---Clean up handles--- */
enrollmentGroup_destroy(eg_handle);
prov_sc_destroy(prov_sc);
platform_deinit();

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ compileAsC99()

set(prov_sc_individual_enrollment_sample_c_files
prov_sc_individual_enrollment_sample.c
../../../certs/certs.c
)

set (prov_sc_individual_enrollment_sample_h_files
Expand All @@ -25,5 +26,15 @@ add_executable(prov_sc_individual_enrollment_sample ${prov_sc_individual_enrollm
target_link_libraries(prov_sc_individual_enrollment_sample
provisioning_service_client)

if(${use_openssl})
add_definitions(-DUSE_OPENSSL)
if (WIN32)
target_link_libraries(prov_sc_individual_enrollment_sample $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)
file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
endif()


linkSharedUtil(prov_sc_individual_enrollment_sample)
linkUHTTP(prov_sc_individual_enrollment_sample)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@

#include "azure_c_shared_utility/platform.h"

#include "../../../certs/certs.h"

#include "provisioning_service_client.h"

static bool g_use_trace = true;

#ifdef USE_OPENSSL
static bool g_use_certificate = true;
#else
static bool g_use_certificate = false;
#endif //USE_OPENSSL

int main()
{
int result = 0;
Expand Down Expand Up @@ -38,8 +48,14 @@ int main()
prov_sc = prov_sc_create_from_connection_string(connectionString);

/* ---Optionally set connection options--- */
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
//Other options can also be set here - refer to the APIs
if (g_use_trace)
{
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
}
if (g_use_certificate)
{
prov_sc_set_certificate(prov_sc, certificates);
}

/* ---Create an Individual Enrollment structure--- */
printf("Creating an Individual Enrollment structure...\n");
Expand Down Expand Up @@ -83,6 +99,7 @@ int main()
/* ---Clean up handles--- */
individualEnrollment_destroy(ie_handle);
prov_sc_destroy(prov_sc);
platform_deinit();

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ compileAsC99()

set(prov_sc_query_sample_c_files
prov_sc_query_sample.c
../../../certs/certs.c
)

set (prov_sc_query_sample_h_files
Expand All @@ -25,5 +26,14 @@ add_executable(prov_sc_query_sample ${prov_sc_query_sample_c_files} ${prov_sc_qu
target_link_libraries(prov_sc_query_sample
provisioning_service_client)

if(${use_openssl})
add_definitions(-DUSE_OPENSSL)
if (WIN32)
target_link_libraries(prov_sc_query_sample $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)
file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
endif()

linkSharedUtil(prov_sc_query_sample)
linkUHTTP(prov_sc_query_sample)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@

#include "azure_c_shared_utility/platform.h"

#include "../../../certs/certs.h"

#include "provisioning_service_client.h"

static bool g_use_trace = true;

#ifdef USE_OPENSSL
static bool g_use_certificate = true;
#else
static bool g_use_certificate = false;
#endif //USE_OPENSSL

void print_ie_results(PROVISIONING_QUERY_RESPONSE* query_resp)
{
for (int i = 0; i < (int)query_resp->response_arr_size; i++)
Expand All @@ -30,7 +40,14 @@ int main()
PROVISIONING_SERVICE_CLIENT_HANDLE prov_sc = prov_sc_create_from_connection_string(connectionString);

/* ---Optionally set connection options---*/
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
if (g_use_trace)
{
prov_sc_set_trace(prov_sc, TRACING_STATUS_ON);
}
if (g_use_certificate)
{
prov_sc_set_certificate(prov_sc, certificates);
}

/* ---Set the Query Specification details for enrollments--- */
PROVISIONING_QUERY_SPECIFICATION query_spec = { 0 };
Expand All @@ -55,6 +72,7 @@ int main()
/* ---Cleanup memory---*/
free(cont_token);
prov_sc_destroy(prov_sc);
platform_deinit();

return result;
}
2 changes: 2 additions & 0 deletions provisioning_service_client/samples/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ In order to run the samples, you will first need to do the following:

* [Individual Enrollment](prov_sc_individual_enrollment_sample) - Create, update, get and delete Individual Enrollments on the Provisioning Service.
* [Enrollment Group](prov_sc_enrollment_group_sample) - Create, update, get and delete Enrollment Groups on the Provisioning Service.
* [Bulk Enrollment](prov_sc_bulk_operation_sample) - Run bulk enrollment operations for Individual Enrollments on the Provisioning Service.
* [Query](prov_sc_query_sample) - Run a query operation on the Provisioning Service

[setup-iot-hub]: https://aka.ms/howtocreateazureiothub
[setup-provisioning-service]: https://docs.microsoft.com/en-us/azure/iot-dps/quick-setup-auto-provision
Expand Down

0 comments on commit 4482798

Please sign in to comment.