From 2dc31dd5674a453951a6f416fb1c97dcebe7acb0 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Wed, 1 Nov 2017 16:49:28 -0700 Subject: [PATCH] Make encrypt_secret.py work with OpenSSL 0.x The format was changed in 1.0. This enables Mac OS's default openssl CLI tool to work with encrypt_secret.py Change-Id: Ib5d7a0c5cc6a729bed6fa4a64193444bb48022fb --- tools/encrypt_secret.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/encrypt_secret.py b/tools/encrypt_secret.py index df4f449baa..9b528467d4 100755 --- a/tools/encrypt_secret.py +++ b/tools/encrypt_secret.py @@ -86,7 +86,12 @@ def main(): if p.returncode != 0: raise Exception("Return code %s from openssl" % p.returncode) output = stdout.decode('utf-8') - m = re.match(r'^Public-Key: \((\d+) bit\)$', output, re.MULTILINE) + openssl_version = subprocess.check_output( + ['openssl', 'version']).split()[1] + if openssl_version.startswith(b'0.'): + m = re.match(r'^Modulus \((\d+) bit\):$', output, re.MULTILINE) + else: + m = re.match(r'^Public-Key: \((\d+) bit\)$', output, re.MULTILINE) nbits = int(m.group(1)) nbytes = int(nbits / 8) max_bytes = nbytes - 42 # PKCS1-OAEP overhead