MongoDB C++ Driver  legacy-1.1.2
ssl_manager.h
1 /* Copyright 2009 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "mongo/config.h"
19 
20 #include <string>
21 
22 #ifdef MONGO_SSL
23 
24 #include "mongo/base/disallow_copying.h"
25 #include "mongo/util/net/sock.h"
26 
27 #include <openssl/err.h>
28 #include <openssl/ssl.h>
29 
30 #endif // #ifdef MONGO_SSL
31 
32 namespace mongo {
33 /*
34  * @return the SSL version string prefixed with prefix and suffixed with suffix
35  */
36 const std::string getSSLVersion(const std::string& prefix, const std::string& suffix);
37 }
38 
39 #ifdef MONGO_SSL
40 namespace mongo {
41 
42 class SSLConnection {
43 public:
44  SSL* ssl;
45  BIO* networkBIO;
46  BIO* internalBIO;
47  Socket* socket;
48 
49  SSLConnection(SSL_CTX* ctx, Socket* sock, const char* initialBytes, int len);
50 
51  ~SSLConnection();
52 };
53 
54 class SSLManagerInterface {
55 public:
56  virtual ~SSLManagerInterface();
57 
63  virtual SSLConnection* connect(Socket* socket) = 0;
64 
70  virtual SSLConnection* accept(Socket* socket, const char* initialBytes, int len) = 0;
71 
77  virtual std::string parseAndValidatePeerCertificate(const SSLConnection* conn,
78  const std::string& remoteHost) = 0;
79 
84  virtual void cleanupThreadLocals() = 0;
85 
90  virtual std::string getServerSubjectName() = 0;
91 
97  virtual std::string getClientSubjectName() = 0;
98 
102  virtual std::string getSSLErrorMessage(int code) = 0;
103 
107  virtual int SSL_read(SSLConnection* conn, void* buf, int num) = 0;
108 
109  virtual int SSL_write(SSLConnection* conn, const void* buf, int num) = 0;
110 
111  virtual unsigned long ERR_get_error() = 0;
112 
113  virtual char* ERR_error_string(unsigned long e, char* buf) = 0;
114 
115  virtual int SSL_get_error(const SSLConnection* conn, int ret) = 0;
116 
117  virtual int SSL_shutdown(SSLConnection* conn) = 0;
118 
119  virtual void SSL_free(SSLConnection* conn) = 0;
120 };
121 
122 // Access SSL functions through this instance.
123 SSLManagerInterface* getSSLManager();
124 }
125 #endif // #ifdef MONGO_SSL
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20