Display SANs in output
This commit is contained in:
parent
df5ad71a40
commit
5f4e35843a
13
helpers.go
13
helpers.go
|
@ -108,6 +108,8 @@ type CertInfo struct {
|
||||||
SubjectParseError error
|
SubjectParseError error
|
||||||
Issuer RDNSequence
|
Issuer RDNSequence
|
||||||
IssuerParseError error
|
IssuerParseError error
|
||||||
|
SANs []SubjectAltName
|
||||||
|
SANsParseError error
|
||||||
SerialNumber *big.Int
|
SerialNumber *big.Int
|
||||||
SerialNumberParseError error
|
SerialNumberParseError error
|
||||||
Validity *CertValidity
|
Validity *CertValidity
|
||||||
|
@ -122,6 +124,7 @@ func MakeCertInfoFromTBS (tbs *TBSCertificate) *CertInfo {
|
||||||
info.Identifiers, info.IdentifiersParseError = tbs.ParseIdentifiers()
|
info.Identifiers, info.IdentifiersParseError = tbs.ParseIdentifiers()
|
||||||
info.Subject, info.SubjectParseError = tbs.ParseSubject()
|
info.Subject, info.SubjectParseError = tbs.ParseSubject()
|
||||||
info.Issuer, info.IssuerParseError = tbs.ParseIssuer()
|
info.Issuer, info.IssuerParseError = tbs.ParseIssuer()
|
||||||
|
info.SANs, info.SANsParseError = tbs.ParseSubjectAltNames()
|
||||||
info.SerialNumber, info.SerialNumberParseError = tbs.ParseSerialNumber()
|
info.SerialNumber, info.SerialNumberParseError = tbs.ParseSerialNumber()
|
||||||
info.Validity, info.ValidityParseError = tbs.ParseValidity()
|
info.Validity, info.ValidityParseError = tbs.ParseValidity()
|
||||||
info.IsCA, info.IsCAParseError = tbs.ParseBasicConstraints()
|
info.IsCA, info.IsCAParseError = tbs.ParseBasicConstraints()
|
||||||
|
@ -244,6 +247,8 @@ func (info *CertInfo) Environ () []string {
|
||||||
env = append(env, "ISSUER_DN=" + info.Issuer.String())
|
env = append(env, "ISSUER_DN=" + info.Issuer.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: include SANs in environment
|
||||||
|
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +257,7 @@ func (info *EntryInfo) HasParseErrors () bool {
|
||||||
info.CertInfo.IdentifiersParseError != nil ||
|
info.CertInfo.IdentifiersParseError != nil ||
|
||||||
info.CertInfo.SubjectParseError != nil ||
|
info.CertInfo.SubjectParseError != nil ||
|
||||||
info.CertInfo.IssuerParseError != nil ||
|
info.CertInfo.IssuerParseError != nil ||
|
||||||
|
info.CertInfo.SANsParseError != nil ||
|
||||||
info.CertInfo.SerialNumberParseError != nil ||
|
info.CertInfo.SerialNumberParseError != nil ||
|
||||||
info.CertInfo.ValidityParseError != nil ||
|
info.CertInfo.ValidityParseError != nil ||
|
||||||
info.CertInfo.IsCAParseError != nil
|
info.CertInfo.IsCAParseError != nil
|
||||||
|
@ -345,6 +351,13 @@ func (info *EntryInfo) Write (out io.Writer) {
|
||||||
}
|
}
|
||||||
writeField(out, "Pubkey", info.CertInfo.PubkeyHash(), nil)
|
writeField(out, "Pubkey", info.CertInfo.PubkeyHash(), nil)
|
||||||
writeField(out, "Subject", info.CertInfo.Subject, info.CertInfo.SubjectParseError)
|
writeField(out, "Subject", info.CertInfo.Subject, info.CertInfo.SubjectParseError)
|
||||||
|
if info.CertInfo.SANsParseError != nil {
|
||||||
|
writeField(out, "Alt Names", nil, info.CertInfo.SANsParseError)
|
||||||
|
} else {
|
||||||
|
for _, san := range info.CertInfo.SANs {
|
||||||
|
writeField(out, "Alt Name", san.String(), nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
writeField(out, "Issuer", info.CertInfo.Issuer, info.CertInfo.IssuerParseError)
|
writeField(out, "Issuer", info.CertInfo.Issuer, info.CertInfo.IssuerParseError)
|
||||||
writeField(out, "Serial", info.CertInfo.SerialNumber, info.CertInfo.SerialNumberParseError)
|
writeField(out, "Serial", info.CertInfo.SerialNumber, info.CertInfo.SerialNumberParseError)
|
||||||
writeField(out, "Not Before", info.CertInfo.NotBefore(), info.CertInfo.ValidityParseError)
|
writeField(out, "Not Before", info.CertInfo.NotBefore(), info.CertInfo.ValidityParseError)
|
||||||
|
|
17
x509.go
17
x509.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/asn1"
|
"encoding/asn1"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -146,6 +147,22 @@ func (rdns RDNSequence) String () string {
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (san SubjectAltName) String () string {
|
||||||
|
switch san.Type {
|
||||||
|
case sanDNSName:
|
||||||
|
return "DNS:" + string(san.Value) // TODO: escape non-printable characters, '\', and ','
|
||||||
|
case sanIPAddress:
|
||||||
|
if len(san.Value) == 4 || len(san.Value) == 16 {
|
||||||
|
return "IP:" + net.IP(san.Value).String()
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("IP:%v", san.Value)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// TODO: support other types of SANs
|
||||||
|
return fmt.Sprintf("%d:%v", san.Type, san.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ParseTBSCertificate (tbsBytes []byte) (*TBSCertificate, error) {
|
func ParseTBSCertificate (tbsBytes []byte) (*TBSCertificate, error) {
|
||||||
var tbs TBSCertificate
|
var tbs TBSCertificate
|
||||||
if rest, err := asn1.Unmarshal(tbsBytes, &tbs); err != nil {
|
if rest, err := asn1.Unmarshal(tbsBytes, &tbs); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue