Skip to content

Commit

Permalink
Add PKCS12.get_cert()
Browse files Browse the repository at this point in the history
The PKCS12.get_cert() has been added to export a cert from a
PKCS #12 file using pki pkcs12-cert-export.
  • Loading branch information
edewata committed Feb 5, 2025
1 parent e4cfd4c commit 57387d8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions base/common/python/pki/pkcs12.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,29 @@ def show_certs(self):
])

subprocess.check_call(cmd)

def get_cert(self, nickname, cert_format='PEM'):

cmd = ['pki']

if self.nssdb:
cmd.extend([
'-d', self.nssdb.directory,
'-C', self.nssdb.password_file
])

cmd.extend([
'pkcs12-cert-export',
'--pkcs12-file', self.path,
'--pkcs12-password-file', self.password_file,
'--cert-format', cert_format
])

cmd.append(nickname)

result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
check=True)

return result.stdout.decode('utf-8')

0 comments on commit 57387d8

Please sign in to comment.