Make changes to 5.1 to compile with new TLS Plugin.
This commit is contained in:
parent
23335eb4d3
commit
488da10d75
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
* ITLSPlugin.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FDB_ITLSPLUGIN_H
|
||||
#define FDB_ITLSPLUGIN_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct ITLSSession {
|
||||
enum { SUCCESS = 0, WANT_READ = -1, WANT_WRITE = -2, FAILED = -3 };
|
||||
|
||||
virtual void addref() = 0;
|
||||
virtual void delref() = 0;
|
||||
|
||||
// handshake should return SUCCESS if the handshake is complete,
|
||||
// FAILED on fatal error, or one of WANT_READ or WANT_WRITE if the
|
||||
// handshake should be reattempted after more data can be
|
||||
// read/written on the underlying connection.
|
||||
virtual int handshake() = 0;
|
||||
|
||||
// read should return the (non-zero) number of bytes read,
|
||||
// WANT_READ or WANT_WRITE if the operation is blocked by the
|
||||
// underlying stream, or FAILED if there is an error (including a
|
||||
// closed connection).
|
||||
virtual int read(uint8_t* data, int length) = 0;
|
||||
|
||||
// write should return the (non-zero) number of bytes written, or
|
||||
// WANT_READ or WANT_WRITE if the operation is blocked by the
|
||||
// underlying stream, or FAILED if there is an error.
|
||||
virtual int write(const uint8_t* data, int length) = 0;
|
||||
};
|
||||
|
||||
// Returns the number of bytes sent (possibly 0), or -1 on error
|
||||
// (including connection close)
|
||||
typedef int (*TLSSendCallbackFunc)(void* ctx, const uint8_t* buf, int len);
|
||||
|
||||
// Returns the number of bytes read (possibly 0), or -1 on error
|
||||
// (including connection close)
|
||||
typedef int (*TLSRecvCallbackFunc)(void* ctx, uint8_t* buf, int len);
|
||||
|
||||
struct ITLSPolicy {
|
||||
virtual void addref() = 0;
|
||||
virtual void delref() = 0;
|
||||
|
||||
// set_ca_data should import the provided certificate list and
|
||||
// associate it with this policy. cert_data will point to a PEM
|
||||
// encoded certificate list of trust roots.
|
||||
//
|
||||
// set_ca_data should return true if the operation succeeded,
|
||||
// and false otherwise. After the first call to create_session for
|
||||
// a given policy, set_ca_data should immediately return false
|
||||
// if called.
|
||||
virtual bool set_ca_data(const uint8_t* ca_data, int ca_len) = 0;
|
||||
|
||||
// set_cert_data should import the provided certificate list and
|
||||
// associate it with this policy. cert_data will point to a PEM
|
||||
// encoded certificate list, ordered such that each certificate
|
||||
// certifies the one before it.
|
||||
//
|
||||
// cert_data may additionally contain key information, which must
|
||||
// be ignored.
|
||||
//
|
||||
// set_cert_data should return true if the operation succeeded,
|
||||
// and false otherwise. After the first call to create_session for
|
||||
// a given policy, set_cert_data should immediately return false
|
||||
// if called.
|
||||
virtual bool set_cert_data(const uint8_t* cert_data, int cert_len) = 0;
|
||||
|
||||
// set_key_data should import the provided private key and
|
||||
// associate it with this policy. key_data will point to a PEM
|
||||
// encoded key, which may be encrypted. If encrypted the password
|
||||
// argument should be specified, otherwise it may be NULL.
|
||||
//
|
||||
// key_data may additionally contain certificate information,
|
||||
// which must be ignored.
|
||||
//
|
||||
// set_key_data should return true if the operation succeeded, and
|
||||
// false otherwise. After the first call to create_session for a
|
||||
// given policy, set_key_data should immediately return false if
|
||||
// called.
|
||||
virtual bool set_key_data(const uint8_t* key_data, int key_len, const char* password) = 0;
|
||||
|
||||
// set_verify_peers should modify the validation rules for
|
||||
// verifying a peer during connection handshake. The format of
|
||||
// verify_peers is implementation specific.
|
||||
//
|
||||
// set_verify_peers should return true if the operation succeed,
|
||||
// and false otherwise. After the first call to create_session for
|
||||
// a given policy, set_verify_peers should immediately return
|
||||
// false if called.
|
||||
virtual bool set_verify_peers(int count, const uint8_t* verify_peers[], int verify_peers_len[]) = 0;
|
||||
|
||||
// create_session should return a new object that implements
|
||||
// ITLSSession, associated with this policy. After the first call
|
||||
// to create_session for a given policy, further calls to
|
||||
// ITLSPolicy::set_* will fail and return false.
|
||||
//
|
||||
// The newly created session should use send_func and recv_func to
|
||||
// send and receive data on the underlying transport, and must
|
||||
// provide send_ctx/recv_ctx to the callbacks.
|
||||
//
|
||||
// uid should only be provided when invoking an ITLSLogFunc, which
|
||||
// will use it to identify this session.
|
||||
virtual ITLSSession* create_session(bool is_client, const char *servername, TLSSendCallbackFunc send_func, void* send_ctx, TLSRecvCallbackFunc recv_func, void* recv_ctx, void* uid) = 0;
|
||||
};
|
||||
|
||||
// Logs a message/error to the appropriate trace log.
|
||||
//
|
||||
// event must be a valid XML attribute value. uid may be NULL or the
|
||||
// uid provided to ITLSPolicy::create_session by the caller. is_error
|
||||
// should be true for errors and false for informational messages. The
|
||||
// remaining arguments must be pairs of (const char*); the first of
|
||||
// each pair must be a valid XML attribute name, and the second a
|
||||
// valid XML attribute value. The final parameter must be NULL.
|
||||
typedef void (*ITLSLogFunc)(const char* event, void* uid, bool is_error, ...);
|
||||
|
||||
struct ITLSPlugin {
|
||||
virtual void addref() = 0;
|
||||
virtual void delref() = 0;
|
||||
|
||||
// create_policy should return a new object that implements
|
||||
// ITLSPolicy.
|
||||
//
|
||||
// The newly created policy, and any session further created from
|
||||
// the policy, should use logf to log any messages or errors that
|
||||
// occur.
|
||||
virtual ITLSPolicy* create_policy( ITLSLogFunc logf ) = 0;
|
||||
|
||||
static inline const char* get_plugin_type_name_and_version() { return "ITLSPlugin"; }
|
||||
};
|
||||
|
||||
#endif /* FDB_ITLSPLUGIN_H */
|
|
@ -1,4 +1,4 @@
|
|||
FDBLibTLS_CFLAGS := -fPIC -I/usr/local/include -I$(BOOSTDIR)
|
||||
FDBLibTLS_CFLAGS := -fPIC -I/usr/local/include -I$(BOOSTDIR) -Ifdbrpc
|
||||
FDBLibTLS_STATIC_LIBS := -ltls -lssl -lcrypto
|
||||
FDBLibTLS_LDFLAGS := -L/usr/local/lib -static-libstdc++ -static-libgcc -lrt
|
||||
FDBLibTLS_LDFLAGS += -Wl,-soname,FDBLibTLS.so -Wl,--version-script=FDBLibTLS/FDBLibTLS.map
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
* ITLSPlugin.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
* ITLSPlugin.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FDB_ITLSPLUGIN_H
|
||||
#define FDB_ITLSPLUGIN_H
|
||||
|
@ -51,20 +51,30 @@ struct ITLSSession {
|
|||
|
||||
// Returns the number of bytes sent (possibly 0), or -1 on error
|
||||
// (including connection close)
|
||||
typedef int (*TLSSendCallbackFunc)(void* ctx, const uint8_t* buf, int len);
|
||||
typedef int(*TLSSendCallbackFunc)(void* ctx, const uint8_t* buf, int len);
|
||||
|
||||
// Returns the number of bytes read (possibly 0), or -1 on error
|
||||
// (including connection close)
|
||||
typedef int (*TLSRecvCallbackFunc)(void* ctx, uint8_t* buf, int len);
|
||||
typedef int(*TLSRecvCallbackFunc)(void* ctx, uint8_t* buf, int len);
|
||||
|
||||
struct ITLSPolicy {
|
||||
virtual void addref() = 0;
|
||||
virtual void delref() = 0;
|
||||
|
||||
// set_ca_data should import the provided certificate list and
|
||||
// associate it with this policy. cert_data will point to a PEM
|
||||
// encoded certificate list of trust roots.
|
||||
//
|
||||
// set_ca_data should return true if the operation succeeded,
|
||||
// and false otherwise. After the first call to create_session for
|
||||
// a given policy, set_ca_data should immediately return false
|
||||
// if called.
|
||||
virtual bool set_ca_data(const uint8_t* ca_data, int ca_len) = 0;
|
||||
|
||||
// set_cert_data should import the provided certificate list and
|
||||
// associate it with this policy. cert_data will point to a PEM
|
||||
// encoded certificate list, ordered such that each certificate
|
||||
// certifies the one befor it.
|
||||
// certifies the one before it.
|
||||
//
|
||||
// cert_data may additionally contain key information, which must
|
||||
// be ignored.
|
||||
|
@ -77,7 +87,8 @@ struct ITLSPolicy {
|
|||
|
||||
// set_key_data should import the provided private key and
|
||||
// associate it with this policy. key_data will point to a PEM
|
||||
// encoded key.
|
||||
// encoded key, which may be encrypted. If encrypted the password
|
||||
// argument should be specified, otherwise it may be NULL.
|
||||
//
|
||||
// key_data may additionally contain certificate information,
|
||||
// which must be ignored.
|
||||
|
@ -86,7 +97,7 @@ struct ITLSPolicy {
|
|||
// false otherwise. After the first call to create_session for a
|
||||
// given policy, set_key_data should immediately return false if
|
||||
// called.
|
||||
virtual bool set_key_data(const uint8_t* key_data, int key_len) = 0;
|
||||
virtual bool set_key_data(const uint8_t* key_data, int key_len, const char* password) = 0;
|
||||
|
||||
// set_verify_peers should modify the validation rules for
|
||||
// verifying a peer during connection handshake. The format of
|
||||
|
@ -96,7 +107,7 @@ struct ITLSPolicy {
|
|||
// and false otherwise. After the first call to create_session for
|
||||
// a given policy, set_verify_peers should immediately return
|
||||
// false if called.
|
||||
virtual bool set_verify_peers(const uint8_t* verify_peers, int verify_peers_len) = 0;
|
||||
virtual bool set_verify_peers(int count, const uint8_t* verify_peers[], int verify_peers_len[]) = 0;
|
||||
|
||||
// create_session should return a new object that implements
|
||||
// ITLSSession, associated with this policy. After the first call
|
||||
|
@ -109,7 +120,7 @@ struct ITLSPolicy {
|
|||
//
|
||||
// uid should only be provided when invoking an ITLSLogFunc, which
|
||||
// will use it to identify this session.
|
||||
virtual ITLSSession* create_session(bool is_client, TLSSendCallbackFunc send_func, void* send_ctx, TLSRecvCallbackFunc recv_func, void* recv_ctx, void* uid ) = 0;
|
||||
virtual ITLSSession* create_session(bool is_client, const char *servername, TLSSendCallbackFunc send_func, void* send_ctx, TLSRecvCallbackFunc recv_func, void* recv_ctx, void* uid) = 0;
|
||||
};
|
||||
|
||||
// Logs a message/error to the appropriate trace log.
|
||||
|
@ -120,7 +131,7 @@ struct ITLSPolicy {
|
|||
// remaining arguments must be pairs of (const char*); the first of
|
||||
// each pair must be a valid XML attribute name, and the second a
|
||||
// valid XML attribute value. The final parameter must be NULL.
|
||||
typedef void (*ITLSLogFunc)(const char* event, void* uid, int is_error, ...);
|
||||
typedef void(*ITLSLogFunc)(const char* event, void* uid, bool is_error, ...);
|
||||
|
||||
struct ITLSPlugin {
|
||||
virtual void addref() = 0;
|
||||
|
@ -132,7 +143,7 @@ struct ITLSPlugin {
|
|||
// The newly created policy, and any session further created from
|
||||
// the policy, should use logf to log any messages or errors that
|
||||
// occur.
|
||||
virtual ITLSPolicy* create_policy( ITLSLogFunc logf ) = 0;
|
||||
virtual ITLSPolicy* create_policy(ITLSLogFunc logf) = 0;
|
||||
|
||||
static inline const char* get_plugin_type_name_and_version() { return "ITLSPlugin"; }
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "ITLSPlugin.h"
|
||||
#include "LoadPlugin.h"
|
||||
#include "Platform.h"
|
||||
#include <memory>
|
||||
|
||||
// Must not throw an exception from this function!
|
||||
static int send_func(void* ctx, const uint8_t* buf, int len) {
|
||||
|
@ -84,7 +85,7 @@ ACTOR static Future<Void> handshake( TLSConnection* self ) {
|
|||
}
|
||||
|
||||
TLSConnection::TLSConnection( Reference<IConnection> const& conn, Reference<ITLSPolicy> const& policy, bool is_client ) : conn(conn), write_wants(0), read_wants(0), uid(conn->getDebugID()) {
|
||||
session = Reference<ITLSSession>( policy->create_session(is_client, send_func, this, recv_func, this, (void*)&uid) );
|
||||
session = Reference<ITLSSession>( policy->create_session(is_client, NULL, send_func, this, recv_func, this, (void*)&uid) );
|
||||
if ( !session ) {
|
||||
// If session is NULL, we're trusting policy->create_session
|
||||
// to have used its provided logging function to have logged
|
||||
|
@ -232,7 +233,7 @@ void TLSOptions::set_key_data( std::string const& key_data ) {
|
|||
init_plugin();
|
||||
|
||||
TraceEvent("TLSConnectionSettingKeyData").detail("KeyDataSize", key_data.size());
|
||||
if ( !policy->set_key_data( (const uint8_t*)&key_data[0], key_data.size() ) )
|
||||
if ( !policy->set_key_data( (const uint8_t*)&key_data[0], key_data.size(), NULL ) )
|
||||
throw tls_error();
|
||||
|
||||
key_set = true;
|
||||
|
@ -243,7 +244,12 @@ void TLSOptions::set_verify_peers( std::string const& verify_peers ) {
|
|||
init_plugin();
|
||||
|
||||
TraceEvent("TLSConnectionSettingVerifyPeers").detail("Value", verify_peers);
|
||||
if ( !policy->set_verify_peers( (const uint8_t*)&verify_peers[0], verify_peers.size() ) )
|
||||
std::unique_ptr<const uint8_t *[]> verify_peers_arr(new const uint8_t*[1]);
|
||||
std::unique_ptr<int[]> verify_peers_len(new int[1]);
|
||||
verify_peers_arr[0] = (const uint8_t *)&verify_peers[0];
|
||||
verify_peers_len[0] = verify_peers.size();
|
||||
|
||||
if ( !policy->set_verify_peers( 1, verify_peers_arr.get(), verify_peers_len.get() ) )
|
||||
throw tls_error();
|
||||
|
||||
verify_peers_set = true;
|
||||
|
@ -272,12 +278,14 @@ Reference<ITLSPolicy> TLSOptions::get_policy() {
|
|||
std::string verifyPeerString;
|
||||
if ( platform::getEnvironmentVar( "FDB_TLS_VERIFY_PEERS", verifyPeerString ) )
|
||||
set_verify_peers( verifyPeerString );
|
||||
else
|
||||
set_verify_peers({ std::string("Check.Valid=0") });
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
static void TLSConnectionLogFunc( const char* event, void* uid_ptr, int is_error, ... ) {
|
||||
static void TLSConnectionLogFunc( const char* event, void* uid_ptr, bool is_error, ... ) {
|
||||
UID uid;
|
||||
|
||||
if ( uid_ptr )
|
||||
|
|
Loading…
Reference in New Issue