-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificatechecker.go
671 lines (573 loc) · 20.2 KB
/
certificatechecker.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
// is root in?
// all chains - use golang to test all? maybe graph like Rob's crt.sh
package main
import (
_ "bytes"
"crypto/dsa"
"crypto/ecdsa"
"crypto/rsa"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/json"
"encoding/pem"
"fmt"
_ "io"
"io/ioutil"
"net"
"net/http"
"regexp"
_ "strconv"
"strings"
"time"
"github.com/bogdanovich/dns_resolver"
"github.com/domainr/dnsr"
"github.com/weppos/publicsuffix-go/publicsuffix"
certchecker "certchecker/utils"
)
// Global regular expressions
var (
reg *regexp.Regexp
timeoutSecs time.Duration = 3 * time.Second
timeoutDeadline time.Duration = 3 * time.Second
connRetry int = 2
)
// Trust stores
var (
mozStore *x509.CertPool
msStore *x509.CertPool
appleStore *x509.CertPool
)
// Trust store files
var (
mozFile string = "truststores/Mozilla-PEM-13112023.pem"
msFile string = "truststores/MS-PEM-13112023.pem"
appleFile string = "truststores/Apple-PEM-13112023.pem"
)
func init() {
// Compile regular expressions for IP-address check and HTTP-Header server-token parsing
reg = regexp.MustCompile("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
// Load the root stores from the PEM files
mozCerts, _ := ioutil.ReadFile(mozFile)
mozStore = x509.NewCertPool()
mozStore.AppendCertsFromPEM(mozCerts)
appleCerts, _ := ioutil.ReadFile(appleFile)
appleStore = x509.NewCertPool()
appleStore.AppendCertsFromPEM(appleCerts)
msCerts, _ := ioutil.ReadFile(msFile)
msStore = x509.NewCertPool()
msStore.AppendCertsFromPEM(msCerts)
}
// - - - - -
func main() {
//certificatechecker.StoreSummaries()
var certTest CertResult
certTest = CheckCertificate("blog.cloudflare.com")
PrettyPrint(certTest)
}
func PrettyPrint(v interface{}) {
b, _ := json.MarshalIndent(v, "", " ")
println(string(b))
}
// - - - - -
/*
Summary info?
expired?
trusted?
mismatch?
installed?root included?
or not
TLS version
cipher suites
expiry of chain
sels-signed root in chain
*/
type TLSCheck struct {
ScanInformation ScanInfo `json:"scaninformation"`
CertInformation CertInfo `json:"certinformation"`
ConnInformation ConnectionInfo `json:"conninformation"`
ErrorMessage string `json:"errormessage"`
}
type ScanInfo struct {
ScanTime int `json:"scantime"`
ScanDuration int `json:"scanduration"`
ScanInput string `json:"scaninput"`
RawInput string `json:"rawinput"`
PublicSuffix string `json:"publicsuffix"`
PortNumber int `json:"portnumber"`
IPAddress string `json:"ipaddress"`
HostName string `json:"hostname"`
}
type CertInfo struct {
SubjectInformation SubjectInfo `json:"subjectinformation"`
IssuerInformation IssuerInfo `json:"issuerinformation"`
TrustInformation TrustInfo `json:"trustinformation"`
PEMCertificate string `json:"pemcertificate"`
PEMChain string `json:"pemchain,omitempty"`
NotBefore int `json:"notbefore"`
NotAfter int `json:"notafter"`
KeySize int `json:"keysize"`
KeyType string `json:"keytype"`
SigAlg string `json:"sigalg"`
PolicyOIDS string `json:"policyoids"`
AIAUrl string `json:"aiaurl"`
OCSPUrl string `json:"ocspurl"`
CRLUrl string `json:"crlurl"`
FingerprintSHA256 string `json:"fingerprintsha256"`
SerialNumber string `json:"serialnumber"`
ValidationType string `json:"valdationtype"`
ProductType string `json:"producttype"`
Validity string `json:"validity"`
NameMismatch string `json:"namemistmatch"`
RevocationStatus string `json:"revocationstatus"`
}
type IssuerInfo struct {
FullIssuer string `json:"fullissuer"`
IssuerCN string `json:"issuercn"`
IssuerBrand string `json:"issuerbrand,omitempty"`
}
type TrustInfo struct {
AppleTrust string `json:"appletrust"`
MozTrust string `json:"moztrust"`
MSTrust string `json:"mstrust"`
}
type SubjectInfo struct {
CN string `json:"cn,omitempty"`
O string `json:"o,omitempty"`
OU string `json:"ou,omitempty"`
L string `json:"l,omitempty"`
ST string `json:"st,omitempty"`
C string `json:"c,omitempty"`
SANS string `json:"sans,omitempty"`
CertSANSCount int `json:"certsanscount"`
FullSubject string `json:"fullsubject"`
}
type ConnectionInfo struct {
ServerType string `json:"servertype,omitempty"`
OCSPStaple string `json:"ocspstaple,omitempty"`
HTTPHeaders []HTTPHeader `json:"httpheaders,omitempty"`
NSRecords string `json:"nsrecords,omitempty"`
MXRecords string `json:"mxrecords,omitempty"`
CAARecords string `json:"caarecords,omitempty"`
RevDNSRecord string `json:"revdnsrecord,omitempty"`
}
type HTTPHeader struct {
Header string `json:"header,omitempty"`
HeaderValue string `json:"headervalue,omitempty"`
}
// Certificate structure
type CertResult struct {
ScanTime int
ScanDuration int
ScanInput string
RawAddress string
PublicSuffix string
PortNumber string
IPAddress string
HostName string
PEMCertificate string
PEMChain string
NotBefore int
NotAfter int
KeySize int
KeyType string
SigAlg string
OCSPStaple string
CertIssuerCN string
CertSubjectCN string
CertCountry string
CertSubject string
CertFingerprintSHA256 string
SerialNumber string
CertIssuer string
CertSANS string
CertSANSCount int
CertOrg string
PolicyOIDS string
ValidationType string
Validity string
NameMismatch string
RevocationStatus string
AIAUrl string
OCSPUrl string
CRLUrl string
ServerType string
NSRecords string
MXRecords string
CAARecords string
RevDNSRecord string
HTTPHeaders string
TLSVersion string
ScanTimings string
MozTrust string
MSTrust string
AppleTrust string
CertificateOwner string
ProductType string
ErrorMessage string
}
func StoreSummaries() {
fmt.Printf("Apple Root Store loaded from [%v] - number of certs : %v\n", appleFile, len(appleStore.Subjects()))
fmt.Printf("Microsoft Root Store loaded from [%v] - number of certs : %v\n", msFile, len(msStore.Subjects()))
fmt.Printf("Moz Root Store loaded from [%v] - number of certs : %v\n", mozFile, len(mozStore.Subjects()))
}
func CheckCertificate(address string) CertResult {
// CertPool for the server-provided chain
providedIntermediates := x509.NewCertPool()
// Some variables and input-cleaning to begin with, and of course the start time marker
startTime := int(time.Now().Unix())
accurateStartTime := time.Now()
var domainName, port, finalConnection string
var thisCertificate CertResult
thisCertificate.ScanTime = startTime
address = strings.TrimSpace(address)
thisCertificate.ScanInput = address
// address = 'raw' address from the input file
// we need to determine if it's an FQDN, IPv4 address, IPv6 address or any combination thereof with a ':port' appended...
var hostPort = strings.Split(address, ":")
// Length of result is 1: No colons, hence no specified port. Assume 443.
// 2: 1 colon, assume IPv4 or FQDN with specified hostname.
// >2: So many colons! Let's assume an IPv6 address. [Need to work out later about host to determine port - presumably > 7 colons = port specified?]
if len(hostPort) == 1 {
domainName = hostPort[0]
port = "443"
} else if len(hostPort) == 2 {
domainName = hostPort[0]
port = hostPort[1]
} else {
domainName = address
port = "443"
}
// PSL
thisCertificate.PublicSuffix, _ = publicsuffix.Domain(domainName)
// Determine if the 'HostName' part is an IP address or not - if it's a domain, attempt a DNS lookup
// If we do DNS here (via a couple of packages including the amazing miekg's DNS) - then we hopefully avoid the cgo/host lookup threading problems
// Determination is done with a regexp. Yes, yes. I know.
if reg.FindString(domainName) == "" {
resolver := dns_resolver.New([]string{"8.8.8.8"})
resolver.RetryTimes = 3
ipAdd, err := resolver.LookupHost(domainName)
//ipAdd, err := net.LookupIP(domainName)
//ip, err := net.LookupHost(domainName)
if err != nil {
thisCertificate.ErrorMessage = "Failed DNS lookup"
return thisCertificate
}
if len(ipAdd) >= 1 {
resolvedIP := ipAdd[0].String()
finalConnection = resolvedIP + ":" + port
thisCertificate.IPAddress = resolvedIP
} else {
thisCertificate.ErrorMessage = "Failed DNS lookup"
return thisCertificate
}
} else {
finalConnection = domainName + ":" + port
thisCertificate.IPAddress = domainName
}
thisCertificate.RawAddress = address
thisCertificate.PortNumber = port
thisCertificate.HostName = domainName
// Additional DNS lookups
r := dnsr.New(10000)
var caaRecords, mxRecords, nsRecords, ptrRecords strings.Builder
for _, rr := range r.Resolve(thisCertificate.HostName, "CAA") {
if rr.Type == "CAA" {
caaRecords.WriteString(rr.Value + ",")
}
}
for _, rr := range r.Resolve(thisCertificate.HostName, "MX") {
if rr.Type == "MX" {
mxRecords.WriteString(rr.Value + ",")
}
}
for _, rr := range r.Resolve(thisCertificate.HostName, "NS") {
if rr.Type == "NS" {
nsRecords.WriteString(rr.Value + ",")
}
}
ptrLookup, _ := net.LookupAddr(thisCertificate.IPAddress)
for _, rr := range ptrLookup {
ptrRecords.WriteString(rr + ",")
}
thisCertificate.NSRecords = strings.TrimSuffix(nsRecords.String(), ",")
thisCertificate.MXRecords = strings.TrimSuffix(mxRecords.String(), ",")
thisCertificate.CAARecords = strings.TrimSuffix(caaRecords.String(), ",")
thisCertificate.RevDNSRecord = strings.TrimSuffix(ptrRecords.String(), ",")
dnsLookupTime := time.Now()
// New version of TLS connection and HTTP request
//
// Disable normal certificate validation checking, attempt TLS connection to host - also use 'servername' to support SNI
// Ordering of ciphersuites set here (rather than Go defaults) in an effort to seem more 'browserlike'
tlsConfig := tls.Config{
ServerName: domainName,
InsecureSkipVerify: true,
CipherSuites: []uint16{
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
},
}
var conn *tls.Conn
var err error
tr := &http.Transport{
DialTLS: func(network, addr string) (net.Conn, error) {
conn, err = tls.Dial("tcp", finalConnection, &tlsConfig)
return conn, err
},
TLSHandshakeTimeout: 2 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
client := &http.Client{Transport: tr}
response, err := client.Get("https://" + domainName + "/")
if err != nil {
thisCertificate.ErrorMessage = "Failed TCP connection / Connection refused"
return thisCertificate
}
ipConnTime := time.Now()
// Check TLS version from connection (or the highest version, at least) - should implement proper testing of each version, but that might need multiple handshakes
connState := conn.ConnectionState()
switch connState.Version {
case tls.VersionSSL30:
thisCertificate.TLSVersion = "TLS 1.0 and up not supported"
case tls.VersionTLS10:
thisCertificate.TLSVersion = "TLS 1.1 and up not supported"
case tls.VersionTLS11:
thisCertificate.TLSVersion = "TLS 1.2 and up not supported"
case tls.VersionTLS12:
thisCertificate.TLSVersion = "TLS 1.3 not supported"
case tls.VersionTLS13:
thisCertificate.TLSVersion = "TLS 1.3 supported"
}
// HTTP headers, separating out servertype
var httpHeaders strings.Builder
thisCertificate.ServerType = response.Header.Get("Server")
for httpHeaderName, httpHeaderValues := range response.Header {
var httpHeaderValueString strings.Builder
for _, httpHeaderValue := range httpHeaderValues {
httpHeaderValueString.WriteString(httpHeaderValue)
}
httpHeaders.WriteString(httpHeaderName + ": " + httpHeaderValueString.String() + ",")
}
thisCertificate.HTTPHeaders = strings.TrimSuffix(httpHeaders.String(), ",")
defer response.Body.Close()
httpHeaderTime := time.Now()
// Log the OCSP response (in base64) if we are given one
if len(conn.OCSPResponse()) != 0 {
thisCertificate.OCSPStaple = base64.StdEncoding.EncodeToString(conn.OCSPResponse())
}
defer conn.Close()
var trustTestCert *x509.Certificate
// Loop each certificate in the PeerCertificates (from the server) and analyse each - grab subject info, SANs, key & KeySize, PEM version
checkedCert := make(map[string]bool)
i := 0
certChain := ""
for _, cert := range conn.ConnectionState().PeerCertificates {
// Ensure that each unique certificate is checked only once per host.
if _, checked := checkedCert[string(cert.Signature)]; checked {
continue
}
checkedCert[string(cert.Signature)] = true
if i == 0 {
// Put the whole subject (well, what is already formatted into a pkix.Name) into one string
thisCertificate.CertSubject = fmt.Sprintf("%+v", cert.Subject.Names)
thisCertificate.CertIssuer = fmt.Sprintf("%+v", cert.Issuer.Names)
// Other informational bits
thisCertificate.CertSubjectCN = cert.Subject.CommonName
thisCertificate.CertIssuerCN = cert.Issuer.CommonName
thisCertificate.CertCountry = strings.Join(cert.Subject.Country, "")
thisCertificate.CertSANS = strings.Join(cert.DNSNames, ",")
thisCertificate.CertSANSCount = len(cert.DNSNames)
thisCertificate.NotBefore = int(cert.NotBefore.Unix())
thisCertificate.NotAfter = int(cert.NotAfter.Unix())
thisCertificate.CertOrg = strings.Join(cert.Subject.Organization, "")
//fmt.Printf("subject: %+v\n", cert.Subject)
// Policy OIDs for EV checking
PolicyOIDSString := fmt.Sprintf("%d", cert.PolicyIdentifiers)
PolicyOIDS := strings.Replace(PolicyOIDSString, "[[", "", -1)
PolicyOIDS = strings.Replace(PolicyOIDS, "]]", "", -1)
PolicyOIDS = strings.Replace(PolicyOIDS, "] [", ",", -1)
PolicyOIDS = strings.Replace(PolicyOIDS, " ", ".", -1)
thisCertificate.PolicyOIDS = strings.TrimSpace(PolicyOIDS)
switch cert.PublicKeyAlgorithm {
case 0:
thisCertificate.KeyType = "Unknown"
thisCertificate.KeySize = 0
case 1:
thisCertificate.KeyType = "RSA"
rsaKey, err := x509.ParsePKIXPublicKey(cert.RawSubjectPublicKeyInfo)
if err == nil {
rsaPub := rsaKey.(*rsa.PublicKey)
KeySize := rsaPub.N
thisCertificate.KeySize = KeySize.BitLen()
}
case 2:
thisCertificate.KeyType = "DSA"
dsaKey, err := x509.ParsePKIXPublicKey(cert.RawSubjectPublicKeyInfo)
if err == nil {
dsaPub := dsaKey.(*dsa.PublicKey)
KeySize := dsaPub.Y
thisCertificate.KeySize = KeySize.BitLen()
}
case 3:
thisCertificate.KeyType = "ECDSA"
ecdsaKey, err := x509.ParsePKIXPublicKey(cert.RawSubjectPublicKeyInfo)
if err == nil {
ecdsaPub := ecdsaKey.(*ecdsa.PublicKey)
KeySize := ecdsaPub.X
thisCertificate.KeySize = KeySize.BitLen()
}
default:
thisCertificate.KeyType = "Unknown"
thisCertificate.KeySize = 0
}
switch cert.SignatureAlgorithm {
case 0:
thisCertificate.SigAlg = "UnknownSignatureAlgorithm"
case 1:
thisCertificate.SigAlg = "MD2WithRSA"
case 2:
thisCertificate.SigAlg = "MD5WithRSA"
case 3:
thisCertificate.SigAlg = "SHA1WithRSA"
case 4:
thisCertificate.SigAlg = "SHA256WithRSA"
case 5:
thisCertificate.SigAlg = "SHA384WithRSA"
case 6:
thisCertificate.SigAlg = "SHA512WithRSA"
case 7:
thisCertificate.SigAlg = "DSAWithSHA1"
case 8:
thisCertificate.SigAlg = "DSAWithSHA256"
case 9:
thisCertificate.SigAlg = "ECDSAWithSHA1"
case 10:
thisCertificate.SigAlg = "ECDSAWithSHA256"
case 11:
thisCertificate.SigAlg = "ECDSAWithSHA384"
case 12:
thisCertificate.SigAlg = "ECDSAWithSHA512"
}
thisCertificate.PEMCertificate = string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}))
trustTestCert = cert
// Cert fingerprint (SHA-256)
thisCertificate.CertFingerprintSHA256 = strings.Replace(fmt.Sprintf("% X", sha256.Sum256(cert.Raw)), " ", ":", -1)
// Cert serial
thisCertificate.SerialNumber = cert.SerialNumber.String()
} else {
certChain += string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}))
providedIntermediates.AppendCertsFromPEM(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}))
}
sha256HashCert := sha256.New()
sha256HashCert.Write(cert.Raw)
//fmt.Println("Cert sha-256: ", hex.EncodeToString(sha256HashCert.Sum(nil)))
if certchecker.CertificateOwner[hex.EncodeToString(sha256HashCert.Sum(nil))] != "" {
thisCertificate.CertificateOwner = certchecker.CertificateOwner[hex.EncodeToString(sha256HashCert.Sum(nil))]
}
i++
}
// Trust store checking
// Omit the 'dnsName' value in VerifyOptions - we do our own name-mismatch checking and want to keep separate - this is 'just' for path validation
if mozStore != nil {
opts := x509.VerifyOptions{
Roots: mozStore,
Intermediates: providedIntermediates,
}
if _, err := trustTestCert.Verify(opts); err != nil {
thisCertificate.MozTrust = "N"
} else {
thisCertificate.MozTrust = "Y"
}
}
if msStore != nil {
opts := x509.VerifyOptions{
Roots: msStore,
Intermediates: providedIntermediates,
}
if _, err := trustTestCert.Verify(opts); err != nil {
thisCertificate.MSTrust = "N"
} else {
thisCertificate.MSTrust = "Y"
}
}
if appleStore != nil {
opts := x509.VerifyOptions{
Roots: appleStore,
Intermediates: providedIntermediates,
}
if _, err := trustTestCert.Verify(opts); err != nil {
thisCertificate.AppleTrust = "N"
} else {
thisCertificate.AppleTrust = "Y"
}
}
// Add the chain of all certs provided by the server
thisCertificate.PEMChain = certChain
// Cert validation type - SS DV OV EV
// Self-signed: if CN is issuer, OR, if CN is in issuer (may produce small number of false positives?)
// No org in Subject - DV
// EV OID in the cert - EV
// Otherwise, OV?
// Should we factor trust in here too? What about a valid 'trusted' OV cert that simply wasn't installed fully?
// Split OIDs for testing
PolicyOIDArray := strings.Split(thisCertificate.PolicyOIDS, ",")
if thisCertificate.CertSubjectCN == thisCertificate.CertIssuerCN || strings.Contains(thisCertificate.CertIssuerCN, thisCertificate.CertSubjectCN) {
thisCertificate.ValidationType = "SS"
} else if thisCertificate.CertOrg == "" {
thisCertificate.ValidationType = "DV"
} else {
for _, thisOID := range PolicyOIDArray {
_, evOID := certchecker.EVIssuers[thisOID]
if evOID {
thisCertificate.ValidationType = "EV"
}
}
if thisCertificate.ValidationType != "EV" {
thisCertificate.ValidationType = "OV"
}
}
// Certificate 'type' determination - single, wildcard, multi-domain
if thisCertificate.CertSANSCount > 2 {
if strings.Contains(thisCertificate.CertSANS, "*") {
thisCertificate.ProductType = "MDC with Wildcard"
} else {
thisCertificate.ProductType = "MDC"
}
} else {
if strings.Contains(thisCertificate.CertSANS, "*") {
thisCertificate.ProductType = "Wildcard"
} else {
thisCertificate.ProductType = "Single"
}
}
// Naming mis-match - using Go function
if trustTestCert.VerifyHostname(thisCertificate.HostName) != nil {
thisCertificate.NameMismatch = "Y"
} else {
thisCertificate.NameMismatch = "N"
}
// CDPs, AIA
thisCertificate.CRLUrl = strings.Join(trustTestCert.CRLDistributionPoints, ",")
thisCertificate.AIAUrl = strings.Join(trustTestCert.IssuingCertificateURL, ",")
thisCertificate.OCSPUrl = strings.Join(trustTestCert.OCSPServer, ",")
// Dates
if thisCertificate.NotAfter < int(time.Now().Unix()) {
thisCertificate.Validity = "Expired"
} else if thisCertificate.NotBefore > int(time.Now().Unix()) {
thisCertificate.Validity = "Not yet valid"
} else {
thisCertificate.Validity = "Valid"
}
scanTime := time.Now()
accurateScanDuration := int(scanTime.Sub(accurateStartTime) / time.Millisecond)
thisCertificate.ScanDuration = accurateScanDuration
timeForDNSLookup := int(dnsLookupTime.Sub(accurateStartTime) / time.Millisecond)
timeForIPConnection := int(ipConnTime.Sub(dnsLookupTime) / time.Millisecond)
timeForHTTPHeader := int(httpHeaderTime.Sub(ipConnTime) / time.Millisecond)
scanTimings := fmt.Sprintf("Timings - DNS Lookup: %dms, Connection: %dms, HTTP Header: %dms, Scan processing: %dms", timeForDNSLookup, timeForIPConnection, timeForHTTPHeader, accurateScanDuration)
thisCertificate.ScanTimings = scanTimings
return thisCertificate
}