1
0
mirror of https://github.com/laurivosandi/certidude synced 2024-12-23 00:25:18 +00:00

Improve Unicode handling in bundle generation

This commit is contained in:
Lauri Võsandi 2016-09-18 14:32:14 +03:00
parent 9cf5e298e8
commit 1b04a848e3
2 changed files with 9 additions and 8 deletions

View File

@ -8,10 +8,10 @@ from certidude.auth import login_required
logger = logging.getLogger("api") logger = logging.getLogger("api")
KEYWORDS = ( KEYWORDS = (
("Android", "android"), (u"Android", u"android"),
("iPhone", "iphone"), (u"iPhone", u"iphone"),
("iPad", "ipad"), (u"iPad", u"ipad"),
("Ubuntu", "ubuntu"), (u"Ubuntu", u"ubuntu"),
) )
class BundleResource(object): class BundleResource(object):
@ -24,9 +24,10 @@ class BundleResource(object):
device_identifier = value device_identifier = value
break break
else: else:
device_identifier = "unknown-device" device_identifier = u"unknown-device"
common_name += "@" + device_identifier + "-" + \ common_name = u"%s@%s-%s" % (common_name, device_identifier, \
hashlib.sha256(req.user_agent).hexdigest()[:8] hashlib.sha256(req.user_agent).hexdigest()[:8])
logger.info(u"Signing bundle %s for %s", common_name, req.context.get("user")) logger.info(u"Signing bundle %s for %s", common_name, req.context.get("user"))
resp.set_header("Content-Type", "application/x-pkcs12") resp.set_header("Content-Type", "application/x-pkcs12")
resp.set_header("Content-Disposition", "attachment; filename=%s.p12" % common_name.encode("ascii")) resp.set_header("Content-Disposition", "attachment; filename=%s.p12" % common_name.encode("ascii"))

View File

@ -46,7 +46,7 @@ class PosixUserManager(object):
_, _, _, _, gecos, _, _ = pwd.getpwnam(username) _, _, _, _, gecos, _, _ = pwd.getpwnam(username)
gecos = gecos.decode("utf-8").split(",") gecos = gecos.decode("utf-8").split(",")
full_name = gecos[0] full_name = gecos[0]
mail = username + "@" + const.DOMAIN mail = u"%s@%s" % (username, const.DOMAIN)
if full_name and " " in full_name: if full_name and " " in full_name:
given_name, surname = full_name.split(" ", 1) given_name, surname = full_name.split(" ", 1)
return User(username, mail, given_name, surname) return User(username, mail, given_name, surname)