r46954 - shuffle some things about
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Wed, 9 Mar 2016 00:41:59 -0700 (MST)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Wed Mar 9 00:41:55 2016
New Revision: 46954
Modified:
branches/manhole-hardcodedkey-8229/twisted/conch/manhole_tap.py
branches/manhole-hardcodedkey-8229/twisted/conch/ssh/keys.py
branches/manhole-hardcodedkey-8229/twisted/conch/test/test_keys.py
Log:
shuffle some things about
Modified: branches/manhole-hardcodedkey-8229/twisted/conch/manhole_tap.py
==============================================================================
--- branches/manhole-hardcodedkey-8229/twisted/conch/manhole_tap.py (original)
+++ branches/manhole-hardcodedkey-8229/twisted/conch/manhole_tap.py Wed Mar 9 00:41:55 2016
@@ -130,7 +130,7 @@
sshPortal = portal.Portal(sshRealm, [checker])
sshFactory = manhole_ssh.ConchFactory(sshPortal)
- sshKey = keys._generateSavedRSAKey(options['sshKeyDir'],
+ sshKey = keys._getPersistentRSAKey(options['sshKeyDir'],
options['sshKeyName'],
int(options['sshKeySize']))
sshFactory.publicKeys["ssh-rsa"] = sshKey
Modified: branches/manhole-hardcodedkey-8229/twisted/conch/ssh/keys.py
==============================================================================
--- branches/manhole-hardcodedkey-8229/twisted/conch/ssh/keys.py (original)
+++ branches/manhole-hardcodedkey-8229/twisted/conch/ssh/keys.py Wed Mar 9 00:41:55 2016
@@ -11,6 +11,8 @@
import base64
import itertools
import warnings
+import appdirs
+
from hashlib import md5
from cryptography.exceptions import InvalidSignature
@@ -1230,16 +1232,29 @@
-def _generateSavedRSAKey(directory=None, filename=None, keySize=4096):
+def _getPersistentRSAKey(directory=None, filename=None, keySize=4096,
+ _appdirs=appdirs):
"""
- This function generates a persistent server key
+ This function returns a persistent L{Key}.
+
+ The key is loaded from a PEM file in C{directory}, named C{filename}. If it
+ does not exist, a key with the key size of C{keySize} is generated and
+ saved.
+
+ @param directory: The directory the key is stored in.
+ @type directory: L{str} or L{bytes}
+
+ @param filename: The filename of the key file.
+ @type filename: L{str} or L{bytes}
+
+ @returns: A persistent key.
+ @rtype: L{Key}
"""
if filename is None:
filename = "server.pem"
if directory is None:
- from appdirs import user_data_dir
- directory = user_data_dir("Twisted", "Conch")
+ directory = _appdirs.user_data_dir("Twisted", "Conch")
configDir = filepath.FilePath(directory)
configDir.makedirs(ignoreExistingDirectory=True)
Modified: branches/manhole-hardcodedkey-8229/twisted/conch/test/test_keys.py
==============================================================================
--- branches/manhole-hardcodedkey-8229/twisted/conch/test/test_keys.py (original)
+++ branches/manhole-hardcodedkey-8229/twisted/conch/test/test_keys.py Wed Mar 9 00:41:55 2016
@@ -1159,3 +1159,13 @@
'e': keydata.RSAData['e'],
},
key.data())
+
+
+
+class PersistentRSAKeyTests(unittest.TestCase):
+ """
+ Tests for L{keys._getPersistentRSAKey}.
+ """
+
+ if cryptography is None:
+ skip = skipCryptography