Exemple #1
0
        // Install a signed leaft X509 Cert in a Device HSM-based
        private IIoTDevice InjectChainOfTrust(IIoTDevice device,
                                              X509Certificate2Collection chain)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            X509Certificate2 deviceLeafCert = null;

            // Create csr for a Device
            CertificateRequest deviceLeafRequest =
                X509CertificateOperations.CreateChainRequest(
                    this.GenerateLeafCertDistinguishedName(
                        device
                        .HardwareSecurityModel
                        .GetUniqueDeviceId),
                    device.HardwareSecurityModel.GetPublicKey,
                    HashAlgorithmName.SHA256,
                    false, null);

            // issue a signed leaf crt
            deviceLeafCert = this.CreateSignedCrt(deviceLeafRequest);

            device.HardwareSecurityModel.StoreX509Cert(deviceLeafCert, chain);

            return(device);
        }
Exemple #2
0
        public void IoTCompanyMakeAnIoTDeviceSucessfully()
        {
            // Arrange
            var mockProvisioningService = new Mock <IProvisioningService>();

            mockProvisioningService
            .Setup(
                pS => pS.CleanUpAndCreateEnrollmentGroupAsync(
                    It.IsAny <Attestation>()))
            .Returns(Task.FromResult(true));
            var mockFactory = new Mock <IIoTHardwareIntegrator>();

            mockFactory
            .Setup(
                f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                Task.FromResult <IIoTDevice>(new Mock <IIoTDevice>().Object));
            IIoTCompany company = new IoTCompany(
                this.config.Object,
                mockProvisioningService.Object,
                mockFactory.Object);

            IIoTDevice brandNewIoTDevice = null;

            // Act
            company.CleanUpAndCreateEnrollmentGroupAsync().GetAwaiter().GetResult();
            brandNewIoTDevice = company.MakeDeviceAsync().GetAwaiter().GetResult();

            // Assert
            Assert.NotNull(brandNewIoTDevice);
            mockFactory.Verify(f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>()));
        }
Exemple #3
0
 public async Task ShipAsync(IIoTDevice device,
                             string dpsGlobalEndpoint,
                             string dpsScopeId)
 {
     await this.Deployer.InstallAsync(device,
                                      dpsGlobalEndpoint,
                                      dpsScopeId)
     .ConfigureAwait(false);
 }
Exemple #4
0
        public IoTService(IIoTDevice iotDevice, ILogger logger)
        {
            _iotDevice = iotDevice;
            _logger    = logger.ForContext <IoTService>();

            ServiceName  = FullServiceName;
            EventLog.Log = "Application";

            CanStop = true;
            AutoLog = true;
        }
Exemple #5
0
#pragma warning disable CA1822 // Mark members as static
        public void IIoTDeviceIsProperlyInitialized()
#pragma warning restore CA1822 // Mark members as static
        {
            // Arrange
            IIoTDevice device = null;

            // Act
            device = new IoTDevice();

            // Assert
            Assert.NotNull(device.HardwareSecurityModel);
            Assert.True(string.IsNullOrEmpty(device.DeviceID));
            Assert.True(string.IsNullOrEmpty(device.AssignedIoTHub));
        }
Exemple #6
0
        public async Task InstallAsync(IIoTDevice device, string dpsGlobalEndpoint, string dpsScopeId)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            var chain = new X509Certificate2Collection();

            this.CollectCerts(this, chain);
            this.InjectChainOfTrust(device, chain);
            // provisioning here
            await device.ProvisionAsync(dpsGlobalEndpoint, dpsScopeId).ConfigureAwait(false);
        }