requests.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. RequestID string
  74. }
  75. // RenewCertificateResponse is the response to a renew certificate request.
  76. type RenewCertificateResponse struct {
  77. Certificate *x509.Certificate
  78. CertificateChain []*x509.Certificate
  79. }
  80. // RevokeCertificateRequest is the request used to revoke a certificate.
  81. type RevokeCertificateRequest struct {
  82. Certificate *x509.Certificate
  83. SerialNumber string
  84. Reason string
  85. ReasonCode int
  86. PassiveOnly bool
  87. RequestID string
  88. }
  89. // RevokeCertificateResponse is the response to a revoke certificate request.
  90. type RevokeCertificateResponse struct {
  91. Certificate *x509.Certificate
  92. CertificateChain []*x509.Certificate
  93. }
  94. // GetCertificateAuthorityRequest is the request used to get the root
  95. // certificate from a CAS.
  96. type GetCertificateAuthorityRequest struct {
  97. Name string
  98. }
  99. // GetCertificateAuthorityResponse is the response that contains
  100. // the root certificate.
  101. type GetCertificateAuthorityResponse struct {
  102. RootCertificate *x509.Certificate
  103. }
  104. // CreateKeyRequest is the request used to generate a new key using a KMS.
  105. type CreateKeyRequest = apiv1.CreateKeyRequest
  106. // CreateCertificateAuthorityRequest is the request used to generate a root or
  107. // intermediate certificate.
  108. type CreateCertificateAuthorityRequest struct {
  109. Name string
  110. Type CertificateAuthorityType
  111. Template *x509.Certificate
  112. Lifetime time.Duration
  113. Backdate time.Duration
  114. RequestID string
  115. Project string
  116. Location string
  117. // Parent is the signer of the new CertificateAuthority.
  118. Parent *CreateCertificateAuthorityResponse
  119. // CreateKey defines the KMS CreateKeyRequest to use when creating a new
  120. // CertificateAuthority. If CreateKey is nil, a default algorithm will be
  121. // used.
  122. CreateKey *CreateKeyRequest
  123. }
  124. // CreateCertificateAuthorityResponse is the response for
  125. // CreateCertificateAuthority method and contains the root or intermediate
  126. // certificate generated as well as the CA chain.
  127. type CreateCertificateAuthorityResponse struct {
  128. Name string
  129. Certificate *x509.Certificate
  130. CertificateChain []*x509.Certificate
  131. KeyName string
  132. PublicKey crypto.PublicKey
  133. PrivateKey crypto.PrivateKey
  134. Signer crypto.Signer
  135. }