Skip to content

Commit

Permalink
handle commented and empty lines in authorized_indentities
Browse files Browse the repository at this point in the history
  • Loading branch information
francoismichel committed Dec 18, 2023
1 parent d868c6c commit 16d34b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ jobs:
run: sudo useradd -m ${{matrix.testuser}} && echo "${{matrix.testuser}}:${{matrix.testpasswd}}" | sudo chpasswd
- name: Create .ssh3 directory
run: sudo su ${{matrix.testuser}} -c 'mkdir ${{matrix.testuserhome}}/.ssh ${{matrix.testuserhome}}/.ssh3'
- name: add the attacker's key as commented in testuser's authorzed identities
run: echo "#" $(cat attacker_id_rsa.pub) | sudo tee -a ${{matrix.testuserhome}}/.ssh3/authorized_identities
- name: Put test public keys in testuser's authorized_identities
run: cat /testuser_id_rsa.pub /testuser_id_ed25519.pub | sudo tee -a ${{matrix.testuserhome}}/.ssh3/authorized_identities
- name: log authorized_identities
run: cat ${{matrix.testuserhome}}/.ssh3/authorized_identities
- name: Classical unit tests
run: env CC=${{matrix.archparams.cc}} CGO_ENABLED=1 GOOS=${{matrix.goos}} GOARCH=${{matrix.archparams.goarch}} go run github.com/onsi/ginkgo/v2/ginkgo -r
- name: Integration tests
Expand Down
10 changes: 10 additions & 0 deletions linux_server/authorized_identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,18 @@ func ParseIdentity(user *linux_util.User, identityStr string) (Identity, error)

func ParseAuthorizedIdentitiesFile(user *linux_util.User, file *os.File) (identities []Identity, err error) {
scanner := bufio.NewScanner(file)
lineNumber := 0
for scanner.Scan() {
lineNumber += 1
line := scanner.Text()
if len(strings.TrimSpace(line)) == 0 {
log.Info().Msgf("%s:%d: skip empty line", file.Name(), lineNumber)
continue
} else if line[0] == '#' {
// commented line
log.Info().Msgf("%s:%d: skip commented identity", file.Name(), lineNumber)
continue
}
identity, err := ParseIdentity(user, line)
if err == nil {
identities = append(identities, identity)
Expand Down

0 comments on commit 16d34b1

Please sign in to comment.