Ejemplo n.º 1
0
<?php

require_once "../tractis_identity.php";
echo "<h1>Welcome to the test php site </h1>";
// Calculate your url (for the notification callback)
$notification_callback = !empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$notification_callback_method = "GET";
// Get an api_key: http://www.tractis.com/identity
// tractis_identity contructor class (api_key, notification_callback, public_verification (true/false), image_button_url, $notification_callback_method (GET/POST))
$tractis_identity = new tractis_identity("Your API KEY HERE", $notification_callback, "false", "/your/url/to/images/trac_but_bg_lrg_b_en.png", $notification_callback_method);
echo $tractis_identity->show_form();
echo "<h2>Button Information</h2>";
echo "Notification callback is {$notification_callback} and will be sent with the {$notification_callback_method} HTTP method.<br/><br/>";
echo "<h2>Status Information</h2>";
// Check if a callback from Tractis if performed and the Authentication Response
if ($user = $tractis_identity->check_auth()) {
    // Own code to integrate in the auth mechanism or sessions, ...
    echo "The Tractis Auth has been performed, the data received needs to be integrated on your site. <br/><br/>";
    echo "Now you have in the \$user array the follow information:<br/><br/>";
    print_r($user);
} else {
    echo "Not Tractis Auth, please click on the button and follow the intructions";
}
Ejemplo n.º 2
0
include_once "database.php";
if (!$_SERVER['HTTPS']) {
    redirect(SSL_URL . 'loginDNIe.php');
}
// Fuerza el uso de una conexion segura entre navegador y servidor. (https SSL)
// Comprueba si el usuario está autentificado o no.
$dnie_autentificado = false;
$result = mysql_query("SELECT u_id FROM users WHERE u_id = '" . $pol['user_ID'] . "' AND dnie = 'true'", $link);
while ($r = mysql_fetch_array($result)) {
    $dnie_autentificado = true;
}
if (isset($pol['user_ID']) and $dnie_autentificado == false) {
    // Es un usuario y no está autentificado con DNIe
    // Plugin de Tractis para PHP. Software Libre. Fuente: https://github.com/tractis/tractis_identity_verifications_for_php
    require 'tractis_identity/tractis_identity.php';
    $tractis_identity = new tractis_identity(CLAVE_API_TRACTIS, SSL_URL . 'dnie.php', 'false', IMG . 'lib/tractis_identity/images/trac_but_bg_lrg_b_es.png', 'POST');
    // Trata la redireccion desde Tractis tras una autentificacion correcta.
    if ($data = $tractis_identity->check_auth()) {
        /* LA SIGUIENTE LINEA ES EL QUID DE LA CUESTION
        Consiste en una miniaturización irreversible de la información extraida del DNIe (proveeida por la pasarela de Tractis), junto con otra información estatica para evitar ataques por diccionario y hacer inéditos los hash. Se hace mediante el algoritmo de hash "sha256".
        Por ejemplo, este código: 
        	hash('sha256', '.VirtualPol.clave_del_sistema.72135000A.JAVIER RUBALCABA RAJOY.')
        Se convierte en:
        	da39a3ee5e6b4b0d3255bfef95606b4b0d3255bfef95601890afdd80709
        Este resultado final no supone ninguna información en claro.
        */
        $dnie_check = hash('sha256', '.VirtualPol.' . CLAVE_DNIE . '.' . strtoupper($data['tractis:attribute:dni']) . '.' . str_replace('+', ' ', strtoupper($data['tractis:attribute:name'])) . '.');
        // Generacion del hash anteriormente explicado.
        // Elimina todos los datos obtenidos del DNIe y desaparecen definitivamente a partir de aquí.
        unset($data);
        // Busca checks coincidentes (para garantizar que cada DNIe se inscribe una vez).