Created
November 6, 2023 16:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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