Forum Discussion

Jnon's avatar
Jnon
Icon for Nimbostratus rankNimbostratus
Mar 08, 2018

Better option for multiple delimiters

I'm thinking there has to be a smarter way to accomplish what I'm doing here. I need to break out each value in the SSL Subject_dn, maybe a regex or ?? this is getting me what I need, but pretty sure there is a better way to accomplish this... any ideas appreciated.

 

if {[SSL::cert count ] > 0}{ set subject_dn [X509::subject [SSL::cert 0]] log local0. "this is the SSL Subject $subject_dn" set cn [getfield $subject_dn "," 1 ] set ou [getfield $subject_dn "," 2 ] set o [getfield $subject_dn "," 3 ] log local0. "CN=$cn, OU=$ou, O=$o" set cn2 [ getfield $cn "=" 2 ] set ou2 [ getfield $ou "=" 2 ] set o2 [ getfield $o "=" 2 ] log local0. "$cn2 $ou2 $o2"

 

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    Try something like this (but test it, because I haven't):

    lassign [split $subject_dn ","] cn ou o

    • Jnon's avatar
      Jnon
      Icon for Nimbostratus rankNimbostratus

      That looks like it's doing the same thing as getfields, it will get the variables for each CN, OU, O. but then it would need to be split again to remove the CN=, O=, OU= unless I'm missing something on how lassign work.

       

  • Try something like this (but test it, because I haven't):

    lassign [split $subject_dn ","] cn ou o

    • Jnon's avatar
      Jnon
      Icon for Nimbostratus rankNimbostratus

      That looks like it's doing the same thing as getfields, it will get the variables for each CN, OU, O. but then it would need to be split again to remove the CN=, O=, OU= unless I'm missing something on how lassign work.

       

  • Use this command to convert subject to an array with attribute name as key

    array set dnparts [split [string map [list "\\," "," "," "|" " , " "|" " ," "|" ", " "|"] $subject_dn] "|="]