-
Notifications
You must be signed in to change notification settings - Fork 297
Expand file tree
/
Copy pathssl.cpp
More file actions
75 lines (54 loc) · 2.27 KB
/
ssl.cpp
File metadata and controls
75 lines (54 loc) · 2.27 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Copyright (c) DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ssl.hpp"
#include "cassandra.h"
#include "external.hpp"
#include <uv.h>
using namespace datastax::internal::core;
extern "C" {
CassSsl* cass_ssl_new() {
SslContextFactory::init_once();
return cass_ssl_new_no_lib_init();
}
CassSsl* cass_ssl_new_no_lib_init() {
SslContext::Ptr ssl_context(SslContextFactory::create());
ssl_context->inc_ref();
return CassSsl::to(ssl_context.get());
}
void cass_ssl_free(CassSsl* ssl) { ssl->dec_ref(); }
CassError cass_ssl_add_trusted_cert(CassSsl* ssl, const char* cert) {
return cass_ssl_add_trusted_cert_n(ssl, cert, SAFE_STRLEN(cert));
}
CassError cass_ssl_add_trusted_cert_n(CassSsl* ssl, const char* cert, size_t cert_length) {
return ssl->add_trusted_cert(cert, cert_length);
}
void cass_ssl_set_verify_flags(CassSsl* ssl, int flags) { ssl->set_verify_flags(flags); }
CassError cass_ssl_set_cert(CassSsl* ssl, const char* cert) {
return cass_ssl_set_cert_n(ssl, cert, SAFE_STRLEN(cert));
}
CassError cass_ssl_set_cert_n(CassSsl* ssl, const char* cert, size_t cert_length) {
return ssl->set_cert(cert, cert_length);
}
CassError cass_ssl_set_private_key(CassSsl* ssl, const char* key, const char* password) {
return cass_ssl_set_private_key_n(ssl, key, SAFE_STRLEN(key), password, SAFE_STRLEN(password));
}
CassError cass_ssl_set_private_key_n(CassSsl* ssl, const char* key, size_t key_length,
const char* password, size_t password_length) {
return ssl->set_private_key(key, key_length, password, password_length);
}
CassError cass_ssl_set_default_verify_paths(CassSsl* ssl) {
return ssl->set_default_verify_paths();
}
} // extern "C"
template <class T>
uv_once_t SslContextFactoryBase<T>::ssl_init_guard = UV_ONCE_INIT;