4
0

types.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package webhook
  2. import (
  3. "fmt"
  4. "time"
  5. "go.step.sm/crypto/sshutil"
  6. "go.step.sm/crypto/x509util"
  7. )
  8. // ResponseBody is the body returned by webhook servers.
  9. type ResponseBody struct {
  10. Data any `json:"data"`
  11. Allow bool `json:"allow"`
  12. Error *Error `json:"error,omitempty"`
  13. }
  14. // Error provides details explaining why the webhook was not permitted.
  15. type Error struct {
  16. Code string `json:"code"`
  17. Message string `json:"message"`
  18. }
  19. func (e *Error) Error() string {
  20. return fmt.Sprintf("%s (%s)", e.Message, e.Code)
  21. }
  22. // X509CertificateRequest is the certificate request sent to webhook servers for
  23. // enriching webhooks when signing x509 certificates
  24. type X509CertificateRequest struct {
  25. *x509util.CertificateRequest
  26. PublicKey []byte `json:"publicKey"`
  27. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  28. Raw []byte `json:"raw"`
  29. }
  30. // X509Certificate is the certificate sent to webhook servers for authorizing
  31. // webhooks when signing x509 certificates
  32. type X509Certificate struct {
  33. *x509util.Certificate
  34. PublicKey []byte `json:"publicKey"`
  35. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  36. NotBefore time.Time `json:"notBefore"`
  37. NotAfter time.Time `json:"notAfter"`
  38. Raw []byte `json:"raw"`
  39. }
  40. // SSHCertificateRequest is the certificate request sent to webhook servers for
  41. // enriching webhooks when signing SSH certificates
  42. type SSHCertificateRequest struct {
  43. PublicKey []byte `json:"publicKey"`
  44. Type string `json:"type"`
  45. KeyID string `json:"keyID"`
  46. Principals []string `json:"principals"`
  47. }
  48. // SSHCertificate is the certificate sent to webhook servers for authorizing
  49. // webhooks when signing SSH certificates
  50. type SSHCertificate struct {
  51. *sshutil.Certificate
  52. PublicKey []byte `json:"publicKey"`
  53. SignatureKey []byte `json:"signatureKey"`
  54. ValidBefore uint64 `json:"validBefore"`
  55. ValidAfter uint64 `json:"validAfter"`
  56. }
  57. // AttestationData is data validated by acme device-attest-01 challenge
  58. type AttestationData struct {
  59. PermanentIdentifier string `json:"permanentIdentifier"`
  60. }
  61. // X5CCertificate is the authorization certificate sent to webhook servers for
  62. // enriching or authorizing webhooks when signing X509 or SSH certificates using
  63. // the X5C provisioner.
  64. type X5CCertificate struct {
  65. Raw []byte `json:"raw"`
  66. PublicKey []byte `json:"publicKey"`
  67. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  68. NotBefore time.Time `json:"notBefore"`
  69. NotAfter time.Time `json:"notAfter"`
  70. }
  71. // RequestBody is the body sent to webhook servers.
  72. type RequestBody struct {
  73. Timestamp time.Time `json:"timestamp"`
  74. ProvisionerName string `json:"provisionerName,omitempty"`
  75. // Only set after successfully completing acme device-attest-01 challenge
  76. AttestationData *AttestationData `json:"attestationData,omitempty"`
  77. // Set for most provisioners, but not acme or scep
  78. // Token any `json:"token,omitempty"`
  79. // Exactly one of the remaining fields should be set
  80. X509CertificateRequest *X509CertificateRequest `json:"x509CertificateRequest,omitempty"`
  81. X509Certificate *X509Certificate `json:"x509Certificate,omitempty"`
  82. SSHCertificateRequest *SSHCertificateRequest `json:"sshCertificateRequest,omitempty"`
  83. SSHCertificate *SSHCertificate `json:"sshCertificate,omitempty"`
  84. // Only set for SCEP webhook requests
  85. SCEPChallenge string `json:"scepChallenge,omitempty"`
  86. SCEPTransactionID string `json:"scepTransactionID,omitempty"`
  87. SCEPErrorCode int `json:"scepErrorCode,omitempty"`
  88. SCEPErrorDescription string `json:"scepErrorDescription,omitempty"`
  89. // Only set for X5C provisioners
  90. X5CCertificate *X5CCertificate `json:"x5cCertificate,omitempty"`
  91. // Set for X5C, AWS, GCP, and Azure provisioners
  92. AuthorizationPrincipal string `json:"authorizationPrincipal,omitempty"`
  93. }