Kimmel
Kimmel

Reputation: 577

Formatting "userCertificate;binary" for OpenSSL Processing

Goal: To query an LDAP server and identify certificate expiration dates.

Background: I am able to dump user certificates (via ldapsearch) in the "userCertificate;binary" format. This results in data similar to the below:

userCertificate:: MIIABUNCHMORECHARACTERSFORCERT1

userCertificate:: MIIABUNCHMORECHARACTERSFORCERT2

(I believe )To process the above with OpenSSL I must format the output as below:

File1:

-----BEGIN CERTIFICATE-----

MIIABUNCHMORECHARACTERSFORCERT1

-----END CERTIFICATE-----

File2:

-----BEGIN CERTIFICATE-----

MIIABUNCHMORECHARACTERSFORCERT2

-----END CERTIFICATE-----

Questions:

Thank you.

Upvotes: 0

Views: 811

Answers (1)

Kimmel
Kimmel

Reputation: 577

cat ldap_search_results.ldi |
grep userCertificate |
while read line
do
    cert=$(echo $line | awk -F '::' '{print $2}')
    echo -e "-----BEGIN CERTIFICATE-----\n${cert}\n-----END CERTIFICATE-----" | 
    openssl x509 -text |
    grep -Ei 'Subject|not after'
done

Upvotes: 1

Related Questions