-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Code of conduct. E2E tests for provisioning client. Adding logging for both prod and test code. Updating API Removing Dice Changing HSM API to sync. Fixing Android sample. Adding SecurityClientX509 Adding ProvisioningTransportHandle delegating pipeline. Refactoring HTTP and AMQP code. Adding chain CertificateInstaller to support Group Enrollment. TPM, X509 samples
- Loading branch information
Showing
113 changed files
with
3,847 additions
and
1,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
common/src/device/provisioning/Logging.ProvisioningDeviceClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Microsoft.Azure.Devices.Shared | ||
{ | ||
[EventSource(Name = "Microsoft-Azure-Devices-Provisioning-Client")] | ||
internal sealed partial class Logging : EventSource | ||
{ | ||
[NonEvent] | ||
public static void RegisterAsync( | ||
object thisOrContextObject, | ||
string globalDeviceEndpoint, | ||
string idScope, | ||
object transport, | ||
object security) | ||
{ | ||
DebugValidateArg(thisOrContextObject); | ||
DebugValidateArg(security); | ||
DebugValidateArg(transport); | ||
|
||
if (IsEnabled) Log.RegisterAsync( | ||
IdOf(thisOrContextObject), | ||
globalDeviceEndpoint, | ||
idScope, | ||
IdOf(transport), | ||
IdOf(security)); | ||
} | ||
|
||
[Event(RegisterAsyncId, Keywords = Keywords.Default, Level = EventLevel.Informational)] | ||
private void RegisterAsync( | ||
string thisOrContextObject, | ||
string globalDeviceEndpoint, | ||
string idScope, | ||
string transport, | ||
string security) => | ||
WriteEvent(RegisterAsyncId, thisOrContextObject, globalDeviceEndpoint, idScope, transport, security); | ||
|
||
[NonEvent] | ||
public static void RegisterDevice( | ||
object thisOrContextObject, | ||
string registrationId, | ||
string idScope, | ||
string attestationType, | ||
string operationId, | ||
TimeSpan? retryAfter, | ||
string status) | ||
{ | ||
DebugValidateArg(thisOrContextObject); | ||
DebugValidateArg(attestationType); | ||
DebugValidateArg(retryAfter); | ||
if (IsEnabled) Log.RegisterDevice( | ||
IdOf(thisOrContextObject), | ||
registrationId, | ||
idScope, | ||
attestationType, | ||
operationId, | ||
(int)(retryAfter?.TotalSeconds), | ||
status); | ||
} | ||
|
||
[Event(RegisterDeviceId, Keywords = Keywords.Default, Level = EventLevel.Informational)] | ||
private void RegisterDevice( | ||
string thisOrContextObject, | ||
string registrationId, | ||
string idScope, | ||
string attestationType, | ||
string operationId, | ||
int retryAfterSeconds, | ||
string status) => | ||
WriteEvent( | ||
RegisterDeviceId, | ||
thisOrContextObject, | ||
registrationId, | ||
idScope, | ||
attestationType, | ||
operationId, | ||
retryAfterSeconds, | ||
status); | ||
|
||
[NonEvent] | ||
public static void OperationStatusLookup( | ||
object thisOrContextObject, | ||
string registrationId, | ||
string operationId, | ||
TimeSpan? retryAfter, | ||
string status, | ||
int attempts) | ||
{ | ||
DebugValidateArg(thisOrContextObject); | ||
DebugValidateArg(retryAfter); | ||
|
||
if (IsEnabled) Log.OperationStatusLookup( | ||
IdOf(thisOrContextObject), | ||
registrationId, | ||
operationId, | ||
(int)(retryAfter?.TotalSeconds), | ||
status, | ||
attempts); | ||
} | ||
|
||
[Event(OperationStatusLookupId, Keywords = Keywords.Default, Level = EventLevel.Informational)] | ||
private void OperationStatusLookup( | ||
string thisOrContextObject, | ||
string registrationId, | ||
string operationId, | ||
int retryAfterSeconds, | ||
string status, | ||
int attempts) => | ||
WriteEvent( | ||
OperationStatusLookupId, | ||
thisOrContextObject, | ||
registrationId, | ||
operationId, | ||
retryAfterSeconds, | ||
status, | ||
attempts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Microsoft.Azure.Devices.E2ETests | ||
{ | ||
public partial class Configuration | ||
{ | ||
public static partial class IoTHub | ||
{ | ||
public static string ConnectionString => GetValue("IOTHUB_CONN_STRING_CSHARP"); | ||
|
||
public static string ConsumerGroup => GetValue("IOTHUB_EVENTHUB_CONSUMER_GROUP", "$Default"); | ||
|
||
public static X509Certificate2 GetCertificateWithPrivateKey() | ||
=> GetBase64EncodedCertificate("IOTHUB_X509_PFX_CERTIFICATE"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Microsoft.Azure.Devices.E2ETests | ||
{ | ||
public partial class Configuration | ||
{ | ||
public static partial class Provisioning | ||
{ | ||
public const string CertificatePassword = "testcertificate"; | ||
|
||
public static string GlobalDeviceEndpoint => | ||
GetValue("DPS_GLOBALDEVICEENDPOINT", "global.azure-devices-provisioning.net"); | ||
|
||
public static string IdScope => GetValue("DPS_IDSCOPE"); | ||
|
||
public static string TpmDeviceRegistrationId => GetValue("DPS_TPM_REGISTRATIONID"); | ||
|
||
public static string TpmDeviceId => GetValue("DPS_TPM_DEVICEID"); | ||
|
||
// To generate use Powershell: [System.Convert]::ToBase64String( (Get-Content .\certificate.pfx -Encoding Byte) ) | ||
public static X509Certificate2 GetIndividualEnrollmentCertificate() | ||
=> GetBase64EncodedCertificate("DPS_INDIVIDUALX509_PFX_CERTIFICATE", CertificatePassword); | ||
|
||
public static X509Certificate2 GetGroupEnrollmentCertificate() | ||
=> GetBase64EncodedCertificate("DPS_GROUPX509_PFX_CERTIFICATE", CertificatePassword); | ||
|
||
public static X509Certificate2Collection GetGroupEnrollmentChain() | ||
=> GetBase64EncodedCertificateCollection("DPS_GROUPX509_CERTIFICATE_CHAIN"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Microsoft.Azure.Devices.E2ETests | ||
{ | ||
public partial class Configuration | ||
{ | ||
private static string GetValue(string envName, string defaultValue=null) | ||
{ | ||
string envValue = Environment.GetEnvironmentVariable(envName); | ||
|
||
if (string.IsNullOrWhiteSpace(envValue)) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
return Environment.ExpandEnvironmentVariables(envValue); | ||
} | ||
|
||
private static Uri GetUriValue(string envName, Uri defaultValue=null) | ||
{ | ||
string envValue = GetValue(envName, null); | ||
|
||
if (envValue == null) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
return new Uri(envValue); | ||
} | ||
|
||
// To generate environment variables value use | ||
// [Convert]::ToBase64String((Get-Content myFileName -Encoding Byte)). | ||
|
||
private static X509Certificate2 GetBase64EncodedCertificate(string envName, string password=null, string defaultValue=null) | ||
{ | ||
string certBase64 = GetValue(envName, null); | ||
|
||
if (certBase64 == null) | ||
{ | ||
certBase64 = defaultValue; | ||
} | ||
|
||
Byte[] buff = Convert.FromBase64String(certBase64); | ||
|
||
if (password == null) | ||
{ | ||
return new X509Certificate2(buff); | ||
} | ||
else | ||
{ | ||
return new X509Certificate2(buff, password); | ||
} | ||
} | ||
|
||
private static X509Certificate2Collection GetBase64EncodedCertificateCollection( | ||
string envName, | ||
string defaultValue = null) | ||
{ | ||
string certBase64 = GetValue(envName, null); | ||
|
||
if (certBase64 == null) | ||
{ | ||
certBase64 = defaultValue; | ||
} | ||
|
||
Byte[] buff = Convert.FromBase64String(certBase64); | ||
var collection = new X509Certificate2Collection(); | ||
collection.Import(buff); | ||
return collection; | ||
} | ||
} | ||
} |
Oops, something went wrong.