title: Parsing a DN from certificate in pem format (correct order)
body: <p>I have seen a few posts related to parsing DN from a certificate in PEM format. I am writing a UNIX script that will read the pem files in a given path and spits out their corresponding Distinguished Name (DN) in the correct order. Created a simple script but the command that parses the pem file within the script is..</p>
  <p><strong>openssl x509 -in &lt;<em>file name.pem</em>&gt; -noout -subject</strong></p>
  <p>My confusion is when I run the above command, it spits the DN in this order starting with /C=US/ST=...but I know for a fact that the certificate DN starts with &quot;CN=&quot; which is exact reverse of what the command is spitting out. I am having a hard time trusting which command to run that gives me the exact order because I use that order to authenticate the user and if I onboard with the wrong order, requests will not be authorized and it defeats the purpose.</p>