aboutsummaryrefslogtreecommitdiff
path: root/actions/suck.php
blob: fd801e2de71cce85901934b6ebd7ddcb915d4103 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

//require_once("config.php");
global $CONFIG;
require_once($CONFIG->pluginspath."foafssl/lib/Authentication.php");

$config = array('db_name'=>'arc','db_user'=>'arc','db_pwd'=>'chjdladhsjk34!arcarc','store_name'=>'arc_tests');
if ($_SERVER['SSL_CLIENT_CERT']) {
	error_log("going to add");
	$cert = $_SERVER['SSL_CLIENT_CERT'];
	$res = openssl_x509_read($cert);
	$cert_data = openssl_x509_parse($cert);
	$uid = $cert_data["subject"]["UID"];
	$altName = $cert_data["extensions"]["subjectAltName"];
        $pubKey  = openssl_pkey_get_public($res);
        $keyData = openssl_pkey_get_details($pubKey);

        //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]);
 	  set_input("name",$cert_data["subject"]["CN"]);
	    set_input("webid",$altName);
	    set_input("modulus",$modulus);
	    set_input("exponent",$exponent);
	    include($CONFIG->pluginspath."foafssl/actions/add.php");
}


/*
$auth = new Authentication_FoafSSLARC($config);
//$auth = new Authentication_AgentARC($config, $webId);
//var_dump($auth);
//if ($auth->agentId !== $auth->agentURI) {
if ($auth->isAuthenticated()) {
    //print "Hello : $auth->webid<br/>";
    $base_url = $CONFIG->wwwroot."pg/profile/";
    if (strpos($auth->webid, $base_url) == 0) {
	$root_len = strlen($base_url);
    	$username = substr($auth->webid, $root_len, strlen($auth->webid)-$root_len-strlen("?view=foaf"));
	$user = get_user_by_username($username);
	login($user, true);
	system_message(elgg_echo("you logged in successfully with your certificate!"));
	forward();
	
	}
}
else {
    print "Sorry you are not logged in<br/>";
	print $auth->authnDiagnostic;
}
*/
//$auth->logout();

?>