From f7b892905c62b94a6e54d115ee2d6d32d66af013 Mon Sep 17 00:00:00 2001 From: "Jeremy T. Bouse" Date: Fri, 27 Nov 2009 16:25:55 -0500 Subject: Imported Upstream version 1.7.6 Closes: #543784 --- docs/paramiko.pkey-pysrc.html | 154 +++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 77 deletions(-) (limited to 'docs/paramiko.pkey-pysrc.html') diff --git a/docs/paramiko.pkey-pysrc.html b/docs/paramiko.pkey-pysrc.html index 8a9e368..ef16bb0 100644 --- a/docs/paramiko.pkey-pysrc.html +++ b/docs/paramiko.pkey-pysrc.html @@ -54,24 +54,24 @@

Source Code for Module paramiko.pkey

-  1  # Copyright (C) 2003-2007  Robey Pointer <robey@lag.net> 
-  2  # 
-  3  # This file is part of paramiko. 
-  4  # 
-  5  # Paramiko is free software; you can redistribute it and/or modify it under the 
-  6  # terms of the GNU Lesser General Public License as published by the Free 
-  7  # Software Foundation; either version 2.1 of the License, or (at your option) 
-  8  # any later version. 
-  9  # 
- 10  # Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY 
- 11  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
- 12  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
- 13  # details. 
- 14  # 
- 15  # You should have received a copy of the GNU Lesser General Public License 
- 16  # along with Paramiko; if not, write to the Free Software Foundation, Inc., 
- 17  # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. 
- 18   
+  1  # Copyright (C) 2003-2007  Robey Pointer <robeypointer@gmail.com> 
+  2  # 
+  3  # This file is part of paramiko. 
+  4  # 
+  5  # Paramiko is free software; you can redistribute it and/or modify it under the 
+  6  # terms of the GNU Lesser General Public License as published by the Free 
+  7  # Software Foundation; either version 2.1 of the License, or (at your option) 
+  8  # any later version. 
+  9  # 
+ 10  # Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY 
+ 11  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
+ 12  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
+ 13  # details. 
+ 14  # 
+ 15  # You should have received a copy of the GNU Lesser General Public License 
+ 16  # along with Paramiko; if not, write to the Free Software Foundation, Inc., 
+ 17  # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. 
+ 18   
  19  """ 
  20  Common API for all public keys. 
  21  """ 
@@ -95,7 +95,7 @@
  39      """ 
  40   
  41      # known encryption types for private key files: 
- 42      _CIPHER_TABLE = { 
+ 42      _CIPHER_TABLE = { 
  43          'DES-EDE3-CBC': { 'cipher': DES3, 'keysize': 24, 'blocksize': 8, 'mode': DES3.MODE_CBC } 
  44      } 
  45   
@@ -186,7 +186,7 @@
 130              format. 
 131          @rtype: str 
 132          """ 
-133          return MD5.new(str(self)).digest() 
+133          return MD5.new(str(self)).digest() 
 134   
 
135 - def get_base64(self):
136 """ @@ -252,7 +252,7 @@ 196 """ 197 key = cls(filename=filename, password=password) 198 return key -
199 from_private_key_file = classmethod(from_private_key_file) +199 from_private_key_file = classmethod(from_private_key_file) 200
201 - def from_private_key(cls, file_obj, password=None):
202 """ @@ -276,7 +276,7 @@ 220 """ 221 key = cls(file_obj=file_obj, password=password) 222 return key -
223 from_private_key = classmethod(from_private_key) +223 from_private_key = classmethod(from_private_key) 224
225 - def write_private_key_file(self, filename, password=None):
226 """ @@ -331,9 +331,9 @@ 275 encrypted, and C{password} is C{None}. 276 @raise SSHException: if the key file is invalid. 277 """ -278 f = open(filename, 'r') +278 f = open(filename, 'r') 279 data = self._read_private_key(tag, f, password) -280 f.280 f.close() +paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick="return doclink('link-18', 'close', 'link-18');">close() 281 return data
282
283 - def _read_private_key(self, tag, f, password=None): -
284 lines = f.readlines() +
284 lines = f.readlines() 285 start = 0 286 while (start < len(lines)) and (lines[start].strip() != '-----BEGIN ' + tag + ' PRIVATE KEY-----'): 287 start += 1 288 if start >= len(lines): -289 raise SSHException('not a valid ' + tag + ' private key file') +289 raise SSHException('not a valid ' + tag + ' private key file') 290 # parse any headers first -291 headers = {} +291 headers = {} 292 start += 1 293 while start < len(lines): 294 l = lines[start].split(': ') @@ -364,35 +364,35 @@ paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick=" 297 headers[l[0].lower()] = l[1].strip() 298 start += 1 299 # find end -300 end = start +300 end = start 301 while (lines[end].strip() != '-----END ' + tag + ' PRIVATE KEY-----') and (end < len(lines)): 302 end += 1 303 # if we trudged to the end of the file, just try to cope. -304 try: +304 try: 305 data = base64.decodestring(''.join(lines[start:end])) 306 except base64.binascii.Error, e: -307 raise SSHException('base64 decoding error: ' + str(e)) +307 raise SSHException('base64 decoding error: ' + str(e)) 308 if 'proc-type' not in headers: 309 # unencryped: done -310 return data +310 return data 311 # encrypted keyfile: will need a password -312 if headers['proc-type'] != '4,ENCRYPTED': -313 raise SSHException('Unknown private key structure "%s"' % headers['proc-type']) +312 if headers['proc-type'] != '4,ENCRYPTED': +313 raise SSHException('Unknown private key structure "%s"' % headers['proc-type']) 314 try: 315 encryption_type, saltstr = headers['dek-info'].split(',') 316 except: -317 raise SSHException('Can\'t parse DEK-info in private key file') -318 if encryption_type not in self._CIPHER_TABLE: -319 raise SSHException('Unknown private key cipher "%s"' % encryption_type) +317 raise SSHException('Can\'t parse DEK-info in private key file') +318 if encryption_type not in self._CIPHER_TABLE: +319 raise SSHException('Unknown private key cipher "%s"' % encryption_type) 320 # if no password was passed in, raise an exception pointing out that we need one -321 if password is None: -322 raise PasswordRequiredException('Private key file is encrypted') -323 cipher = self._CIPHER_TABLE[encryption_type]['cipher'] -324 keysize = self._CIPHER_TABLE[encryption_type]['keysize'] -325 mode = self._CIPHER_TABLE[encryption_type]['mode'] +321 if password is None: +322 raise PasswordRequiredException('Private key file is encrypted') +323 cipher = self._CIPHER_TABLE[encryption_type]['cipher'] +324 keysize = self._CIPHER_TABLE[encryption_type]['keysize'] +325 mode = self._CIPHER_TABLE[encryption_type]['mode'] 326 salt = unhexlify(saltstr) -327 key = util.generate_key_bytes(MD5, salt, password, keysize) -328 return cipher.new(key, mode, salt).decrypt(data) +327 key = util.generate_key_bytes(MD5, salt, password, keysize) +328 return cipher.new(key, mode, salt).decrypt(data)
329
330 - def _write_private_key_file(self, tag, filename, data, password=None):
331 """ @@ -412,12 +412,12 @@ paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick=" 345 346 @raise IOError: if there was an error writing the file. 347 """ -348 f = open(filename, 'w', 0600) +348 f = open(filename, 'w', 0600) 349 # grrr... the mode doesn't always take hold -350 os.chmod(filename, 0600) +350 os.chmod(filename, 0600) 351 self._write_private_key(tag, f, data, password) -352 f.352 f.close() +paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick="return doclink('link-35', 'close', 'link-18');">close()
353
354 - def _write_private_key(self, tag, f, data, password=None): -
355 f.write('-----BEGIN %s PRIVATE KEY-----\n' % tag) +
355 f.write('-----BEGIN %s PRIVATE KEY-----\n' % tag) 356 if password is not None: 357 # since we only support one cipher here, use it -358 cipher_name = self._CIPHER_TABLE.keys()[0] -359 cipher = self._CIPHER_TABLE[cipher_name]['cipher'] -360 keysize = self._CIPHER_TABLE[cipher_name]['keysize'] -361 blocksize = self._CIPHER_TABLE[cipher_name]['blocksize'] -362 mode = self._CIPHER_TABLE[cipher_name]['mode'] -363 salt = 358 cipher_name = self._CIPHER_TABLE.keys()[0] +359 cipher = self._CIPHER_TABLE[cipher_name]['cipher'] +360 keysize = self._CIPHER_TABLE[cipher_name]['keysize'] +361 blocksize = self._CIPHER_TABLE[cipher_name]['blocksize'] +362 mode = self._CIPHER_TABLE[cipher_name]['mode'] +363 salt = randpool.get_bytes(8) -364 key = util.generate_key_bytes(MD5, salt, password, keysize) +paramiko.util.randpool" class="py-name" href="#" onclick="return doclink('link-43', 'randpool', 'link-43');">randpool.get_bytes(8) +364 key = util.generate_key_bytes(MD5, salt, password, keysize) 365 if len(data) % blocksize != 0: 366 n = blocksize - len(data) % blocksize 367 #data += randpool.get_bytes(n) -368 # that would make more sense ^, but it confuses openssh. -369 data += '\0' * n -370 data = cipher.new(key, mode, salt).encrypt(data) -371 f.write('Proc-Type: 4,ENCRYPTED\n') -372 f.write('DEK-Info: %s,%s\n' % (cipher_name, hexlify(salt).upper())) -373 f.write('\n') +368 # that would make more sense ^, but it confuses openssh. +369 data += '\0' * n +370 data = cipher.new(key, mode, salt).encrypt(data) +371 f.write('Proc-Type: 4,ENCRYPTED\n') +372 f.write('DEK-Info: %s,%s\n' % (cipher_name, hexlify(salt).upper())) +373 f.write('\n') 374 s = base64.encodestring(data) 375 # re-wrap to 64-char lines -376 s = ''.join(s.split('\n')) +376 s = ''.join(s.split('\n')) 377 s = '\n'.join([s[i : i+64] for i in range(0, len(s), 64)]) -378 f.write(s) -379 f.write('\n') -380 f.write('-----END %s PRIVATE KEY-----\n' % tag) +378 f.write(s) +379 f.write('\n') +380 f.write('-----END %s PRIVATE KEY-----\n' % tag)
381