Exemplo n.º 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)
Exemplo n.º 2
0
Arquivo: dsskey.py Projeto: bobbyi/ssh
 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 bytes(b)
Exemplo n.º 3
0
Arquivo: rsakey.py Projeto: bobbyi/ssh
 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 bytes(b)
Exemplo n.º 4
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)
Exemplo n.º 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, x:
         raise SSHException('Unable to parse key file: ' + str(x))
Exemplo n.º 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)