types.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 BindingDigest, SHA-256 of the challenge's key
  67. // authorization followed by the DER SubjectPublicKeyInfo of the certificate's
  68. // key. The CA has checked it against the certificate request, so the evidence is
  69. // fresh, is the account's, and attests the certificate's key. A TDX quote or an
  70. // SEV-SNP report also carries the relying party's ClaimNonce, which the CA does
  71. // not interpret; a Confidential Space token carries the relying party's nonces
  72. // after the binding in its eat_nonce claim. Binary values are hex encoded,
  73. // except the nonces. The fields of the embedded attestation.Result, the format
  74. // and the verified measurements or claims, are at the top level.
  75. type Attestation struct {
  76. // Challenge is the challenge type that verified the evidence,
  77. // remote-attest-01.
  78. Challenge string `json:"challenge"`
  79. // Hint is the value of the order's remote-attestation identifier.
  80. Hint string `json:"hint"`
  81. // FreshnessNonce is the challenge's freshness nonce.
  82. FreshnessNonce string `json:"freshnessNonce"`
  83. // KeyAuthorization is the challenge's key authorization: the freshness
  84. // nonce, a period, and the account key's thumbprint.
  85. KeyAuthorization string `json:"keyAuthorization"`
  86. // BindingDigest is SHA-256 of the key authorization followed by the DER
  87. // SubjectPublicKeyInfo of the certificate's key, which the evidence binds.
  88. BindingDigest string `json:"bindingDigest"`
  89. // ClaimNonce is the second half of a TDX quote's or SEV-SNP report's
  90. // report data, base64url encoded without padding.
  91. ClaimNonce string `json:"claimNonce,omitempty"`
  92. // Account is the ACME account that ordered the certificate.
  93. Account *AttestationAccount `json:"account,omitempty"`
  94. *attestation.Result
  95. }
  96. // AttestationAccount is the ACME account of an attested order, and the external
  97. // account binding key it was created with, if any.
  98. type AttestationAccount struct {
  99. ID string `json:"id"`
  100. // ExternalAccountKeyID and Reference identify the EAB key the account was
  101. // created with.
  102. ExternalAccountKeyID string `json:"externalAccountKeyID,omitempty"`
  103. Reference string `json:"reference,omitempty"`
  104. }
  105. // X5CCertificate is the authorization certificate sent to webhook servers for
  106. // enriching or authorizing webhooks when signing X509 or SSH certificates using
  107. // the X5C provisioner.
  108. type X5CCertificate struct {
  109. Raw []byte `json:"raw"`
  110. PublicKey []byte `json:"publicKey"`
  111. PublicKeyAlgorithm string `json:"publicKeyAlgorithm"`
  112. NotBefore time.Time `json:"notBefore"`
  113. NotAfter time.Time `json:"notAfter"`
  114. }
  115. // RequestBody is the body sent to webhook servers.
  116. type RequestBody struct {
  117. Timestamp time.Time `json:"timestamp"`
  118. ProvisionerName string `json:"provisionerName,omitempty"`
  119. // Only set after successfully completing acme device-attest-01 challenge
  120. AttestationData *AttestationData `json:"attestationData,omitempty"`
  121. // Only set after successfully completing acme remote-attest-01 challenge
  122. Attestation *Attestation `json:"attestation,omitempty"`
  123. // Set for most provisioners, but not acme or scep
  124. // Token any `json:"token,omitempty"`
  125. // Exactly one of the remaining fields should be set
  126. X509CertificateRequest *X509CertificateRequest `json:"x509CertificateRequest,omitempty"`
  127. X509Certificate *X509Certificate `json:"x509Certificate,omitempty"`
  128. SSHCertificateRequest *SSHCertificateRequest `json:"sshCertificateRequest,omitempty"`
  129. SSHCertificate *SSHCertificate `json:"sshCertificate,omitempty"`
  130. // Only set for SCEP webhook requests
  131. SCEPChallenge string `json:"scepChallenge,omitempty"`
  132. SCEPTransactionID string `json:"scepTransactionID,omitempty"`
  133. SCEPErrorCode int `json:"scepErrorCode,omitempty"`
  134. SCEPErrorDescription string `json:"scepErrorDescription,omitempty"`
  135. // Only set for X5C provisioners
  136. X5CCertificate *X5CCertificate `json:"x5cCertificate,omitempty"`
  137. // Set for X5C, AWS, GCP, and Azure provisioners
  138. AuthorizationPrincipal string `json:"authorizationPrincipal,omitempty"`
  139. }