types.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package webhook
  2. import (
  3. "fmt"
  4. "time"
  5. "go.step.sm/crypto/sshutil"
  6. "go.step.sm/crypto/x509util"
  7. "github.com/smallstep/certificates/attestation"
  8. )
  9. // ResponseBody is the body returned by webhook servers.
  10. type ResponseBody struct {
  11. Data any `json:"data"`
  12. Allow bool `json:"allow"`
  13. Error *Error `json:"error,omitempty"`
  14. }
  15. // Error provides details explaining why the webhook was not permitted.
  16. type Error struct {
  17. Code string `json:"code"`
  18. Message string `json:"message"`
  19. }
  20. func (e *Error) Error() string {
  21. return fmt.Sprintf("%s (%s)", e.Message, e.Code)
  22. }
  23. // X509CertificateRequest is the certificate request sent to webhook servers for
  24. // enriching webhooks when signing x509 certificates
  25. type X509CertificateRequest struct {
  26. *x509util.CertificateRequest
  27. PublicKey []byte `json:"publicKey"`
  28. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  29. Raw []byte `json:"raw"`
  30. }
  31. // X509Certificate is the certificate sent to webhook servers for authorizing
  32. // webhooks when signing x509 certificates
  33. type X509Certificate struct {
  34. *x509util.Certificate
  35. PublicKey []byte `json:"publicKey"`
  36. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  37. NotBefore time.Time `json:"notBefore"`
  38. NotAfter time.Time `json:"notAfter"`
  39. Raw []byte `json:"raw"`
  40. }
  41. // SSHCertificateRequest is the certificate request sent to webhook servers for
  42. // enriching webhooks when signing SSH certificates
  43. type SSHCertificateRequest struct {
  44. PublicKey []byte `json:"publicKey"`
  45. Type string `json:"type"`
  46. KeyID string `json:"keyID"`
  47. Principals []string `json:"principals"`
  48. }
  49. // SSHCertificate is the certificate sent to webhook servers for authorizing
  50. // webhooks when signing SSH certificates
  51. type SSHCertificate struct {
  52. *sshutil.Certificate
  53. PublicKey []byte `json:"publicKey"`
  54. SignatureKey []byte `json:"signatureKey"`
  55. ValidBefore uint64 `json:"validBefore"`
  56. ValidAfter uint64 `json:"validAfter"`
  57. }
  58. // AttestationData is data validated by acme device-attest-01 challenge
  59. type AttestationData struct {
  60. PermanentIdentifier string `json:"permanentIdentifier"`
  61. }
  62. // Attestation is the attestation evidence an ACME remote-attest-01 challenge
  63. // verified (draft-ietf-acme-rats), sent to webhook servers when the order is
  64. // finalized and given to certificate templates as .Attestation.
  65. //
  66. // The evidence binds two SHA-256 digests: of the challenge's key authorization,
  67. // and of the DER SubjectPublicKeyInfo of the certificate's key. The CA has
  68. // checked both, so the certificate's key is the attested one. Binary values are
  69. // hex encoded. The fields of the embedded attestation.Result, the format and the
  70. // verified measurements or claims, are at the top level.
  71. type Attestation struct {
  72. // Challenge is the challenge type that verified the evidence,
  73. // remote-attest-01.
  74. Challenge string `json:"challenge"`
  75. // Hint is the value of the order's remote-attestation identifier.
  76. Hint string `json:"hint"`
  77. // FreshnessNonce is the challenge's freshness nonce.
  78. FreshnessNonce string `json:"freshnessNonce"`
  79. // KeyAuthorizationDigest is the SHA-256 digest of the challenge's key
  80. // authorization, which the evidence binds.
  81. KeyAuthorizationDigest string `json:"keyAuthorizationDigest"`
  82. // KeyDigest is the SHA-256 digest of the DER SubjectPublicKeyInfo of the
  83. // certificate's key, which the evidence binds.
  84. KeyDigest string `json:"keyDigest"`
  85. *attestation.Result
  86. }
  87. // X5CCertificate is the authorization certificate sent to webhook servers for
  88. // enriching or authorizing webhooks when signing X509 or SSH certificates using
  89. // the X5C provisioner.
  90. type X5CCertificate struct {
  91. Raw []byte `json:"raw"`
  92. PublicKey []byte `json:"publicKey"`
  93. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  94. NotBefore time.Time `json:"notBefore"`
  95. NotAfter time.Time `json:"notAfter"`
  96. }
  97. // RequestBody is the body sent to webhook servers.
  98. type RequestBody struct {
  99. Timestamp time.Time `json:"timestamp"`
  100. ProvisionerName string `json:"provisionerName,omitempty"`
  101. // Only set after successfully completing acme device-attest-01 challenge
  102. AttestationData *AttestationData `json:"attestationData,omitempty"`
  103. // Only set after successfully completing acme remote-attest-01 challenge
  104. Attestation *Attestation `json:"attestation,omitempty"`
  105. // Set for most provisioners, but not acme or scep
  106. // Token any `json:"token,omitempty"`
  107. // Exactly one of the remaining fields should be set
  108. X509CertificateRequest *X509CertificateRequest `json:"x509CertificateRequest,omitempty"`
  109. X509Certificate *X509Certificate `json:"x509Certificate,omitempty"`
  110. SSHCertificateRequest *SSHCertificateRequest `json:"sshCertificateRequest,omitempty"`
  111. SSHCertificate *SSHCertificate `json:"sshCertificate,omitempty"`
  112. // Only set for SCEP webhook requests
  113. SCEPChallenge string `json:"scepChallenge,omitempty"`
  114. SCEPTransactionID string `json:"scepTransactionID,omitempty"`
  115. SCEPErrorCode int `json:"scepErrorCode,omitempty"`
  116. SCEPErrorDescription string `json:"scepErrorDescription,omitempty"`
  117. // Only set for X5C provisioners
  118. X5CCertificate *X5CCertificate `json:"x5cCertificate,omitempty"`
  119. // Set for X5C, AWS, GCP, and Azure provisioners
  120. AuthorizationPrincipal string `json:"authorizationPrincipal,omitempty"`
  121. }