This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
/
main.go
58 lines (53 loc) · 1.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"crypto/x509"
"encoding/base64"
"fmt"
"github.com/miekg/dns"
)
func main() {
c := new(dns.Client)
c.Net = "tcp"
m := new(dns.Msg)
m.SetQuestion("direct1.demo.direct-test.com.", dns.TypeCERT)
//m.SetQuestion("kryptiq.direct-ci.com.", dns.TypeCERT)
in, _, err := c.Exchange(m, "8.8.8.8:53")
if err != nil {
fmt.Println("ERROR: ", err)
return
}
//fmt.Println("MsgHdr: ", in.MsgHdr)
if in.MsgHdr.Rcode != 0 {
fmt.Println("ERROR from DNS server: ",
dns.RcodeToString[in.MsgHdr.Rcode])
return
}
//fmt.Println("Length of answer: ", len(in.Answer))
if rr, ok := in.Answer[0].(*dns.CERT); ok {
//fmt.Println(rr.Type, rr.KeyTag, rr.Algorithm, rr.Certificate)
asn, err := base64.StdEncoding.DecodeString(rr.Certificate)
if err != nil {
fmt.Println("Error b64 decoding: ", err)
return
}
cert, err := x509.ParseCertificate(asn)
if err != nil {
fmt.Println("Error decoding cert: ", err)
return
}
//fmt.Println(cert.Subject)
//fmt.Println(cert.DNSNames)
//fmt.Println(cert.EmailAddresses)
//fmt.Println("--- Subject ---")
//fmt.Println(cert.Subject.SerialNumber)
/*for _, v := range cert.Subject.Names {
fmt.Println(v)
}
fmt.Println("--- Issuer ---")
for _, v := range cert.Issuer.Names {
fmt.Println(v)
}*/
fmt.Println("Subject: ", GetNameString(cert.Subject.Names))
fmt.Println("Issuer: ", GetNameString(cert.Issuer.Names))
}
}