xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth.h (revision d909946ca08dceb44d7d0f22ec9488679695d976)
1 /*	$NetBSD: auth.h,v 1.13 2016/08/02 13:45:12 christos Exp $	*/
2 /* $OpenBSD: auth.h,v 1.88 2016/05/04 14:04:40 markus Exp $ */
3 
4 /*
5  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef AUTH_H
30 #define AUTH_H
31 
32 #include <signal.h>
33 
34 #include <openssl/rsa.h>
35 
36 #ifdef HAVE_LOGIN_CAP
37 #include <login_cap.h>
38 #endif
39 #ifdef BSD_AUTH
40 #include <bsd_auth.h>
41 #endif
42 #ifdef KRB5
43 #include <krb5.h>
44 #endif
45 
46 struct ssh;
47 struct sshkey;
48 
49 typedef struct Authctxt Authctxt;
50 typedef struct Authmethod Authmethod;
51 typedef struct KbdintDevice KbdintDevice;
52 
53 struct Authctxt {
54 	sig_atomic_t	 success;
55 	int		 authenticated;	/* authenticated and alarms cancelled */
56 	int		 postponed;	/* authentication needs another step */
57 	int		 valid;		/* user exists and is allowed to login */
58 	int		 attempt;
59 	int		 failures;
60 	int		 server_caused_failure;
61 	int		 force_pwchange;
62 	char		*user;		/* username sent by the client */
63 	char		*service;
64 	struct passwd	*pw;		/* set if 'valid' */
65 	char		*style;
66 	void		*kbdintctxt;
67 	char		*info;		/* Extra info for next auth_log */
68 #ifdef BSD_AUTH
69 	auth_session_t	*as;
70 #endif
71 #ifdef KRB4
72 	char		*krb4_ticket_file;
73 #endif
74 	char		**auth_methods;	/* modified from server config */
75 	u_int		 num_auth_methods;
76 #ifdef KRB5
77 	krb5_context	 krb5_ctx;
78 	krb5_auth_context krb5_auth_ctx;
79 	krb5_ccache	 krb5_fwd_ccache;
80 	krb5_principal	 krb5_user;
81 	char		*krb5_ticket_file;
82 #endif
83 	void		*methoddata;
84 
85 	struct sshkey	**prev_userkeys;
86 	u_int		 nprev_userkeys;
87 };
88 /*
89  * Every authentication method has to handle authentication requests for
90  * non-existing users, or for users that are not allowed to login. In this
91  * case 'valid' is set to 0, but 'user' points to the username requested by
92  * the client.
93  */
94 
95 #ifdef USE_PAM
96 #include "auth-pam.h"
97 #endif
98 
99 struct Authmethod {
100 	const char	*name;
101 	int	(*userauth)(Authctxt *authctxt);
102 	int	*enabled;
103 };
104 
105 /*
106  * Keyboard interactive device:
107  * init_ctx	returns: non NULL upon success
108  * query	returns: 0 - success, otherwise failure
109  * respond	returns: 0 - success, 1 - need further interaction,
110  *		otherwise - failure
111  */
112 struct KbdintDevice
113 {
114 	const char *name;
115 	void*	(*init_ctx)(Authctxt*);
116 	int	(*query)(void *ctx, char **name, char **infotxt,
117 		    u_int *numprompts, char ***prompts, u_int **echo_on);
118 	int	(*respond)(void *ctx, u_int numresp, char **responses);
119 	void	(*free_ctx)(void *ctx);
120 };
121 
122 void 	 disable_forwarding(void);
123 int      auth_rhosts(struct passwd *, const char *);
124 int
125 auth_rhosts2(struct passwd *, const char *, const char *, const char *);
126 
127 int	 auth_rhosts_rsa(Authctxt *, char *, Key *);
128 int      auth_password(Authctxt *, const char *);
129 int      auth_rsa(Authctxt *, BIGNUM *);
130 int      auth_rsa_challenge_dialog(Key *);
131 BIGNUM	*auth_rsa_generate_challenge(Key *);
132 int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
133 int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
134 
135 int	 auth_rhosts_rsa_key_allowed(struct passwd *, const char *,
136     const char *, Key *);
137 int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
138 int	 user_key_allowed(struct passwd *, Key *, int);
139 void	 pubkey_auth_info(Authctxt *, const Key *, const char *, ...)
140 	    __attribute__((__format__ (printf, 3, 4)));
141 void	 auth2_record_userkey(Authctxt *, struct sshkey *);
142 int	 auth2_userkey_already_used(Authctxt *, struct sshkey *);
143 
144 #ifdef KRB4
145 #include <krb.h>
146 int     auth_krb4(Authctxt *, KTEXT, char **, KTEXT);
147 int	auth_krb4_password(Authctxt *, const char *);
148 void    krb4_cleanup_proc(void *);
149 
150 #ifdef AFS
151 #include <kafs.h>
152 int     auth_krb4_tgt(Authctxt *, const char *);
153 int     auth_afs_token(Authctxt *, const char *);
154 #endif /* AFS */
155 
156 #endif /* KRB4 */
157 
158 struct stat;
159 int	 auth_secure_path(const char *, struct stat *, const char *, uid_t,
160     char *, size_t);
161 
162 #ifdef KRB5
163 int	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
164 int	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
165 int	auth_krb5_password(Authctxt *authctxt, const char *password);
166 void	krb5_cleanup_proc(Authctxt *authctxt);
167 #endif /* KRB5 */
168 
169 void	do_authentication(Authctxt *);
170 void	do_authentication2(Authctxt *);
171 
172 void	auth_info(Authctxt *authctxt, const char *, ...)
173 	    __attribute__((__format__ (printf, 2, 3)))
174 	    __attribute__((__nonnull__ (2)));
175 void	auth_log(Authctxt *, int, int, const char *, const char *);
176 void	auth_maxtries_exceeded(Authctxt *) __attribute__((noreturn));
177 void	userauth_finish(Authctxt *, int, const char *, const char *);
178 int	auth_root_allowed(const char *);
179 
180 char	*auth2_read_banner(void);
181 int	 auth2_methods_valid(const char *, int);
182 int	 auth2_update_methods_lists(Authctxt *, const char *, const char *);
183 int	 auth2_setup_methods_lists(Authctxt *);
184 int	 auth2_method_allowed(Authctxt *, const char *, const char *);
185 
186 void	privsep_challenge_enable(void);
187 
188 int	auth2_challenge(Authctxt *, char *);
189 void	auth2_challenge_stop(Authctxt *);
190 int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
191 int	bsdauth_respond(void *, u_int, char **);
192 
193 int	allowed_user(struct passwd *);
194 struct passwd * getpwnamallow(const char *user);
195 
196 char	*get_challenge(Authctxt *);
197 int	verify_response(Authctxt *, const char *);
198 
199 char	*expand_authorized_keys(const char *, struct passwd *pw);
200 char	*authorized_principals_file(struct passwd *);
201 
202 FILE	*auth_openkeyfile(const char *, struct passwd *, int);
203 FILE	*auth_openprincipals(const char *, struct passwd *, int);
204 int	 auth_key_is_revoked(Key *);
205 
206 const char	*auth_get_canonical_hostname(struct ssh *, int);
207 
208 HostStatus
209 check_key_in_hostfiles(struct passwd *, Key *, const char *,
210     const char *, const char *);
211 
212 /* hostkey handling */
213 Key	*get_hostkey_by_index(int);
214 Key	*get_hostkey_public_by_index(int, struct ssh *);
215 Key	*get_hostkey_public_by_type(int, int, struct ssh *);
216 Key	*get_hostkey_private_by_type(int, int, struct ssh *);
217 int	 get_hostkey_index(Key *, int, struct ssh *);
218 int	 ssh1_session_key(BIGNUM *);
219 int	 sshd_hostkey_sign(Key *, Key *, u_char **, size_t *,
220 	     const u_char *, size_t, const char *, u_int);
221 
222 /* debug messages during authentication */
223 void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
224 void	 auth_debug_send(void);
225 void	 auth_debug_reset(void);
226 
227 struct passwd *fakepw(void);
228 
229 #define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
230 
231 #define SKEY_PROMPT "\nS/Key Password: "
232 
233 #if defined(KRB5) && !defined(HEIMDAL)
234 #include <krb5.h>
235 krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
236 #endif
237 #endif
238