Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active June 21, 2024 00:10
Show Gist options
  • Save x-yuri/755e2f7f67fa662911f5fc44c34da88d to your computer and use it in GitHub Desktop.
Save x-yuri/755e2f7f67fa662911f5fc44c34da88d to your computer and use it in GitHub Desktop.
Displaying an ssl certificate from a commit

Displaying an ssl certificate from a commit

a.awk:

/BEGIN/ {
    close(cmd);
    getline cn < "/tmp/cn";
    close("/tmp/cn")
    if (cn == "DST Root CA X3") {
        exit
    }
}
{print | cmd}
/ # rm /tmp/cn
/ # tee='tee /tmp/cert'
/ # openssl='openssl x509 -noout -subject -nameopt multiline'
/ # sed='sed -n \\"/^\\s*commonName\\s*=\\s*/{s///; p}\\"'
/ # git show v8.16.1:src/node_root_certs.h \
    | sed '/"/!d; s/^"//; s/\(\\n\)\?",\?//' \
    | awk -v cmd='sh -c "'"$tee"' | '"$openssl"' | '"$sed"' > /tmp/cn"' -f a.awk
/ # openssl x509 -in /tmp/cert -noout -text | less

b.awk:

BEGIN {
    cmd = "sh -c '" \
        "tee /tmp/cert" \
        " | openssl x509 -noout -subject -nameopt multiline" \
        " | sed -n \"/^\\s*commonName\\s*=\\s*/{s///; p}\" > /tmp/cn" \
    "'"
}
/BEGIN/ {
    close(cmd);
    getline cn < "/tmp/cn";
    close("/tmp/cn")
    if (cn == "DST Root CA X3") {
        exit
    }
}
{print | cmd}
/ # rm /tmp/cn
/ # git show v8.16.1:src/node_root_certs.h \
    | sed '/"/!d; s/^"//; s/\(\\n\)\?",\?//' \
    | awk -f b.awk
/ # openssl x509 -in /tmp/cert -noout -text | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment