File: OpenSSL.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (116 lines) | stat: -rw-r--r-- 2,385 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once

#ifdef POSIX
#include "Data.h"
#include "Core/Io/Buffer.h"
#include "Core/Io/Stream.h"

#include <openssl/ssl.h>
#include <openssl/conf.h>
#include <openssl/crypto.h>

namespace ssl {

	class ClientContext;
	class ServerContext;
	class CertificateKey;

	// Ensure the library is initialized.
	void init();

	/**
	 * OpenSSL context.
	 */
	class OpenSSLContext : public SSLContext {
	public:
		// Destroy.
		~OpenSSLContext();

		// Create a client context.
		static OpenSSLContext *createClient(ClientContext *context);

		// Create a server context.
		static OpenSSLContext *createServer(ServerContext *context, CertificateKey *key);

		// Our OpenSSL context.
		SSL_CTX *context;

		// Verify hostname?
		bool checkHostname;

		// Create a session.
		virtual SSLSession *createSession();

	private:
		// Create.
		OpenSSLContext(SSL_CTX *ctx, bool isServer);

		// Server context?
		bool isServer;
	};

	/**
	 * OpenSSL session.
	 */
	class OpenSSLSession : public SSLSession {
	public:
		// Create from a context.
		OpenSSLSession(OpenSSLContext *ctx);

		// Destroy.
		virtual ~OpenSSLSession();

		// Implementation of the generic interface.
		virtual Bool more(void *gcData);
		virtual void read(Buffer &to, void *gcData);
		virtual void peek(Buffer &to, void *gcData);
		virtual Nat write(const Buffer &from, Nat start, void *gcData);
		virtual Bool flush(void *gcData);
		virtual void shutdown(void *gcData);
		virtual void close(void *gcData);

	protected:
		// Session.
		OpenSSLContext *context;

		// Allocated BIO for the SSL connection.
		BIO *connection;

		// Did we see an end-of-file?
		Bool eof;

		// Fill the buffer.
		void fillBuffer(Nat bytes, void *data);

		// Read data from OpenSSL into a buffer, filling as much space as possible. Sets eof, etc.
		// as appropriate.
		Nat readIntoBuffer(void *buffer, Nat bytes, void *gcData);
	};

	/**
	 * OpenSSL client session.
	 */
	class OpenSSLClientSession : public OpenSSLSession {
	public:
		// Create.
		OpenSSLClientSession(OpenSSLContext *ctx);

		// Overrides.
		virtual void *connect(IStream *input, OStream *output, Str *host);
	};

	/**
	 * OpenSSL server session.
	 */
	class OpenSSLServerSession : public OpenSSLSession {
	public:
		// Create.
		OpenSSLServerSession(OpenSSLContext *ctx);

		// Overrides.
		virtual void *connect(IStream *input, OStream *output, Str *host);
	};

}

#endif