def consume(self, tag, message, region): # Get values version, signature_type, public_key_algorithm, hash_algorithm, hashed_subpacket_length = region.readlist( """ uint:8, uint:8, uint:8, uint:8, uint:16""" ) # Complain if any values haven't been implemented yet self.only_implemented(version, (4,), "version four signature packets") self.only_implemented(signature_type, (0x13, 0x18), "UserId and Subkey binding signatures") # Get key algorithm algorithm = Mapped.algorithms.keys[public_key_algorithm] # Get hasher hasher = Mapped.algorithms.hashes[hash_algorithm] # Determine hashed data subsignature = region.read(hashed_subpacket_length * 8) hashed_subpacket_data = message.consume_subsignature(subsignature) # Not cyrptographically protected by signature # Should only contain advisory information unhashed_subpacket_length = region.read("uint:16") unhashed_subpacket_body = region.read(unhashed_subpacket_length * 8) unhashed_subpacket_data = message.consume_subsignature(unhashed_subpacket_body) # Left 16 bits of the signed hash value provided for a heuristic test for valid signatures left_of_signed_hash = region.read(8 * 2) # Get the mpi value for the RSA hash # RSA signature value m**d mod n mdn = Mpi.parse(region).read("uint")
def consume_rest(self, tag, message, region, info): """Already have public key things""" s2k_type = region.read("uint:8") mpis = self.get_mpis(s2k_type, message, region, info) # Get the rest of the mpi values and combine with those from public portion mpi_values = Mpi.consume_private(mpis, info["algorithm"]) mpi_tuple = info["mpi_values"] + mpi_values # Record key and key_id info["key"] = info["algorithm"].construct(list(long(i.read("uint")) for i in mpi_tuple)) info["key_id"] = self.determine_key_id(info)
def get_mpi_values(self, region, algorithm): """ * Determine position before * Get individual mpi values * Determine how much was read * Reset region to what it was before * Return byte stream for the amount read in the first pass """ pos_before = region.pos mpi_values = Mpi.consume_public(region, algorithm) pos_after = region.pos region.pos = pos_before mpi_length = (pos_after - pos_before) / 8 raw_mpi_bytes = region.read("bytes:%d" % mpi_length) return mpi_values, raw_mpi_bytes