From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C417F42D76 for ; Tue, 27 Jun 2023 18:20:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BED7D40F18; Tue, 27 Jun 2023 18:20:30 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C8EF940EE1 for ; Tue, 27 Jun 2023 18:20:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687882829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hYwCNz1XesimmVAPEjaf1dSiVLTs6ZQSxpc6Pac1LOE=; b=OlQ8bZfwPousfJsHF2zJZ1CAhwCLe+4mt79kcwbo1/daoE11wL/jgDXGtRuPKFhZSCqL1T MU0sQ5ft1JgBVLAThympPthiLpdT0NeBVs+cjcY0KQqZoK1nmRygpWrlBWN1XpVA7FlqOm 7OkFF+/ajb8KPz5V5BmsVceT1q/+YfI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-427-eWNevHVRN0CjO1xWz6-Y8A-1; Tue, 27 Jun 2023 12:20:25 -0400 X-MC-Unique: eWNevHVRN0CjO1xWz6-Y8A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC11D185A7A7; Tue, 27 Jun 2023 16:20:22 +0000 (UTC) Received: from RHTPC1VM0NT (unknown [10.22.32.232]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C64040C2063; Tue, 27 Jun 2023 16:20:22 +0000 (UTC) From: Aaron Conole To: Ali Alnubani Cc: ci@dpdk.org Subject: Re: [PATCH v2] tools: add jwt renewal function to acvp_tool References: <20230626213746.25465-2-jspewock@iol.unh.edu> Date: Tue, 27 Jun 2023 12:20:21 -0400 In-Reply-To: <20230626213746.25465-2-jspewock@iol.unh.edu> (jspewock@iol.unh.edu's message of "Mon, 26 Jun 2023 17:36:01 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: ci@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK CI discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ci-bounces@dpdk.org Hi Ali, This patch didn't appear at the patches.dpdk.org/project/ci/list/ Is there something we need to do (or do I need to be logged in) to have them show up? -Aaron jspewock@iol.unh.edu writes: > From: Jeremy Spewock > > Adds a method that follows the process for renewing your jwt according > to NIST API documentation. This way, if there are load issues and it > takes too long to get vectors back with multi-algorithm testing, the > script will always handle the jwt expiring. > > Also added a maximum number of renewals so that the script cannot run > infinitely. > > Signed-off-by: Jeremy Spewock > --- > tools/acvp/acvp_tool.py | 71 ++++++++++++++++++++++++++++++++++++----- > 1 file changed, 63 insertions(+), 8 deletions(-) > mode change 100755 => 100644 tools/acvp/acvp_tool.py > > diff --git a/tools/acvp/acvp_tool.py b/tools/acvp/acvp_tool.py > old mode 100755 > new mode 100644 > index 40d2f2f..a28760d > --- a/tools/acvp/acvp_tool.py > +++ b/tools/acvp/acvp_tool.py > @@ -1,7 +1,7 @@ > #!/usr/bin/env python3 > > # SPDX-License-Identifier: BSD-3-Clause > -# Copyright 2022 The University of New Hampshire > +# Copyright 2023 The University of New Hampshire > > import hashlib > import sys > @@ -36,6 +36,8 @@ class ACVPProxy: > self.totp_path: str = totp_path > self.login_data: Optional[Dict[str, Any]] = None > self.session_data: Optional[Dict[str, Any]] = None > + self.retries: int = 0 > + self.max_retries: int = 2 > > with open(config_path, 'r') as f: > self.config: Any = json.load(f) > @@ -70,7 +72,13 @@ class ACVPProxy: > cert=self.cert, > headers={'Authorization': f'Bearer {token}'} > ) > - if not response.ok: > + if response.status_code == 401: > + if self.__renew_jwt(): > + token = self.session_data['jwt'] > + continue > + logging.error("Failed to renew expired jwt") > + return None > + elif not response.ok: > logging.error(f'Failed to fetch vector set {url}') > logging.error(json.dumps(response.json(), indent=4)) > return None > @@ -85,6 +93,35 @@ class ACVPProxy: > logging.info(f'Downloaded vector set {url}') > return vector_set_json > > + def __renew_jwt(self) -> bool: > + """Renews the jwt in session_data. > + > + JWTs provided by the NIST API last 30 minutes which can cause this > + script to fail even with good data. This method renews the jwt using > + the login endpoint. > + > + @return: True if successfully renewed token > + """ > + if self.retries >= self.max_retries: > + logging.error("Maximum number of jwt renewals has been reached.") > + return False > + response = requests.post( > + url=f'{self.config["url"]}/acvp/v1/login', > + json=[ > + {'acvVersion': '1.0'}, > + { > + 'password': self.__get_totp(), > + 'accessToken': self.session_data["jwt"] > + } > + ], > + cert=self.cert, > + ) > + if response.ok: > + self.retries += 1 > + self.session_data["jwt"] = response.json()[1].pop("accessToken") > + return True > + return False > + > def login(self) -> bool: > """Log into the API server. > > @@ -178,6 +215,12 @@ class ACVPProxy: > 'Authorization': f'Bearer {self.session_data["jwt"]}' > } > ) > + if result.status_code == 401: > + if self.__renew_jwt(): > + write_data[0]["jwt"] = self.session_data["jwt"] > + continue > + logging.error("Failed to renew jwt") > + return None > version, result_json = result.json() > if 'retry' in result_json: > duration = result_json['retry'] > @@ -208,7 +251,19 @@ class ACVPProxy: > headers={'Authorization': f'Bearer {self.session_data["jwt"]}'} > ) > > - if not response.ok: > + if response.status_code == 401: > + if self.__renew_jwt(): > + response = requests.post( > + f'{self.config["url"]}{session_url}/vectorSets/' > + f'{vector_set["vsId"]}/results', > + json=[version, vector_set], > + cert=self.cert, > + headers={'Authorization': f'Bearer {self.session_data["jwt"]}'} > + ) > + else: > + logging.error("Failed to renew jwt") > + return False > + elif not response.ok: > has_error = True > logging.error(f'Could not upload vector set response for ' > f'vector set ID {vector_set["vsId"]}.') > @@ -239,13 +294,13 @@ def main(request_path: Optional[str], > config_path=config_path, > ) > > - logging.info('Attempting to log in...') > - if not proxy.login(): > - logging.error('Could not log in.') > - sys.exit(1) > - logging.info('Successfully logged in.') > > if request_path: > + logging.info('Attempting to log in...') > + if not proxy.login(): > + logging.error('Could not log in.') > + sys.exit(1) > + logging.info('Successfully logged in.') > logging.info('Creating a new test session and downloading vectors...') > test_session = proxy.register() > if not test_session: