1<?php
2
3/*
4* @version    2010 05 22
5* @author     mxrgus.pxrt <margus@tione.eu>
6**/
7
8// include dokuwiki ness things (sets session.id also)
9if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../../');
10require_once(DOKU_INC.'inc/init.php');
11require_once(DOKU_INC.'inc/common.php');
12require_once(DOKU_INC.'inc/events.php');
13require_once(DOKU_INC.'inc/pageutils.php');
14
15// if smartcard auth was success, write SSL_CLIENT_CERT to session (it will be used from auth_smartcard later on)
16if(isset($_SERVER['SSL_CLIENT_CERT'])){
17  session_start();
18  $cert = $_SERVER['SSL_CLIENT_CERT'];
19
20  // Strip BEGIN/END CERTIFICATE
21  $pattern = '/-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----/msU';
22  if (1 === preg_match($pattern, $cert, $matches)) {
23	  $cert = $matches[1];
24  }
25
26  // Create one long string of the certificate
27  $replaceCharacters = array(" ", "\t", "\n", "\r", "\0" , "\x0B");
28  $cert = str_replace($replaceCharacters, '', $cert);
29
30  // Wrap into lines and save
31  $wrapped = wordwrap($cert, 64, "\n", true);
32  $_SESSION['SSL_CLIENT_CERT'] = "-----BEGIN CERTIFICATE-----".PHP_EOL.$wrapped.PHP_EOL."-----END CERTIFICATE-----".PHP_EOL;
33
34  session_write_close();
35}
36
37// redirect back to dokuwiki main url
38$gotowikiurl = "../../../../doku.php?u=smartcard&p=smartcard&id=" . getID();
39header("Location: $gotowikiurl");
40
41