ret = -ENOMEM;
goto out;
}
- form->auth_id = strdup("fortinet_auth");
+ form->auth_id = strdup("_login");
if (!form->auth_id)
goto nomem;
opt = form->opts = calloc(1, sizeof(*opt));
opt->type = OC_FORM_OPT_HIDDEN;
free(opt2->label);
free(opt2->_value);
+ opt2->label = opt2->_value = NULL;
/* Change 'credential' field to 'code'. */
opt2->_value = NULL;
else
opt2->type = OC_FORM_OPT_PASSWORD;
+ /* Change 'auth_id' to '_challenge'. */
+ free(form->auth_id);
+ if (!(form->auth_id = strdup("_challenge")))
+ goto nomem;
+
/* Save a bunch of values to parrot back */
filter_opts(action_buf, resp_buf, "reqid,polid,grp,portal,peer,magic", 1);
if ((ret = buf_error(action_buf)))
* XX: See do_https_request() for why ret==0 can only happen
* if there was a successful-but-unfetched redirect.
*/
+#if 0
invalid_cookie:
+#endif
ret = -EPERM;
goto out;
}
# values via a (cookie-based) session.
#
# In order to test with 2FA, the initial 'GET /' request should include
-# the query string '?want_2fa=1'.
+# the query string '?want_2fa=1'. If >1, multiple rounds of 2FA token entry
+# will be required.
########################################
import sys
@app.route('/')
@app.route('/<realm>')
def realm(realm=None):
- session.update(step='GET-realm', want_2fa='want_2fa' in request.args)
+ session.update(step='GET-realm', want_2fa=int(request.args.get('want_2fa', 0)))
# print(session)
if realm:
return redirect(url_for('login', realm=realm))
def logincheck():
want_2fa = session.get('want_2fa')
- if (want_2fa and request.form.get('code')):
- return complete_2fa()
+ if want_2fa and request.form.get('username') and request.form.get('code'):
+ if want_2fa == 1:
+ return complete_2fa()
+ else:
+ session.update(want_2fa=want_2fa - 1)
+ return send_2fa_challenge()
elif (want_2fa and request.form.get('username') and request.form.get('credential')):
return send_2fa_challenge()
elif (request.form.get('username') and request.form.get('credential')):
# print(session)
return ('ret=2,reqid={reqid},polid={polid},grp={grp},portal={portal},magic={magic},'
- 'tokeninfo=,chal_msg=Please enter your token code'.format(**session),
+ 'tokeninfo=,chal_msg=Please enter your token code ({want_2fa} remaining)'.format(**session),
{'content-type': 'text/plain'})
( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/?want_2fa=1 -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Fortinet server"
+ok
+
+echo -n "Authenticating with username/password/(2 round of token) and DEFAULT path... "
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/?want_2fa=2 -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
+ fail $PID "Could not receive cookie from fake Fortinet server"
+
echo ok
echo -n "Authenticating with username/password/token and NON-DEFAULT path... "