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
This commit is contained in:
Clint Byrum 2017-11-01 16:49:28 -07:00
parent 458ab7bc90
commit 2dc31dd567
1 changed files with 6 additions and 1 deletions

View File

@ -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