comparison cli-agentfwd.c @ 612:1aee049681bd

Tidy error handling and get rid of some commented out code
author Matt Johnston <matt@ucc.asn.au>
date Thu, 07 Apr 2011 12:30:20 +0000
parents 3c5f631358a0
children 5e8d84f3ee72
comparison
equal deleted inserted replaced
611:870c63519757 612:1aee049681bd
256 agent_get_key_list(ret_list); 256 agent_get_key_list(ret_list);
257 } 257 }
258 258
259 void agent_buf_sign(buffer *sigblob, sign_key *key, 259 void agent_buf_sign(buffer *sigblob, sign_key *key,
260 const unsigned char *data, unsigned int len) { 260 const unsigned char *data, unsigned int len) {
261 buffer *request_data = buf_new(MAX_PUBKEY_SIZE + len + 12); 261 buffer *request_data = NULL;
262 buffer *response; 262 buffer *response = NULL;
263 unsigned int keylen, siglen; 263 unsigned int keylen, siglen;
264 int packet_type; 264 int packet_type;
265 265
266 /* Request format 266 /* Request format
267 byte SSH2_AGENTC_SIGN_REQUEST 267 byte SSH2_AGENTC_SIGN_REQUEST
268 string key_blob 268 string key_blob
269 string data 269 string data
270 uint32 flags 270 uint32 flags
271 */ 271 */
272 /* We write the key, then figure how long it was and write that */ 272 request_data = buf_new(MAX_PUBKEY_SIZE + len + 12);
273 //buf_putint(request_data, 0);
274 buf_put_pub_key(request_data, key, key->type); 273 buf_put_pub_key(request_data, key, key->type);
275 keylen = request_data->len - 4; 274 keylen = request_data->len - 4;
276 //buf_setpos(request_data, 0); 275
277 //buf_putint(request_data, keylen);
278
279 //buf_setpos(request_data, request_data->len);
280 buf_putstring(request_data, data, len); 276 buf_putstring(request_data, data, len);
281 buf_putint(request_data, 0); 277 buf_putint(request_data, 0);
282 278
283 response = agent_request(SSH2_AGENTC_SIGN_REQUEST, request_data); 279 response = agent_request(SSH2_AGENTC_SIGN_REQUEST, request_data);
284 buf_free(request_data);
285 280
286 if (!response) { 281 if (!response) {
287 goto fail; 282 goto fail;
288 } 283 }
289 284
296 byte SSH2_AGENT_SIGN_RESPONSE 291 byte SSH2_AGENT_SIGN_RESPONSE
297 string signature_blob 292 string signature_blob
298 */ 293 */
299 siglen = buf_getint(response); 294 siglen = buf_getint(response);
300 buf_putbytes(sigblob, buf_getptr(response, siglen), siglen); 295 buf_putbytes(sigblob, buf_getptr(response, siglen), siglen);
301 buf_free(response); 296 goto cleanup;
302 297
303 return;
304 fail: 298 fail:
305 /* XXX don't fail badly here. instead propagate a failure code back up to 299 /* XXX don't fail badly here. instead propagate a failure code back up to
306 the cli auth pubkey code, and just remove this key from the list of 300 the cli auth pubkey code, and just remove this key from the list of
307 ones to try. */ 301 ones to try. */
308 dropbear_exit("Agent failed signing key"); 302 dropbear_exit("Agent failed signing key");
303
304 cleanup:
305 if (request_data) {
306 buf_free(request_data);
307 }
308 if (response) {
309 buf_free(response);
310 }
309 } 311 }
310 312
311 #endif 313 #endif