-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient_auth.cc
54 lines (46 loc) · 1.76 KB
/
client_auth.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2021 Google LLC
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
#include <grpc/grpc_security.h>
#include <grpcpp/security/credentials.h>
namespace lisp {
namespace grpc {
extern "C" {
grpc_ssl_pem_key_cert_pair* create_grpc_ssl_pem_key_cert_pair(
const char* private_key, const char* cert_chain) {
// The validation check in the underlying cpp code will raise an error if either
// of these is null and the overall struct isn't also a nullptr.
// https://github.com/grpc/grpc/blob/master/src/core/lib/security/credentials/ssl/ssl_credentials.cc#L99-L101
if (private_key == nullptr || cert_chain == nullptr) {
return nullptr;
}
grpc_ssl_pem_key_cert_pair* keypair = new grpc_ssl_pem_key_cert_pair;
*keypair = (grpc_ssl_pem_key_cert_pair) {
.private_key = private_key,
.cert_chain = cert_chain};
return keypair;
}
void delete_grpc_ssl_pem_key_cert_pair(
grpc_ssl_pem_key_cert_pair* keypair) {
delete keypair;
}
grpc_ssl_verify_peer_options* create_grpc_ssl_verify_peer_options(
int (*verify_peer_callback)(const char* target_name, const char* peer_pem, void* userdata),
void* verify_peer_callback_userdata,
void (*verify_peer_destruct)(void* userdata)) {
grpc_ssl_verify_peer_options* options = new grpc_ssl_verify_peer_options;
*options = (grpc_ssl_verify_peer_options) {
.verify_peer_callback = verify_peer_callback,
.verify_peer_callback_userdata = verify_peer_callback_userdata,
.verify_peer_destruct = verify_peer_destruct};
return options;
}
void delete_grpc_ssl_verify_peer_options(
grpc_ssl_verify_peer_options* options) {
delete options;
}
} // extern "C"
} // namespace grpc
} // namespace lisp