|
6 | 6 | import os
|
7 | 7 | import sys
|
8 | 8 | import shutil
|
| 9 | +import subprocess |
9 | 10 | from datetime import datetime
|
| 11 | +from subprocess import PIPE, run, STDOUT |
| 12 | +from tempfile import TemporaryDirectory |
10 | 13 |
|
11 | 14 | from DIRAC import gLogger
|
12 |
| -from DIRAC.Core.Utilities.Subprocess import shellCall |
13 | 15 | from DIRAC.Core.Base.Script import Script
|
14 | 16 |
|
15 | 17 |
|
@@ -38,15 +40,19 @@ def main():
|
38 | 40 | shutil.move(old, old + nowPrefix)
|
39 | 41 |
|
40 | 42 | # new OpenSSL version require OPENSSL_CONF to point to some accessible location',
|
41 |
| - gLogger.notice("Converting p12 key to pem format") |
42 |
| - result = shellCall(900, f"export OPENSSL_CONF=/tmp && openssl pkcs12 -nocerts -in {p12} -out {key}") |
43 |
| - # The last command was successful |
44 |
| - if result["OK"] and result["Value"][0] == 0: |
45 |
| - gLogger.notice("Converting p12 certificate to pem format") |
46 |
| - result = shellCall(900, f"export OPENSSL_CONF=/tmp && openssl pkcs12 -clcerts -nokeys -in {p12} -out {cert}") |
| 43 | + with TemporaryDirectory() as tmpdir: |
| 44 | + env = os.environ | {"OPENSSL_CONF": tmpdir} |
| 45 | + gLogger.notice("Converting p12 key to pem format") |
| 46 | + cmd = ["openssl", "pkcs12", "-nocerts", "-in", p12, "-out", key] |
| 47 | + res = run(cmd, env=env, check=False, timeout=900, text=True, stdout=PIPE, stderr=STDOUT) |
| 48 | + # The last command was successful |
| 49 | + if res.returncode == 0: |
| 50 | + gLogger.notice("Converting p12 certificate to pem format") |
| 51 | + cmd = ["openssl", "pkcs12", "-clcerts", "-nokeys", "-in", p12, "-out", cert] |
| 52 | + res = run(cmd, env=env, check=False, timeout=900, text=True, stdout=PIPE, stderr=STDOUT) |
47 | 53 | # Something went wrong
|
48 |
| - if not result["OK"] or result["Value"][0] != 0: |
49 |
| - gLogger.fatal(result.get("Message", result["Value"][2])) |
| 54 | + if res.returncode != 0: |
| 55 | + gLogger.fatal(res.stdout) |
50 | 56 | for old in [cert, key]:
|
51 | 57 | if os.path.isfile(old + nowPrefix):
|
52 | 58 | gLogger.notice(f"Restore {old} file from the {old + nowPrefix}")
|
|
0 commit comments