示例#1
0
 def _encode_key(self):
     if self.x is None:
         raise SSHException('Not enough key information')
     keylist = [ 0, self.p, self.q, self.g, self.y, self.x ]
     try:
         b = BER()
         b.encode(keylist)
     except BERException:
         raise SSHException('Unable to create ber encoding of key')
     return str(b)
示例#2
0
 def _encode_key(self):
     if (self.p is None) or (self.q is None):
         raise SSHException('Not enough key info to write private key file')
     keylist = [ 0, self.n, self.e, self.d, self.p, self.q,
                 self.d % (self.p - 1), self.d % (self.q - 1),
                 util.mod_inverse(self.q, self.p) ]
     try:
         b = BER()
         b.encode(keylist)
     except BERException:
         raise SSHException('Unable to create ber encoding of key')
     return str(b)
示例#3
0
 def _encode_key(self):
     if (self.p is None) or (self.q is None):
         raise SSHException('Not enough key info to write private key file')
     keylist = [
         0, self.n, self.e, self.d, self.p, self.q, self.d % (self.p - 1),
         self.d % (self.q - 1),
         util.mod_inverse(self.q, self.p)
     ]
     try:
         b = BER()
         b.encode(keylist)
     except BERException:
         raise SSHException('Unable to create ber encoding of key')
     return str(b)
示例#4
0
 def _decode_key(self, data):
     # private key file contains:
     # DSAPrivateKey = { version = 0, p, q, g, y, x }
     try:
         keylist = BER(data).decode()
     except BERException, x:
         raise SSHException('Unable to parse key file: ' + str(x))
示例#5
0
 def _decode_key(self, data):
     # private key file contains:
     # DSAPrivateKey = { version = 0, p, q, g, y, x }
     try:
         keylist = BER(data).decode()
     except BERException as e:
         raise SSHException('Unable to parse key file: ' + str(e))
     if (type(keylist) is not list or len(keylist) < 6 or keylist[0] != 0):
         raise SSHException(
             'not a valid DSA private key file (bad ber encoding)')
     self.p = keylist[1]
     self.q = keylist[2]
     self.g = keylist[3]
     self.y = keylist[4]
     self.x = keylist[5]
     self.size = util.bit_length(self.p)
示例#6
0
 def _decode_key(self, data):
     # private key file contains:
     # RSAPrivateKey = { version = 0, n, e, d, p, q, d mod p-1, d mod q-1, q**-1 mod p }
     try:
         keylist = BER(data).decode()
     except BERException:
         raise SSHException('Unable to parse key file')
     if (type(keylist)
             is not list) or (len(keylist) < 4) or (keylist[0] != 0):
         raise SSHException(
             'Not a valid RSA private key file (bad ber encoding)')
     self.n = keylist[1]
     self.e = keylist[2]
     self.d = keylist[3]
     # not really needed
     self.p = keylist[4]
     self.q = keylist[5]
     self.size = util.bit_length(self.n)