validation.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package x509
  5. import "time"
  6. // Validation stores different validation levels for a given certificate
  7. type Validation struct {
  8. BrowserTrusted bool `json:"browser_trusted"`
  9. BrowserError string `json:"browser_error,omitempty"`
  10. MatchesDomain bool `json:"matches_domain,omitempty"`
  11. Domain string `json:"-"`
  12. }
  13. // ValidateWithStupidDetail fills out a Validation struct given a leaf
  14. // certificate and intermediates / roots. If opts.DNSName is set, then it will
  15. // also check if the domain matches.
  16. //
  17. // Deprecated: Use verifier.Verify() instead.
  18. func (c *Certificate) ValidateWithStupidDetail(opts VerifyOptions) (chains []CertificateChain, validation *Validation, err error) {
  19. // Manually set the time, so that all verifies we do get the same time
  20. if opts.CurrentTime.IsZero() {
  21. opts.CurrentTime = time.Now()
  22. }
  23. // XXX: Don't pass a KeyUsage to the Verify API
  24. opts.KeyUsages = nil
  25. domain := opts.DNSName
  26. opts.DNSName = ""
  27. out := new(Validation)
  28. out.Domain = domain
  29. if chains, _, _, err = c.Verify(opts); err != nil {
  30. out.BrowserError = err.Error()
  31. } else {
  32. out.BrowserTrusted = true
  33. }
  34. if domain != "" {
  35. nameErr := c.VerifyHostname(domain)
  36. if nameErr != nil {
  37. out.MatchesDomain = false
  38. } else {
  39. out.MatchesDomain = true
  40. }
  41. // Make sure we return an error if either chain building or hostname
  42. // verification fails.
  43. if err == nil && nameErr != nil {
  44. err = nameErr
  45. }
  46. }
  47. validation = out
  48. return
  49. }