summaryrefslogtreecommitdiffstats
path: root/services/checkers.py
blob: dbfe13232ca5891bc86d6bb310a131f0fc7ab746 (plain)
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

import base64, binascii
from twisted.python.filepath import FilePath
from twisted.conch.checkers import SSHPublicKeyDatabase


class PublicKeyChecker(SSHPublicKeyDatabase):

    def __init__(self, filename):
        self.filepath = FilePath(filename)

    def getAuthorizedKeysFiles(self, credentials):
        return [self.filepath]

    def checkKey(self, credentials):
        for line in self.filepath.open():
            parts = line.split()
            if len(parts) < 2:
                continue
            try:
                if base64.decodestring(parts[1]) == credentials.blob:
                    return True
            except binascii.Error:
                continue
        return False