ssl.py
1 |
# Copyright (C) 2006 PreludeIDS Technologies. All Rights Reserved.
|
---|---|
2 |
# Author: Francois Harvey <fharvey+prelude at securiweb dot net>
|
3 |
#
|
4 |
# This file is part of the Prewikka program.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2, or (at your option)
|
9 |
# any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful,
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
# GNU General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; see the file COPYING. If not, write to
|
18 |
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 |
|
20 |
import os |
21 |
|
22 |
from prewikka import Auth, User, Database |
23 |
|
24 |
# Use the SSL_CLIENT_S_DN_CN from a SSL x509 Certificate to map the user
|
25 |
class SSLAuth(Auth.Auth): |
26 |
def getUser(self, request): |
27 |
if not request._req.subprocess_env['HTTPS']: |
28 |
raise Auth.AuthError(message=_("SSL Authentication failed: Not in a SSL session.")) |
29 |
user = request._req.subprocess_env['SSL_CLIENT_S_DN_CN']
|
30 |
if not user: |
31 |
raise Auth.AuthError(message=_("SSL Authentication failed: no user specified (hint: look at the certificate CN).")) |
32 |
|
33 |
return User.User(self.db, user, self.db.getLanguage(user), User.ALL_PERMISSIONS, self.db.getConfiguration(user)) |
34 |
|
35 |
def load(env, config): |
36 |
return SSLAuth(env)
|
37 |
|
38 |
|