From a7ca14b06435ea00fab48bf6e5b4aadfa4eda64c Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 20 Apr 2020 19:37:18 +0530 Subject: [PATCH] CI: Fix prov example test cryptography package version exception handling --- tools/esp_prov/security/security1.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/esp_prov/security/security1.py b/tools/esp_prov/security/security1.py index 650abd795..90bffff8a 100644 --- a/tools/esp_prov/security/security1.py +++ b/tools/esp_prov/security/security1.py @@ -24,7 +24,7 @@ import proto from .security import Security from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes @@ -82,7 +82,13 @@ class Security1(Security): def __generate_key(self): # Generate private and public key pair for client self.client_private_key = X25519PrivateKey.generate() - self.client_public_key = self.client_private_key.public_key().public_bytes() + try: + self.client_public_key = self.client_private_key.public_key().public_bytes( + encoding=serialization.Encoding.Raw, + format=serialization.PublicFormat.Raw) + except TypeError: + # backward compatible call for older cryptography library + self.client_public_key = self.client_private_key.public_key().public_bytes() def _print_verbose(self, data): if (self.verbose):