1 //
2 //
3 // Copyright 2020 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 #include <grpc/support/port_platform.h>
20
21 #include <grpc/grpc_security.h>
22
23 #include "src/core/lib/security/credentials/credentials.h"
24 #include "src/core/lib/security/security_connector/insecure/insecure_security_connector.h"
25
26 namespace grpc_core {
27 namespace {
28
29 constexpr char kCredentialsTypeInsecure[] = "insecure";
30
31 class InsecureCredentials final : public grpc_channel_credentials {
32 public:
InsecureCredentials()33 InsecureCredentials() : grpc_channel_credentials(kCredentialsTypeInsecure) {}
34
create_security_connector(RefCountedPtr<grpc_call_credentials> call_creds,const char *,const grpc_channel_args *,grpc_channel_args **)35 RefCountedPtr<grpc_channel_security_connector> create_security_connector(
36 RefCountedPtr<grpc_call_credentials> call_creds,
37 const char* /* target_name */, const grpc_channel_args* /* args */,
38 grpc_channel_args** /* new_args */) override {
39 return MakeRefCounted<InsecureChannelSecurityConnector>(
40 Ref(), std::move(call_creds));
41 }
42 };
43
44 class InsecureServerCredentials final : public grpc_server_credentials {
45 public:
InsecureServerCredentials()46 InsecureServerCredentials()
47 : grpc_server_credentials(kCredentialsTypeInsecure) {}
48
create_security_connector()49 RefCountedPtr<grpc_server_security_connector> create_security_connector()
50 override {
51 return MakeRefCounted<InsecureServerSecurityConnector>(Ref());
52 }
53 };
54
55 } // namespace
56 } // namespace grpc_core
57
grpc_insecure_credentials_create()58 grpc_channel_credentials* grpc_insecure_credentials_create() {
59 return new grpc_core::InsecureCredentials();
60 }
61
grpc_insecure_server_credentials_create()62 grpc_server_credentials* grpc_insecure_server_credentials_create() {
63 return new grpc_core::InsecureServerCredentials();
64 }
65