2016-04-18 17:30:12 +02:00
|
|
|
<?php
|
|
|
|
// Marcel Kapfer (mmk2410)
|
|
|
|
// License: MIT License
|
|
|
|
// api digest auth
|
|
|
|
|
|
|
|
require 'DigestAuth.php';
|
|
|
|
|
2016-04-22 18:18:21 +02:00
|
|
|
require '../../password.php';
|
|
|
|
|
2016-04-18 17:30:12 +02:00
|
|
|
use \mmk2410\rbe\digestAuth\DigestAuth as DigestAuth;
|
|
|
|
|
|
|
|
$realm = 'Restricted area';
|
|
|
|
|
2016-04-22 18:18:21 +02:00
|
|
|
$users = array($username => $password);
|
2016-04-18 17:30:12 +02:00
|
|
|
|
|
|
|
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
|
|
|
|
header('HTTP/1.1 401 Unauthorized');
|
|
|
|
header('WWW-Authenticate: Digest realm="'.$realm.
|
|
|
|
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
|
|
|
|
|
|
|
die('Access to RCC API not granted');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// analyze the PHP_AUTH_DIGEST variable
|
|
|
|
if (!($data = DigestAuth::httpDigestParse($_SERVER['PHP_AUTH_DIGEST'])) ||
|
|
|
|
!isset($users[$data['username']])) {
|
2016-04-22 18:18:21 +02:00
|
|
|
var_dump($_SERVER["PHP_AUTH_DIGEST"]);
|
2016-04-18 17:30:12 +02:00
|
|
|
die('Wrong Credentials!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// generate the valid response
|
|
|
|
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
|
|
|
|
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
|
|
|
|
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
|
|
|
|
|
|
|
|
if ($data['response'] != $valid_response) {
|
2016-04-22 18:18:21 +02:00
|
|
|
var_dump($_SERVER["PHP_AUTH_PW"]);
|
2016-04-18 17:30:12 +02:00
|
|
|
die('Wrong Credentials!');
|
|
|
|
}
|