mirror of
				https://github.com/SSLMate/certspotter.git
				synced 2025-07-03 10:47:17 +02:00 
			
		
		
		
	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
 | 
			
		||||
	Issuer			RDNSequence
 | 
			
		||||
	IssuerParseError	error
 | 
			
		||||
	SANs			[]SubjectAltName
 | 
			
		||||
	SANsParseError		error
 | 
			
		||||
	SerialNumber		*big.Int
 | 
			
		||||
	SerialNumberParseError	error
 | 
			
		||||
	Validity		*CertValidity
 | 
			
		||||
@ -122,6 +124,7 @@ func MakeCertInfoFromTBS (tbs *TBSCertificate) *CertInfo {
 | 
			
		||||
	info.Identifiers, info.IdentifiersParseError = tbs.ParseIdentifiers()
 | 
			
		||||
	info.Subject, info.SubjectParseError = tbs.ParseSubject()
 | 
			
		||||
	info.Issuer, info.IssuerParseError = tbs.ParseIssuer()
 | 
			
		||||
	info.SANs, info.SANsParseError = tbs.ParseSubjectAltNames()
 | 
			
		||||
	info.SerialNumber, info.SerialNumberParseError = tbs.ParseSerialNumber()
 | 
			
		||||
	info.Validity, info.ValidityParseError = tbs.ParseValidity()
 | 
			
		||||
	info.IsCA, info.IsCAParseError = tbs.ParseBasicConstraints()
 | 
			
		||||
@ -244,6 +247,8 @@ func (info *CertInfo) Environ () []string {
 | 
			
		||||
		env = append(env, "ISSUER_DN=" + info.Issuer.String())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TODO: include SANs in environment
 | 
			
		||||
 | 
			
		||||
	return env
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -252,6 +257,7 @@ func (info *EntryInfo) HasParseErrors () bool {
 | 
			
		||||
		info.CertInfo.IdentifiersParseError != nil ||
 | 
			
		||||
		info.CertInfo.SubjectParseError != nil ||
 | 
			
		||||
		info.CertInfo.IssuerParseError != nil ||
 | 
			
		||||
		info.CertInfo.SANsParseError != nil ||
 | 
			
		||||
		info.CertInfo.SerialNumberParseError != nil ||
 | 
			
		||||
		info.CertInfo.ValidityParseError != 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, "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, "Serial", info.CertInfo.SerialNumber, info.CertInfo.SerialNumberParseError)
 | 
			
		||||
		writeField(out, "Not Before", info.CertInfo.NotBefore(), info.CertInfo.ValidityParseError)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								x509.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								x509.go
									
									
									
									
									
								
							@ -7,6 +7,7 @@ import (
 | 
			
		||||
	"encoding/asn1"
 | 
			
		||||
	"math/big"
 | 
			
		||||
	"time"
 | 
			
		||||
	"net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@ -146,6 +147,22 @@ func (rdns RDNSequence) String () 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) {
 | 
			
		||||
	var tbs TBSCertificate
 | 
			
		||||
	if rest, err := asn1.Unmarshal(tbsBytes, &tbs); err != nil {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user