diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-07-09 13:01:57 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-07-09 23:20:17 +0300 |
commit | 131b6ab56cbec838346fd493f3fe96438e3b58e7 (patch) | |
tree | 1a30a33f6447fcbeba9810542121dc7003d3129a /lib/q2url.c | |
parent | 7f40bb8674983f8e4fc11fbebe56f88daa812c1a (diff) | |
download | eclat-131b6ab56cbec838346fd493f3fe96438e3b58e7.tar.gz eclat-131b6ab56cbec838346fd493f3fe96438e3b58e7.tar.bz2 |
Implement signature version 4 signing process
* lib/libeclat.h (ec2_param) <encoded>: New member.
(ec2_query) <signature>: Remove.
<headers,region,access_key>: New members
(eclat_query_create): Take two more arguments. All uses changed.
(eclat_query_add_param_encoded)
(eclat_query_add_header): New functions.
* lib/q2url.c (eclat_query_to_url): Don't create Signature param:
it is already in the param list (for v2 process).
* lib/qaddparm.c (eclat_query_add_param_encoded): New function.
(eclat_query_add_header): New function.
* lib/qcreat.c (eclat_query_create): Take region and access key
as additional parameters.
* lib/qencode.c (encode_param): Skip parameters that have encoded
set to true.
* lib/reqsign.c (querysign2): Store access key in AWSAccessKeyId
and the generated signature in the Signature parameters.
(eclat_hex_encode): New function.
(querysign4): Implement signature version 4 signing process.
* src/ec2map.c: Update call to eclat_query_create.
* src/eclat.c: Likewise.
* src/util.c (eclat_send_query): Sign the query and add
requested headers prior to sending.
* doc/eclat.conf.5: Document signature-version.
* NEWS: Likewise.
Diffstat (limited to 'lib/q2url.c')
-rw-r--r-- | lib/q2url.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/q2url.c b/lib/q2url.c index f5d8863..da0ebdc 100644 --- a/lib/q2url.c +++ b/lib/q2url.c @@ -19,17 +19,24 @@ #include "libeclat.h" #include "grecs.h" +struct param_closure { + struct grecs_txtacc *acc; + int count; +}; + static int add_param(void *sym, void *data) { struct ec2_param *p = sym; - struct grecs_txtacc *acc = data; + struct param_closure *pc = data; - grecs_txtacc_grow_char(acc, '&'); - grecs_txtacc_grow(acc, p->name, strlen(p->name)); + if (pc->count) + grecs_txtacc_grow_char(pc->acc, '&'); + ++pc->count; + grecs_txtacc_grow_string(pc->acc, p->name); if (p->value) { - grecs_txtacc_grow_char(acc, '='); - grecs_txtacc_grow(acc, p->value, strlen(p->value)); + grecs_txtacc_grow_char(pc->acc, '='); + grecs_txtacc_grow_string(pc->acc, p->value); } return 0; @@ -40,7 +47,8 @@ eclat_query_to_url(struct ec2_query *req, char **post_params) { struct grecs_txtacc *acc; char *ret = NULL, *p; - + struct param_closure pc; + acc = grecs_txtacc_create(); grecs_txtacc_grow(acc, "http", 4); @@ -57,16 +65,10 @@ eclat_query_to_url(struct ec2_query *req, char **post_params) grecs_txtacc_grow_char(acc, '?'); } - /* Add signature */ - grecs_txtacc_grow(acc, "Signature", sizeof("Signature")-1); - grecs_txtacc_grow_char(acc, '='); - - urlencode(req->signature, strlen(req->signature), &p, NULL); - grecs_txtacc_grow(acc, p, strlen(p)); - free(p); - /* Add other parameters */ - grecs_symtab_enumerate(req->params, add_param, acc); + pc.acc = acc; + pc.count = 0; + grecs_symtab_enumerate(req->params, add_param, &pc); grecs_txtacc_grow_char(acc, 0); @@ -79,3 +81,4 @@ eclat_query_to_url(struct ec2_query *req, char **post_params) return ret; } + |