Exemplo n.º 1
0
 def test_l5block_signing_hashing(self):
     block = make_l5_block()
     sig = crypto.sign_l5_block(blake2b, secp256k1, key, block)
     self.assertEqual(sig, "MEQCIAiTBQg2HnJ9ho8M2J0ld9f8S+mKHC3/warPhAIGAXDtAiAwmcjbNkbANFxx46pBr3VyzAf59aQwAFV7bQEHZCv7rQ==")
     sig = crypto.sign_l5_block(sha256, secp256k1, key, block)
     self.assertEqual(sig, "MEQCID3V1WcHCuxLHthMve+Dv5Ad81GeDOYZO3W3UQrjOT/rAiBxo6qSa2su1QC3Mk6ZA+/dut0DoUgzaa7NParo/FGUxA==")
     sig = crypto.sign_l5_block(sha3_256, secp256k1, key, block)
     self.assertEqual(sig, "MEQCIC/WuXKBBFTKUyEKJTLu9q/tacsAuAX2MYl+6wsVAuiFAiB9wj9HP34BDeeWpUs3GLHGHNp7nD/EuJGoO6bQrnUvYg==")
Exemplo n.º 2
0
 def sign_block(self, signable_block: "model.BlockModel") -> str:
     """Sign a block with this class' keys
     Args:
         block: BlockModel to sign
     Returns:
         Base64 encoded string of the block signature
     Raises:
         exceptions.InvalidNodeLevel when invalid level on self
         RuntimeError when no private key is set on self
     """
     if self.priv is None:
         raise RuntimeError("No private key has been set for signing")
     if self.level == 1:
         return crypto.sign_l1_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 2:
         return crypto.sign_l2_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 3:
         return crypto.sign_l3_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 4:
         return crypto.sign_l4_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 5:
         return crypto.sign_l5_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     else:
         raise exceptions.InvalidNodeLevel(
             f"Node level {self.level} not implemented yet")
Exemplo n.º 3
0
 def test_l5block_trust_verifying(self):
     block = make_l5_block()
     sig = crypto.sign_l5_block(blake2b, secp256k1, key, block)
     block.proof = sig
     block.scheme = "trust"
     self.assertTrue(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     valid_block = copy.deepcopy(block)
     block.dc_id = "forged"
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     block = copy.deepcopy(valid_block)
     block.block_id = "forged"
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     block = copy.deepcopy(valid_block)
     block.timestamp = "forged"
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     block = copy.deepcopy(valid_block)
     block.prev_proof = "forged=="
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     block = copy.deepcopy(valid_block)
     block.l4_blocks[0] = "forged"
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))
     block = copy.deepcopy(valid_block)
     block.proof = "MEQCIF+o3DHBiTbpw8X6W4/yOuPF/FfANIiNnG0mFLgjBAjuAiAe/QAHN8ufmHMeRvHFItdrzVHFORGED4/msipzFORGED=="
     self.assertFalse(
         crypto.verify_l5_block_trust(blake2b, secp256k1, key.pubkey,
                                      block))