-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_SecureMemory.Tests.ps1
More file actions
48 lines (37 loc) · 1.6 KB
/
26_SecureMemory.Tests.ps1
File metadata and controls
48 lines (37 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
BeforeAll {
. $PSScriptRoot/26_SecureMemory.ps1
}
Describe 'PinnedKeyBuffer' {
It 'derives a pinned 32-byte key from a password and salt' {
$salt = [byte[]](1, 2, 3, 4, 5, 6, 7, 8)
$buffer = [PinnedKeyBuffer]::FromPassword('correct horse battery staple', $salt)
$bytes = $buffer.ReadBytes()
$bytes.Length | Should -Be 32
$bytes | Should -Be ([System.Security.Cryptography.Rfc2898DeriveBytes]::Pbkdf2(
'correct horse battery staple',
$salt,
100000,
[System.Security.Cryptography.HashAlgorithmName]::SHA256,
32))
$buffer.IsZeroed() | Should -BeFalse
$buffer.Dispose()
$buffer.IsZeroed() | Should -BeTrue
Should -Throw -ActualValue { $buffer.ReadBytes() } -ExceptionType ([System.ObjectDisposedException])
}
It 'zeroes generated buffers on dispose' {
$buffer = [PinnedKeyBuffer]::Generate(16)
$buffer.IsZeroed() | Should -BeFalse
$buffer.Dispose()
$buffer.IsZeroed() | Should -BeTrue
Should -Throw -ActualValue { $buffer.ReadBytes() } -ExceptionType ([System.ObjectDisposedException])
}
}
Describe 'DpapiKeyVault' {
It 'guards Windows-only protect and unprotect operations' {
if (-not $IsWindows) {
$vault = [DpapiKeyVault]::new()
Should -Throw -ActualValue { $vault.Protect([byte[]](1, 2, 3)) } -ExceptionType ([System.PlatformNotSupportedException])
Should -Throw -ActualValue { $vault.Unprotect([byte[]](1, 2, 3)) } -ExceptionType ([System.PlatformNotSupportedException])
}
}
}