@@ -10,7 +10,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
10
10
{
11
11
Throw " `$ OpenSSHTestInfo is null. Please run Set-OpenSSHTestEnvironment to set test environments."
12
12
}
13
-
13
+
14
14
$testDir = " $ ( $OpenSSHTestInfo [" TestDataPath" ]) \$suite "
15
15
if ( -not (Test-path $testDir - PathType Container))
16
16
{
@@ -21,24 +21,24 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
21
21
$NoLibreSSL = $OpenSSHTestInfo [" NoLibreSSL" ]
22
22
if ($NoLibreSSL )
23
23
{
24
- $keytypes = @ (" ed25519" )
24
+ $keytypes = @ (" ed25519" )
25
25
}
26
26
else
27
27
{
28
- $keytypes = @ (" rsa" , " dsa " , " ecdsa" , " ed25519" )
28
+ $keytypes = @ (" rsa" , " ecdsa" , " ed25519" )
29
29
}
30
-
30
+
31
31
$ssouser = $OpenSSHTestInfo [" SSOUser" ]
32
-
32
+
33
33
$systemSid = Get-UserSID - WellKnownSidType ([System.Security.Principal.WellKnownSidType ]::LocalSystemSid)
34
- $adminsSid = Get-UserSID - WellKnownSidType ([System.Security.Principal.WellKnownSidType ]::BuiltinAdministratorsSid)
34
+ $adminsSid = Get-UserSID - WellKnownSidType ([System.Security.Principal.WellKnownSidType ]::BuiltinAdministratorsSid)
35
35
$currentUserSid = Get-UserSID - User " $ ( $env: USERDOMAIN ) \$ ( $env: USERNAME ) "
36
36
$objUserSid = Get-UserSID - User $ssouser
37
- $everyoneSid = Get-UserSID - WellKnownSidType ([System.Security.Principal.WellKnownSidType ]::WorldSid)
37
+ $everyoneSid = Get-UserSID - WellKnownSidType ([System.Security.Principal.WellKnownSidType ]::WorldSid)
38
38
39
39
function ValidateRegistryACL {
40
40
param ([string ]$UserSid = $currentUserSid , $count )
41
- $agentPath = " Registry::HKEY_Users\$UserSid \Software\OpenSSH\Agent"
41
+ $agentPath = " Registry::HKEY_Users\$UserSid \Software\OpenSSH\Agent"
42
42
$myACL = Get-ACL $agentPath
43
43
$OwnerSid = Get-UserSid - User $myACL.Owner
44
44
$OwnerSid.Equals ($adminsSid ) | Should Be $true
@@ -48,8 +48,8 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
48
48
49
49
foreach ($a in $myACL.Access ) {
50
50
$id = Get-UserSid - User $a.IdentityReference
51
- $identities -contains $id | Should Be $true
52
- ([System.UInt32 ]$a.RegistryRights.value__ ) | Should Be $FullControlPerm
51
+ $identities -contains $id | Should Be $true
52
+ ([System.UInt32 ]$a.RegistryRights.value__ ) | Should Be $FullControlPerm
53
53
$a.AccessControlType | Should Be ([System.Security.AccessControl.AccessControlType ]::Allow)
54
54
$a.IsInherited | Should Be $false
55
55
$a.InheritanceFlags | Should Be ([System.Security.AccessControl.InheritanceFlags ]::None)
@@ -60,27 +60,27 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
60
60
$entries.Count | Should Be $count
61
61
if ($count -gt 0 )
62
62
{
63
- Test-Path $agentPath \keys | Should be $true
63
+ Test-Path $agentPath \keys | Should be $true
64
64
$entries | % {
65
65
$keyentryAcl = Get-Acl $_.pspath
66
66
$OwnerSid = Get-UserSid - User $keyentryAcl.Owner
67
67
$OwnerSid.Equals ($adminsSid ) | Should Be $true
68
68
$keyentryAcl.Access | Should Not Be $
69
69
foreach ($a in $keyentryAcl.Access ) {
70
70
$id = Get-UserSid - User $a.IdentityReference
71
- $identities -contains $id | Should Be $true
72
- ([System.UInt32 ]$a.RegistryRights.value__ ) | Should Be $FullControlPerm
71
+ $identities -contains $id | Should Be $true
72
+ ([System.UInt32 ]$a.RegistryRights.value__ ) | Should Be $FullControlPerm
73
73
$a.AccessControlType | Should Be ([System.Security.AccessControl.AccessControlType ]::Allow)
74
74
$a.IsInherited | Should Be $false
75
75
$a.InheritanceFlags | Should Be ([System.Security.AccessControl.InheritanceFlags ]::None)
76
76
$a.PropagationFlags | Should Be ([System.Security.AccessControl.PropagationFlags ]::None)
77
77
}
78
- }
78
+ }
79
79
}
80
80
else
81
81
{
82
82
Test-Path $agentPath \keys | Should be $false
83
- }
83
+ }
84
84
}
85
85
86
86
# only validate owner and ACEs of the file
@@ -94,7 +94,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
94
94
$currentOwnerSid = Get-UserSid - User $myACL.Owner
95
95
$currentOwnerSid.Equals ($currentUserSid ) | Should Be $true
96
96
$myACL.Access | Should Not Be $null
97
-
97
+
98
98
$ReadAccessPerm = ([System.UInt32 ] [System.Security.AccessControl.FileSystemRights ]::Read.value__) -bor `
99
99
([System.UInt32 ] [System.Security.AccessControl.FileSystemRights ]::ReadAndExecute.value__) -bor `
100
100
([System.UInt32 ] [System.Security.AccessControl.FileSystemRights ]::Synchronize.value__)
@@ -105,7 +105,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
105
105
([System.UInt32 ] [System.Security.AccessControl.FileSystemRights ]::Synchronize.value__)
106
106
107
107
$FullControlPerm = [System.UInt32 ] [System.Security.AccessControl.FileSystemRights ]::FullControl.value__
108
-
108
+
109
109
if ($FilePath.EndsWith (" .pub" )) {
110
110
if ($IsHostKey ) {
111
111
$myACL.Access.Count | Should Be 3
@@ -123,7 +123,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
123
123
124
124
foreach ($a in $myACL.Access ) {
125
125
$id = Get-UserSid - User $a.IdentityReference
126
- $identities -contains $id | Should Be $true
126
+ $identities -contains $id | Should Be $true
127
127
128
128
switch ($id )
129
129
{
@@ -144,7 +144,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
144
144
break ;
145
145
}
146
146
}
147
-
147
+
148
148
$a.AccessControlType | Should Be ([System.Security.AccessControl.AccessControlType ]::Allow)
149
149
$a.IsInherited | Should Be $false
150
150
$a.InheritanceFlags | Should Be ([System.Security.AccessControl.InheritanceFlags ]::None)
@@ -157,9 +157,9 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
157
157
$stderrFile = Join-Path $testDir " $tC .$tI .stderr.txt"
158
158
$stdoutFile = Join-Path $testDir " $tC .$tI .stdout.txt"
159
159
$logFile = Join-Path $testDir " $tC .$tI .log.txt"
160
- }
160
+ }
161
161
162
- AfterEach {$tI ++ ;}
162
+ AfterEach {$tI ++ ;}
163
163
164
164
Context " $tC -ssh-keygen all key types" {
165
165
@@ -171,14 +171,14 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
171
171
remove-item ssh_host_* _key* - ErrorAction SilentlyContinue
172
172
ssh- keygen - A
173
173
Pop-Location
174
-
174
+
175
175
Get-ChildItem (join-path $testDir ssh_host_* _key) | % {
176
176
ValidateKeyFile - FilePath $_.FullName
177
177
}
178
178
179
179
Get-ChildItem (join-path $testDir ssh_host_* _key.pub) | % {
180
180
ValidateKeyFile - FilePath $_.FullName
181
- }
181
+ }
182
182
}
183
183
184
184
It " $tC .$tI - Keygen -t -f" {
@@ -193,7 +193,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
193
193
else
194
194
{
195
195
ssh- keygen - t $type - P $keypassphrase -f $keyPath
196
- }
196
+ }
197
197
ValidateKeyFile - FilePath $keyPath
198
198
ValidateKeyFile - FilePath " $keyPath .pub" - IsHostKey $false
199
199
}
@@ -216,7 +216,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
216
216
AfterAll{$tC ++ }
217
217
218
218
# Executing ssh-agent will start agent service
219
- # This is to support typical Unix scenarios where
219
+ # This is to support typical Unix scenarios where
220
220
# running ssh-agent will setup the agent for current session
221
221
It " $tC .$tI - ssh-agent starts agent service" {
222
222
if ((Get-Service ssh- agent).Status -eq " Running" ) {
@@ -237,7 +237,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
237
237
238
238
$nullFile = join-path $testDir (" $tC .$tI .nullfile" )
239
239
$null > $nullFile
240
-
240
+
241
241
foreach ($type in $keytypes )
242
242
{
243
243
$keyPath = Join-Path $testDir " id_$type "
@@ -259,7 +259,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
259
259
Set-content - Path $keyPathDifferentEnding - value " $newcontent "
260
260
Repair-UserKeyPermission $keyPathDifferentEnding - confirm:$false
261
261
iex " cmd /c `" ssh-add $keyPathDifferentEnding < $nullFile 2> nul `" "
262
- }
262
+ }
263
263
}
264
264
265
265
# remove SSH_ASKPASS
@@ -269,7 +269,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
269
269
$allkeys = ssh- add - L
270
270
$allkeys | Set-Content (Join-Path $testDir " $tC .$tI .allkeyonAdd.txt" )
271
271
ValidateRegistryACL - count $allkeys.Count
272
-
272
+
273
273
foreach ($type in $keytypes )
274
274
{
275
275
$keyPath = Join-Path $testDir " id_$type "
@@ -297,7 +297,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
297
297
298
298
$allkeys = @ (ssh- add - L)
299
299
ValidateRegistryACL - count $allkeys.count
300
- }
300
+ }
301
301
}
302
302
303
303
Context " $tC ssh-keygen known_hosts operations" {
@@ -329,7 +329,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
329
329
$keyFileName = " sshadd_userPermTestkey_ed25519"
330
330
$keyFilePath = Join-Path $testDir $keyFileName
331
331
Remove-Item - path " $keyFilePath *" - Force - ErrorAction SilentlyContinue
332
- ssh-keygen.exe - t ed25519 -f $keyFilePath - P $keypassphrase
332
+ ssh-keygen.exe - t ed25519 -f $keyFilePath - P $keypassphrase
333
333
# set up SSH_ASKPASS
334
334
Add-PasswordSetting - Pass $keypassphrase
335
335
$tI = 1
@@ -341,7 +341,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
341
341
AfterEach {
342
342
if (Test-Path $keyFilePath ) {
343
343
Repair-FilePermission - FilePath $keyFilePath - Owner $currentUserSid - FullAccessNeeded $currentUserSid , $systemSid , $adminsSid - confirm:$false
344
- }
344
+ }
345
345
}
346
346
347
347
AfterAll {
@@ -351,22 +351,22 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
351
351
}
352
352
353
353
It " $tC .$tI - ssh-add - positive (Secured private key owned by current user)" {
354
- # setup to have current user as owner and grant it full control
354
+ # setup to have current user as owner and grant it full control
355
355
Repair-FilePermission - FilePath $keyFilePath - Owner $currentUserSid - FullAccessNeeded $currentUserSid , $systemSid , $adminsSid - confirm:$false
356
356
357
357
# for ssh-add to consume SSh_ASKPASS, stdin should not be TTY
358
358
cmd / c " ssh-add $keyFilePath < $nullFile 2> nul"
359
359
$LASTEXITCODE | Should Be 0
360
360
$allkeys = ssh- add - L
361
- $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
361
+ $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
362
362
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 1
363
-
363
+
364
364
# clean up
365
365
cmd / c " ssh-add -d $keyFilePath 2> nul "
366
366
}
367
367
368
368
It " $tC .$tI - ssh-add - positive (Secured private key owned by Administrators group and the current user has no explicit ACE)" {
369
- # setup to have local admin group as owner and grant it full control
369
+ # setup to have local admin group as owner and grant it full control
370
370
Repair-FilePermission - FilePath $keyFilePath - Owner $adminsSid - FullAccessNeeded $adminsSid , $systemSid - confirm:$false
371
371
372
372
# for ssh-add to consume SSh_ASKPASS, stdin should not be TTY
@@ -375,7 +375,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
375
375
$allkeys = ssh- add - L
376
376
$pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
377
377
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 1
378
-
378
+
379
379
# clean up
380
380
cmd / c " ssh-add -d $keyFilePath 2> nul "
381
381
}
@@ -390,13 +390,13 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
390
390
$allkeys = ssh- add - L
391
391
$pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
392
392
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 1
393
-
393
+
394
394
# clean up
395
395
cmd / c " ssh-add -d $keyFilePath 2> nul "
396
396
}
397
397
398
398
It " $tC .$tI - ssh-add - positive (Secured private key owned by local system group)" {
399
- # setup to have local admin group as owner and grant it full control
399
+ # setup to have local admin group as owner and grant it full control
400
400
Repair-FilePermission - FilePath $keyFilePath - Owners $systemSid - FullAccessNeeded $systemSid , $adminsSid - confirm:$false
401
401
402
402
# for ssh-add to consume SSh_ASKPASS, stdin should not be TTY
@@ -405,11 +405,11 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
405
405
$allkeys = ssh- add - L
406
406
$pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
407
407
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 1
408
-
408
+
409
409
# clean up
410
410
cmd / c " ssh-add -d $keyFilePath 2> nul "
411
411
}
412
-
412
+
413
413
It " $tC .$tI - ssh-add - negative (other account can access private key file)" {
414
414
# setup to have current user as owner and grant it full control
415
415
Repair-FilePermission - FilePath $keyFilePath - Owners $currentUserSid - FullAccessNeeded $currentUserSid , $adminsSid , $systemSid - ReadAccessNeeded $objUserSid - confirm:$false
@@ -418,7 +418,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
418
418
$LASTEXITCODE | Should Not Be 0
419
419
420
420
$allkeys = ssh- add - L
421
- $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
421
+ $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
422
422
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 0
423
423
}
424
424
@@ -430,13 +430,13 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
430
430
$LASTEXITCODE | Should Not Be 0
431
431
432
432
$allkeys = ssh- add - L
433
- $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
433
+ $pubkeyraw = ((Get-Content " $keyFilePath .pub" ).Split(' ' ))[1 ]
434
434
@ ($allkeys | where { $_.contains ($pubkeyraw ) }).count | Should Be 0
435
435
}
436
436
}
437
-
437
+
438
438
Context " $tC - ssh-keyscan test cases" {
439
- BeforeAll {
439
+ BeforeAll {
440
440
$tI = 1
441
441
$port = $OpenSSHTestInfo [" Port" ]
442
442
Remove-item (join-path $testDir " $tC .$tI .out.txt" ) - force - ErrorAction SilentlyContinue
@@ -464,7 +464,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
464
464
465
465
It " $tC .$tI - ssh-keyscan with -f -t" - Skip:$NoLibreSSL {
466
466
Set-Content - Path tmp.txt - Value " 127.0.0.1"
467
- cmd / c " ssh-keyscan -p $port -f tmp.txt -t rsa,dsa 2>&1 > $outputFile "
467
+ cmd / c " ssh-keyscan -p $port -f tmp.txt -t rsa 2>&1 > $outputFile "
468
468
$outputFile | Should Contain ' .*ssh-rsa.*'
469
469
}
470
470
}
0 commit comments