aboutsummaryrefslogtreecommitdiff
path: root/mod/foafssl/actions/add.php
blob: 494229aad776daef4ca15e542cbf49ef4f0b725a (plain)
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
<?php
global $CONFIG;
$user = get_loggedin_user();
$name = get_input('name');
$webid = get_input('webid');
$modulus = get_input('modulus');
$exponent = get_input('exponent');

error_log($name);
error_log($webid);
error_log($modulus);
error_log($exponent);

if (isset($_FILES['cert_file'])) {
	$cert = get_uploaded_file('cert_file');
        $res = openssl_x509_read($cert);
	$cert_data = openssl_x509_parse($cert);
	$pubKey  = openssl_pkey_get_public($res);
        $keyData = openssl_pkey_get_details($pubKey);
        $webid = $cert_data["extensions"]["subjectAltName"];

        //Remove certificate armour
        $unpacked_n = unpack("H*",$keyData['rsa']['n']);
        $modulus = strtoupper($unpacked_n[1]);

        $unpacked_e = unpack("H*",$keyData['rsa']['e']);
        $exponent = hexdec($unpacked_e[1]);
	$name = $cert_data["subject"]["CN"];
	error_log("load file");
	error_log("webid:".$webid);
	error_log("exponent".$exponent);
	error_log("mod".$modulus);
}

if ($modulus && $exponent && $user && $webid) {
	$key = elgg_foafssl_createkey($modulus, $exponent, $user, $webid, $name);
	system_message(elgg_echo("foafssl:addkey"));
}
else {
	register_error(elgg_echo("foafssl:cantadd"));
}
forward($CONFIG->wwwroot."pg/foafssl/manage");
?>