I'd like to parse a .csr file in order to retrieve a Common Name (CN) value.
I have a csr file with the following structure:
verify OK
Certificate Request:
Data:
Version: 0(0x0)
Subject: C=XX, ST=SSSSSSS, L=SSSSSS, O=CORPORATION X.X, OUT=XX, CN=IAM.YOUARE.COM
.....
I'd like to retrieve the CN value (in the example above "IAM.YOUARE.COM")
Once I have this value, I'd like to insert it in a .txt file next to the DNS.X field (please notice that it's important to respect the white space between the equal operator and the inserted value). The structure of the .txt field is shown below:
[xxxxx]
basicConstraints = CA:FALSE^M
extendedkeyUsage = serverAuth
subjectAltNAme = @alt_names
[alt_name]
DNS.X = IAM.YOUARE.COM
Up until now, I've been accessing the csr file using the command "openssl req -text - noout -verify -in XXX.csr" and copying the CN value manually. However, I now have a vast list of .csr files to "parse" and I was wondering whether you could give me some indications on how to automate this process.