zlint.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * ZLint Copyright 2023 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  11. * implied. See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. */
  14. // Used to check parsed info from certificate for compliance
  15. package zlint
  16. import (
  17. "time"
  18. "github.com/zmap/zcrypto/x509"
  19. "github.com/zmap/zlint/v3/lint"
  20. _ "github.com/zmap/zlint/v3/lints/apple"
  21. _ "github.com/zmap/zlint/v3/lints/cabf_br"
  22. _ "github.com/zmap/zlint/v3/lints/cabf_ev"
  23. _ "github.com/zmap/zlint/v3/lints/community"
  24. _ "github.com/zmap/zlint/v3/lints/etsi"
  25. _ "github.com/zmap/zlint/v3/lints/mozilla"
  26. _ "github.com/zmap/zlint/v3/lints/rfc"
  27. )
  28. const Version int64 = 3
  29. // LintCertificate runs all registered lints on c using default options,
  30. // producing a ResultSet.
  31. //
  32. // Using LintCertificate(c) is equivalent to calling LintCertificateEx(c, nil).
  33. func LintCertificate(c *x509.Certificate) *ResultSet {
  34. // Run all lints from the global registry
  35. return LintCertificateEx(c, nil)
  36. }
  37. // LintCertificateEx runs lints from the provided registry on c producing
  38. // a ResultSet. Providing an explicit registry allows the caller to filter the
  39. // lints that will be run. (See lint.Registry.Filter())
  40. //
  41. // If registry is nil then the global registry of all lints is used and this
  42. // function is equivalent to calling LintCertificate(c).
  43. func LintCertificateEx(c *x509.Certificate, registry lint.Registry) *ResultSet {
  44. if c == nil {
  45. return nil
  46. }
  47. if registry == nil {
  48. registry = lint.GlobalRegistry()
  49. }
  50. res := new(ResultSet)
  51. res.executeCertificate(c, registry)
  52. res.Version = Version
  53. res.Timestamp = time.Now().Unix()
  54. return res
  55. }
  56. // LintRevocationList runs all registered lints on r using default options,
  57. // producing a ResultSet.
  58. //
  59. // Using LintRevocationList(r) is equivalent to calling LintRevocationListEx(r, nil).
  60. func LintRevocationList(r *x509.RevocationList) *ResultSet {
  61. return LintRevocationListEx(r, nil)
  62. }
  63. // LintRevocationListEx runs lints from the provided registry on r producing
  64. // a ResultSet. Providing an explicit registry allows the caller to filter the
  65. // lints that will be run. (See lint.Registry.Filter())
  66. //
  67. // If registry is nil then the global registry of all lints is used and this
  68. // function is equivalent to calling LintRevocationListEx(r).
  69. func LintRevocationListEx(r *x509.RevocationList, registry lint.Registry) *ResultSet {
  70. if r == nil {
  71. return nil
  72. }
  73. if registry == nil {
  74. registry = lint.GlobalRegistry()
  75. }
  76. res := new(ResultSet)
  77. res.executeRevocationList(r, registry)
  78. res.Version = Version
  79. res.Timestamp = time.Now().Unix()
  80. return res
  81. }