grpc_security_constants.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. *
  3. * Copyright 2016 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_GRPC_SECURITY_CONSTANTS_H
  19. #define GRPC_GRPC_SECURITY_CONSTANTS_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME "transport_security_type"
  24. #define GRPC_SSL_TRANSPORT_SECURITY_TYPE "ssl"
  25. #define GRPC_TLS_TRANSPORT_SECURITY_TYPE "tls"
  26. #define GRPC_X509_CN_PROPERTY_NAME "x509_common_name"
  27. #define GRPC_X509_SUBJECT_PROPERTY_NAME "x509_subject"
  28. #define GRPC_X509_SAN_PROPERTY_NAME "x509_subject_alternative_name"
  29. #define GRPC_X509_PEM_CERT_PROPERTY_NAME "x509_pem_cert"
  30. // Please note that internally, we just faithfully pass whatever value we got by
  31. // calling SSL_get_peer_cert_chain() in OpenSSL/BoringSSL. This will mean in
  32. // OpenSSL, the following conditions might apply:
  33. // 1. On the client side, this property returns the full certificate chain. On
  34. // the server side, this property will return the certificate chain without the
  35. // leaf certificate. Application can use GRPC_X509_PEM_CERT_PROPERTY_NAME to
  36. // get the peer leaf certificate.
  37. // 2. If the session is resumed, this property could be empty for OpenSSL (but
  38. // not for BoringSSL).
  39. // For more, please refer to the official OpenSSL manual:
  40. // https://www.openssl.org/docs/man1.1.0/man3/SSL_get_peer_cert_chain.html.
  41. #define GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME "x509_pem_cert_chain"
  42. #define GRPC_SSL_SESSION_REUSED_PROPERTY "ssl_session_reused"
  43. #define GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME "security_level"
  44. #define GRPC_PEER_DNS_PROPERTY_NAME "peer_dns"
  45. #define GRPC_PEER_SPIFFE_ID_PROPERTY_NAME "peer_spiffe_id"
  46. #define GRPC_PEER_URI_PROPERTY_NAME "peer_uri"
  47. #define GRPC_PEER_EMAIL_PROPERTY_NAME "peer_email"
  48. #define GRPC_PEER_IP_PROPERTY_NAME "peer_ip"
  49. /** Environment variable that points to the default SSL roots file. This file
  50. must be a PEM encoded file with all the roots such as the one that can be
  51. downloaded from https://pki.google.com/roots.pem. */
  52. #define GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR \
  53. "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH"
  54. /** Environment variable that points to the google default application
  55. credentials json key or refresh token. Used in the
  56. grpc_google_default_credentials_create function. */
  57. #define GRPC_GOOGLE_CREDENTIALS_ENV_VAR "GOOGLE_APPLICATION_CREDENTIALS"
  58. /** Results for the SSL roots override callback. */
  59. typedef enum {
  60. GRPC_SSL_ROOTS_OVERRIDE_OK,
  61. GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY, /** Do not try fallback options. */
  62. GRPC_SSL_ROOTS_OVERRIDE_FAIL
  63. } grpc_ssl_roots_override_result;
  64. /** Callback results for dynamically loading a SSL certificate config. */
  65. typedef enum {
  66. GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED,
  67. GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW,
  68. GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL
  69. } grpc_ssl_certificate_config_reload_status;
  70. typedef enum {
  71. /** Server does not request client certificate.
  72. The certificate presented by the client is not checked by the server at
  73. all. (A client may present a self signed or signed certificate or not
  74. present a certificate at all and any of those option would be accepted) */
  75. GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE,
  76. /** Server requests client certificate but does not enforce that the client
  77. presents a certificate.
  78. If the client presents a certificate, the client authentication is left to
  79. the application (the necessary metadata will be available to the
  80. application via authentication context properties, see grpc_auth_context).
  81. The client's key certificate pair must be valid for the SSL connection to
  82. be established. */
  83. GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY,
  84. /** Server requests client certificate but does not enforce that the client
  85. presents a certificate.
  86. If the client presents a certificate, the client authentication is done by
  87. the gRPC framework. (For a successful connection the client needs to either
  88. present a certificate that can be verified against the root certificate
  89. configured by the server or not present a certificate at all)
  90. The client's key certificate pair must be valid for the SSL connection to
  91. be established. */
  92. GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY,
  93. /** Server requests client certificate and enforces that the client presents a
  94. certificate.
  95. If the client presents a certificate, the client authentication is left to
  96. the application (the necessary metadata will be available to the
  97. application via authentication context properties, see grpc_auth_context).
  98. The client's key certificate pair must be valid for the SSL connection to
  99. be established. */
  100. GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY,
  101. /** Server requests client certificate and enforces that the client presents a
  102. certificate.
  103. The certificate presented by the client is verified by the gRPC framework.
  104. (For a successful connection the client needs to present a certificate that
  105. can be verified against the root certificate configured by the server)
  106. The client's key certificate pair must be valid for the SSL connection to
  107. be established. */
  108. GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
  109. } grpc_ssl_client_certificate_request_type;
  110. /* Security levels of grpc transport security. It represents an inherent
  111. * property of a backend connection and is determined by a channel credential
  112. * used to create the connection. */
  113. typedef enum {
  114. GRPC_SECURITY_MIN,
  115. GRPC_SECURITY_NONE = GRPC_SECURITY_MIN,
  116. GRPC_INTEGRITY_ONLY,
  117. GRPC_PRIVACY_AND_INTEGRITY,
  118. GRPC_SECURITY_MAX = GRPC_PRIVACY_AND_INTEGRITY,
  119. } grpc_security_level;
  120. /**
  121. * Type of local connections for which local channel/server credentials will be
  122. * applied. It supports UDS and local TCP connections.
  123. */
  124. typedef enum { UDS = 0, LOCAL_TCP } grpc_local_connect_type;
  125. /** The TLS versions that are supported by the SSL stack. **/
  126. typedef enum { TLS1_2, TLS1_3 } grpc_tls_version;
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif /* GRPC_GRPC_SECURITY_CONSTANTS_H */