Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Last active February 10, 2016 11:47
Show Gist options
  • Save binarytemple/1c96d62ea22d71d60c94 to your computer and use it in GitHub Desktop.
Save binarytemple/1c96d62ea22d71d60c94 to your computer and use it in GitHub Desktop.
I'm sure it's been done before, but here's a script which dumps asn information from PEM encoded x509 certificate files
#!/usr/bin/awk -f
# Takes a single argument, the path to a file containing PEM encoded certificate(s)
BEGIN{count=0}
/-----BEGIN CERTIFICATE-----/{
count++
items[count] = $0
}
/-----END CERTIFICATE-----/{
items[count] = items[count] "\n" $0
}
!/---/{
items[count] = items[count] "\n" $0
}
END{
for (item in items) {
sanitize="| tr -cd '[a-zA-Z0-9= -\(\):<>+\.\/\n]' |"
cmd = "cat <<END " sanitize " openssl x509 -noout -text "
cmd = cmd "\n" "END"
system(cmd)
}
}
@binarytemple
Copy link
Author

really wonder if this enough... this script is only for use with trusted input sources

@binarytemple
Copy link
Author

tr works on OS-X irrespective of the position of the newline ('\n') in the list of allowed characters, on Linux it crashes unless it's the last character in the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment