Skip to content

Instantly share code, notes, and snippets.

@brimston3
Created October 13, 2018 07:57
Show Gist options
  • Save brimston3/c45a42a07f49f92ceaf94126af0e67fb to your computer and use it in GitHub Desktop.
Save brimston3/c45a42a07f49f92ceaf94126af0e67fb to your computer and use it in GitHub Desktop.
Inline expand x509 certificates using awk to buffer and openssl to parse.
# openssl s_client -connect google.com:443 -showcerts </dev/null | awk -f expand_certs_inline.awk
#or pack it all into one line, see if I care.
BEGIN{
e="";
flag=0;
ssl_proc_cmd="openssl x509 -noout -text";
}
/-----BEGIN CERTIFICATE/{
e=$0 "\n";
l=NR;
flag=1;
next;
}
!flag{print}
/END CERTIFICATE-----/{
e=e $0 "\n";
print "### Cert at " l;
print e|ssl_proc_cmd;
close(ssl_proc_cmd);
e="";
flag=0;
}
flag{
e=e $0 "\n";
}
END{
if (flag) {
print "Unterminated certificate starting at" l;
print e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment