scep.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Package scep implements Simple Certificate Enrollment Protocol related functionality.
  2. package scep
  3. import (
  4. "crypto/x509"
  5. "encoding/asn1"
  6. "github.com/smallstep/pkcs7"
  7. smallscep "github.com/smallstep/scep"
  8. )
  9. func init() {
  10. // enable the fallback X509 certificate parser to support parsing
  11. // Windows SCEP enrollment certificates that contain a critical
  12. // authority key identifier extension. Starting with Go 1.23 those
  13. // fail to be parsed by crypto/x509. Enabling the legacy fallback
  14. // parser is a workaround for that.
  15. pkcs7.SetFallbackLegacyX509CertificateParserEnabled(true)
  16. }
  17. // FailInfoName models the name/value of failInfo
  18. type FailInfoName smallscep.FailInfo
  19. // FailInfo models a failInfo object consisting of a
  20. // name/identifier and a failInfoText, the latter of
  21. // which can be more descriptive and is intended to be
  22. // read by humans.
  23. type FailInfo struct {
  24. Name FailInfoName
  25. Text string
  26. }
  27. // SCEP OIDs
  28. var (
  29. oidSCEPmessageType = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 2}
  30. oidSCEPpkiStatus = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 3}
  31. oidSCEPfailInfo = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 4}
  32. oidSCEPsenderNonce = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 5}
  33. oidSCEPrecipientNonce = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 6}
  34. oidSCEPtransactionID = asn1.ObjectIdentifier{2, 16, 840, 1, 113733, 1, 9, 7}
  35. oidSCEPfailInfoText = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 24, 1}
  36. //oidChallengePassword = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 7}
  37. )
  38. // PKIMessage defines the possible SCEP message types
  39. type PKIMessage struct {
  40. smallscep.TransactionID
  41. smallscep.MessageType
  42. smallscep.SenderNonce
  43. *smallscep.CSRReqMessage
  44. *CertRepMessage
  45. // DER Encoded PKIMessage
  46. Raw []byte
  47. // parsed
  48. P7 *pkcs7.PKCS7
  49. // decrypted enveloped content
  50. pkiEnvelope []byte
  51. // Used to sign message
  52. Recipients []*x509.Certificate
  53. }
  54. // CertRepMessage is a type of PKIMessage
  55. type CertRepMessage struct {
  56. smallscep.PKIStatus
  57. smallscep.RecipientNonce
  58. smallscep.FailInfo
  59. Certificate *x509.Certificate
  60. degenerate []byte
  61. }