Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[targetReleaseBranch] Update dirac_cert_convert.py, adding cmd-line option "--legacy" to allow pcks12 certificate with legacy crypto #7418

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/DIRAC/Core/scripts/dirac_cert_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@
@Script()
def main():
Script.registerArgument("P12: user certificate in the p12")
_, args = Script.parseCommandLine(ignoreErrors=True)
# Allow legacy pcks12 certificates (as for some providers)
# Only use long option, to show that this is not recommended,
# and may be deprecated later (if providers gets their acts together)
Script.registerSwitch("", "legacy", "Allow legacy crypto pcks12 certificates (may be deprecated in future)")

switches, args = Script.parseCommandLine(ignoreErrors=True)

# Handle legacy option
legacy = ''
for switch in switches:
# Check only for "legacy", not for "l"
# (otherwise would have "or switch[0].lower() == 'l'")
if switch[0].lower() == "legacy":
legacy = "-legacy"

if len(legacy)>0:
gLogger.warn("Warning: using legacy crypto option: "+legacy
+" ... May be deprecated in future")

p12 = args[0]
if not os.path.isfile(p12):
Expand All @@ -43,12 +60,12 @@ def main():
with TemporaryDirectory() as tmpdir:
env = os.environ | {"OPENSSL_CONF": tmpdir}
gLogger.notice("Converting p12 key to pem format")
cmd = ["openssl", "pkcs12", "-nocerts", "-in", p12, "-out", key]
cmd = ["openssl", "pkcs12", "-nocerts", "-in", p12, "-out", key, legacy]
res = run(cmd, env=env, check=False, timeout=900, text=True, stdout=PIPE, stderr=STDOUT)
# The last command was successful
if res.returncode == 0:
gLogger.notice("Converting p12 certificate to pem format")
cmd = ["openssl", "pkcs12", "-clcerts", "-nokeys", "-in", p12, "-out", cert]
cmd = ["openssl", "pkcs12", "-clcerts", "-nokeys", "-in", p12, "-out", cert, legacy]
res = run(cmd, env=env, check=False, timeout=900, text=True, stdout=PIPE, stderr=STDOUT)
# Something went wrong
if res.returncode != 0:
Expand Down
Loading