def generate_raw_signed_model( self, key_pair, add_self_sign=False, virgil_key_pair=None, extra_key_pair=None, previous_card_id=None ): create_time = 1515686245 raw_card_content = RawCardContent( created_at=create_time, identity="test", public_key=key_pair.public_key, version="5.0", previous_card_id=previous_card_id ) model = RawSignedModel(raw_card_content.content_snapshot) signer = ModelSigner(CardCrypto()) if add_self_sign: signer.self_sign(model, key_pair.private_key) if virgil_key_pair: signer.sign(model, ModelSigner.VIRGIL_SIGNER, virgil_key_pair.private_key) if extra_key_pair: signer.sign(model, "extra", extra_key_pair.private_key) return model
def test_extra_sign_valid_signature(self): self_key_pair = self._crypto.generate_keys() extra_key_pair = self._crypto.generate_keys() raw_signed_model = self._data_generator.generate_raw_signed_model( self_key_pair, add_self_sign=True) signer = ModelSigner(CardCrypto()) self.assertEqual(len(raw_signed_model.signatures), 1) signer.sign(raw_signed_model, "test_id", extra_key_pair.private_key) self.assertEqual(len(raw_signed_model.signatures), 2) extra_signature = raw_signed_model.signatures[-1] self.assertEqual(extra_signature.signer, "test_id") self.assertTrue( self._crypto.verify( bytearray(Utils.b64_decode(raw_signed_model.content_snapshot)), extra_signature.signature, extra_key_pair.public_key))