Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 880a392

Browse filesBrowse files
ogizanagifabpot
authored andcommitted
[Security] Fix deprecated usage of DigestAuthenticationEntryPoint::getKey() in DigestAuthenticationListener
1 parent 1f70837 commit 880a392
Copy full SHA for 880a392

File tree

2 files changed

+80
-1
lines changed
Filter options

2 files changed

+80
-1
lines changed

‎src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function handle(GetResponseEvent $event)
7878
}
7979

8080
try {
81-
$digestAuth->validateAndDecode($this->authenticationEntryPoint->getKey(), $this->authenticationEntryPoint->getRealmName());
81+
$digestAuth->validateAndDecode($this->authenticationEntryPoint->getSecret(), $this->authenticationEntryPoint->getRealmName());
8282
} catch (BadCredentialsException $e) {
8383
$this->fail($event, $request, $e);
8484

+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Http\Tests\Firewall;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
7+
use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint;
8+
use Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener;
9+
10+
class DigestAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testHandleWithValidDigest()
13+
{
14+
$time = microtime(true) + 1000;
15+
$secret = 'ThisIsASecret';
16+
$nonce = base64_encode($time.':'.md5($time.':'.$secret));
17+
$username = 'user';
18+
$password = 'password';
19+
$realm = 'Welcome, robot!';
20+
$cnonce = 'MDIwODkz';
21+
$nc = '00000001';
22+
$qop = 'auth';
23+
$uri = '/path/info?p1=5&p2=5';
24+
25+
$serverDigest = $this->calculateServerDigest($username, $realm, $password, $nc, $nonce, $cnonce, $qop, 'GET', $uri);
26+
27+
$digestData =
28+
'username="'.$username.'", realm="'.$realm.'", nonce="'.$nonce.'", '.
29+
'uri="'.$uri.'", cnonce="'.$cnonce.'", nc='.$nc.', qop="'.$qop.'", '.
30+
'response="'.$serverDigest.'"'
31+
;
32+
33+
$request = new Request(array(), array(), array(), array(), array(), array('PHP_AUTH_DIGEST' => $digestData));
34+
35+
$entryPoint = new DigestAuthenticationEntryPoint($realm, $secret);
36+
37+
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
38+
$user->method('getPassword')->willReturn($password);
39+
40+
$providerKey = 'TheProviderKey';
41+
42+
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
43+
$tokenStorage
44+
->expects($this->once())
45+
->method('getToken')
46+
->will($this->returnValue(null))
47+
;
48+
$tokenStorage
49+
->expects($this->once())
50+
->method('setToken')
51+
->with($this->equalTo(new UsernamePasswordToken($user, $password, $providerKey)))
52+
;
53+
54+
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
55+
$userProvider->method('loadUserByUsername')->willReturn($user);
56+
57+
$listener = new DigestAuthenticationListener($tokenStorage, $userProvider, $providerKey, $entryPoint);
58+
59+
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
60+
$event
61+
->expects($this->any())
62+
->method('getRequest')
63+
->will($this->returnValue($request))
64+
;
65+
66+
$listener->handle($event);
67+
}
68+
69+
private function calculateServerDigest($username, $realm, $password, $nc, $nonce, $cnonce, $qop, $method, $uri)
70+
{
71+
$response = md5(
72+
md5($username.':'.$realm.':'.$password).':'.$nonce.':'.$nc.':'.$cnonce.':'.$qop.':'.md5($method.':'.$uri)
73+
);
74+
75+
return sprintf('username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc=%s, qop="%s", response="%s"',
76+
$username, $realm, $nonce, $uri, $cnonce, $nc, $qop, $response
77+
);
78+
}
79+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.