4 usage: %(progname)s [args] 8 import os, sys, string, time, getopt
19 now = int(time.time())
20 checkval =
"%s:%s" % (username, now)
21 realcheckval =
"%s:%s:%s" % (checkval, pw_hash, vcode)
22 checkval_hash = crypt.crypt(realcheckval,config.gAuthSalt)
23 checkval_hash = checkval_hash[2:]
24 return checkval, checkval_hash
34 now = int(time.time())
35 checkval, checkval_hash =
_createCheckVal(username, now, pw_hash, config.gAuthVCode)
36 cookie =
"V1/%s=%s" % (checkval,checkval_hash)
41 hostname = hdf.getValue(
"HTTP.Host",
"")
42 parts = hostname.split(
":", 1)
44 if hostname[-1]
in string.digits:
46 parts = string.split(hostname,
".")
47 domain = string.join(parts[1:],
".")
52 persist = hdf.getIntValue(
"Cookie.MB_persist", 0)
58 ncgi.cookieSet(
"MB_persist", persist, persist=1, domain=config.gDomain)
67 browserid = browserauth.checkBrowserCookie(authdb, ncgi)
70 browserid = browserauth.issueBrowserCookie(ncgi, authdb, domain)
72 debug(
"cookieauth.py",
"BrowserID", browserid)
73 debug(
"cookieauth.py",
"domain", domain)
78 timestr = time.strftime(
"%A, %d-%b-%Y %H:%M:%S GMT", time.localtime(t))
84 ncgi.cookieSet(
"MB_L1", cookie, persist=persist, path=config.gBaseURL, time_str=timestr)
91 ncgi.cookieClear(
"MB_L1",
"", config.gBaseURL)
92 ncgi.cookieClear(
"MB_L1",
"",
"/")
94 ncgi.cookieClear(
"MB_L1", domain, config.gBaseURL)
95 ncgi.cookieClear(
"MB_L1", domain,
"/")
106 cookie = ncgi.hdf.getValue(
"Cookie.MB_L1",
"")
111 version, restCookie = string.split(cookie,
"/", 1)
113 warn(
"cookieauth.py",
"invalid cookie, version", version, cookie)
115 checkval,checkval_hash = string.split(restCookie,
"=", 1)
116 username,issued_at = string.split(checkval,
":")
119 cookie.cookie = cookie
120 cookie.username = username
121 cookie.issued_at = int(issued_at)
122 cookie.checkval_hash = checkval_hash
130 if username != logincookie.username:
131 warn(
"cookieauth.py",
"invalid cookie, username mismatch", username, logincookie.username)
138 if (time.time() - logincookie.issued_at) > config.LOGIN_TIMEOUT:
139 warn(
"cookieauth.py",
"invalid cookie, timeout", logincookie.issued_at)
142 pw_hash = userRec.pw_hash
146 v_checkval, v_checkval_hash =
_createCheckVal(username, logincookie.issued_at, pw_hash, config.gAuthVCode)
148 if logincookie.checkval_hash != v_checkval_hash:
149 warn(
"cookieauth.py",
"checkval mismatch", logincookie.checkval_hash, v_checkval_hash)
162 print __doc__ % vars()
164 def main(argv, stdout, environ):
166 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
172 for (field, val)
in optlist:
173 if field ==
"--help":
176 elif field ==
"--debug":
178 elif field ==
"--test":
186 if __name__ ==
"__main__":
187 main(sys.argv, sys.stdout, os.environ)
def parseLoginCookie(ncgi)
def clearLoginCookie(ncgi, username, domain=None)
def checkLoginCookie(ncgi, logincookie, authdb, username, userRec)
def issueLoginCookie(ncgi, authdb, username, pw_hash, persist=None)
def getPersistCookie(hdf)
def main(argv, stdout, environ)
def generateCookie(username, pw_hash)
def _createCheckVal(username, issued_at, pw_hash, vcode)
def setPersistCookie(ncgi, persist)