Beispiel #1
0
 def write_private_key_file(self, filename, password=None):
     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')
     self._write_private_key_file('DSA', filename, str(b), password)
Beispiel #2
0
 def test_encode_decode(self):
     """
     When decoding an encoded integer, the original integer should be returned
     """
     ber = BER()
     ber.encode(1337)
     decoded = ber.decode()
     self.assertEqual(decoded, 1337)
Beispiel #3
0
 def test_encode_works_on_lists_directly(self):
     """
     Encode should raise exception when used with string
     """
     ber = BER()
     original_list = [1, 2, 3, 4, 5]
     ber.encode(original_list)
     self.assertEqual(ber.decode(), original_list)
Beispiel #4
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 b.asbytes()
Beispiel #5
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 b.asbytes()
Beispiel #6
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)
Beispiel #7
0
 def write_private_key_file(self, filename, password=None):
     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')
     self._write_private_key_file('RSA', filename, str(b), password)
Beispiel #8
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 b.asbytes()
Beispiel #9
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 b.asbytes()
Beispiel #10
0
 def write_private_key_file(self, filename, password=None):
     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')
     self._write_private_key_file('RSA', filename, str(b), password)