public override void ExecuteCmdlet()
        {
            Path = ResolveUserPath(Path);
            if (ShouldProcess(CertificateName, Properties.Resources.VerifyIotHubCertificate))
            {
                string   certificate = string.Empty;
                FileInfo fileInfo    = new FileInfo(this.Path);
                switch (fileInfo.Extension.ToLower(CultureInfo.InvariantCulture))
                {
                case ".cer":
                    var certificateByteContent = File.ReadAllBytes(this.Path);
                    certificate = Convert.ToBase64String(certificateByteContent);
                    break;

                case ".pem":
                    certificate = File.ReadAllText(this.Path);
                    break;

                default:
                    certificate = this.Path;
                    break;
                }

                if (ParameterSetName.Equals(InputObjectParameterSet))
                {
                    this.ResourceGroupName = this.InputObject.ResourceGroupName;
                    this.Name            = this.InputObject.Name;
                    this.CertificateName = this.InputObject.CertificateName;
                    this.Etag            = this.InputObject.Etag;
                }

                if (ParameterSetName.Equals(ResourceIdParameterSet))
                {
                    this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
                    this.Name            = IotHubUtils.GetIotHubName(this.ResourceId);
                    this.CertificateName = IotHubUtils.GetIotHubCertificateName(this.ResourceId);
                }

                try
                {
                    certificate = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(certificate));

                    CertificateVerificationDescription certificateVerificationDescription = new CertificateVerificationDescription();
                    certificateVerificationDescription.Certificate = certificate;

                    CertificateDescription certificateDescription = this.IotHubClient.Certificates.Verify(this.ResourceGroupName, this.Name, this.CertificateName, certificateVerificationDescription, this.Etag);
                    this.WriteObject(IotHubUtils.ToPSCertificateDescription(certificateDescription));
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Verify certificate's private key possession.
 /// </summary>
 /// <remarks>
 /// Verifies the certificate's private key possession by providing the leaf
 /// cert issued by the verifying pre uploaded certificate.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the IoT hub.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the IoT hub.
 /// </param>
 /// <param name='certificateName'>
 /// The name of the certificate
 /// </param>
 /// <param name='certificateVerificationBody'>
 /// The name of the certificate
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Certificate.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <CertificateDescription> VerifyAsync(this ICertificatesOperations operations, string resourceGroupName, string resourceName, string certificateName, CertificateVerificationDescription certificateVerificationBody, string ifMatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.VerifyWithHttpMessagesAsync(resourceGroupName, resourceName, certificateName, certificateVerificationBody, ifMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Verify certificate's private key possession.
 /// </summary>
 /// <remarks>
 /// Verifies the certificate's private key possession by providing the leaf
 /// cert issued by the verifying pre uploaded certificate.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the IoT hub.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the IoT hub.
 /// </param>
 /// <param name='certificateName'>
 /// The name of the certificate
 /// </param>
 /// <param name='certificateVerificationBody'>
 /// The name of the certificate
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Certificate.
 /// </param>
 public static CertificateDescription Verify(this ICertificatesOperations operations, string resourceGroupName, string resourceName, string certificateName, CertificateVerificationDescription certificateVerificationBody, string ifMatch)
 {
     return(operations.VerifyAsync(resourceGroupName, resourceName, certificateName, certificateVerificationBody, ifMatch).GetAwaiter().GetResult());
 }