def test_compute_prf(self): keyset_servicer = services.KeysetServicer() prf_set_servicer = services.PrfSetServicer() template = prf.prf_key_templates.HMAC_SHA256.SerializeToString() gen_request = testing_api_pb2.KeysetGenerateRequest(template=template) gen_response = keyset_servicer.Generate(gen_request, self._ctx) self.assertEqual(gen_response.WhichOneof('result'), 'keyset') keyset = gen_response.keyset key_ids_request = testing_api_pb2.PrfSetKeyIdsRequest(keyset=keyset) key_ids_response = prf_set_servicer.KeyIds(key_ids_request, self._ctx) self.assertEqual(key_ids_response.WhichOneof('result'), 'output') self.assertLen(key_ids_response.output.key_id, 1) self.assertEqual(key_ids_response.output.key_id[0], key_ids_response.output.primary_key_id) output_length = 31 compute_request = testing_api_pb2.PrfSetComputeRequest( keyset=keyset, key_id=key_ids_response.output.primary_key_id, input_data=b'input_data', output_length=output_length) compute_response = prf_set_servicer.Compute(compute_request, self._ctx) self.assertEqual(compute_response.WhichOneof('result'), 'output') self.assertLen(compute_response.output, output_length)
def main(unused_argv): aead.register() daead.register() hybrid.register() mac.register() prf.register() signature.register() streaming_aead.register() jwt.register_jwt_mac() fake_kms.register_client() server = grpc.server(futures.ThreadPoolExecutor(max_workers=2)) testing_api_pb2_grpc.add_MetadataServicer_to_server( services.MetadataServicer(), server) testing_api_pb2_grpc.add_KeysetServicer_to_server( services.KeysetServicer(), server) testing_api_pb2_grpc.add_AeadServicer_to_server(services.AeadServicer(), server) testing_api_pb2_grpc.add_DeterministicAeadServicer_to_server( services.DeterministicAeadServicer(), server) testing_api_pb2_grpc.add_MacServicer_to_server(services.MacServicer(), server) testing_api_pb2_grpc.add_PrfSetServicer_to_server( services.PrfSetServicer(), server) testing_api_pb2_grpc.add_HybridServicer_to_server( services.HybridServicer(), server) testing_api_pb2_grpc.add_SignatureServicer_to_server( services.SignatureServicer(), server) testing_api_pb2_grpc.add_StreamingAeadServicer_to_server( services.StreamingAeadServicer(), server) testing_api_pb2_grpc.add_JwtServicer_to_server(jwt_service.JwtServicer(), server) server.add_secure_port('[::]:%d' % FLAGS.port, grpc.local_server_credentials()) server.start() server.wait_for_termination()
def test_compute_prf_fail(self): keyset_servicer = services.KeysetServicer() prf_set_servicer = services.PrfSetServicer() template = prf.prf_key_templates.HMAC_SHA256.SerializeToString() gen_request = testing_api_pb2.KeysetGenerateRequest(template=template) gen_response = keyset_servicer.Generate(gen_request, self._ctx) self.assertEqual(gen_response.WhichOneof('result'), 'keyset') keyset = gen_response.keyset key_ids_request = testing_api_pb2.PrfSetKeyIdsRequest(keyset=keyset) key_ids_response = prf_set_servicer.KeyIds(key_ids_request, self._ctx) self.assertEqual(key_ids_response.WhichOneof('result'), 'output') primary_key_id = key_ids_response.output.primary_key_id invalid_output_length = 123456 invalid_compute_request = testing_api_pb2.PrfSetComputeRequest( keyset=keyset, key_id=primary_key_id, input_data=b'input_data', output_length=invalid_output_length) invalid_compute_response = prf_set_servicer.Compute( invalid_compute_request, self._ctx) self.assertEqual(invalid_compute_response.WhichOneof('result'), 'err') self.assertNotEmpty(invalid_compute_response.err)
def test_key_ids_prf_fail(self): prf_set_servicer = services.PrfSetServicer() invalid_key_ids_response = prf_set_servicer.KeyIds( testing_api_pb2.PrfSetKeyIdsRequest(keyset=b'badkeyset'), self._ctx) self.assertNotEmpty(invalid_key_ids_response.err)