| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2018 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 |
|
| 19 |
#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H |
| 20 |
#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include <grpc/grpc.h> |
| 25 |
#include <grpc/grpc_security.h> |
| 26 |
|
| 27 |
#include "src/core/lib/channel/channel_args.h" |
| 28 |
#include "src/core/lib/gpr/useful.h" |
| 29 |
#include "src/core/lib/gprpp/ref_counted_ptr.h" |
| 30 |
#include "src/core/lib/gprpp/unique_type_name.h" |
| 31 |
#include "src/core/lib/security/credentials/credentials.h" |
| 32 |
#include "src/core/lib/security/security_connector/security_connector.h" |
| 33 |
|
| 34 |
/* Main struct for grpc ALTS channel credential. */ |
| 35 |
class grpc_alts_credentials final : public grpc_channel_credentials { |
| 36 |
public: |
| 37 |
grpc_alts_credentials(const grpc_alts_credentials_options* options, |
| 38 |
const char* handshaker_service_url); |
| 39 |
~grpc_alts_credentials() override; |
| 40 |
|
| 41 |
grpc_core::RefCountedPtr<grpc_channel_security_connector> |
| 42 |
create_security_connector( |
| 43 |
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds, |
| 44 |
const char* target_name, grpc_core::ChannelArgs* args) override; |
| 45 |
|
| 46 |
grpc_core::UniqueTypeName type() const override; |
| 47 |
|
| 48 |
const grpc_alts_credentials_options* options() const { return options_; } |
| 49 |
grpc_alts_credentials_options* mutable_options() { return options_; } |
| 50 |
const char* handshaker_service_url() const { return handshaker_service_url_; } |
| 51 |
|
| 52 |
private: |
| 53 |
int cmp_impl(const grpc_channel_credentials* other) const override { |
| 54 |
// TODO(yashykt): Check if we can do something better here |
| 55 |
return grpc_core::QsortCompare( |
| 56 |
static_cast<const grpc_channel_credentials*>(this), other); |
| 57 |
} |
| 58 |
|
| 59 |
grpc_alts_credentials_options* options_; |
| 60 |
char* handshaker_service_url_; |
| 61 |
}; |
| 62 |
|
| 63 |
/* Main struct for grpc ALTS server credential. */ |
| 64 |
class grpc_alts_server_credentials final : public grpc_server_credentials { |
| 65 |
public: |
| 66 |
grpc_alts_server_credentials(const grpc_alts_credentials_options* options, |
| 67 |
const char* handshaker_service_url); |
| 68 |
~grpc_alts_server_credentials() override; |
| 69 |
|
| 70 |
grpc_core::RefCountedPtr<grpc_server_security_connector> |
| 71 |
create_security_connector(const grpc_core::ChannelArgs& /* args */) override; |
| 72 |
|
| 73 |
grpc_core::UniqueTypeName type() const override; |
| 74 |
|
| 75 |
const grpc_alts_credentials_options* options() const { return options_; } |
| 76 |
grpc_alts_credentials_options* mutable_options() { return options_; } |
| 77 |
const char* handshaker_service_url() const { return handshaker_service_url_; } |
| 78 |
|
| 79 |
private: |
| 80 |
grpc_alts_credentials_options* options_; |
| 81 |
char* handshaker_service_url_; |
| 82 |
}; |
| 83 |
|
| 84 |
/** |
| 85 |
* This method creates an ALTS channel credential object with customized |
| 86 |
* information provided by caller. |
| 87 |
* |
| 88 |
* - options: grpc ALTS credentials options instance for client. |
| 89 |
* - handshaker_service_url: address of ALTS handshaker service in the format of |
| 90 |
* "host:port". If it's nullptr, the address of default metadata server will |
| 91 |
* be used. |
| 92 |
* - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted |
| 93 |
* mode. This mode can be enabled when we are sure ALTS is running on GCP or |
| 94 |
* for testing purpose. |
| 95 |
* |
| 96 |
* It returns nullptr if the flag is disabled AND ALTS is not running on GCP. |
| 97 |
* Otherwise, it returns the created credential object. |
| 98 |
*/ |
| 99 |
|
| 100 |
grpc_channel_credentials* grpc_alts_credentials_create_customized( |
| 101 |
const grpc_alts_credentials_options* options, |
| 102 |
const char* handshaker_service_url, bool enable_untrusted_alts); |
| 103 |
|
| 104 |
/** |
| 105 |
* This method creates an ALTS server credential object with customized |
| 106 |
* information provided by caller. |
| 107 |
* |
| 108 |
* - options: grpc ALTS credentials options instance for server. |
| 109 |
* - handshaker_service_url: address of ALTS handshaker service in the format of |
| 110 |
* "host:port". If it's nullptr, the address of default metadata server will |
| 111 |
* be used. |
| 112 |
* - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted |
| 113 |
* mode. This mode can be enabled when we are sure ALTS is running on GCP or |
| 114 |
* for testing purpose. |
| 115 |
* |
| 116 |
* It returns nullptr if the flag is disabled and ALTS is not running on GCP. |
| 117 |
* Otherwise, it returns the created credential object. |
| 118 |
*/ |
| 119 |
grpc_server_credentials* grpc_alts_server_credentials_create_customized( |
| 120 |
const grpc_alts_credentials_options* options, |
| 121 |
const char* handshaker_service_url, bool enable_untrusted_alts); |
| 122 |
|
| 123 |
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H */ |