blob: 14b9bee94d6089c39568a600bd47a8d2aeefb2df [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller4af51302000-04-16 11:18:38 +10002 *
Damien Miller95def091999-11-25 00:26:21 +11003 * authfd.h
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Miller95def091999-11-25 00:26:21 +11005 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Miller95def091999-11-25 00:26:21 +11007 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10009 *
Damien Miller95def091999-11-25 00:26:21 +110010 * Created: Wed Mar 29 01:17:41 1995 ylo
Damien Miller4af51302000-04-16 11:18:38 +100011 *
Damien Miller95def091999-11-25 00:26:21 +110012 * Functions to interface with the SSH_AUTHENTICATION_FD socket.
Damien Miller4af51302000-04-16 11:18:38 +100013 *
Damien Miller95def091999-11-25 00:26:21 +110014 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Miller994cf142000-07-21 10:19:44 +100016/* RCSID("$OpenBSD: authfd.h,v 1.9 2000/07/16 08:27:21 markus Exp $"); */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100017
18#ifndef AUTHFD_H
19#define AUTHFD_H
20
21#include "buffer.h"
22
23/* Messages for the authentication agent connection. */
24#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
25#define SSH_AGENT_RSA_IDENTITIES_ANSWER 2
26#define SSH_AGENTC_RSA_CHALLENGE 3
27#define SSH_AGENT_RSA_RESPONSE 4
28#define SSH_AGENT_FAILURE 5
29#define SSH_AGENT_SUCCESS 6
30#define SSH_AGENTC_ADD_RSA_IDENTITY 7
31#define SSH_AGENTC_REMOVE_RSA_IDENTITY 8
32#define SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9
33
Damien Miller994cf142000-07-21 10:19:44 +100034#define SSH2_AGENTC_REQUEST_IDENTITIES 11
35#define SSH2_AGENT_IDENTITIES_ANSWER 12
36#define SSH2_AGENTC_SIGN_REQUEST 13
37#define SSH2_AGENT_SIGN_RESPONSE 14
38#define SSH2_AGENT_FAILURE SSH_AGENT_FAILURE
39#define SSH2_AGENT_SUCCESS SSH_AGENT_SUCCESS
40#define SSH2_AGENTC_ADD_IDENTITY 17
41#define SSH2_AGENTC_REMOVE_IDENTITY 18
42#define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
43
Damien Miller95def091999-11-25 00:26:21 +110044typedef struct {
45 int fd;
46 Buffer packet;
47 Buffer identities;
48 int howmany;
49} AuthenticationConnection;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050/* Returns the number of the authentication fd, or -1 if there is none. */
Damien Miller95def091999-11-25 00:26:21 +110051int ssh_get_authentication_socket();
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052
Damien Miller5428f641999-11-25 11:54:57 +110053/*
54 * This should be called for any descriptor returned by
55 * ssh_get_authentication_socket(). Depending on the way the descriptor was
56 * obtained, this may close the descriptor.
57 */
Damien Miller95def091999-11-25 00:26:21 +110058void ssh_close_authentication_socket(int authfd);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059
Damien Miller5428f641999-11-25 11:54:57 +110060/*
61 * Opens and connects a private socket for communication with the
62 * authentication agent. Returns NULL if an error occurred and the
63 * connection could not be opened. The connection should be closed by the
64 * caller by calling ssh_close_authentication_connection().
65 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100066AuthenticationConnection *ssh_get_authentication_connection();
67
Damien Miller5428f641999-11-25 11:54:57 +110068/*
69 * Closes the connection to the authentication agent and frees any associated
70 * memory.
71 */
Damien Miller95def091999-11-25 00:26:21 +110072void ssh_close_authentication_connection(AuthenticationConnection * ac);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100073
Damien Miller5428f641999-11-25 11:54:57 +110074/*
75 * Returns the first authentication identity held by the agent. Returns true
76 * if an identity is available, 0 otherwise. The caller must initialize the
77 * integers before the call, and free the comment after a successful call
78 * (before calling ssh_get_next_identity).
79 */
Damien Miller4af51302000-04-16 11:18:38 +100080int
Damien Miller95def091999-11-25 00:26:21 +110081ssh_get_first_identity(AuthenticationConnection * connection,
82 BIGNUM * e, BIGNUM * n, char **comment);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100083
Damien Miller5428f641999-11-25 11:54:57 +110084/*
85 * Returns the next authentication identity for the agent. Other functions
86 * can be called between this and ssh_get_first_identity or two calls of this
87 * function. This returns 0 if there are no more identities. The caller
88 * must free comment after a successful return.
89 */
Damien Miller4af51302000-04-16 11:18:38 +100090int
Damien Miller95def091999-11-25 00:26:21 +110091ssh_get_next_identity(AuthenticationConnection * connection,
92 BIGNUM * e, BIGNUM * n, char **comment);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100093
94/* Requests the agent to decrypt the given challenge. Returns true if
95 the agent claims it was able to decrypt it. */
Damien Miller4af51302000-04-16 11:18:38 +100096int
Damien Miller95def091999-11-25 00:26:21 +110097ssh_decrypt_challenge(AuthenticationConnection * auth,
98 BIGNUM * e, BIGNUM * n, BIGNUM * challenge,
99 unsigned char session_id[16],
100 unsigned int response_type,
101 unsigned char response[16]);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000102
Damien Miller5428f641999-11-25 11:54:57 +1100103/*
104 * Adds an identity to the authentication server. This call is not meant to
105 * be used by normal applications. This returns true if the identity was
106 * successfully added.
107 */
Damien Miller4af51302000-04-16 11:18:38 +1000108int
Damien Miller994cf142000-07-21 10:19:44 +1000109ssh_add_identity(AuthenticationConnection * connection, Key *key,
Damien Miller5428f641999-11-25 11:54:57 +1100110 const char *comment);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000111
Damien Miller5428f641999-11-25 11:54:57 +1100112/*
113 * Removes the identity from the authentication server. This call is not
114 * meant to be used by normal applications. This returns true if the
115 * identity was successfully added.
116 */
117int ssh_remove_identity(AuthenticationConnection * connection, RSA * key);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000118
Damien Miller5428f641999-11-25 11:54:57 +1100119/*
120 * Removes all identities from the authentication agent. This call is not
121 * meant to be used by normal applications. This returns true if the
122 * operation was successful.
123 */
124int ssh_remove_all_identities(AuthenticationConnection * connection);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000125
126/* Closes the connection to the authentication agent. */
Damien Miller5428f641999-11-25 11:54:57 +1100127void ssh_close_authentication(AuthenticationConnection * connection);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000128
Damien Miller95def091999-11-25 00:26:21 +1100129#endif /* AUTHFD_H */