Skip to content

Instantly share code, notes, and snippets.

@mrbuk
Created November 6, 2023 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbuk/787d7c5d0ad7ad51c33f40494148ecf6 to your computer and use it in GitHub Desktop.
Save mrbuk/787d7c5d0ad7ad51c33f40494148ecf6 to your computer and use it in GitHub Desktop.
Prints out signature algorithm, as well as type and the length of the public key for a DER formated certifacted on STDIN
package main
import (
"crypto/ecdsa"
"crypto/rsa"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
cert, err := x509.ParseCertificate(b)
if err != nil {
log.Fatal(err)
}
var length int
switch v := cert.PublicKey.(type) {
case *rsa.PublicKey:
length = v.N.BitLen()
case *ecdsa.PublicKey:
length = v.Curve.Params().BitSize
default:
length = 0
}
fmt.Printf("SignatureAlgorithm: %-15v\tPublicKeyAlgorithm: %-15v\tPublicKeyLength: %d\n", cert.SignatureAlgorithm, cert.PublicKeyAlgorithm, length)
}
for url in apple.com twitter.com netflix.com google.com facebook.com instagram.com; do
cipher=$(echo "" | openssl s_client -connect $url:443 -servername $url |& openssl x509 -outform der | go run main.go)
printf "%-30s -> %s\n" "$url" "$cipher";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment