Parsing of email address from Debian client cert CN fixed

This commit is contained in:
Christoph Haas 2018-08-10 12:42:08 +02:00
parent 3bc317b572
commit bf96a72158

View file

@ -25,8 +25,14 @@ class ApplicationController < ActionController::Base
# Only run if the user is not yet logged in
if not user_signed_in?
if debian_sso_dn = request.env['HTTP_X_DEBIAN_SSO_DN']
debian_sso_dn =~ /^CN=(.+),/
debian_email = $1
# Turn
# "/O=Debian SSO client certificate/CN=haas@debian.org"
# into
# haas@debian.org
debian_email = debian_sso_dn.split('/').grep(/^CN/).first.split('=').last
raise "No valid certificate CN found" unless debian_email.include? '@'
@user = User.where(provider: 'debian-sso', email: debian_email).first_or_create do |user|
user.provider = 'debian-sso'