- buffer_append(&buffer, (char *)buf, l);
- len -= l;
- }
-
- /* Get the type of the packet. */
- buffer_get(&buffer, (char *)buf, 1);
-
- /* Check for agent failure message. */
- if (buf[0] == SSH_AGENT_FAILURE)
- {
- log("Agent admitted failure to authenticate using the key.");
- goto error_cleanup;
- }
-
- /* Now it must be an authentication response packet. */
- if (buf[0] != SSH_AGENT_RSA_RESPONSE)
- fatal("Bad authentication response: %d", buf[0]);
-
- /* Get the response from the packet. This will abort with a fatal error
- if the packet is corrupt. */
- for (i = 0; i < 16; i++)
- response[i] = buffer_get_char(&buffer);
-
- /* The buffer containing the packet is no longer needed. */
- buffer_free(&buffer);
-
- /* Correct answer. */
- return 1;
-}
-
-/* Adds an identity to the authentication server. This call is not meant to
- be used by normal applications. */
-
-int ssh_add_identity(AuthenticationConnection *auth,
- RSA *key, const char *comment)
+ buffer_free(&msg);
+ return ret;
+}
+
+/* Encode key for a message to the agent. */
+
+void
+ssh_encode_identity_rsa1(Buffer *b, RSA *key, const char *comment)
+{
+ buffer_clear(b);
+ buffer_put_char(b, SSH_AGENTC_ADD_RSA_IDENTITY);
+ buffer_put_int(b, BN_num_bits(key->n));
+ buffer_put_bignum(b, key->n);
+ buffer_put_bignum(b, key->e);
+ buffer_put_bignum(b, key->d);
+ /* To keep within the protocol: p < q for ssh. in SSL p > q */
+ buffer_put_bignum(b, key->iqmp); /* ssh key->u */
+ buffer_put_bignum(b, key->q); /* ssh key->p, SSL key->q */
+ buffer_put_bignum(b, key->p); /* ssh key->q, SSL key->p */
+ buffer_put_string(b, comment, strlen(comment));
+}
+
+void
+ssh_encode_identity_ssh2(Buffer *b, Key *key, const char *comment)
+{
+ buffer_clear(b);
+ buffer_put_char(b, SSH2_AGENTC_ADD_IDENTITY);
+ buffer_put_cstring(b, key_ssh_name(key));
+ switch(key->type){
+ case KEY_RSA:
+ buffer_put_bignum2(b, key->rsa->n);
+ buffer_put_bignum2(b, key->rsa->e);
+ buffer_put_bignum2(b, key->rsa->d);
+ buffer_put_bignum2(b, key->rsa->iqmp);
+ buffer_put_bignum2(b, key->rsa->p);
+ buffer_put_bignum2(b, key->rsa->q);
+ break;
+ case KEY_DSA:
+ buffer_put_bignum2(b, key->dsa->p);
+ buffer_put_bignum2(b, key->dsa->q);
+ buffer_put_bignum2(b, key->dsa->g);
+ buffer_put_bignum2(b, key->dsa->pub_key);
+ buffer_put_bignum2(b, key->dsa->priv_key);
+ break;
+ }
+ buffer_put_cstring(b, comment);
+}
+
+/*
+ * Adds an identity to the authentication server. This call is not meant to
+ * be used by normal applications.
+ */
+
+int
+ssh_add_identity(AuthenticationConnection *auth, Key *key, const char *comment)