mirror of
https://github.com/square/certigo.git
synced 2024-04-21 12:32:40 +00:00
first few files, main.go can work with .pem files that have just certs in them. Sample .pem and .jceks included as well
This commit is contained in:
committed by
Sarah Harvey
parent
a8f650175e
commit
dad3ab27b7
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data, _ := ioutil.ReadFile("service2service.ca.pem")
|
||||
block, data := pem.Decode(data)
|
||||
for block != nil {
|
||||
cert, _ := x509.ParseCertificates(block.Bytes)
|
||||
displayCert(cert[0])
|
||||
block, data = pem.Decode(data)
|
||||
}
|
||||
}
|
||||
|
||||
func displayCert(cert *x509.Certificate) {
|
||||
|
||||
//Expiry Date
|
||||
fmt.Println("Expiry Date:", cert.NotAfter)
|
||||
|
||||
//Algorithm
|
||||
fmt.Println("Algorithm Type:", cert.SignatureAlgorithm)
|
||||
|
||||
//Subject Info
|
||||
fmt.Println("Subject Info:")
|
||||
fmt.Println(" CommonName:", cert.Subject.CommonName)
|
||||
fmt.Println(" Organization:", cert.Subject.Organization)
|
||||
fmt.Println(" OrganizationalUnit:", cert.Subject.OrganizationalUnit)
|
||||
fmt.Println(" Country:", cert.Subject.Country)
|
||||
fmt.Println(" Locality:", cert.Subject.Locality)
|
||||
|
||||
//Issuer Info
|
||||
fmt.Println("Issuer Info:")
|
||||
fmt.Println(" CommonName:", cert.Issuer.CommonName)
|
||||
fmt.Println(" Organization:", cert.Issuer.Organization)
|
||||
fmt.Println(" OrganizationalUnit:", cert.Issuer.OrganizationalUnit)
|
||||
fmt.Println(" Country:", cert.Issuer.Country)
|
||||
fmt.Println(" Locality:", cert.Issuer.Locality)
|
||||
|
||||
//Subject Key ID
|
||||
fmt.Print("Subject Key ID: ")
|
||||
for i := 0; i < len(cert.SubjectKeyId); i++ {
|
||||
fmt.Print(hex.EncodeToString(cert.SubjectKeyId[i : i+1]))
|
||||
if i < len(cert.SubjectKeyId)-1 {
|
||||
fmt.Print(":")
|
||||
}
|
||||
}
|
||||
|
||||
//Authority Key ID
|
||||
fmt.Print("\nAuthority Key ID: ")
|
||||
for i := 0; i < len(cert.AuthorityKeyId); i++ {
|
||||
fmt.Print(hex.EncodeToString(cert.AuthorityKeyId[i : i+1]))
|
||||
if i < len(cert.AuthorityKeyId)-1 {
|
||||
fmt.Print(":")
|
||||
}
|
||||
}
|
||||
|
||||
//SANs, (alternate DNS Names)
|
||||
fmt.Println("\nAlternate DNS Names:", cert.DNSNames)
|
||||
|
||||
//Serial Number
|
||||
fmt.Println("Serial Number:", cert.SerialNumber)
|
||||
fmt.Println("\n")
|
||||
}
|
||||
Reference in New Issue
Block a user