Perl Monks, I am working on a project and need to parse the content's of a user's firefox keystore. My current method is to use the certutil command to generate the output and look for matching lines. e.g.

# certutil -L -d /home/$username/.mozilla/firefox/*.default/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI CN=$certname,OU=site,O=org,L=city,ST=state,C=US u,u,u CN=Certificate Authority,OU=site,O=org CT,C,C

In my script I basically do something like:

my $command = "certutil -L -d $config{firefox_profile}"; open(OUTPUT , "-|", "$command"); while (my $current = <OUTPUT>){ chomp $current; if ($current =~ /^($certname)/i) { #Do something } }

This works, but I am not happy with it. For this to work, I need to know the certificate name in advance or at least the pattern to do actual work on it and I never capture the certificate name. I would like to be able to dynamically capture the CN and trust level as separate values and place them in a hash. For example:

$cert_hash{CN=$certname,OU=site,O=org,L=city,ST=state,C=US}{trust} = “ +u,u,u”; $cert_hash{CN=Certificate Authority,OU=site,O=org}{trust} = “CT,C,C”;

No clean break exists between the certficate name and the trust level in the certutil output. Additionally, the certificate name is not a fixed length, may or may not have spaces, and may have a different path structures depending. In short, my questions are:

- Is certutil the only way to get the certificate data from firefox's db files or is there a more Perl way to do it?

- If certutil is my only option, is there a clean way to extract the certificate name and the trust level?

Thanks in advance,


In reply to Firefox Keystore - Parsing Certutil Output by fixed_1978

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.