Forum Discussion

eric_haupt1's avatar
eric_haupt1
Icon for Nimbostratus rankNimbostratus
Aug 28, 2019

7 character extraction from string (Cert subject)

I'm working a solution for an PKI requirement and I need to extract seven alphanumeric characters from the end of a cert subject. An example subject would be:

 

SUBJECT: C=BLAH, O=Barf, OU=Help, OU=People, Lastname Firstname MI xxxxxxx

 

I want to grab xxxxxxx to place into a variable. Note that not everyone will have a middle initial, but all will have xxxxxxx at the end of their x509 subject. xxxxxxx will always be a mix of lowercase alpha/0-9 numeric.

 

Thanks...

2 Replies

  • if the last blank is always before the 7 Chars use the following simple irule line :

    set last7Chars [string last " " [X509::subject [SSL::cert 0] end]

    Otherwise:

    set certSubject [X509::subject [SSL::cert 0]]
    set lenSubject [string length $certSubject]
    set last7Location [expr {$lenSubject - 8}] 
    set last7Chars [substr $certSubject $last7Location 7]