Merge lp:~brianaker/gearmand/cyassl-1.2-part-2 into lp:gearmand

Proposed by Brian Aker on 2013-05-13
Status: Merged
Merged at revision: 738
Proposed branch: lp:~brianaker/gearmand/cyassl-1.2-part-2
Merge into: lp:gearmand
Diff against target: 264 lines (+118/-8)
8 files modified
configure.ac (+3/-0)
libgearman-server/include.am (+1/-0)
libgearman-server/io.cc (+16/-1)
libgearman-server/plugins/protocol/gear/protocol.cc (+74/-6)
libgearman-server/struct/gearmand.h (+7/-0)
libgearman-server/struct/io.h (+7/-0)
libgearman/connection.hpp (+8/-0)
libgearman/include.am (+2/-1)
To merge this branch: bzr merge lp:~brianaker/gearmand/cyassl-1.2-part-2
Reviewer Review Type Date Requested Status
Tangent Trunk 2013-05-13 Pending
Review via email: mp+163451@code.launchpad.net

Description of the change

Don't expect make test to work.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-05-12 20:30:19 +0000
3+++ configure.ac 2013-05-13 02:54:27 +0000
4@@ -208,6 +208,9 @@
5 AC_CHECK_FUNC([bind],[],[AC_CHECK_LIB([bind],[bind])])
6
7
8+# Check for CyaSSL
9+AX_CHECK_LIBRARY([CYASSL],[cyassl/ssl.h],[cyassl])
10+
11 # Check for the ability to call dlopen (used in libhostile)
12 AX_DLOPEN
13
14
15=== modified file 'libgearman-server/include.am'
16--- libgearman-server/include.am 2013-05-06 11:51:41 +0000
17+++ libgearman-server/include.am 2013-05-13 02:54:27 +0000
18@@ -95,3 +95,4 @@
19 libgearman_server_libgearman_server_la_LIBADD+= @LIBM@
20 libgearman_server_libgearman_server_la_LIBADD+= @DL_LIB@
21 libgearman_server_libgearman_server_la_LIBADD+= @RT_LIB@
22+libgearman_server_libgearman_server_la_LIBADD+= @CYASSL_LIB@
23
24=== modified file 'libgearman-server/io.cc'
25--- libgearman-server/io.cc 2013-05-12 01:03:50 +0000
26+++ libgearman-server/io.cc 2013-05-13 02:54:27 +0000
27@@ -66,6 +66,12 @@
28 }
29 else
30 {
31+#if defined(HAVE_CYASSL) && HAVE_CYASSL
32+ if (connection->root and connection->root->_ssl)
33+ {
34+ CyaSSL_shutdown(connection->root->_ssl);
35+ }
36+#endif
37 (void)gearmand_sockfd_close(connection->fd);
38 assert_msg(false, "We should never have an internal fd");
39 }
40@@ -99,7 +105,11 @@
41
42 while (1)
43 {
44+#if defined(HAVE_CYASSL) && HAVE_CYASSL
45+ read_size= CyaSSL_recv(con->_ssl, data, data_size, MSG_DONTWAIT);
46+#else
47 read_size= recv(connection->fd, data, data_size, MSG_DONTWAIT);
48+#endif
49
50 if (read_size == 0)
51 {
52@@ -228,7 +238,12 @@
53 case gearmand_io_st::GEARMAND_CON_UNIVERSAL_CONNECTED:
54 while (connection->send_buffer_size)
55 {
56- ssize_t write_size= send(connection->fd, connection->send_buffer_ptr, connection->send_buffer_size, MSG_NOSIGNAL|MSG_DONTWAIT);
57+ ssize_t write_size;
58+#if defined(HAVE_CYASSL) && HAVE_CYASSL
59+ write_size= CyaSSL_send(con->_ssl, connection->send_buffer_ptr, connection->send_buffer_size, MSG_NOSIGNAL|MSG_DONTWAIT);
60+#else
61+ write_size= send(connection->fd, connection->send_buffer_ptr, connection->send_buffer_size, MSG_NOSIGNAL|MSG_DONTWAIT);
62+#endif
63
64 if (write_size == 0) // detect infinite loop?
65 {
66
67=== modified file 'libgearman-server/plugins/protocol/gear/protocol.cc'
68--- libgearman-server/plugins/protocol/gear/protocol.cc 2013-05-07 11:07:18 +0000
69+++ libgearman-server/plugins/protocol/gear/protocol.cc 2013-05-13 02:54:27 +0000
70@@ -50,9 +50,16 @@
71 #include <cstdio>
72 #include <cstdlib>
73
74+#if defined(HAVE_CYASSL) && HAVE_CYASSL
75+# include <cyassl/ssl.h>
76+#endif
77+
78 #include <libgearman-server/plugins/protocol/gear/protocol.h>
79 #include "libgearman/command.h"
80
81+#define CERT_PEM "/home/brian/cyassl/certs/server-cert.pem"
82+#define CERT_KEY_PEM "/home/brian/cyassl/certs/server-key.pem"
83+
84 static gearmand_error_t gearmand_packet_unpack_header(gearmand_packet_st *packet)
85 {
86 uint32_t tmp;
87@@ -300,9 +307,40 @@
88
89 static Geartext gear_context;
90
91+#if defined(HAVE_CYASSL) && HAVE_CYASSL
92+static struct CYASSL_CTX *ctx_ssl= NULL;
93+#endif
94+
95 static gearmand_error_t _gear_con_add(gearman_server_con_st *connection)
96 {
97- gearmand_info("Gear connection made");
98+#if defined(HAVE_CYASSL) && HAVE_CYASSL
99+ assert(ctx_ssl);
100+ if ((connection->_ssl = CyaSSL_new(ctx_ssl)) == NULL)
101+ {
102+ return gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "CyaSSL_new() failed");
103+ }
104+
105+ CyaSSL_set_fd(connection->_ssl, connection->con.fd);
106+
107+ bool connecting= true;
108+ while (connecting)
109+ {
110+ if (CyaSSL_accept(connection->_ssl) == SSL_SUCCESS)
111+ {
112+ connecting= false;
113+ break;
114+ }
115+
116+ if (CyaSSL_get_error(connection->_ssl, 0) != SSL_ERROR_WANT_READ)
117+ {
118+ int cyassl_error= CyaSSL_get_error(connection->_ssl, 0);
119+ char cyassl_error_buffer[1024]= { 0 };
120+ CyaSSL_ERR_error_string(cyassl_error, cyassl_error_buffer);
121+ return gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "%s(%d)", cyassl_error_buffer, cyassl_error);
122+ }
123+ }
124+ gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM, "GearSSL connection made: %d", connection->con.fd);
125+#endif
126
127 connection->set_protocol(&gear_context);
128
129@@ -314,11 +352,41 @@
130
131 Gear::Gear() :
132 Plugin("Gear")
133-{
134- command_line_options().add_options()
135- ("port,p", boost::program_options::value(&_port)->default_value(GEARMAN_DEFAULT_TCP_PORT_STRING),
136- "Port the server should listen on.");
137-}
138+ {
139+ command_line_options().add_options()
140+ ("port,p", boost::program_options::value(&_port)->default_value(GEARMAN_DEFAULT_TCP_PORT_STRING),
141+ "Port the server should listen on.");
142+
143+#if defined(HAVE_CYASSL) && HAVE_CYASSL
144+ CyaSSL_Init();
145+
146+ ctx_ssl= CyaSSL_CTX_new(CyaTLSv1_2_server_method());
147+
148+ if (access(CERT_PEM, R_OK) == -1)
149+ {
150+ assert("access()" == NULL);
151+ }
152+
153+ if (CyaSSL_CTX_use_certificate_file(ctx_ssl, CERT_PEM, SSL_FILETYPE_PEM) != SSL_SUCCESS)
154+ {
155+ CyaSSL_CTX_free(ctx_ssl);
156+ gearmand_fatal("CyaSSL_CTX_use_certificate_file() cannot obtain certificate");
157+ }
158+
159+ if (access(CERT_KEY_PEM, R_OK) == -1)
160+ {
161+ gearmand_fatal("access(CERT_KEY_PEM, R_OK) == -1");
162+ }
163+
164+ if (CyaSSL_CTX_use_PrivateKey_file(ctx_ssl, CERT_KEY_PEM, SSL_FILETYPE_PEM) != SSL_SUCCESS)
165+ {
166+ CyaSSL_CTX_free(ctx_ssl);
167+ gearmand_fatal("CyaSSL_CTX_use_PrivateKey_file() cannot obtain certificate");
168+ }
169+
170+ assert(ctx_ssl);
171+#endif
172+ }
173
174 Gear::~Gear()
175 {
176
177=== modified file 'libgearman-server/struct/gearmand.h'
178--- libgearman-server/struct/gearmand.h 2013-05-05 01:54:09 +0000
179+++ libgearman-server/struct/gearmand.h 2013-05-13 02:54:27 +0000
180@@ -38,6 +38,9 @@
181 #pragma once
182
183 #include "libgearman-server/struct/server.h"
184+#if defined(HAVE_CYASSL) && HAVE_CYASSL
185+# include <cyassl/ssl.h>
186+#endif
187
188 #include "libgearman-server/struct/port.h"
189
190@@ -174,6 +177,10 @@
191 }
192 }
193
194+#if defined(HAVE_CYASSL) && HAVE_CYASSL
195+ CYASSL_CTX *ctx_ssl;
196+#endif
197+
198 bool exceptions() const
199 {
200 return _exceptions;
201
202=== modified file 'libgearman-server/struct/io.h'
203--- libgearman-server/struct/io.h 2013-05-05 01:54:09 +0000
204+++ libgearman-server/struct/io.h 2013-05-13 02:54:27 +0000
205@@ -39,6 +39,10 @@
206
207 #include "libgearman-server/plugins/base.h"
208
209+#if defined(HAVE_CYASSL) && HAVE_CYASSL
210+# include <cyassl/ssl.h>
211+#endif
212+
213 struct gearmand_io_st
214 {
215 struct {
216@@ -162,4 +166,7 @@
217 protocol= NULL;
218 }
219 }
220+#if defined(HAVE_CYASSL) && HAVE_CYASSL
221+ CYASSL* _ssl;
222+#endif
223 };
224
225=== modified file 'libgearman/connection.hpp'
226--- libgearman/connection.hpp 2013-05-04 12:05:03 +0000
227+++ libgearman/connection.hpp 2013-05-13 02:54:27 +0000
228@@ -42,6 +42,10 @@
229 #include "libgearman/interface/packet.hpp"
230 #include "libgearman/interface/universal.hpp"
231
232+#if defined(HAVE_CYASSL) && HAVE_CYASSL
233+# include <cyassl/ssl.h>
234+#endif
235+
236 struct gearman_connection_st
237 {
238 struct Options {
239@@ -63,6 +67,10 @@
240 short events;
241 short revents;
242 int fd;
243+#if defined(HAVE_CYASSL) && HAVE_CYASSL
244+ CYASSL* ssl;
245+ CYASSL_CTX* ctx_ssl;
246+#endif
247 int cached_errno;
248 uint32_t created_id;
249 uint32_t created_id_next;
250
251=== modified file 'libgearman/include.am'
252--- libgearman/include.am 2013-05-07 11:07:18 +0000
253+++ libgearman/include.am 2013-05-13 02:54:27 +0000
254@@ -133,8 +133,9 @@
255
256 libgearman_libgearman_la_LDFLAGS+= -version-info $(GEARMAN_LIBRARY_VERSION)
257
258+libgearman_libgearman_la_LIBADD+= @CYASSL_LIB@
259+libgearman_libgearman_la_LIBADD+= @DL_LIB@
260 libgearman_libgearman_la_LIBADD+= @LIBUUID_LIB@
261-libgearman_libgearman_la_LIBADD+= @DL_LIB@
262 libgearman_libgearman_la_LIBADD+= libhashkit/libhashkit.la
263
264 if TARGET_LINUX

Subscribers

People subscribed via source and target branches

to all changes: