def test_mpi(self): data = [ (1, 3, (0x00, 0x01, 0x01)), (511, 4, (0x00, 0x09, 0x01, 0xff)), (65537, 5, bytearray(b'\x00\x11\x01\x00\x01')), ] for expected, offset, invals in data: self.assertEqual((expected, offset), get_mpi(invals, 0))
def _patched_pks(self, offset): try: return orig_pks(self, offset) except: if self.raw_pub_algorithm not in (18, 22): raise self.pub_algorithm_type = "ecc" self.exponent_x, offset = get_mpi(self.data, offset) return offset
def _patched_pkm(self, offset): try: return orig_pkm(self, offset) except: if self.raw_pub_algorithm not in (18, 22): raise self.pub_algorithm_type = "ecc" offset += self.data[offset] + 1 # Skip OID self.key_value, offset = get_mpi(self.data, offset) if self.raw_pub_algorithm == 18: offset += self.data[offset] + 1 # Skip KDF return offset
def parse_key_material(self, offset): if self.raw_pub_algorithm in (1, 2, 3): self.pub_algorithm_type = "rsa" # n, e self.modulus, offset = get_mpi(self.data, offset) self.exponent, offset = get_mpi(self.data, offset) elif self.raw_pub_algorithm == 17: self.pub_algorithm_type = "dsa" # p, q, g, y self.prime, offset = get_mpi(self.data, offset) self.group_order, offset = get_mpi(self.data, offset) self.group_gen, offset = get_mpi(self.data, offset) self.key_value, offset = get_mpi(self.data, offset) elif self.raw_pub_algorithm in (16, 20): self.pub_algorithm_type = "elg" # p, g, y self.prime, offset = get_mpi(self.data, offset) self.group_gen, offset = get_mpi(self.data, offset) self.key_value, offset = get_mpi(self.data, offset) elif self.raw_pub_algorithm in (18, 19): oid_len = self.data[offset] offset += 1 self.raw_curve_oid = self.data[offset:offset + oid_len] #self.curve_oid = offset += oid_len self.curve_size, (self.curve_x, self.curve_y), offset = \ get_M(self.data, offset) # TODO(dlg): support the additional parameters for ECDH keys elif 100 <= self.raw_pub_algorithm <= 110: # Private/Experimental algorithms, just move on pass else: raise PgpdumpException("Unsupported public key algorithm {}" .format(self.raw_pub_algorithm)) return offset
def getrsaparams(key): if key[0]!=0x95: print "first param must be a secret key" sys.exit(1) offset=9 # start of key material n, offset = utils.get_mpi(key, offset) n=long(n) #print 'n', offset, "%x" % n e, offset = utils.get_mpi(key, offset) e=long(e) #print 'e', offset, "%x" % e d, offset = utils.get_mpi(key, offset+1) #print 'd', offset, "%x" % d p, offset = utils.get_mpi(key, offset) #print 'p', offset, "%x" % p q, offset = utils.get_mpi(key, offset) #print 'q', offset, "%x" % q u, offset = utils.get_mpi(key, offset) #print 'u', offset, "%x" % u return RSA.construct(([n, e, d, p, q, u]))
def parse_private_key_material(self, offset): if self.raw_pub_algorithm in (1, 2, 3): self.pub_algorithm_type = "rsa" # d, p, q, u self.exponent_d, offset = get_mpi(self.data, offset) self.prime_p, offset = get_mpi(self.data, offset) self.prime_q, offset = get_mpi(self.data, offset) self.multiplicative_inverse, offset = get_mpi(self.data, offset) elif self.raw_pub_algorithm == 17: self.pub_algorithm_type = "dsa" # x self.exponent_x, offset = get_mpi(self.data, offset) elif self.raw_pub_algorithm in (16, 20): self.pub_algorithm_type = "elg" # x self.exponent_x, offset = get_mpi(self.data, offset) elif 100 <= self.raw_pub_algorithm <= 110: # Private/Experimental algorithms, just move on pass else: raise PgpdumpException("Unsupported public key algorithm {}" .format(self.raw_pub_algorithm)) return offset