Imported Debian patch 4.0.5-6~numeezy

This commit is contained in:
Alexandre Ellert
2016-02-17 15:07:45 +01:00
committed by Mario Fetka
parent c44de33144
commit 10dfc9587b
1203 changed files with 53869 additions and 241462 deletions

View File

@@ -25,15 +25,9 @@ SSH utilities.
import base64
import re
import struct
import binascii
from hashlib import md5, sha1
from hashlib import sha256 #pylint: disable=E0611
import six
if six.PY3:
unicode = str
__all__ = ['SSHPublicKey']
OPENSSH_BASE_REGEX = re.compile(r'^[\t ]*(?P<keytype>[^\x00\n\r]+?) [\t ]*(?P<key>[^\x00\n\r]+?)(?:[\t ]+(?P<comment>[^\x00\n\r]*?)[\t ]*)?$')
@@ -54,16 +48,15 @@ class SSHPublicKey(object):
self._options = key._options
return
if not isinstance(key, (bytes, unicode)):
raise TypeError("argument must be bytes or unicode, got %s" % type(key).__name__)
if not isinstance(key, (str, unicode)):
raise TypeError("argument must be str or unicode, got %s" % type(key).__name__)
# All valid public key blobs start with 3 null bytes (see RFC 4253
# section 6.6, RFC 4251 section 5 and RFC 4250 section 4.6)
if isinstance(key, bytes) and key[:3] != b'\0\0\0':
if isinstance(key, str) and key[:3] != '\0\0\0':
key = key.decode(encoding)
valid = self._parse_raw(key) or self._parse_base64(key) or self._parse_openssh(key)
if not valid:
raise ValueError("not a valid SSH public key")
@@ -73,7 +66,7 @@ class SSHPublicKey(object):
self._options = options
def _parse_raw(self, key):
if not isinstance(key, bytes):
if not isinstance(key, str):
return False
try:
@@ -102,7 +95,7 @@ class SSHPublicKey(object):
try:
key = base64.b64decode(key)
except (TypeError, ValueError):
except TypeError:
return False
return self._parse_raw(key)
@@ -170,8 +163,7 @@ class SSHPublicKey(object):
return bool(self._options)
def openssh(self):
key = base64.b64encode(self._key).decode('ascii')
out = u'%s %s' % (self._keytype, key)
out = u'%s %s' % (self._keytype, base64.b64encode(self._key))
if self._options:
options = []
@@ -203,8 +195,6 @@ class SSHPublicKey(object):
keytype = 2
elif self._keytype.startswith('ecdsa-sha2-') and '@' not in self._keytype:
keytype = 3
elif self._keytype == 'ssh-ed25519':
keytype = 4
else:
return
fp = fpfunc(self._key).hexdigest().upper()