chunkd: change net protocol to support arbitrary keys
PATCH 1/1 chunkd: change net protocol to support arbitrary keys
Incompatible network protocol change just committed...
commit 6fb485cbffcf61d73b0cfe7effbf88c9e0b48377
Author: Jeff Garzik <[email protected]> Date: Thu Nov 5 00:06:16 2009 -0500
Change protocol to permit arbitrary binary keys, up to 1K in size.
Also,
- remove several unused struct members from struct chunksrv_resp.
- improve client disconnect logging
Signed-off-by Jeff Garzik <[email protected]>
include/chunk_msg.h +7 -8
@@ -8,7 +8,7 @@enum {CHD_MAGIC_SZ =8 ,CHD_USER_SZ =64 , -CHD_KEY_SZ =64 , +CHD_KEY_SZ =1024 ,CHD_CSUM_SZ =64 ,CHD_SIG_SZ =64 , };
@@ -38,23 +38,22 @@ enum errcode {struct chunksrv_req {uint8_t magic[CHD_MAGIC_SZ ];/* CHUNKD_MAGIC */ uint8_t op;/* CHO_xxx */ -uint8_t rsv1[3 ]; +uint8_t rsv1[1 ]; +uint16_t key_len;uint32_t nonce;/* random number, to stir checksum */ uint64_t data_len;/* len of addn'l data */ char user[CHD_USER_SZ ];/* username */ -char key[CHD_KEY_SZ ];/* object id */ char sig[CHD_SIG_SZ ];/* HMAC signature */ + +/* variable-length key */ };struct chunksrv_resp {uint8_t magic[CHD_MAGIC_SZ ];/* CHUNKD_MAGIC */ -uint8_t op;/* CHO_xxx */ uint8_t resp_code;/* errcode's */ -uint8_t rsv1[2 ]; -uint32_t nonce;/* random number, to stir checksum */ +uint8_t rsv1[3 ]; +uint32_t nonce;/* txn id, copied from request */ uint64_t data_len;/* len of addn'l data */ -char user[CHD_USER_SZ ];/* username */ -char key[CHD_KEY_SZ ];/* object id */ char checksum[CHD_CSUM_SZ ];/* SHA1 checksum */ };
include/chunkc.h +1 -1
@@ -32,7 +32,7 @@ struct st_client {SSL_CTX *ssl_ctx;SSL *ssl; -char req_buf[sizeof (struct chunksrv_req )]; +char req_buf[sizeof (struct chunksrv_req ) +CHD_KEY_SZ ]; };extern void stc_free (struct st_client *stc);
lib/chunkdc.c +3 -5
@@ -45,12 +45,10 @@ static void req_init(struct st_client *stc, struct chunksrv_req *req) }static void req_set_key (struct chunksrv_req *req,const void *key, -size_t key_len) +uint16_t key_len) { -/* length must include nul, and already be checked for range -* validity -*/ -memcpy (req->key, key, key_len); + req->key_len =GUINT16_TO_LE (key_len); +memcpy ((req +1 ), key, key_len); }static bool net_read (struct st_client *stc,void *data,size_t datalen)
lib/chunksrv.c +6 -2
@@ -7,7 +7,11 @@size_t req_len (const struct chunksrv_req *req) { -return sizeof (*req); +size_t len; + + len =sizeof (struct chunksrv_req ) +GUINT16_FROM_LE (req->key_len); + +return len; }void chreq_sign (struct chunksrv_req *req,const char *key,char *b64hmac_out)
@@ -17,7 +21,7 @@ void chreq_sign(struct chunksrv_req *req, const char *key, char *b64hmac_out)int save =0 , state =0 , b64_len;const void *p = req; -HMAC (EVP_sha1 (), key,strlen (key), p,sizeof (*req), md, &len); +HMAC (EVP_sha1 (), key,strlen (key), p,req_len (req), md, &len); b64_len =g_base64_encode_step (md, len, FALSE, b64hmac_out, &state, &save);
server/chunkd.h +4 -1
@@ -60,7 +60,8 @@ struct client_write {/* internal client socket state */ enum client_state { - evt_read_req,/* read request line */ + evt_read_fixed,/* read fixed-len rec */ + evt_read_var,/* read variable-len rec */ evt_exec_req,/* execute request */ evt_data_in,/* request's content */ evt_dispose,/* dispose of client */
@@ -85,6 +86,7 @@ struct client {struct chunksrv_req creq;unsigned int req_used;/* amount of req_buf in use */ void *req_ptr;/* start of unexamined data */ +uint16_t key_len;char *hdr_start;/* current hdr start */ char *hdr_end;/* current hdr end (so far) */
@@ -103,6 +105,7 @@ struct client {char netbuf[CLI_DATA_BUF_SZ ];char netbuf_out[CLI_DATA_BUF_SZ ]; +char key[CHD_KEY_SZ ]; };struct backend_obj {
server/object.c +4 -8
@@ -17,7 +17,6 @@ static bool object_get_more(struct client *cli, struct client_write *wr,bool object_del (struct client *cli) { -const char *obj_key = cli->creq.key;int rc;enum errcode err = InternalError;bool rcb;
@@ -31,8 +30,7 @@ bool object_del(struct client *cli)resp_init_req (resp, &cli->creq); - rcb =fs_obj_delete (cli->creq.user, obj_key, -strnlen (obj_key,CHD_KEY_SZ ), &err); + rcb =fs_obj_delete (cli->creq.user, cli->key, cli->key_len, &err);if (!rcb)return cli_err (cli, err, true);
@@ -192,14 +190,13 @@ bool cli_evt_data_in(struct client *cli, unsigned int events)bool object_put (struct client *cli) {const char *user = cli->creq.user; -const char *key = cli->creq.key;uint64_t content_len =le64_to_cpu (cli->creq.data_len);enum errcode err;if (!user)return cli_err (cli, AccessDenied, true); - cli->out_bo =fs_obj_new (key,strnlen (key,CHD_KEY_SZ ), &err); + cli->out_bo =fs_obj_new (cli->key, cli->key_len, &err);if (!cli->out_bo)return cli_err (cli, err, true);
@@ -277,7 +274,6 @@ err_out_buf:bool object_get (struct client *cli,bool want_body) { -const char *obj_key = cli->creq.key;int rc;enum errcode err = InternalError;struct backend_obj *obj;
@@ -291,8 +287,8 @@ bool object_get(struct client *cli, bool want_body)resp_init_req (&get_resp->resp, &cli->creq); - cli->in_obj = obj =fs_obj_open (cli->creq.user, obj_key, -strnlen (obj_key,CHD_KEY_SZ ), &err); + cli->in_obj = obj =fs_obj_open (cli->creq.user, cli->key, + cli->key_len, &err);if (!obj) {free (get_resp);return cli_err (cli, err, true);
server/server.c +56 -22
166 lines not on this page · raw message