#!/usr/bin/env python 
# Just a handy script to check what that p12 file is.
# Usage: beACertive.py somep12file
import sys
import OpenSSL
from OpenSSL.crypto import load_pkcs12, FILETYPE_PEM, FILETYPE_ASN1
 
with open(sys.argv[1], 'rb') as f:
  c = f.read()
 
p = load_pkcs12(c, '')
 
certificate = p.get_certificate()
private_key = p.get_privatekey()
 
# Where type is FILETYPE_PEM or FILETYPE_ASN1 (for DER).
type_ = FILETYPE_PEM
 
OpenSSL.crypto.dump_privatekey(type_, private_key)
OpenSSL.crypto.dump_certificate(type_, certificate)
 
# Get CSR fields (as a list of 2-tuples).
fields = certificate.get_subject().get_components()
print(fields)