Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/System.Management.Automation/resources/Serialization.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,7 @@
<data name="InvalidKeyLength" xml:space="preserve">
<value>The specified {0} is not valid. Valid {0} length settings are either 128 bits, 192 bits, or 256 bits.</value>
</data>
<data name="DeserializeSecureStringNotSupported" xml:space="preserve">
<value>Deserialization of SecureString is currently only supported on Windows.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtec
/// </summary>
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
{
#if UNIX
throw new PlatformNotSupportedException(Serialization.DeserializeSecureStringNotSupported);
#else
if (encryptedData == null)
throw new ArgumentNullException("encryptedData");

Expand Down Expand Up @@ -556,6 +559,7 @@ public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, Dat
CAPI.LocalFree(userData.pbData);
}
}
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,39 @@ Describe "CliXml test" -Tags "CI" {
Export-Clixml -Path $testPath -InputObject "string" -WhatIf
$testPath | Should -Not -Exist
}

It "should fail to import PSCredential on non-Windows" -Skip:$IsWindows {
$cliXml = @"
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>System.Management.Automation.PSCredential</T>
<T>System.Object</T>
</TN>
<ToString>System.Management.Automation.PSCredential</ToString>
<Props>
<S N="UserName">foo</S>
<!-- this is just an empty password, but needs to be a valid hash -->
<SS N="Password">01000000d08c9ddf0115d1118c7a00c04fc297eb01000000977756228672474da9bfbe7b6acc02cb0000000002000000000003660000c0000000100000002529194617877bbbc952c6aacb6535f00000000004800000a000000010000000703ca974777a8335d5e2f8b3e592ff4208000000635d9fcda035734e140000001b6940e3222117a1014c67377e8786549f3dca29</SS>
</Props>
</Obj>
</Objs>
"@
$path = "$testdrive/cred.xml"
Set-Content -Path $path -Value $cliXml
{ Import-Clixml -Path $path } | Should -Throw -ErrorId "System.PlatformNotSupportedException,Microsoft.PowerShell.Commands.ImportClixmlCommand"
}

It "should import PSCredential" -Skip:(!$IsWindows) {
$UserName = "Foo"
$pass = ConvertTo-SecureString "bar" -AsPlainText -Force
$cred = [PSCredential]::new($UserName, $pass)
$path = "$testdrive/cred.xml"
$cred | Export-Clixml -Path $path
$cred = Import-Clixml -Path $path
$cred.UserName | Should -BeExactly "Foo"
$cred.Password | Should -BeOfType "System.Security.SecureString"
}
}
}

Expand Down