2 RCSID("$OpenBSD: auth2-skey.c,v 1.1 2000/10/11 20:14:38 markus Exp $");
12 void send_userauth_into_request(Authctxt *authctxt, int echo);
13 void input_userauth_info_response(int type, int plen, void *ctxt);
16 * try skey authentication, always return -1 (= postponed) since we have to
17 * wait for the s/key response.
20 auth2_skey(Authctxt *authctxt)
22 send_userauth_into_request(authctxt, 0);
23 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, &input_userauth_info_response);
28 send_userauth_into_request(Authctxt *authctxt, int echo)
32 char challenge[SKEY_MAX_CHALLENGE];
35 if (authctxt->user == NULL)
36 fatal("send_userauth_into_request: internal error: no user");
38 /* get skey challenge */
40 retval = skeychallenge(&skey, authctxt->user, challenge);
43 fake = skey_fake_keyinfo(authctxt->user);
44 strlcpy(challenge, fake, sizeof challenge);
46 /* send our info request */
47 packet_start(SSH2_MSG_USERAUTH_INFO_REQUEST);
48 packet_put_cstring("S/Key Authentication"); /* Name */
49 packet_put_cstring(challenge); /* Instruction */
50 packet_put_cstring(""); /* Language */
51 packet_put_int(1); /* Number of prompts */
52 packet_put_cstring(echo ?
53 "Response [Echo]: ": "Response: "); /* Prompt */
54 packet_put_char(echo); /* Echo */
57 memset(challenge, 'c', sizeof challenge);
61 input_userauth_info_response(int type, int plen, void *ctxt)
63 Authctxt *authctxt = ctxt;
64 int authenticated = 0;
65 unsigned int nresp, rlen;
69 fatal("input_userauth_info_response: no authentication context");
71 if (authctxt->attempt++ >= AUTH_FAIL_MAX)
72 packet_disconnect("too many failed userauth_requests");
74 nresp = packet_get_int();
76 /* we only support s/key and assume s/key for nresp == 1 */
78 resp = packet_get_string(&rlen);
80 if (strlen(resp) == 0) {
82 * if we received a null response, resend prompt with
86 userauth_log(authctxt, authenticated, method);
87 send_userauth_into_request(authctxt, 1);
89 /* verify skey response */
90 if (authctxt->valid &&
91 skey_haskey(authctxt->pw->pw_name) == 0 &&
92 skey_passcheck(authctxt->pw->pw_name, resp) != -1) {
97 memset(resp, 'r', rlen);
98 /* unregister callback */
99 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
100 userauth_log(authctxt, authenticated, method);
101 userauth_reply(authctxt, authenticated);