Пример #1
0
 def sign_ssh_data(self, rpool, data):
     digest = SHA.new(data).digest()
     rsa = RSA.construct((long(self.n), long(self.e), long(self.d)))
     sig = util.deflate_long(rsa.sign(self._pkcs1imify(digest), '')[0], 0)
     m = Message()
     m.add_string('ssh-rsa')
     m.add_string(sig)
     return m
Пример #2
0
 def sign_ssh_data(self, rpool, data):
     digest = SHA.new(data).digest()
     rsa = RSA.construct((int(self.n), int(self.e), int(self.d)))
     sig = util.deflate_long(rsa.sign(self._pkcs1imify(digest), '')[0], 0)
     m = Message()
     m.add_string(b'ssh-rsa')
     m.add_string(sig)
     return m
Пример #3
0
 def _pkcs1imify(self, data):
     """
     turn a 20-byte SHA1 hash into a blob of data as large as the key's N,
     using PKCS1's \"emsa-pkcs1-v1_5\" encoding.  totally bizarre.
     """
     SHA1_DIGESTINFO = b'\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14'
     size = len(util.deflate_long(self.n, 0))
     filler = b'\xff' * (size - len(SHA1_DIGESTINFO) - len(data) - 3)
     return b'\x00\x01' + filler + b'\x00' + SHA1_DIGESTINFO + data
Пример #4
0
 def _pkcs1imify(self, data):
     """
     turn a 20-byte SHA1 hash into a blob of data as large as the key's N,
     using PKCS1's \"emsa-pkcs1-v1_5\" encoding.  totally bizarre.
     """
     SHA1_DIGESTINFO = '\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14'
     size = len(util.deflate_long(self.n, 0))
     filler = '\xff' * (size - len(SHA1_DIGESTINFO) - len(data) - 3)
     return '\x00\x01' + filler + '\x00' + SHA1_DIGESTINFO + data
Пример #5
0
 def add_mpint(self, z):
     """
     Add a long int to the stream, encoded as an infinite-precision
     integer.  This method only works on positive numbers.
     
     @param z: long int to add
     @type z: long
     """
     self.add_string(util.deflate_long(z))
     return self
Пример #6
0
 def add_mpint(self, z):
     """
     Add a long int to the stream, encoded as an infinite-precision
     integer.  This method only works on positive numbers.
     
     @param z: long int to add
     @type z: long
     """
     self.add_string(util.deflate_long(z))
     return self
Пример #7
0
 def sign_ssh_data(self, rng, data):
     digest = SHA.new(data).digest()
     dss = DSA.construct((int(self.y), int(self.g), int(self.p), int(self.q), int(self.x)))
     # generate a suitable k
     qsize = len(util.deflate_long(self.q, 0))
     while True:
         k = util.inflate_long(rng.read(qsize), 1)
         if (k > 2) and (k < self.q):
             break
     r, s = dss.sign(util.inflate_long(digest, 1), k)
     m = Message()
     m.add_string(b'ssh-dss')
     # apparently, in rare cases, r or s may be shorter than 20 bytes!
     rstr = util.deflate_long(r, 0)
     sstr = util.deflate_long(s, 0)
     if len(rstr) < 20:
         rstr = b'\x00' * (20 - len(rstr)) + rstr
     if len(sstr) < 20:
         sstr = b'\x00' * (20 - len(sstr)) + sstr
     m.add_string(rstr + sstr)
     return m
Пример #8
0
 def sign_ssh_data(self, rng, data):
     digest = SHA.new(data).digest()
     dss = DSA.construct((long(self.y), long(self.g), long(self.p), long(self.q), long(self.x)))
     # generate a suitable k
     qsize = len(util.deflate_long(self.q, 0))
     while True:
         k = util.inflate_long(rng.read(qsize), 1)
         if (k > 2) and (k < self.q):
             break
     r, s = dss.sign(util.inflate_long(digest, 1), k)
     m = Message()
     m.add_string('ssh-dss')
     # apparently, in rare cases, r or s may be shorter than 20 bytes!
     rstr = util.deflate_long(r, 0)
     sstr = util.deflate_long(s, 0)
     if len(rstr) < 20:
         rstr = '\x00' * (20 - len(rstr)) + rstr
     if len(sstr) < 20:
         sstr = '\x00' * (20 - len(sstr)) + sstr
     m.add_string(rstr + sstr)
     return m
Пример #9
0
 def _generate_x(self):
     # generate an "x" (1 < x < (p-1)/2).
     q = (self.p - 1) // 2
     qnorm = util.deflate_long(q, 0)
     qhbyte = ord(qnorm[0])
     bytes = len(qnorm)
     qmask = 0xff
     while not (qhbyte & 0x80):
         qhbyte <<= 1
         qmask >>= 1
     while True:
         x_bytes = self.transport.rng.read(bytes)
         x_bytes = chr(ord(x_bytes[0]) & qmask) + x_bytes[1:]
         x = util.inflate_long(x_bytes, 1)
         if (x > 1) and (x < q):
             break
     self.x = x
Пример #10
0
 def _generate_x(self):
     # generate an "x" (1 < x < (p-1)/2).
     q = (self.p - 1) // 2
     qnorm = util.deflate_long(q, 0)
     qhbyte = ord(qnorm[0])
     bytes = len(qnorm)
     qmask = 0xff
     while not (qhbyte & 0x80):
         qhbyte <<= 1
         qmask >>= 1
     while True:
         x_bytes = self.transport.rng.read(bytes)
         x_bytes = chr(ord(x_bytes[0]) & qmask) + x_bytes[1:]
         x = util.inflate_long(x_bytes, 1)
         if (x > 1) and (x < q):
             break
     self.x = x