title: Working with openssl to extract information from a pkcs12 certificate
body: <p>I would like some help with the openssl command. I need to automate the retrieval of the subject= line in a pkcs12 certificate for a script I'm working on. </p>
  
  <p>I've used openssl to view the contents of the Identity/Certificate:</p>
  
  <pre><code>openssl pkcs12 -info -in /Users/[user]/Desktop/ID.pfx
  </code></pre>
  
  <p>But I am prompted three times for the password. I used -passin to eliminate one of the password prompts, but I am still being prompted for the PEM pass phrase and verification entry.<br>
  I need to figure out a way to pass ${password} to the other two password challenges or have the scrip issue a ctl-c. The piece of info I need is outputted to the stdout before the second password prompt. </p>
  
  <p>Any help would be appreciated!  </p>
  
  <p>Obviously I gutted the certificate output for this post.... but you should get the idea of what I'm seeing:</p>
  
  <pre><code>bash-3.2#  openssl pkcs12 -info -in /Users/[user]/Desktop/ID.pfx -passin pass:${password}
  MAC Iteration 2048
  MAC verified OK
  PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
  Certificate bag
  Bag Attributes
      localKeyID: ****
      friendlyName: ****
  subject=****
  issuer=****
  -----BEGIN CERTIFICATE-----
  ::HASH REMOVED::
  -----END CERTIFICATE-----
  PKCS7 Data
  Shrouded Keybag: ****
  Bag Attributes
      localKeyID: **** 
      friendlyName: ****
  Key Attributes: &lt;No Attributes&gt;
  
  Enter PEM pass phrase:
  Verifying - Enter PEM pass phrase:
  
  -----BEGIN RSA PRIVATE KEY-----
  Proc-Type: 4,ENCRYPTED
  DEK-Info: 
  
  ::HASH REMOVED::
  -----END RSA PRIVATE KEY-----
  bash-3.2# 
  </code></pre>