Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/auth.h.2auth openssh-5.9p1/auth.h
Jan F. Chadima cff1d0c
--- openssh-5.9p1/auth.h.2auth	2011-05-29 13:39:38.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/auth.h	2011-09-13 20:25:22.250474950 +0200
Jan F. Chadima 69dd72f
@@ -149,6 +149,8 @@ int	auth_root_allowed(char *);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 char	*auth2_read_banner(void);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
+void	userauth_restart(const char *);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 void	privsep_challenge_enable(void);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 int	auth2_challenge(Authctxt *, char *);
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/auth2.c.2auth openssh-5.9p1/auth2.c
Jan F. Chadima cff1d0c
--- openssh-5.9p1/auth2.c.2auth	2011-05-05 06:04:11.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/auth2.c	2011-09-13 20:25:22.348458588 +0200
Jan F. Chadima 69dd72f
@@ -290,6 +290,23 @@ input_userauth_request(int type, u_int32
Jan F. Chadima 69dd72f
 }
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 void
Jan F. Chadima 69dd72f
+userauth_restart(const char *method)
Jan F. Chadima 69dd72f
+{
Jan F. Chadima 69dd72f
+	options.two_factor_authentication = 0;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	options.pubkey_authentication = options.second_pubkey_authentication && strcmp(method, method_pubkey.name);
Jan F. Chadima 69dd72f
+#ifdef GSSAPI
Jan F. Chadima 69dd72f
+	options.gss_authentication = options.second_gss_authentication && strcmp(method, method_gssapi.name);
Jan F. Chadima 69dd72f
+#endif
Jan F. Chadima 69dd72f
+#ifdef JPAKE
Jan F. Chadima 69dd72f
+	options.zero_knowledge_password_authentication = options.second_zero_knowledge_password_authentication && strcmp(method, method_jpake.name);
Jan F. Chadima 69dd72f
+#endif
Jan F. Chadima 69dd72f
+	options.password_authentication = options.second_password_authentication && strcmp(method, method_passwd.name);
Jan F. Chadima 69dd72f
+	options.kbd_interactive_authentication = options.second_kbd_interactive_authentication && strcmp(method, method_kbdint.name);
Jan F. Chadima 69dd72f
+	options.hostbased_authentication = options.second_hostbased_authentication && strcmp(method, method_hostbased.name);
Jan F. Chadima 69dd72f
+}
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+void
Jan F. Chadima 69dd72f
 userauth_finish(Authctxt *authctxt, int authenticated, char *method)
Jan F. Chadima 69dd72f
 {
Jan F. Chadima 69dd72f
 	char *methods;
Jan F. Chadima 69dd72f
@@ -337,6 +354,15 @@ userauth_finish(Authctxt *authctxt, int
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 	/* XXX todo: check if multiple auth methods are needed */
Jan F. Chadima 69dd72f
 	if (authenticated == 1) {
Jan F. Chadima 69dd72f
+		if (options.two_factor_authentication) {
Jan F. Chadima 69dd72f
+			userauth_restart(method);
Jan F. Chadima 69dd72f
+			if (use_privsep) 
Jan F. Chadima 69dd72f
+				PRIVSEP(userauth_restart(method));
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+			debug("1st factor authentication done go to 2nd factor");
Jan F. Chadima 69dd72f
+			goto ask_methods;
Jan F. Chadima 69dd72f
+		}
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 		/* turn off userauth */
Jan F. Chadima 69dd72f
 		dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &dispatch_protocol_ignore);
Jan F. Chadima 69dd72f
 		packet_start(SSH2_MSG_USERAUTH_SUCCESS);
Jan F. Chadima 69dd72f
@@ -356,6 +382,7 @@ userauth_finish(Authctxt *authctxt, int
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
 			packet_disconnect(AUTH_FAIL_MSG, authctxt->user);
Jan F. Chadima 69dd72f
 		}
Jan F. Chadima 69dd72f
+ask_methods:
Jan F. Chadima 69dd72f
 		methods = authmethods_get();
Jan F. Chadima 69dd72f
 		packet_start(SSH2_MSG_USERAUTH_FAILURE);
Jan F. Chadima 69dd72f
 		packet_put_cstring(methods);
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/monitor.c.2auth openssh-5.9p1/monitor.c
Jan F. Chadima cff1d0c
--- openssh-5.9p1/monitor.c.2auth	2011-09-13 20:25:18.031458843 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/monitor.c	2011-09-13 20:53:29.345644462 +0200
Jan F. Chadima 69dd72f
@@ -165,6 +165,7 @@ int mm_answer_jpake_step1(int, Buffer *)
Jan F. Chadima 69dd72f
 int mm_answer_jpake_step2(int, Buffer *);
Jan F. Chadima 69dd72f
 int mm_answer_jpake_key_confirm(int, Buffer *);
Jan F. Chadima 69dd72f
 int mm_answer_jpake_check_confirm(int, Buffer *);
Jan F. Chadima 69dd72f
+int mm_answer_userauth_restart(int, Buffer *);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 #ifdef USE_PAM
Jan F. Chadima 69dd72f
 int mm_answer_pam_start(int, Buffer *);
Jan F. Chadima 69dd72f
@@ -259,6 +260,7 @@ struct mon_table mon_dispatch_proto20[]
Jan F. Chadima 69dd72f
     {MONITOR_REQ_JPAKE_KEY_CONFIRM, MON_ONCE, mm_answer_jpake_key_confirm},
Jan F. Chadima 69dd72f
     {MONITOR_REQ_JPAKE_CHECK_CONFIRM, MON_AUTH, mm_answer_jpake_check_confirm},
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
+    {MONITOR_REQ_USERAUTH_RESTART, MON_PERMIT, mm_answer_userauth_restart},
Jan F. Chadima 69dd72f
     {0, 0, NULL}
Jan F. Chadima 69dd72f
 };
Jan F. Chadima 69dd72f
 
Jan F. Chadima cff1d0c
@@ -378,7 +380,7 @@ monitor_child_preauth(Authctxt *_authctx
Jan F. Chadima 69dd72f
 	}
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 	/* The first few requests do not require asynchronous access */
Jan F. Chadima 69dd72f
-	while (!authenticated) {
Jan F. Chadima 69dd72f
+	while (!authenticated || options.two_factor_authentication) {
Jan F. Chadima 69dd72f
 		auth_method = "unknown";
Jan F. Chadima 69dd72f
 		authenticated = (monitor_read(pmonitor, mon_dispatch, &ent) == 1);
Jan F. Chadima 69dd72f
 		if (authenticated) {
Jan F. Chadima cff1d0c
@@ -390,7 +392,7 @@ monitor_child_preauth(Authctxt *_authctx
Jan F. Chadima 69dd72f
 				authenticated = 0;
Jan F. Chadima 69dd72f
 #ifdef USE_PAM
Jan F. Chadima 69dd72f
 			/* PAM needs to perform account checks after auth */
Jan F. Chadima 69dd72f
-			if (options.use_pam && authenticated) {
Jan F. Chadima 69dd72f
+			if (options.use_pam && authenticated && !options.two_factor_authentication) {
Jan F. Chadima 69dd72f
 				Buffer m;
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 				buffer_init(&m);
Jan F. Chadima cff1d0c
@@ -2001,6 +2003,24 @@ monitor_reinit(struct monitor *mon)
Jan F. Chadima 69dd72f
 	monitor_openfds(mon, 0);
Jan F. Chadima 69dd72f
 }
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
+int
Jan F. Chadima 69dd72f
+mm_answer_userauth_restart(int sock, Buffer *m)
Jan F. Chadima 69dd72f
+{
Jan F. Chadima 69dd72f
+	char *method;
Jan F. Chadima 69dd72f
+	u_int method_len;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	method = buffer_get_string(m, &method_len);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	userauth_restart(method);
Jan F. Chadima 69dd72f
+
Jan F. Chadima cff1d0c
+	xfree(method);
Jan F. Chadima cff1d0c
+	buffer_clear(m);
Jan F. Chadima cff1d0c
+
Jan F. Chadima 69dd72f
+	mm_request_send(sock, MONITOR_ANS_USERAUTH_RESTART, m);
Jan F. Chadima cff1d0c
+
Jan F. Chadima cff1d0c
+	return (0);
Jan F. Chadima 69dd72f
+}
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 #ifdef GSSAPI
Jan F. Chadima 69dd72f
 int
Jan F. Chadima 69dd72f
 mm_answer_gss_setup_ctx(int sock, Buffer *m)
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/monitor.h.2auth openssh-5.9p1/monitor.h
Jan F. Chadima cff1d0c
--- openssh-5.9p1/monitor.h.2auth	2011-06-20 06:42:23.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/monitor.h	2011-09-13 20:25:22.615458574 +0200
Jan F. Chadima 69dd72f
@@ -66,6 +66,7 @@ enum monitor_reqtype {
Jan F. Chadima 69dd72f
 	MONITOR_REQ_JPAKE_STEP2, MONITOR_ANS_JPAKE_STEP2,
Jan F. Chadima 69dd72f
 	MONITOR_REQ_JPAKE_KEY_CONFIRM, MONITOR_ANS_JPAKE_KEY_CONFIRM,
Jan F. Chadima 69dd72f
 	MONITOR_REQ_JPAKE_CHECK_CONFIRM, MONITOR_ANS_JPAKE_CHECK_CONFIRM,
Jan F. Chadima 69dd72f
+	MONITOR_REQ_USERAUTH_RESTART, MONITOR_ANS_USERAUTH_RESTART,
Jan F. Chadima 69dd72f
 };
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 struct mm_master;
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/monitor_wrap.c.2auth openssh-5.9p1/monitor_wrap.c
Jan F. Chadima cff1d0c
--- openssh-5.9p1/monitor_wrap.c.2auth	2011-06-20 06:42:23.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/monitor_wrap.c	2011-09-13 20:25:22.735468462 +0200
Jan F. Chadima 69dd72f
@@ -1173,6 +1173,26 @@ mm_auth_rsa_verify_response(Key *key, BI
Jan F. Chadima 69dd72f
 	return (success);
Jan F. Chadima 69dd72f
 }
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
+void
Jan F. Chadima 69dd72f
+mm_userauth_restart(const char *monitor)
Jan F. Chadima 69dd72f
+{
Jan F. Chadima 69dd72f
+	Buffer m;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	debug3("%s entering", __func__);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	buffer_init(&m);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	buffer_put_cstring(&m, monitor);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	mm_request_send(pmonitor->m_recvfd,
Jan F. Chadima 69dd72f
+	    MONITOR_REQ_USERAUTH_RESTART, &m);
Jan F. Chadima 69dd72f
+	debug3("%s: waiting for MONITOR_ANS_USERAUTH_RESTART", __func__);
Jan F. Chadima 69dd72f
+	mm_request_receive_expect(pmonitor->m_recvfd,
Jan F. Chadima 69dd72f
+	    MONITOR_ANS_USERAUTH_RESTART, &m);
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	buffer_free(&m);
Jan F. Chadima 69dd72f
+}
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima 69dd72f
 void
Jan F. Chadima 69dd72f
 mm_audit_event(ssh_audit_event_t event)
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/monitor_wrap.h.2auth openssh-5.9p1/monitor_wrap.h
Jan F. Chadima cff1d0c
--- openssh-5.9p1/monitor_wrap.h.2auth	2011-06-20 06:42:23.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/monitor_wrap.h	2011-09-13 20:25:22.847457505 +0200
Jan F. Chadima 69dd72f
@@ -53,6 +53,7 @@ int mm_key_verify(Key *, u_char *, u_int
Jan F. Chadima 69dd72f
 int mm_auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
Jan F. Chadima 69dd72f
 int mm_auth_rsa_verify_response(Key *, BIGNUM *, u_char *);
Jan F. Chadima 69dd72f
 BIGNUM *mm_auth_rsa_generate_challenge(Key *);
Jan F. Chadima 69dd72f
+void mm_userauth_restart(const char *);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
 #ifdef GSSAPI
Jan F. Chadima 69dd72f
 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/servconf.c.2auth openssh-5.9p1/servconf.c
Jan F. Chadima cff1d0c
--- openssh-5.9p1/servconf.c.2auth	2011-09-13 20:25:18.836495701 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/servconf.c	2011-09-13 20:25:22.994584169 +0200
Jan F. Chadima 69dd72f
@@ -92,6 +92,13 @@ initialize_server_options(ServerOptions
Jan F. Chadima 69dd72f
 	options->hostbased_uses_name_from_packet_only = -1;
Jan F. Chadima 69dd72f
 	options->rsa_authentication = -1;
Jan F. Chadima 69dd72f
 	options->pubkey_authentication = -1;
Jan F. Chadima 69dd72f
+	options->two_factor_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_pubkey_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_gss_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_password_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_kbd_interactive_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_zero_knowledge_password_authentication = -1;
Jan F. Chadima 69dd72f
+	options->second_hostbased_authentication = -1;
Jan F. Chadima 69dd72f
 	options->kerberos_authentication = -1;
Jan F. Chadima 69dd72f
 	options->kerberos_or_local_passwd = -1;
Jan F. Chadima 69dd72f
 	options->kerberos_ticket_cleanup = -1;
Jan F. Chadima 69dd72f
@@ -237,6 +244,20 @@ fill_default_server_options(ServerOption
Jan F. Chadima 69dd72f
 		options->permit_empty_passwd = 0;
Jan F. Chadima 69dd72f
 	if (options->permit_user_env == -1)
Jan F. Chadima 69dd72f
 		options->permit_user_env = 0;
Jan F. Chadima 69dd72f
+	if (options->two_factor_authentication == -1)
Jan F. Chadima 69dd72f
+		options->two_factor_authentication = 0;
Jan F. Chadima 69dd72f
+	if (options->second_pubkey_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_pubkey_authentication = 1;
Jan F. Chadima 69dd72f
+	if (options->second_gss_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_gss_authentication = 0;
Jan F. Chadima 69dd72f
+	if (options->second_password_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_password_authentication = 1;
Jan F. Chadima 69dd72f
+	if (options->second_kbd_interactive_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_kbd_interactive_authentication = 0;
Jan F. Chadima 69dd72f
+	if (options->second_zero_knowledge_password_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_zero_knowledge_password_authentication = 0;
Jan F. Chadima 69dd72f
+	if (options->second_hostbased_authentication == -1)
Jan F. Chadima 69dd72f
+		options->second_hostbased_authentication = 0;
Jan F. Chadima 69dd72f
 	if (options->use_login == -1)
Jan F. Chadima 69dd72f
 		options->use_login = 0;
Jan F. Chadima 69dd72f
 	if (options->compression == -1)
Jan F. Chadima 69dd72f
@@ -316,8 +337,11 @@ typedef enum {
Jan F. Chadima 69dd72f
 	sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
Jan F. Chadima 69dd72f
 	sMaxStartups, sMaxAuthTries, sMaxSessions,
Jan F. Chadima 69dd72f
 	sBanner, sUseDNS, sHostbasedAuthentication,
Jan F. Chadima 69dd72f
-	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Jan F. Chadima 69dd72f
-	sClientAliveCountMax, sAuthorizedKeysFile,
Jan F. Chadima 69dd72f
+	sHostbasedUsesNameFromPacketOnly, sTwoFactorAuthentication,
Jan F. Chadima 69dd72f
+	sSecondPubkeyAuthentication, sSecondGssAuthentication,
Jan F. Chadima 69dd72f
+	sSecondPasswordAuthentication, sSecondKbdInteractiveAuthentication,
Jan F. Chadima 69dd72f
+	sSecondZeroKnowledgePasswordAuthentication, sSecondHostbasedAuthentication,
Jan F. Chadima 69dd72f
+	sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
Jan F. Chadima 69dd72f
 	sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Jan F. Chadima 69dd72f
 	sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Jan F. Chadima 69dd72f
 	sUsePrivilegeSeparation, sAllowAgentForwarding,
Jan F. Chadima 69dd72f
@@ -395,6 +419,21 @@ static struct {
Jan F. Chadima 69dd72f
 #else
Jan F. Chadima 69dd72f
 	{ "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
+	{ "twofactorauthentication", sTwoFactorAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+	{ "secondpubkeyauthentication", sSecondPubkeyAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#ifdef GSSAPI
Jan F. Chadima 69dd72f
+	{ "secondgssapiauthentication", sSecondGssAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#else
Jan F. Chadima 69dd72f
+	{ "secondgssapiauthentication", sUnsupported, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#endif
Jan F. Chadima 69dd72f
+	{ "secondpasswordauthentication", sSecondPasswordAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+	{ "secondkbdinteractiveauthentication", sSecondKbdInteractiveAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#ifdef JPAKE
Jan F. Chadima 69dd72f
+	{ "secondzeroknowledgepasswordauthentication", sSecondZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#else
Jan F. Chadima 69dd72f
+	{ "secondzeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
Jan F. Chadima 69dd72f
+#endif
Jan F. Chadima 69dd72f
+	{ "secondhostbasedauthentication", sSecondHostbasedAuthentication, SSHCFG_ALL },
Jan F. Chadima 69dd72f
 	{ "checkmail", sDeprecated, SSHCFG_GLOBAL },
Jan F. Chadima 69dd72f
 	{ "listenaddress", sListenAddress, SSHCFG_GLOBAL },
Jan F. Chadima 69dd72f
 	{ "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
Jan F. Chadima 69dd72f
@@ -982,6 +1021,34 @@ process_server_config_line(ServerOptions
Jan F. Chadima 69dd72f
 		intptr = &options->challenge_response_authentication;
Jan F. Chadima 69dd72f
 		goto parse_flag;
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
+	case sTwoFactorAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->two_factor_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondPubkeyAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_pubkey_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondGssAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_gss_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondPasswordAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_password_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondKbdInteractiveAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_kbd_interactive_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondZeroKnowledgePasswordAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_zero_knowledge_password_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
+	case sSecondHostbasedAuthentication:
Jan F. Chadima 69dd72f
+		intptr = &options->second_hostbased_authentication;
Jan F. Chadima 69dd72f
+		goto parse_flag;
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 	case sPrintMotd:
Jan F. Chadima 69dd72f
 		intptr = &options->print_motd;
Jan F. Chadima 69dd72f
 		goto parse_flag;
Jan F. Chadima 69dd72f
@@ -1491,14 +1558,21 @@ void
Jan F. Chadima 69dd72f
 copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Jan F. Chadima 69dd72f
 {
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(password_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_password_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(gss_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_gss_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(rsa_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(pubkey_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_pubkey_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(kerberos_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(hostbased_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_hostbased_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(hostbased_uses_name_from_packet_only);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(kbd_interactive_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_kbd_interactive_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(zero_knowledge_password_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(second_zero_knowledge_password_authentication);
Jan F. Chadima 69dd72f
+	M_CP_INTOPT(two_factor_authentication);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(permit_root_login);
Jan F. Chadima 69dd72f
 	M_CP_INTOPT(permit_empty_passwd);
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
@@ -1720,17 +1794,24 @@ dump_config(ServerOptions *o)
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
 #ifdef GSSAPI
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
Jan F. Chadima 69dd72f
+	dump_cfg_fmtint(sSecondGssAuthentication, o->second_gss_authentication);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
 #ifdef JPAKE
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
Jan F. Chadima 69dd72f
 	    o->zero_knowledge_password_authentication);
Jan F. Chadima 69dd72f
+	dump_cfg_fmtint(sSecondZeroKnowledgePasswordAuthentication,
Jan F. Chadima 69dd72f
+	    o->second_zero_knowledge_password_authentication);
Jan F. Chadima 69dd72f
 #endif
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
Jan F. Chadima 69dd72f
+	dump_cfg_fmtint(sSecondPasswordAuthentication, o->second_password_authentication);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sKbdInteractiveAuthentication,
Jan F. Chadima 69dd72f
 	    o->kbd_interactive_authentication);
Jan F. Chadima 69dd72f
+	dump_cfg_fmtint(sSecondKbdInteractiveAuthentication,
Jan F. Chadima 69dd72f
+	    o->second_kbd_interactive_authentication);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sChallengeResponseAuthentication,
Jan F. Chadima 69dd72f
 	    o->challenge_response_authentication);
Jan F. Chadima 69dd72f
+	dump_cfg_fmtint(sTwoFactorAuthentication, o->two_factor_authentication);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sPrintMotd, o->print_motd);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
Jan F. Chadima 69dd72f
 	dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/servconf.h.2auth openssh-5.9p1/servconf.h
Jan F. Chadima cff1d0c
--- openssh-5.9p1/servconf.h.2auth	2011-06-23 00:30:03.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/servconf.h	2011-09-13 20:25:23.103459846 +0200
Jan F. Chadima 69dd72f
@@ -112,6 +112,14 @@ typedef struct {
Jan F. Chadima 69dd72f
 					/* If true, permit jpake auth */
Jan F. Chadima 69dd72f
 	int     permit_empty_passwd;	/* If false, do not permit empty
Jan F. Chadima 69dd72f
 					 * passwords. */
Jan F. Chadima 69dd72f
+	int	two_factor_authentication;	/* If true, the first sucessful authentication
Jan F. Chadima 69dd72f
+					 * will be followed by the second one from anorher set */
Jan F. Chadima 69dd72f
+	int	second_pubkey_authentication;	/* second set of authentications */
Jan F. Chadima 69dd72f
+	int	second_gss_authentication;
Jan F. Chadima 69dd72f
+	int	second_password_authentication;
Jan F. Chadima 69dd72f
+	int	second_kbd_interactive_authentication;
Jan F. Chadima 69dd72f
+	int	second_zero_knowledge_password_authentication;
Jan F. Chadima 69dd72f
+	int	second_hostbased_authentication;
Jan F. Chadima 69dd72f
 	int     permit_user_env;	/* If true, read ~/.ssh/environment */
Jan F. Chadima 69dd72f
 	int     use_login;	/* If true, login(1) is used */
Jan F. Chadima 69dd72f
 	int     compression;	/* If true, compression is allowed */
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/sshd_config.2auth openssh-5.9p1/sshd_config
Jan F. Chadima cff1d0c
--- openssh-5.9p1/sshd_config.2auth	2011-05-29 13:39:39.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/sshd_config	2011-09-13 20:25:23.221458447 +0200
Jan F. Chadima 69dd72f
@@ -87,6 +87,13 @@ AuthorizedKeysFile	.ssh/authorized_keys
Jan F. Chadima 69dd72f
 # and ChallengeResponseAuthentication to 'no'.
Jan F. Chadima 69dd72f
 #UsePAM no
Jan F. Chadima 69dd72f
 
Jan F. Chadima 69dd72f
+#TwoFactorAuthentication no
Jan F. Chadima 69dd72f
+#SecondPubkeyAuthentication yes
Jan F. Chadima 69dd72f
+#SecondHostbasedAuthentication no
Jan F. Chadima 69dd72f
+#SecondPasswordAuthentication yes
Jan F. Chadima 69dd72f
+#SecondChallengeResponseAuthentication yes
Jan F. Chadima 69dd72f
+#SecondGSSAPIAuthentication no
Jan F. Chadima 69dd72f
+
Jan F. Chadima 69dd72f
 #AllowAgentForwarding yes
Jan F. Chadima 69dd72f
 #AllowTcpForwarding yes
Jan F. Chadima 69dd72f
 #GatewayPorts no
Jan F. Chadima cff1d0c
diff -up openssh-5.9p1/sshd_config.5.2auth openssh-5.9p1/sshd_config.5
Jan F. Chadima cff1d0c
--- openssh-5.9p1/sshd_config.5.2auth	2011-08-05 22:17:33.000000000 +0200
Jan F. Chadima cff1d0c
+++ openssh-5.9p1/sshd_config.5	2011-09-13 20:25:23.416458539 +0200
Jan F. Chadima 69dd72f
@@ -726,6 +726,12 @@ Available keywords are
Jan F. Chadima 69dd72f
 .Cm PubkeyAuthentication ,
Jan F. Chadima 69dd72f
 .Cm RhostsRSAAuthentication ,
Jan F. Chadima 69dd72f
 .Cm RSAAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondGSSAPIAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondHostbasedAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondKbdInteractiveAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondPasswordAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondPubkeyAuthentication ,
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication ,
Jan F. Chadima 69dd72f
 .Cm X11DisplayOffset ,
Jan F. Chadima 69dd72f
 .Cm X11Forwarding
Jan F. Chadima 69dd72f
 and
Jan F. Chadima 69dd72f
@@ -931,6 +937,41 @@ Specifies whether pure RSA authenticatio
Jan F. Chadima 69dd72f
 The default is
Jan F. Chadima 69dd72f
 .Dq yes .
Jan F. Chadima 69dd72f
 This option applies to protocol version 1 only.
Jan F. Chadima 69dd72f
+.It Cm SecondGSSAPIAuthentication
Jan F. Chadima 69dd72f
+Specifies whether the
Jan F. Chadima 69dd72f
+.Cm GSSAPIAuthentication
Jan F. Chadima 69dd72f
+may be used on the second authentication while
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+is set.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “no”.
Jan F. Chadima 69dd72f
+.It Cm SecondHostbasedAuthentication
Jan F. Chadima 69dd72f
+Specifies whether the
Jan F. Chadima 69dd72f
+.Cm HostbasedAuthentication
Jan F. Chadima 69dd72f
+may be used on the second authentication while
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+is set.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “no”.
Jan F. Chadima 69dd72f
+.It Cm SecondKbdInteractiveAuthentication
Jan F. Chadima 69dd72f
+Specifies whether the
Jan F. Chadima 69dd72f
+.Cm KbdInteractiveAuthentication
Jan F. Chadima 69dd72f
+may be used on the second authentication while
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+is set.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “no”.
Jan F. Chadima 69dd72f
+.It Cm SecondPasswordAuthentication
Jan F. Chadima 69dd72f
+Specifies whether the
Jan F. Chadima 69dd72f
+.Cm PasswordAuthentication
Jan F. Chadima 69dd72f
+may be used on the second authentication while
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+is set.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “yes”.
Jan F. Chadima 69dd72f
+.It Cm SecondPubkeyAuthentication 
Jan F. Chadima 69dd72f
+Specifies whether the
Jan F. Chadima 69dd72f
+.Cm PubkeyAuthentication
Jan F. Chadima 69dd72f
+may be used on the second authentication while
Jan F. Chadima 69dd72f
+.Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+is set.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “yes”.
Jan F. Chadima 69dd72f
 .It Cm ServerKeyBits
Jan F. Chadima 69dd72f
 Defines the number of bits in the ephemeral protocol version 1 server key.
Jan F. Chadima 69dd72f
 The minimum value is 512, and the default is 1024.
Jan F. Chadima 69dd72f
@@ -1011,6 +1052,22 @@ For more details on certificates, see th
Jan F. Chadima 69dd72f
 .Sx CERTIFICATES
Jan F. Chadima 69dd72f
 section in
Jan F. Chadima 69dd72f
 .Xr ssh-keygen 1 .
Jan F. Chadima 69dd72f
+.It Cm TwoFactorAuthentication
Jan F. Chadima 69dd72f
+Specifies whether for a successful login is necessary to meet two independent authentications.
Jan F. Chadima 69dd72f
+If select the first method is selected from the set of allowed methods from
Jan F. Chadima 69dd72f
+.Cm GSSAPIAuthentication ,
Jan F. Chadima 69dd72f
+.Cm HostbasedAuthentication ,
Jan F. Chadima 69dd72f
+.Cm KbdInteractiveAuthentication ,
Jan F. Chadima 69dd72f
+.Cm PasswordAuthentication ,
Jan F. Chadima 69dd72f
+.Cm PubkeyAuthentication .
Jan F. Chadima 69dd72f
+And the second method is selected from the set of allowed methods from
Jan F. Chadima 69dd72f
+.Cm SecondGSSAPIAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondHostbasedAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondKbdInteractiveAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondPasswordAuthentication ,
Jan F. Chadima 69dd72f
+.Cm SecondPubkeyAuthentication 
Jan F. Chadima 69dd72f
+without the method used for the first authentication.
Jan F. Chadima 69dd72f
+The argument must be “yes” or “no”.  The default is “no”.
Jan F. Chadima 69dd72f
 .It Cm UseDNS
Jan F. Chadima 69dd72f
 Specifies whether
Jan F. Chadima 69dd72f
 .Xr sshd 8