Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
53ed3aef
Commit
53ed3aef
authored
Apr 10, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check is_missing_host_keys before adding them
parent
838d4533
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
main.py
main.py
+21
-10
No files found.
main.py
View file @
53ed3aef
...
@@ -40,18 +40,29 @@ class AutoAddPolicy(paramiko.client.MissingHostKeyPolicy):
...
@@ -40,18 +40,29 @@ class AutoAddPolicy(paramiko.client.MissingHostKeyPolicy):
"""
"""
lock
=
threading
.
Lock
()
lock
=
threading
.
Lock
()
def
is_missing_host_keys
(
self
,
client
,
hostname
,
key
):
k
=
client
.
_host_keys
.
lookup
(
hostname
)
if
k
is
None
:
return
True
host_key
=
k
.
get
(
key
.
get_name
(),
None
)
if
host_key
is
None
:
return
True
if
host_key
!=
key
:
raise
paramiko
.
BadHostKeyException
(
hostname
,
key
,
host_key
)
def
missing_host_key
(
self
,
client
,
hostname
,
key
):
def
missing_host_key
(
self
,
client
,
hostname
,
key
):
with
self
.
lock
:
with
self
.
lock
:
keytype
=
key
.
get_name
()
if
self
.
is_missing_host_keys
(
client
,
hostname
,
key
):
logging
.
info
(
keytype
=
key
.
get_name
()
'Adding {} host key for {}'
.
format
(
keytype
,
hostname
)
logging
.
info
(
)
'Adding {} host key for {}'
.
format
(
keytype
,
hostname
)
client
.
_host_keys
.
add
(
hostname
,
keytype
,
key
)
)
client
.
_host_keys
.
add
(
hostname
,
keytype
,
key
)
with
open
(
client
.
_host_keys_filename
,
'a'
)
as
f
:
f
.
write
(
'{} {} {}
\n
'
.
format
(
with
open
(
client
.
_host_keys_filename
,
'a'
)
as
f
:
hostname
,
keytype
,
key
.
get_base64
()
f
.
write
(
'{} {} {}
\n
'
.
format
(
))
hostname
,
keytype
,
key
.
get_base64
()
))
paramiko
.
client
.
AutoAddPolicy
=
AutoAddPolicy
paramiko
.
client
.
AutoAddPolicy
=
AutoAddPolicy
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment