Skip to content

Commit

Permalink
fix: Enhance SSH key checks to verify the presence of private keys in…
Browse files Browse the repository at this point in the history
… the .ssh directory

ref: #36
  • Loading branch information
dz0ny committed Dec 30, 2024
1 parent 32bea1e commit cd89891
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 16 additions & 1 deletion checks/ssh_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,22 @@ func (f *SSHKeys) IsRunnable() bool {
return false
}

return true
//check if there are any private keys in the .ssh directory
files, err := os.ReadDir(sshPath)
if err != nil {
return false
}

for _, file := range files {
if strings.HasSuffix(file.Name(), ".pub") {
privateKeyPath := filepath.Join(sshPath, strings.TrimSuffix(file.Name(), ".pub"))
if _, err := os.Stat(privateKeyPath); err == nil {
return true
}
}
}
return false

}

// UUID returns the UUID of the check
Expand Down
16 changes: 15 additions & 1 deletion checks/ssh_keys_algo.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,21 @@ func (f *SSHKeysAlgo) IsRunnable() bool {
return false
}

return true
//check if there are any private keys in the .ssh directory
files, err := os.ReadDir(sshPath)
if err != nil {
return false
}

for _, file := range files {
if strings.HasSuffix(file.Name(), ".pub") {
privateKeyPath := filepath.Join(sshPath, strings.TrimSuffix(file.Name(), ".pub"))
if _, err := os.Stat(privateKeyPath); err == nil {
return true
}
}
}
return false
}

// UUID returns the UUID of the check
Expand Down

0 comments on commit cd89891

Please sign in to comment.