def get_new_pub_key_payload(self, public_key, entity_hash, entity_hash_signature, valid_from, valid_to, public_key_type=NewPubKeyPayload.RSA, entity_type=NewPubKeyPayload.PERSONAL): payload = NewPubKeyPayload() payload.public_key = public_key payload.public_key_type = public_key_type payload.entity_type = entity_type payload.entity_hash = entity_hash payload.entity_hash_signature = entity_hash_signature payload.valid_from = valid_from payload.valid_to = valid_to return payload
def generate_ed25519_payload(key=None, entity_hash=None, entity_hash_signature=None, valid_to=int(CURRENT_TIMESTAMP_PLUS_YEAR)): if key is None: key = ED25519_PUBLIC_KEY if entity_hash is None: entity_hash = generate_entity_hash(MESSAGE) if entity_hash_signature is None: entity_hash_signature = generate_ed25519_signature(entity_hash, ED25519_PRIVATE_KEY) return NewPubKeyPayload( entity_hash=entity_hash, entity_hash_signature=entity_hash_signature, valid_from=int(CURRENT_TIMESTAMP), valid_to=valid_to, ed25519=NewPubKeyPayload.Ed25519Configuration( key=key, ), hashing_algorithm=NewPubKeyPayload.HashingAlgorithm.Value('SHA512') )
def generate_rsa_payload(key=None, entity_hash=None, entity_hash_signature=None, valid_to=int(CURRENT_TIMESTAMP_PLUS_YEAR)): if key is None: key = CERTIFICATE_PUBLIC_KEY if entity_hash is None: entity_hash = generate_entity_hash(MESSAGE) if entity_hash_signature is None: entity_hash_signature = generate_rsa_signature(entity_hash, CERTIFICATE_PRIVATE_KEY) return NewPubKeyPayload( entity_hash=entity_hash, entity_hash_signature=entity_hash_signature, valid_from=int(CURRENT_TIMESTAMP), valid_to=valid_to, rsa=NewPubKeyPayload.RSAConfiguration( padding=NewPubKeyPayload.RSAConfiguration.Padding.Value('PKCS1v15'), key=key, ), hashing_algorithm=NewPubKeyPayload.HashingAlgorithm.Value('SHA512') )
def test_public_key_handler_store_with_empty_proto(): """ Case: send transaction request to store certificate public key with empty proto Expect: invalid transaction error """ new_public_key_payload = NewPubKeyPayload() transaction_payload = TransactionPayload() transaction_payload.method = PubKeyMethod.STORE transaction_payload.data = new_public_key_payload.SerializeToString() serialized_transaction_payload = transaction_payload.SerializeToString() transaction_header = generate_header(serialized_transaction_payload, INPUTS, OUTPUTS) serialized_header = transaction_header.SerializeToString() transaction_request = TpProcessRequest( header=transaction_header, payload=serialized_transaction_payload, signature=create_signer( private_key=SENDER_PRIVATE_KEY).sign(serialized_header), ) mock_context = StubContext(inputs=INPUTS, outputs=OUTPUTS, initial_state={}) with pytest.raises(InvalidTransaction) as error: PubKeyHandler().apply(transaction=transaction_request, context=mock_context) assert proto_error_msg( NewPubKeyPayload, { 'entity_hash': ['This field is required.'], 'entity_hash_signature': ['This field is required.'], 'valid_from': ['This field is required.'], 'valid_to': ['This field is required.'], 'configuration': [ 'At least one of RSAConfiguration, ECDSAConfiguration or Ed25519Configuration must be set' ], }) == str(error.value)
def generate_ecdsa_payload(key=None, entity_hash=None, entity_hash_signature=None, valid_to=int(CURRENT_TIMESTAMP_PLUS_YEAR)): if key is None: key = ECDSA_PUBLIC_KEY if entity_hash is None: entity_hash = generate_entity_hash(MESSAGE) if entity_hash_signature is None: entity_hash_signature = generate_ecdsa_signature(entity_hash, ECDSA_PRIVATE_KEY) return NewPubKeyPayload( entity_hash=entity_hash, entity_hash_signature=entity_hash_signature, valid_from=int(CURRENT_TIMESTAMP), valid_to=valid_to, ecdsa=NewPubKeyPayload.ECDSAConfiguration( key=key, ec=NewPubKeyPayload.ECDSAConfiguration.EC.Value('SECP256k1'), ), hashing_algorithm=NewPubKeyPayload.HashingAlgorithm.Value('SHA256') )