requests.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package apiv1
  2. import (
  3. "crypto"
  4. "crypto/x509"
  5. "time"
  6. "go.step.sm/crypto/kms/apiv1"
  7. )
  8. // CertificateAuthorityType indicates the type of Certificate Authority to
  9. // create.
  10. type CertificateAuthorityType int
  11. const (
  12. // RootCA is the type used to create a self-signed certificate suitable for
  13. // use as a root CA.
  14. RootCA CertificateAuthorityType = iota + 1
  15. // IntermediateCA is the type used to create a subordinated certificate that
  16. // can be used to sign additional leaf certificates.
  17. IntermediateCA
  18. )
  19. // SignatureAlgorithm used for cryptographic signing.
  20. type SignatureAlgorithm int
  21. const (
  22. // Not specified.
  23. UnspecifiedSignAlgorithm SignatureAlgorithm = iota
  24. // RSASSA-PKCS1-v1_5 key and a SHA256 digest.
  25. SHA256WithRSA
  26. // RSASSA-PKCS1-v1_5 key and a SHA384 digest.
  27. SHA384WithRSA
  28. // RSASSA-PKCS1-v1_5 key and a SHA512 digest.
  29. SHA512WithRSA
  30. // RSASSA-PSS key with a SHA256 digest.
  31. SHA256WithRSAPSS
  32. // RSASSA-PSS key with a SHA384 digest.
  33. SHA384WithRSAPSS
  34. // RSASSA-PSS key with a SHA512 digest.
  35. SHA512WithRSAPSS
  36. // ECDSA on the NIST P-256 curve with a SHA256 digest.
  37. ECDSAWithSHA256
  38. // ECDSA on the NIST P-384 curve with a SHA384 digest.
  39. ECDSAWithSHA384
  40. // ECDSA on the NIST P-521 curve with a SHA512 digest.
  41. ECDSAWithSHA512
  42. // EdDSA on Curve25519 with a SHA512 digest.
  43. PureEd25519
  44. )
  45. // CreateCertificateRequest is the request used to sign a new certificate.
  46. type CreateCertificateRequest struct {
  47. Template *x509.Certificate
  48. CSR *x509.CertificateRequest
  49. Lifetime time.Duration
  50. Backdate time.Duration
  51. RequestID string
  52. Provisioner *ProvisionerInfo
  53. IsCAServerCert bool
  54. }
  55. // ProvisionerInfo contains information of the provisioner used to authorize a
  56. // certificate.
  57. type ProvisionerInfo struct {
  58. ID string
  59. Type string
  60. Name string
  61. }
  62. // CreateCertificateResponse is the response to a create certificate request.
  63. type CreateCertificateResponse struct {
  64. Certificate *x509.Certificate
  65. CertificateChain []*x509.Certificate
  66. }
  67. // RenewCertificateRequest is the request used to re-sign a certificate.
  68. type RenewCertificateRequest struct {
  69. Template *x509.Certificate
  70. CSR *x509.CertificateRequest
  71. Lifetime time.Duration
  72. Backdate time.Duration
  73. Token string
  74. RequestID string
  75. }
  76. // RenewCertificateResponse is the response to a renew certificate request.
  77. type RenewCertificateResponse struct {
  78. Certificate *x509.Certificate
  79. CertificateChain []*x509.Certificate
  80. }
  81. // RevokeCertificateRequest is the request used to revoke a certificate.
  82. type RevokeCertificateRequest struct {
  83. Certificate *x509.Certificate
  84. SerialNumber string
  85. Reason string
  86. ReasonCode int
  87. PassiveOnly bool
  88. RequestID string
  89. }
  90. // RevokeCertificateResponse is the response to a revoke certificate request.
  91. type RevokeCertificateResponse struct {
  92. Certificate *x509.Certificate
  93. CertificateChain []*x509.Certificate
  94. }
  95. // GetCertificateAuthorityRequest is the request used to get the root
  96. // certificate from a CAS.
  97. type GetCertificateAuthorityRequest struct {
  98. Name string
  99. }
  100. // GetCertificateAuthorityResponse is the response that contains
  101. // the root certificate.
  102. type GetCertificateAuthorityResponse struct {
  103. RootCertificate *x509.Certificate
  104. IntermediateCertificates []*x509.Certificate
  105. }
  106. // CreateKeyRequest is the request used to generate a new key using a KMS.
  107. type CreateKeyRequest = apiv1.CreateKeyRequest
  108. // CreateCertificateAuthorityRequest is the request used to generate a root or
  109. // intermediate certificate.
  110. type CreateCertificateAuthorityRequest struct {
  111. Name string
  112. Type CertificateAuthorityType
  113. Template *x509.Certificate
  114. Lifetime time.Duration
  115. Backdate time.Duration
  116. RequestID string
  117. Project string
  118. Location string
  119. // Parent is the signer of the new CertificateAuthority.
  120. Parent *CreateCertificateAuthorityResponse
  121. // CreateKey defines the KMS CreateKeyRequest to use when creating a new
  122. // CertificateAuthority. If CreateKey is nil, a default algorithm will be
  123. // used.
  124. CreateKey *CreateKeyRequest
  125. }
  126. // CreateCertificateAuthorityResponse is the response for
  127. // CreateCertificateAuthority method and contains the root or intermediate
  128. // certificate generated as well as the CA chain.
  129. type CreateCertificateAuthorityResponse struct {
  130. Name string
  131. Certificate *x509.Certificate
  132. CertificateChain []*x509.Certificate
  133. KeyName string
  134. PublicKey crypto.PublicKey
  135. PrivateKey crypto.PrivateKey
  136. Signer crypto.Signer
  137. }
  138. // CreateCRLRequest is the request to create a Certificate Revocation List.
  139. type CreateCRLRequest struct {
  140. RevocationList *x509.RevocationList
  141. }
  142. // CreateCRLResponse is the response to a Certificate Revocation List request.
  143. type CreateCRLResponse struct {
  144. CRL []byte //the CRL in DER format
  145. }