File: validation.go

package info (click to toggle)
golang-github-zmap-zcrypto 0.0~git20240512.0fef58d-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,856 kB
  • sloc: python: 567; sh: 124; makefile: 9
file content (60 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download | duplicates (2)
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
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package x509

import "time"

// Validation stores different validation levels for a given certificate
type Validation struct {
	BrowserTrusted bool   `json:"browser_trusted"`
	BrowserError   string `json:"browser_error,omitempty"`
	MatchesDomain  bool   `json:"matches_domain,omitempty"`
	Domain         string `json:"-"`
}

// ValidateWithStupidDetail fills out a Validation struct given a leaf
// certificate and intermediates / roots. If opts.DNSName is set, then it will
// also check if the domain matches.
//
// Deprecated: Use verifier.Verify() instead.
func (c *Certificate) ValidateWithStupidDetail(opts VerifyOptions) (chains []CertificateChain, validation *Validation, err error) {

	// Manually set the time, so that all verifies we do get the same time
	if opts.CurrentTime.IsZero() {
		opts.CurrentTime = time.Now()
	}

	// XXX: Don't pass a KeyUsage to the Verify API
	opts.KeyUsages = nil
	domain := opts.DNSName
	opts.DNSName = ""

	out := new(Validation)
	out.Domain = domain

	if chains, _, _, err = c.Verify(opts); err != nil {
		out.BrowserError = err.Error()
	} else {
		out.BrowserTrusted = true
	}

	if domain != "" {
		nameErr := c.VerifyHostname(domain)
		if nameErr != nil {
			out.MatchesDomain = false
		} else {
			out.MatchesDomain = true
		}

		// Make sure we return an error if either chain building or hostname
		// verification fails.
		if err == nil && nameErr != nil {
			err = nameErr
		}
	}
	validation = out

	return
}