+ {
+ struct RSAKey *key;
+ char *comment;
+ key = smalloc(sizeof(struct RSAKey));
+ memset(key, 0, sizeof(key));
+ p += makekey(p, key, NULL, 1);
+ p += makeprivate(p, key);
+ p += ssh1_read_bignum(p, key->iqmp); /* p^-1 mod q */
+ p += ssh1_read_bignum(p, key->p); /* p */
+ p += ssh1_read_bignum(p, key->q); /* q */
+ comment = smalloc(GET_32BIT(p));
+ if (comment) {
+ memcpy(comment, p+4, GET_32BIT(p));
+ key->comment = comment;
+ }
+ PUT_32BIT(ret, 1);
+ ret[4] = SSH_AGENT_FAILURE;
+ if (add234(rsakeys, key) == key) {
+ keylist_update();
+ ret[4] = SSH_AGENT_SUCCESS;
+ } else {
+ freersakey(key);
+ sfree(key);
+ }
+ }
+ break;
+ case SSH2_AGENTC_ADD_IDENTITY:
+ /*
+ * Add to the list and return SSH_AGENT_SUCCESS, or
+ * SSH_AGENT_FAILURE if the key was malformed.
+ */
+ {
+ struct ssh2_userkey *key;
+ char *comment, *alg;
+ int alglen, commlen;
+ int bloblen;
+
+ key = smalloc(sizeof(struct ssh2_userkey));
+
+ alglen = GET_32BIT(p); p += 4;
+ alg = p; p += alglen;
+ /* Add further algorithm names here. */
+ if (alglen == 7 && !memcmp(alg, "ssh-rsa", 7))
+ key->alg = &ssh_rsa;
+ else {
+ sfree(key);
+ goto failure;
+ }
+
+ bloblen = GET_32BIT((unsigned char *)msg) - (p-(unsigned char *)msg-4);
+ key->data = key->alg->openssh_createkey(&p, &bloblen);
+ if (!key->data) {
+ sfree(key);
+ goto failure;
+ }
+ commlen = GET_32BIT(p); p += 4;
+
+ comment = smalloc(commlen+1);
+ if (comment) {
+ memcpy(comment, p, commlen);
+ comment[commlen] = '\0';
+ }
+ key->comment = comment;
+
+ PUT_32BIT(ret, 1);
+ ret[4] = SSH_AGENT_FAILURE;
+ if (add234(ssh2keys, key) == key) {
+ keylist_update();
+ ret[4] = SSH_AGENT_SUCCESS;
+ } else {
+ key->alg->freekey(key->data);
+ sfree(key->comment);
+ sfree(key);
+ }
+ }
+ break;
+ case SSH1_AGENTC_REMOVE_RSA_IDENTITY:
+ /*
+ * Remove from the list and return SSH_AGENT_SUCCESS, or
+ * perhaps SSH_AGENT_FAILURE if it wasn't in the list to
+ * start with.
+ */
+ {
+ struct RSAKey reqkey, *key;
+
+ p += makekey(p, &reqkey, NULL, 0);
+ key = find234(rsakeys, &reqkey, NULL);
+ freebn(reqkey.exponent);
+ freebn(reqkey.modulus);
+ PUT_32BIT(ret, 1);
+ ret[4] = SSH_AGENT_FAILURE;
+ if (key) {
+ del234(rsakeys, key);
+ keylist_update();
+ freersakey(key);
+ sfree(key);
+ ret[4] = SSH_AGENT_SUCCESS;
+ }
+ }