public function testDigestApacheEdgeCase() { list($nonce, $opaque) = $this->getServerTokens(); $username = '******'; $password = 12345; $nc = '00002'; $cnonce = uniqid(); $digestHash = md5(md5($username . ':' . self::REALM . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . 'auth:' . md5('GET' . ':' . '/')); $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'GET', 'REDIRECT_HTTP_AUTHORIZATION' => 'Digest username="******", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc=' . $nc . ',cnonce="' . $cnonce . '"')); $this->auth->setHTTPRequest($request); $this->auth->init(); $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1'); $this->assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword'); }
<?php // !!!! Make sure the Sabre directory is in the include_path !!! // example: // set_include_path('lib/' . PATH_SEPARATOR . get_include_path()); // settings date_default_timezone_set('Canada/Eastern'); // Files we need require_once 'Sabre/autoload.php'; $u = 'admin'; $p = '1234'; $auth = new Sabre_HTTP_DigestAuth(); $auth->init(); if ($auth->getUsername() != $u || !$auth->validatePassword($p)) { $auth->requireLogin(); echo "Authentication required\n"; die; }
<?php require_once '../lib/Sabre/autoload.php'; $rootdir = new Sabre_DAV_FS_Directory('../source'); $server = new Sabre_DAV_Server($rootdir); $lock_backend = new Sabre_DAV_Locks_Backend_File('../locks/'); $lock_plugin = new Sabre_DAV_Locks_Plugin($lock_backend); $server->addPlugin($lock_plugin); $browser_plugin = new Sabre_DAV_Browser_Plugin(); $server->addPlugin($browser_plugin); $user = '******'; $pass = '******'; $auth = new Sabre_HTTP_DigestAuth(); $auth->init(); if ($auth->getUsername() == $user && $auth->validatePassword($pass)) { $server->exec(); } else { $auth->requireLogin(); echo "Authentication required!\n"; die; }