MCPcopy Create free account
hub / github.com/USArmyResearchLab/Dshell / key_fingerprint

Function key_fingerprint

dshell/plugins/ssh/ssh-pubkey.py:149–173  ·  view source on GitHub ↗
(ssh_pubkey, hashfunction=hashlib.sha256)

Source from the content-addressed store, hash-verified

147
148
149def key_fingerprint(ssh_pubkey, hashfunction=hashlib.sha256):
150
151 # Treat as bytes, not string
152 if type(ssh_pubkey) == str:
153 ssh_pubkey = ssh_pubkey.encode('utf-8')
154
155 # Strip space from end
156 ssh_pubkey = ssh_pubkey.rstrip(b"\r\n\0 ")
157
158 # Only look at first line
159 ssh_pubkey = ssh_pubkey.split(b"\n")[0]
160 # If two spaces, look at middle segment
161 if ssh_pubkey.count(b" ") >= 1:
162 ssh_pubkey = ssh_pubkey.split(b" ")[1]
163
164 # Try to decode key as base64
165 try:
166 keybin = base64.b64decode(ssh_pubkey)
167 except:
168 sys.stderr.write("Invalid key value:\n")
169 sys.stderr.write(" \"%s\":\n" % ssh_pubkey)
170 return None
171
172 # Fingerprint
173 return hashfunction(keybin).digest()
174
175
176if __name__ == "__main__":

Callers 1

connection_handlerMethod · 0.85

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected