chunk: Update protocol to support in-band SSL negotiation
PATCH 1/1 chunk: Update protocol to support in-band SSL negotiation
commit 0df0e18e7fdf2674e4a22f0ca8e57a157dad6ca9
Author: Jeff Garzik <[email protected]> Date: Fri Mar 5 10:04:00 2010 -0500
Protocol: replace SSL/no-SSL split ports with in-band SSL negotiation
Initiating SSL immediately upon connection, based on incoming TCP connection port, is a relic of poor HTTP design and should not have been carried over to chunk protocol. Modern protocols (SMTP, IMAP, etc.) all support binding to a single port, and then negotiating SSL/TLS based on a command from the client.
Change chunk protocol such that clients must issue a CHO_START_TLS command at the beginning of the TCP connection, if they wish encryption.
Signed-off-by Jeff Garzik <[email protected]>
doc/setup.txt +0 -8
@@ -27,14 +27,6 @@ _cld._udp.phx2.ex.com has SRV record 10 50 8081 maika.phx2.ex.com. <Port>8082</Port> </Listen> - You can also set the interface and the encryption: - - <Listen> - <Node>192.168.1.24</Node> - <Port>18082</Port> - <Encrypt>true</Encrypt> - </Listen> - For clouds and their many cheap nodes with one Ethernet it usually is not a great idea to specify interfaces, since they often use IPv6 or acquire IP addresses from DHCP. So, just specify a port.
include/chunk_msg.h +16 -10
@@ -32,16 +32,22 @@ enum { };enum chunksrv_ops { -CHO_NOP =0 , -CHO_GET =1 , -CHO_GET_META =2 , -CHO_PUT =3 , -CHO_DEL =4 , -CHO_LIST =5 , -CHO_LOGIN =6 , -CHO_TABLE_OPEN =7 , -CHO_CHECK_START =8 , -CHO_CHECK_STATUS =9 , +CHO_NOP =0 ,/* No-op (ping server) */ +CHO_GET =1 ,/* GET object */ +CHO_GET_META =2 ,/* GET object metadata */ +CHO_PUT =3 ,/* PUT object */ +CHO_DEL =4 ,/* Delete object */ +CHO_LIST =5 ,/* List objects */ +CHO_LOGIN =6 ,/* Login as user */ +CHO_TABLE_OPEN =7 ,/* Open table */ +CHO_CHECK_START =8 ,/* Begin self-check */ +CHO_CHECK_STATUS =9 ,/* Query self-check status */ + +/* START-TLS is special. It MUST be the first request of a TCP +* cxn, and no chunkd-specific response is returned. The SSL +* functions' success/failure is sufficient indication. +*/ +CHO_START_TLS =10 ,/* Encrypt all subsequent msgs */ };enum chunk_errcode {
lib/chunkdc.c +34 -3
@@ -191,6 +191,27 @@ static bool stc_login(struct st_client *stc)return true; } +static bool stc_start_tls_cmd (struct st_client *stc) +{ +struct chunksrv_req *req = (struct chunksrv_req *) stc->req_buf; + +if (stc->verbose) +fprintf (stderr,"libstc: START-TLS\n" ); + +/* initialize request */ +req_init (stc, req); + req->op =CHO_START_TLS ; +strcpy (req->sig,"START-TLS" ); + +/* write request */ +if (!net_write (stc, req,req_len (req))) +return false; + +/* no response - SSL negotiation begins immediately */ + +return true; +} +struct st_client *stc_new (const char *service_host,int port,const char *user,const char *secret_key,bool use_ssl)
@@ -253,6 +274,9 @@ struct st_client *stc_new(const char *service_host, int port, goto err_out;if (use_ssl) { +if (!stc_start_tls_cmd (stc)) + goto err_out; + stc->ssl_ctx =SSL_CTX_new (TLSv1_client_method ());if (!stc->ssl_ctx) goto err_out;
@@ -266,7 +290,8 @@ struct st_client *stc_new(const char *service_host, int port,if (!SSL_set_fd (stc->ssl, stc->fd)) goto err_out_ssl; -if (SSL_connect (stc->ssl) <=0 ) + rc =SSL_connect (stc->ssl); +if (rc <=0 ) goto err_out_ssl; }
@@ -276,9 +301,15 @@ struct st_client *stc_new(const char *service_host, int port,return stc; err_out_ssl: -SSL_free (stc->ssl); +if (stc->ssl) { +SSL_free (stc->ssl); + stc->ssl =NULL ; + } err_out_ctx: -SSL_CTX_free (stc->ssl_ctx); +if (stc->ssl_ctx) { +SSL_CTX_free (stc->ssl_ctx); + stc->ssl_ctx =NULL ; + } err_out:close (stc->fd);stc_free (stc);
server/chunkd.h +1 -1
@@ -102,6 +102,7 @@ struct client {SSL *ssl;bool read_want_write;bool write_want_read; +bool first_req;struct list_head write_q;/* list of async writes */ bool writing;
@@ -150,7 +151,6 @@ struct listen_cfg {char *node;char *port;char *port_file; -bool encrypt; };struct geo {
server/cldu.c +0 -2
@@ -540,11 +540,9 @@ static int cldu_make_ffile(char **ret, struct cld_session *sp) rc =asprintf (&str," <Socket>\r\n" -" <Type>%s</Type>\r\n" " <Host>%s</Host>\r\n" " <Port>%s</Port>\r\n" " </Socket>\r\n" , - cfg->encrypt ?"chunk-ssl" :"chunk" , host, cfg->port);if (rc ==-1 ) {
server/config.c +0 -10
@@ -398,16 +398,6 @@ static void cfg_elm_end (GMarkupParseContext *context, } } -else if (cc->in_listen && cc->text && - !strcmp (element_name,"Encrypt" )) { -if (!strcasecmp (cc->text,"yes" ) || - !strcasecmp (cc->text,"true" )) - cc->tmp_listen.encrypt = true; - -free (cc->text); - cc->text =NULL ; - } -else if (!strcmp (element_name,"Group" ) && cc->text) {free (chunkd_srv.group); chunkd_srv.group = cc->text;
server/server.c +36 -45
151 lines not on this page · raw message
test/auth.c +1 -1
@@ -43,7 +43,7 @@ static void test(bool do_encrypt)size_t len =0 ;void *mem; - port =stc_readport (do_encrypt ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc1 =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , do_encrypt);
test/basic-object.c +1 -1
@@ -41,7 +41,7 @@ static void test(bool do_encrypt)size_t len =0 ;void *mem; - port =stc_readport (do_encrypt ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , do_encrypt);
test/it-works.c +1 -1
@@ -35,7 +35,7 @@ static void test(bool ssl)int port;bool rcb; - port =stc_readport (ssl ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , ssl);
test/large-object.c +1 -1
@@ -108,7 +108,7 @@ static void test(bool do_encrypt)memset (data,0xdeadbeef ,sizeof (data)); - port =stc_readport (do_encrypt ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , do_encrypt);
test/lotsa-objects.c +1 -1
@@ -47,7 +47,7 @@ static void test(int n_objects, bool do_encrypt)char *k;struct timeval ta, tb; - port =stc_readport (do_encrypt ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , do_encrypt);
test/nop.c +1 -1
@@ -42,7 +42,7 @@ static void test(int n_nops, bool do_encrypt)int i;struct timeval ta, tb; - port =stc_readport (do_encrypt ?TEST_PORTFILE_SSL :TEST_PORTFILE ); + port =stc_readport (TEST_PORTFILE );OK (port >0 ); stc =stc_new (TEST_HOST , port,TEST_USER ,TEST_USER_KEY , do_encrypt);
test/server-test.cfg +0 -6
@@ -10,12 +10,6 @@ <PortFile>chunkd.port</PortFile> </Listen> -<Listen> - <Port>auto</Port> - <PortFile>chunkd-ssl.port</PortFile> - <Encrypt>true</Encrypt> -</Listen> - <PID>chunkd.pid</PID> <Path>data/chunk</Path>
test/test.h +0 -1
@@ -36,7 +36,6 @@#define TEST_PORTFILE_CLD "cld.port"#define TEST_PORTFILE "chunkd.port" -#define TEST_PORTFILE_SSL "chunkd-ssl.port"#define TEST_CHUNKD_CFG "server-test.cfg"