Skip to content

Commit d273037

Browse files
author
maddieclayton
authored
Merge pull request Azure#4898 from jobatzil/hotfix/secureString
#ApplicationGateway Introduce SecureString to cmdlets.
2 parents fb10f3d + f32a243 commit d273037

15 files changed

+22457
-191916
lines changed

src/ResourceManager/Network/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Changed type of parameter -Password from String to SecureString for the following cmdlets:
22+
- Add-AzureRmApplicationGatewaySslCertificate
23+
- New-AzureRmApplicationGatewaySslCertificate
24+
- Set-AzureRmApplicationGatewaySslCertificate
2125
* Added cmdlet to list available internet service providers for a specified Azure region
2226
- Get-AzureRmNetworkWatcherReachabilityProvidersList
2327
* Added cmdlet to get the relative latency score for internet service providers from a specified location to Azure regions

src/ResourceManager/Network/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@
224224
<None Include="ScenarioTests\Common.ps1">
225225
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
226226
</None>
227+
<None Include="ScenarioTests\Data\ApplicationGatewaySslCert1.pfx">
228+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229+
</None>
230+
<None Include="ScenarioTests\Data\ApplicationGatewaySslCert2.pfx">
231+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
232+
</None>
227233
<None Include="ScenarioTests\Data\VmssDeploymentTemplate.json">
228234
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229235
</None>

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ApplicationGatewayTests.ps1

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ function Test-ApplicationGatewayCRUD2
346346
$listener01Name = Get-ResourceName
347347
$listener02Name = Get-ResourceName
348348

349+
$sslCert01Name = Get-ResourceName
350+
$sslCert02Name = Get-ResourceName
351+
349352
$poolName = Get-ResourceName
350353
$poolSetting01Name = Get-ResourceName
351354

@@ -376,11 +379,15 @@ function Test-ApplicationGatewayCRUD2
376379
# Create ip configuration
377380
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name $gipconfigname -Subnet $gwSubnet
378381

379-
#frontend part
382+
# frontend part
383+
$pw01 = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
384+
$sslCert01Path = $basedir + "\ScenarioTests\Data\ApplicationGatewaySslCert1.pfx"
385+
$sslCert01 = New-AzureRmApplicationGatewaySslCertificate -Name $sslCert01Name -CertificateFile $sslCert01Path -Password $pw01
386+
380387
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig -Name $fipconfigName -PublicIPAddress $publicip
381-
$fp01 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort01Name  -Port 80
382-
$fp02 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort02Name  -Port 81
383-
$listener01 = New-AzureRmApplicationGatewayHttpListener -Name $listener01Name -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp01
388+
$fp01 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort01Name  -Port 443
389+
$fp02 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort02Name  -Port 80
390+
$listener01 = New-AzureRmApplicationGatewayHttpListener -Name $listener01Name -Protocol Https -SslCertificate $sslCert01 -FrontendIPConfiguration $fipconfig -FrontendPort $fp01
384391
$listener02 = New-AzureRmApplicationGatewayHttpListener -Name $listener02Name -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp02
385392

386393
# backend part
@@ -401,7 +408,7 @@ function Test-ApplicationGatewayCRUD2
401408
$sslPolicy = New-AzureRmApplicationGatewaySslPolicy -PolicyType Custom -MinProtocolVersion TLSv1_1 -CipherSuite "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256"
402409

403410
# Create Application Gateway
404-
$appgw = New-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -Probes $probeHttp -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01, $fp02 -HttpListeners $listener01, $listener02 -RedirectConfiguration $redirect01 -RequestRoutingRules $rule01, $rule02 -Sku $sku -SslPolicy $sslPolicy
411+
$appgw = New-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -Probes $probeHttp -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01, $fp02 -HttpListeners $listener01, $listener02 -RedirectConfiguration $redirect01 -RequestRoutingRules $rule01, $rule02 -Sku $sku -SslPolicy $sslPolicy -SslCertificates $sslCert01
405412

406413
# Check get/set/remove for RedirectConfiguration
407414
$redirect02 = Get-AzureRmApplicationGatewayRedirectConfiguration -ApplicationGateway $appgw -Name $redirect01Name
@@ -425,11 +432,30 @@ function Test-ApplicationGatewayCRUD2
425432
# Get Application Gateway
426433
$getgw = Get-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname
427434

435+
# Check SSLCertificates
436+
Assert-NotNull $getgw.SslCertificates[0]
437+
Assert-Null $getgw.SslCertificates[0].Password
438+
439+
# Use Set/Add Certificate
440+
$getgw = Set-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $getgw -Name $sslCert01Name -CertificateFile $sslCert01Path -Password $pw01
441+
Assert-NotNull $getgw.SslCertificates[0].Password
442+
443+
$pw02 = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
444+
$sslCert02Path = $basedir + "\ScenarioTests\Data\ApplicationGatewaySslCert2.pfx"
445+
$getgw = Add-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $getgw -Name $sslCert02Name -CertificateFile $sslCert02Path -Password $pw02
446+
428447
# Modify existing application gateway with new configuration
429448
$getgw = Set-AzureRmApplicationGateway -ApplicationGateway $getgw
430449

431450
Assert-AreEqual "Running" $getgw.OperationalState
432451

452+
# Check SSLCertificates again
453+
Assert-AreEqual 2 $getgw.SslCertificates.Count
454+
Assert-NotNull $getgw.SslCertificates[0]
455+
Assert-NotNull $getgw.SslCertificates[1]
456+
Assert-Null $getgw.SslCertificates[0].Password
457+
Assert-Null $getgw.SslCertificates[1].Password
458+
433459
# Stop Application Gateway
434460
$getgw = Stop-AzureRmApplicationGateway -ApplicationGateway $getgw
435461

src/ResourceManager/Network/Commands.Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.ApplicationGatewayTests/TestApplicationGatewayCRUD2.json

Lines changed: 22373 additions & 191885 deletions
Large diffs are not rendered by default.

src/ResourceManager/Network/Commands.Network/ApplicationGateway/SslCertificate/AzureApplicationGatewaySslCertificateBase.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Network.Models;
1615
using System;
1716
using System.IO;
1817
using System.Management.Automation;
19-
using System.Security.Cryptography.X509Certificates;
18+
using System.Security;
19+
using Microsoft.Azure.Commands.Network.Models;
2020

2121
namespace Microsoft.Azure.Commands.Network
2222
{
@@ -38,18 +38,15 @@ public class AzureApplicationGatewaySslCertificateBase : NetworkBaseCmdlet
3838
Mandatory = true,
3939
HelpMessage = "Certificate password")]
4040
[ValidateNotNullOrEmpty]
41-
[Obsolete("(Get/Set/New)-AzureRmApplicationGatewaySslCertificate: The parameter \"Password\" is being changed from a string to a SecureString in an upcoming breaking change release.")]
42-
public string Password { get; set; }
41+
public SecureString Password { get; set; }
4342

4443
public PSApplicationGatewaySslCertificate NewObject()
4544
{
4645
var sslCertificate = new PSApplicationGatewaySslCertificate();
4746

4847
sslCertificate.Name = this.Name;
49-
sslCertificate.Data = Convert.ToBase64String(File.ReadAllBytes(CertificateFile));
50-
#pragma warning disable 0618
48+
sslCertificate.Data = Convert.ToBase64String(File.ReadAllBytes(this.CertificateFile));
5149
sslCertificate.Password = this.Password;
52-
#pragma warning restore 0618
5350
sslCertificate.Id =
5451
ApplicationGatewayChildResourceHelper.GetResourceNotSetId(
5552
this.NetworkClient.NetworkManagementClient.SubscriptionId,

src/ResourceManager/Network/Commands.Network/ApplicationGateway/SslCertificate/SetAzureApplicationGatewaySslCertificateCommand.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public override void ExecuteCmdlet()
3939
{
4040
throw new ArgumentException("Ssl certificate with the specified name does not exist");
4141
}
42-
43-
#pragma warning disable 0618
44-
X509Certificate2 cert = new X509Certificate2(CertificateFile, Password, X509KeyStorageFlags.Exportable);
45-
#pragma warning restore 0618
42+
43+
X509Certificate2 cert = new X509Certificate2(this.CertificateFile, this.Password, X509KeyStorageFlags.Exportable);
4644

4745
var newSslCertificate = base.NewObject();
4846

src/ResourceManager/Network/Commands.Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace Microsoft.Azure.Commands.Network
1818
using System;
1919
using System.Collections;
2020
using System.Collections.Generic;
21+
using System.Security;
22+
using WindowsAzure.Commands.Common;
2123
using CNM = Microsoft.Azure.Commands.Network.Models;
2224
using MNM = Microsoft.Azure.Management.Network.Models;
2325
using Microsoft.WindowsAzure.Commands.Utilities.Common;
@@ -563,7 +565,9 @@ private static void Initialize()
563565
cfg.CreateMap<CNM.PSApplicationGatewayBackendHttpSettings, MNM.ApplicationGatewayBackendHttpSettings>();
564566
cfg.CreateMap<CNM.PSApplicationGatewayFrontendIPConfiguration, MNM.ApplicationGatewayFrontendIPConfiguration>();
565567
cfg.CreateMap<CNM.PSApplicationGatewayFrontendPort, MNM.ApplicationGatewayFrontendPort>();
566-
cfg.CreateMap<CNM.PSApplicationGatewaySslCertificate, MNM.ApplicationGatewaySslCertificate>();
568+
cfg.CreateMap<CNM.PSApplicationGatewaySslCertificate, MNM.ApplicationGatewaySslCertificate>().ForMember(
569+
dest => dest.Password,
570+
opt => opt.ResolveUsing(src => src.Password?.ConvertToString()));
567571
cfg.CreateMap<CNM.PSApplicationGatewayHttpListener, MNM.ApplicationGatewayHttpListener>();
568572
cfg.CreateMap<CNM.PSApplicationGatewayIPConfiguration, MNM.ApplicationGatewayIPConfiguration>();
569573
cfg.CreateMap<CNM.PSApplicationGatewayRequestRoutingRule, MNM.ApplicationGatewayRequestRoutingRule>();
@@ -603,7 +607,9 @@ private static void Initialize()
603607
cfg.CreateMap<MNM.ApplicationGatewayBackendAddressPool, CNM.PSApplicationGatewayBackendAddressPool>();
604608
cfg.CreateMap<MNM.ApplicationGatewayBackendHttpSettings, CNM.PSApplicationGatewayBackendHttpSettings>();
605609
cfg.CreateMap<MNM.ApplicationGatewayFrontendIPConfiguration, CNM.PSApplicationGatewayFrontendIPConfiguration>();
606-
cfg.CreateMap<MNM.ApplicationGatewaySslCertificate, CNM.PSApplicationGatewaySslCertificate>();
610+
cfg.CreateMap<MNM.ApplicationGatewaySslCertificate, CNM.PSApplicationGatewaySslCertificate>().ForMember(
611+
dest => dest.Password,
612+
opt => opt.ResolveUsing(src => src.Password?.ConvertToSecureString()));
607613
cfg.CreateMap<MNM.ApplicationGatewayFrontendPort, CNM.PSApplicationGatewayFrontendPort>();
608614
cfg.CreateMap<MNM.ApplicationGatewayHttpListener, CNM.PSApplicationGatewayHttpListener>();
609615
cfg.CreateMap<MNM.ApplicationGatewayIPConfiguration, CNM.PSApplicationGatewayIPConfiguration>();

src/ResourceManager/Network/Commands.Network/Models/PSApplicationGatewaySslCertificate.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515

1616
namespace Microsoft.Azure.Commands.Network.Models
1717
{
18+
using System.Security;
19+
1820
public class PSApplicationGatewaySslCertificate : PSChildResource
1921
{
2022
public string Data { get; set; }
21-
public string Password { get; set; }
23+
public SecureString Password { get; set; }
2224
public string PublicCertData { get; set; }
2325
public string ProvisioningState { get; set; }
2426
public string Type { get; set; }

src/ResourceManager/Network/Commands.Network/help/Add-AzureRmApplicationGatewaySslCertificate.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Adds an SSL certificate to an application gateway.
1515

1616
```
1717
Add-AzureRmApplicationGatewaySslCertificate -ApplicationGateway <PSApplicationGateway> -Name <String>
18-
-CertificateFile <String> -Password <String> [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
18+
-CertificateFile <String> -Password <SecureString> [-DefaultProfile <IAzureContextContainer>]
19+
[<CommonParameters>]
1920
```
2021

2122
## DESCRIPTION
@@ -25,8 +26,9 @@ The **Add-AzureRmApplicationGatewaySslCertificate** cmdlet adds an SSL certifica
2526

2627
### Example 1: Add an SSL certificate to an application gateway.
2728
```
28-
PS C:\>$AppGW = Get-AzureRmApplicationGateway -Name "ApplicationGateway01" -ResourceGroupName "ResourceGroup01"
29-
PS C:\> $AppGW = Add-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $AppGW -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password "Password01"
29+
PS C:\> $AppGW = Get-AzureRmApplicationGateway -Name "ApplicationGateway01" -ResourceGroupName "ResourceGroup01"
30+
PS C:\> $password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
31+
PS C:\> $AppGW = Add-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $AppGW -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password $password
3032
```
3133

3234
This command gets an application gateway named ApplicationGateway01 and then adds an SSL certificate named Cert01 to it.
@@ -97,7 +99,7 @@ Accept wildcard characters: False
9799
Specifies the password of the SSL certificate that this cmdlet adds.
98100
99101
```yaml
100-
Type: String
102+
Type: SecureString
101103
Parameter Sets: (All)
102104
Aliases:
103105

src/ResourceManager/Network/Commands.Network/help/New-AzureRmApplicationGatewaySslCertificate.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Creates an SSL certificate for an Azure application gateway.
1414
## SYNTAX
1515

1616
```
17-
New-AzureRmApplicationGatewaySslCertificate -Name <String> -CertificateFile <String> -Password <String>
17+
New-AzureRmApplicationGatewaySslCertificate -Name <String> -CertificateFile <String> -Password <SecureString>
1818
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

@@ -25,7 +25,8 @@ The **New-AzureRmApplicationGatewaySslCertificate** cmdlet creates an SSL certif
2525

2626
### Example 1: Create an SSL certificate for an Azure application gateway.
2727
```
28-
PS C:\>$Cert = New-AzureRmApplicationGatewaySslCertificate -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password "Password01"
28+
PS C:\> $password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
29+
PS C:\> $cert = New-AzureRmApplicationGatewaySslCertificate -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password $password
2930
```
3031

3132
This command creates a SSL certificate named Cert01 for the default application gateway and stores the result in the variable named $Cert.
@@ -81,7 +82,7 @@ Accept wildcard characters: False
8182
Specifies the password of the SSL that this cmdlet creates.
8283
8384
```yaml
84-
Type: String
85+
Type: SecureString
8586
Parameter Sets: (All)
8687
Aliases:
8788

src/ResourceManager/Network/Commands.Network/help/Set-AzureRmApplicationGatewaySslCertificate.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Sets the goal state of an SSL certificate.
1515

1616
```
1717
Set-AzureRmApplicationGatewaySslCertificate -ApplicationGateway <PSApplicationGateway> -Name <String>
18-
-CertificateFile <String> -Password <String> [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
18+
-CertificateFile <String> -Password <SecureString> [-DefaultProfile <IAzureContextContainer>]
19+
[<CommonParameters>]
1920
```
2021

2122
## DESCRIPTION
@@ -25,8 +26,9 @@ The **Set-AzureRmApplicationGatewaySslCertificate** cmdlet sets the goal state o
2526

2627
### Example 1: Set the goal state of an SSL certificate
2728
```
28-
PS C:\>$AppGW = Get-AzureRmApplicationGateway -Name "ApplicationGateway01" -ResourceGroupName "ResourceGroup01"
29-
PS C:\> $Cert = Set-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $AppGW -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password "Password01"
29+
PS C:\> $appGW = Get-AzureRmApplicationGateway -Name "ApplicationGateway01" -ResourceGroupName "ResourceGroup01"
30+
PS C:\> $password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
31+
PS C:\> $cert = Set-AzureRmApplicationGatewaySslCertificate -ApplicationGateway $AppGW -Name "Cert01" -CertificateFile "D:\cert01.pfx" -Password $password
3032
```
3133

3234
This command sets the goal state for an SSL certificate from the application gateway named ApplicationGateway01.
@@ -97,7 +99,7 @@ Accept wildcard characters: False
9799
Specifies the password of the SSL certificate.
98100
99101
```yaml
100-
Type: String
102+
Type: SecureString
101103
Parameter Sets: (All)
102104
Aliases:
103105

tools/GlobalFilters.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@
185185
<string>ResourceManager\\Compute\\Stack\\Commands.Compute.Test\\Templates\\client.rb</string>
186186
<string>ResourceManager\\Compute\\Stack\\Commands.Compute.Test\\Templates\\tstorgnztn-validator.pem</string>
187187
<string>ResourceManager\\Network\\Stack\\Commands.Network.Test\\SessionRecords\\Commands.Network.Test.ScenarioTests.ApplicationGatewayTests\\TestApplicationGatewayCRUD.json</string>
188+
<string>ResourceManager\\Network\\Commands.Network.Test\\ScenarioTests\\Data\\ApplicationGatewaySslCert1.pfx</string>
189+
<string>ResourceManager\\Network\\Commands.Network.Test\\ScenarioTests\\Data\\ApplicationGatewaySslCert2.pfx</string>
188190
<string>\\bin\\Debug\\</string>
189191
<string>\\package[s]?\\</string>
190192
</Filters>

0 commit comments

Comments
 (0)