Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/* ----------------------------------------------------------------------------
* INAF - National Institute for Astrophysics
* IRA - Radioastronomical Institute - Bologna
* OATS - Astronomical Observatory - Trieste
* ----------------------------------------------------------------------------
*
* Copyright (C) 2016 Istituto Nazionale di Astrofisica
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License Version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
include '../../include/init.php';
startSession();
function saveUserFromX509Data($x509Data) {
global $session;
$user = new RAP\User();
$identity = new RAP\Identity(RAP\Identity::X509);
$identity->email = $x509Data->email;
$identity->name = $x509Data->name;
$identity->surname = $x509Data->surname;
$identity->typedId = $x509Data->serialNumber;
$identity->institution = $x509Data->institution;
$user->addIdentity($identity);
RAP\UserHandler::saveUser($user);
$session->x509DataToRegister = null;
return $user;
}
if ($session->x509DataToRegister !== null && $session->x509DataToRegister->name !== null) {
$user = saveUserFromX509Data($session->x509DataToRegister);
} else {
if (isset($_SERVER['SSL_CLIENT_VERIFY']) && isset($_SERVER['SSL_CLIENT_V_REMAIN']) &&
$_SERVER['SSL_CLIENT_VERIFY'] === 'SUCCESS' && $_SERVER['SSL_CLIENT_V_REMAIN'] > 0) {
$x509Data = RAP\X509Data::parse($_SERVER);
$user = RAP\UserHandler::findUserByIdentity(RAP\Identity::X509, $x509Data->serialNumber);
if ($user === null) {
if ($x509Data->name === null) {
$session->x509DataToRegister = $x509Data;
$session->save();
header('Location: ' . $BASE_PATH . '/x509-name-surname');
die();
} else {
$user = saveUserFromX509Data($x509Data);
}
}
} else {
http_response_code(500);
die("Unable to verify client certificate");
}
}
RAP\CallbackHandler::manageLoginRedirect($user);