- agent_query(request, reqlen, &vresponse, &resplen);
- response = vresponse;
- if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS)
- MessageBox(NULL, "The already running Pageant "
- "refused to add the key.", APPNAME,
- MB_OK | MB_ICONERROR);
- } else {
- if (add234(rsakeys, rkey) != rkey)
- sfree(rkey); /* already present, don't waste RAM */
- }
- } else {
- if (already_running) {
- unsigned char *request, *response;
- void *vresponse;
- int reqlen, alglen, clen, keybloblen, resplen;
- alglen = strlen(skey->alg->name);
- clen = strlen(skey->comment);
-
- keybloblen = skey->alg->openssh_fmtkey(skey->data, NULL, 0);
-
- reqlen = 4 + 1 + /* length, message type */
- 4 + alglen + /* algorithm name */
- keybloblen + /* key data */
- 4 + clen /* comment */
- ;
-
- request = smalloc(reqlen);
-
- request[4] = SSH2_AGENTC_ADD_IDENTITY;
- reqlen = 5;
- PUT_32BIT(request + reqlen, alglen);
- reqlen += 4;
- memcpy(request + reqlen, skey->alg->name, alglen);
- reqlen += alglen;
- reqlen += skey->alg->openssh_fmtkey(skey->data,
- request + reqlen,
- keybloblen);
- PUT_32BIT(request + reqlen, clen);
- memcpy(request + reqlen + 4, skey->comment, clen);
- PUT_32BIT(request, reqlen - 4);
- reqlen += clen + 4;
-
- agent_query(request, reqlen, &vresponse, &resplen);
- response = vresponse;
- if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS)
- MessageBox(NULL, "The already running Pageant"
- "refused to add the key.", APPNAME,
- MB_OK | MB_ICONERROR);
- } else {
- if (add234(ssh2keys, skey) != skey) {
- skey->alg->freekey(skey->data);
- sfree(skey); /* already present, don't waste RAM */
- }
- }
- }
-}
-
-/*
- * This is the main agent function that answers messages.
- */
-static void answer_msg(void *msg)
-{
- unsigned char *p = msg;
- unsigned char *ret = msg;
- int type;
-
- /*
- * Get the message type.
- */
- type = p[4];
-
- p += 5;
- switch (type) {
- case SSH1_AGENTC_REQUEST_RSA_IDENTITIES:
- /*
- * Reply with SSH1_AGENT_RSA_IDENTITIES_ANSWER.
- */
- {
- struct RSAKey *key;
- int len, nkeys;
- int i;
-
- /*
- * Count up the number and length of keys we hold.
- */
- len = nkeys = 0;
- for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
- nkeys++;
- len += 4; /* length field */
- len += ssh1_bignum_length(key->exponent);
- len += ssh1_bignum_length(key->modulus);
- len += 4 + strlen(key->comment);
- }
-
- /*
- * Packet header is the obvious five bytes, plus four
- * bytes for the key count.
- */
- len += 5 + 4;
- if (len > AGENT_MAX_MSGLEN)
- goto failure; /* aaargh! too much stuff! */
- PUT_32BIT(ret, len - 4);
- ret[4] = SSH1_AGENT_RSA_IDENTITIES_ANSWER;
- PUT_32BIT(ret + 5, nkeys);
- p = ret + 5 + 4;
- for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
- PUT_32BIT(p, bignum_bitcount(key->modulus));
- p += 4;
- p += ssh1_write_bignum(p, key->exponent);
- p += ssh1_write_bignum(p, key->modulus);
- PUT_32BIT(p, strlen(key->comment));
- memcpy(p + 4, key->comment, strlen(key->comment));
- p += 4 + strlen(key->comment);
- }
- }
- break;
- case SSH2_AGENTC_REQUEST_IDENTITIES:
- /*
- * Reply with SSH2_AGENT_IDENTITIES_ANSWER.
- */
- {
- struct ssh2_userkey *key;
- int len, nkeys;
- unsigned char *blob;
- int bloblen;
- int i;
-
- /*
- * Count up the number and length of keys we hold.
- */
- len = nkeys = 0;
- for (i = 0; NULL != (key = index234(ssh2keys, i)); i++) {
- nkeys++;
- len += 4; /* length field */
- blob = key->alg->public_blob(key->data, &bloblen);
- len += bloblen;
- sfree(blob);
- len += 4 + strlen(key->comment);
- }
-
- /*
- * Packet header is the obvious five bytes, plus four
- * bytes for the key count.
- */
- len += 5 + 4;
- if (len > AGENT_MAX_MSGLEN)
- goto failure; /* aaargh! too much stuff! */
- PUT_32BIT(ret, len - 4);