Mercurial > urweb
comparison src/c/request.c @ 1104:72670131dace
Basis.serialize; separate file for mhash; run transactional finishers in reverse order; set needs_sig properly
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 31 Dec 2009 11:41:57 -0500 |
parents | db52c32dbe42 |
children | 150465f2895c |
comparison
equal
deleted
inserted
replaced
1103:2f42c61b8d0a | 1104:72670131dace |
---|---|
65 } | 65 } |
66 | 66 |
67 return ctx; | 67 return ctx; |
68 } | 68 } |
69 | 69 |
70 #define KEYSIZE 16 | |
71 #define PASSSIZE 4 | |
72 | |
73 #define HASH_ALGORITHM MHASH_SHA256 | |
74 #define HASH_BLOCKSIZE 32 | |
75 #define KEYGEN_ALGORITHM KEYGEN_MCRYPT | |
76 | |
77 int uw_hash_blocksize = HASH_BLOCKSIZE; | |
78 | |
79 static int password[PASSSIZE]; | |
80 static unsigned char private_key[KEYSIZE]; | |
81 | |
82 static void init_crypto(void *logger_data, uw_logger log_error) { | |
83 KEYGEN kg = {{HASH_ALGORITHM, HASH_ALGORITHM}}; | |
84 int i; | |
85 | |
86 assert(mhash_get_block_size(HASH_ALGORITHM) == HASH_BLOCKSIZE); | |
87 | |
88 for (i = 0; i < PASSSIZE; ++i) | |
89 password[i] = rand(); | |
90 | |
91 if (mhash_keygen_ext(KEYGEN_ALGORITHM, kg, | |
92 private_key, sizeof(private_key), | |
93 (unsigned char*)password, sizeof(password)) < 0) { | |
94 log_error(logger_data, "Key generation failed\n"); | |
95 exit(1); | |
96 } | |
97 } | |
98 | |
99 void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) { | 70 void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) { |
100 uw_context ctx; | 71 uw_context ctx; |
101 failure_kind fk; | 72 failure_kind fk; |
102 | 73 |
103 uw_global_init(); | 74 uw_global_init(); |
119 uw_rollback(ctx); | 90 uw_rollback(ctx); |
120 exit(1); | 91 exit(1); |
121 } | 92 } |
122 | 93 |
123 uw_free(ctx); | 94 uw_free(ctx); |
124 | 95 } |
125 init_crypto(logger_data, log_error); | 96 |
126 } | |
127 | |
128 void uw_sign(const char *in, char *out) { | |
129 MHASH td; | |
130 | |
131 td = mhash_hmac_init(HASH_ALGORITHM, private_key, sizeof(private_key), | |
132 mhash_get_hash_pblock(HASH_ALGORITHM)); | |
133 | |
134 mhash(td, in, strlen(in)); | |
135 if (mhash_hmac_deinit(td, out) < 0) | |
136 fprintf(stderr, "Signing failed\n"); | |
137 } | |
138 | 97 |
139 typedef struct uw_rc { | 98 typedef struct uw_rc { |
140 size_t path_copy_size; | 99 size_t path_copy_size; |
141 char *path_copy; | 100 char *path_copy; |
142 } *uw_request_context; | 101 } *uw_request_context; |