Skip to content

Commit 2f09b01

Browse files
committed
Fixing style cop issues
1 parent 495817a commit 2f09b01

File tree

7 files changed

+204
-134
lines changed

7 files changed

+204
-134
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesVaultClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class PSRecoveryServicesClient
2727
/// Updates the vault certificate
2828
/// </summary>
2929
/// <param name="args">the certificate update arguments</param>
30-
/// <returns>UploadCertificateResponse</returns>
30+
/// <returns>Upload Certificate Response</returns>
3131
public async Task<UploadCertificateResponse> UpdateVaultCertificate(CertificateArgs args)
3232
{
3333
return await this.GetSiteRecoveryClient().Vaults.UploadCertificateAsync(args, this.GetRequestHeaders(false));

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesVaultExtendedInfoClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public partial class PSRecoveryServicesClient
2626
/// <summary>
2727
/// Gets Vault Extended Information
2828
/// </summary>
29-
/// <returns>ResourceExtendedInformationResponse</returns>
29+
/// <returns>Vault Extended Information Response</returns>
3030
public async Task<ResourceExtendedInformation> GetExtendedInfo()
3131
{
3232
ResourceExtendedInformationResponse response = await this.GetSiteRecoveryClient().VaultExtendedInfo.GetExtendedInfoAsync(this.GetRequestHeaders(false));
@@ -37,8 +37,8 @@ public async Task<ResourceExtendedInformation> GetExtendedInfo()
3737
/// <summary>
3838
/// Creates the extended information for the vault
3939
/// </summary>
40-
/// <param name="extendedInfoArgs">extneded info to be created</param>
41-
/// <returns>ResourceExtendedInformation</returns>
40+
/// <param name="extendedInfoArgs">extended info to be created</param>
41+
/// <returns>Vault Extended Information</returns>
4242
public async Task<ResourceExtendedInformation> CreateExtendedInfo(ResourceExtendedInformationArgs extendedInfoArgs)
4343
{
4444
ResourceExtendedInformationResponse response = await this.GetSiteRecoveryClient().VaultExtendedInfo.CreateExtendedInfoAsync(extendedInfoArgs, this.GetRequestHeaders(false));

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/GetVaultCredentialsFile.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
using System.Management.Automation;
1717
using System.Security.Cryptography.X509Certificates;
1818
using System.Threading.Tasks;
19-
using Microsoft.Azure.Commands.RecoveryServices.lib;
2019
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
2120
using Microsoft.Azure.Portal.HybridServicesCore;
2221
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
23-
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2422
using Microsoft.WindowsAzure.Commands.Common;
2523
using Microsoft.WindowsAzure.Commands.Common.Models;
24+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2625

2726
namespace Microsoft.Azure.Commands.RecoveryServices
2827
{
@@ -33,6 +32,9 @@ namespace Microsoft.Azure.Commands.RecoveryServices
3332
[OutputType(typeof(string))]
3433
public class GetVaultCredentialsFile : RecoveryServicesCmdletBase
3534
{
35+
/// <summary>
36+
/// Expiry in hours for generated certificate.
37+
/// </summary>
3638
private const int VaultCertificateExpiryInHoursForHRM = 120;
3739

3840
#region Parameters
@@ -49,7 +51,7 @@ public class GetVaultCredentialsFile : RecoveryServicesCmdletBase
4951
/// </summary>
5052
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "Vault Name for which the cred file to be generated")]
5153
[ValidateNotNullOrEmpty]
52-
// TODO: devsri - Remove this.
54+
//// TODO: devsri - Remove this.
5355
public string CloudServiceName { get; set; }
5456

5557
/// <summary>
@@ -68,8 +70,7 @@ public class GetVaultCredentialsFile : RecoveryServicesCmdletBase
6870
/// <summary>
6971
/// Gets or sets the path where the credential file is to be generated
7072
/// </summary>
71-
[Parameter(ParameterSetName = ASRParameterSets.ByParam, Mandatory =false, HelpMessage = "The path where the vault credential file is to be created.")]
72-
// TODO:devsri - add file path validator over here.
73+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, Mandatory = false, HelpMessage = "The path where the vault credential file is to be created.")]
7374
public string Path { get; set; }
7475

7576
#endregion Parameters
@@ -119,6 +120,11 @@ public override async void ExecuteCmdlet()
119120
}
120121
}
121122

123+
/// <summary>
124+
/// Method to update vault certificate
125+
/// </summary>
126+
/// <param name="cert">certificate object </param>
127+
/// <returns>Upload Certificate Response</returns>
122128
private async Task<UploadCertificateResponse> UpdateVaultCertificate(X509Certificate2 cert)
123129
{
124130
var certificateArgs = new CertificateArgs()
@@ -132,6 +138,10 @@ private async Task<UploadCertificateResponse> UpdateVaultCertificate(X509Certifi
132138
return response;
133139
}
134140

141+
/// <summary>
142+
/// Get the Integrity key
143+
/// </summary>
144+
/// <returns>key as string.</returns>
135145
private async Task<string> GetChannelIntegrityKey()
136146
{
137147
ResourceExtendedInformation extendedInformation;
@@ -141,7 +151,7 @@ private async Task<string> GetChannelIntegrityKey()
141151
}
142152
catch (Exception)
143153
{
144-
//TODO:devsri - Handle specific error rather than generic once
154+
// TODO:devsri - Handle specific error rather than generic once
145155
extendedInformation = new ResourceExtendedInformation();
146156
}
147157

@@ -158,6 +168,16 @@ private async Task<string> GetChannelIntegrityKey()
158168
return extendedInfo.ChannelIntegrityKey;
159169
}
160170

171+
/// <summary>
172+
/// Method to generate the credential file content
173+
/// </summary>
174+
/// <param name="subscriptionId">subscription id</param>
175+
/// <param name="resourceName">resource name</param>
176+
/// <param name="managementCert">management cert</param>
177+
/// <param name="acsDetails">ACS details</param>
178+
/// <param name="channelIntegrityKey">Integrity key</param>
179+
/// <param name="cloudServiceName">cloud service name</param>
180+
/// <returns>vault credential object</returns>
161181
private ASRVaultCreds GenerateCredential(string subscriptionId, string resourceName, X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, string cloudServiceName)
162182
{
163183
string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));
@@ -175,6 +195,10 @@ private ASRVaultCreds GenerateCredential(string subscriptionId, string resourceN
175195
return vaultCreds;
176196
}
177197

198+
/// <summary>
199+
/// Method to generate the file name
200+
/// </summary>
201+
/// <returns>file name as string.</returns>
178202
private string GenerateFileName()
179203
{
180204
string fileName;

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/CertUtils.cs

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,57 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.IO;
1617
using System.Security.Cryptography;
1718
using System.Security.Cryptography.X509Certificates;
1819
using Security.Cryptography;
1920
using Security.Cryptography.X509Certificates;
20-
using System.IO;
21-
using System.Runtime.InteropServices;
22-
using System.ComponentModel;
2321

24-
namespace Microsoft.Azure.Commands.RecoveryServices.lib
22+
namespace Microsoft.Azure.Commands.RecoveryServices
2523
{
24+
/// <summary>
25+
/// Class to provide methods to manage the certificates.
26+
/// </summary>
2627
public static class CertUtils
2728
{
28-
public const string MsEnhancedProv = "Microsoft Enhanced Cryptographic Provider v1.0"; // MS_ENHANCED_PROV;
29-
private const string DefaultIssuer = "CN=Windows Azure Tools";
30-
private const string DefaultPassword = "";
29+
/// <summary>
30+
/// Enhancement provider
31+
/// </summary>
32+
private const string MsEnhancedProv = "Microsoft Enhanced Cryptographic Provider v1.0";
3133

32-
public const string OIDClientAuthValue = "1.3.6.1.5.5.7.3.2";
33-
public const string OIDClientAuthFriendlyName = "Client Authentication";
34-
public const int KeySize2048 = 2048;
34+
/// <summary>
35+
/// Client Authentication Value
36+
/// </summary>
37+
private const string OIDClientAuthValue = "1.3.6.1.5.5.7.3.2";
3538

3639
/// <summary>
37-
/// Windows Azure Service Management API requires 2048bit RSA keys.
38-
/// The private key needs to be exportable so we can save it to .pfx for sharing with team members.
40+
/// Client Authentication Friendly name
3941
/// </summary>
40-
/// <returns>A 2048 bit RSA key</returns>
41-
private static CngKey Create2048RsaKey()
42-
{
43-
var keyCreationParameters = new CngKeyCreationParameters
44-
{
45-
ExportPolicy = CngExportPolicies.AllowExport,
46-
KeyCreationOptions = CngKeyCreationOptions.None,
47-
KeyUsage = CngKeyUsages.AllUsages,
48-
Provider = new CngProvider(MsEnhancedProv)
49-
};
42+
private const string OIDClientAuthFriendlyName = "Client Authentication";
5043

51-
keyCreationParameters.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(KeySize2048), CngPropertyOptions.None));
44+
/// <summary>
45+
/// Key size
46+
/// </summary>
47+
private const int KeySize2048 = 2048;
5248

53-
return CngKey.Create(CngAlgorithm2.Rsa, null, keyCreationParameters);
54-
}
49+
/// <summary>
50+
/// default issuer name
51+
/// </summary>
52+
private const string DefaultIssuer = "CN=Windows Azure Tools";
5553

5654
/// <summary>
57-
/// Method to generate a self signed certifficate
55+
/// default password.
56+
/// </summary>
57+
private const string DefaultPassword = "";
58+
59+
/// <summary>
60+
/// Method to generate a self signed certificate
5861
/// </summary>
5962
/// <param name="validForHours">number of hours for which the certificate is valid.</param>
6063
/// <param name="subscriptionId">subscriptionId in question</param>
6164
/// <param name="certificateNamePrefix">prefix for the certificate name</param>
6265
/// <param name="issuer">issuer for the certificate</param>
63-
/// <param name="password">certificate passwor</param>
66+
/// <param name="password">certificate password</param>
6467
/// <returns>certificate as an object</returns>
6568
public static X509Certificate2 CreateSelfSignedCertificate(
6669
int validForHours,
@@ -103,18 +106,7 @@ public static X509Certificate2 CreateSelfSignedCertificate(
103106
var bytes = cert.Export(X509ContentType.Pfx, password);
104107

105108
// PfxValidation is not done here because these are newly created certs and assumed valid.
106-
return NewX509Certificate2(bytes, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable, doPfxValidation: false);
107-
}
108-
109-
/// <summary>
110-
/// Generates friendly name
111-
/// </summary>
112-
/// <param name="subscriptionId">subscription id</param>
113-
/// <param name="prefix">prefix, likely resource name</param>
114-
/// <returns>friendly name</returns>
115-
private static string GenerateCertFriendlyName(string subscriptionId, string prefix = "")
116-
{
117-
return string.Format("{0}{1}-{2}-vaultcredentials", prefix, subscriptionId, DateTime.Now.ToString("M-d-yyyy"));
109+
return NewX509Certificate2(bytes, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable, shouldValidatePfx: false);
118110
}
119111

120112
/// <summary>
@@ -123,9 +115,9 @@ private static string GenerateCertFriendlyName(string subscriptionId, string pre
123115
/// <param name="rawData">The bytes that represent the certificate</param>
124116
/// <param name="password">The certificate private password</param>
125117
/// <param name="keyStorageFlags">The certificate loading options</param>
126-
/// <param name="doPfxValidation">Flag to indicate if pfx file should validated. Set to true if the rawData is retrieved from an untrusted source.</param>
118+
/// <param name="shouldValidatePfx">Flag to indicate if file should validated. Set to true if the rawData is retrieved from an untrusted source.</param>
127119
/// <returns>An instance of the X509Certificate</returns>
128-
public static X509Certificate2 NewX509Certificate2(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool doPfxValidation)
120+
public static X509Certificate2 NewX509Certificate2(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool shouldValidatePfx)
129121
{
130122
string temporaryFileName = Path.GetTempFileName();
131123

@@ -147,5 +139,36 @@ public static X509Certificate2 NewX509Certificate2(byte[] rawData, string passwo
147139
}
148140
}
149141
}
142+
143+
/// <summary>
144+
/// Generates friendly name
145+
/// </summary>
146+
/// <param name="subscriptionId">subscription id</param>
147+
/// <param name="prefix">prefix, likely resource name</param>
148+
/// <returns>friendly name</returns>
149+
private static string GenerateCertFriendlyName(string subscriptionId, string prefix = "")
150+
{
151+
return string.Format("{0}{1}-{2}-vaultcredentials", prefix, subscriptionId, DateTime.Now.ToString("M-d-yyyy"));
152+
}
153+
154+
/// <summary>
155+
/// Windows Azure Service Management API requires 2048bit RSA keys.
156+
/// The private key needs to be exportable so we can save it for sharing with team members.
157+
/// </summary>
158+
/// <returns>A 2048 bit RSA key</returns>
159+
private static CngKey Create2048RsaKey()
160+
{
161+
var keyCreationParameters = new CngKeyCreationParameters
162+
{
163+
ExportPolicy = CngExportPolicies.AllowExport,
164+
KeyCreationOptions = CngKeyCreationOptions.None,
165+
KeyUsage = CngKeyUsages.AllUsages,
166+
Provider = new CngProvider(MsEnhancedProv)
167+
};
168+
169+
keyCreationParameters.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(KeySize2048), CngPropertyOptions.None));
170+
171+
return CngKey.Create(CngAlgorithm2.Rsa, null, keyCreationParameters);
172+
}
150173
}
151174
}

0 commit comments

Comments
 (0)