Skip to content

Commit 659f876

Browse files
authored
Allow to specify hashing algorithm for WSSE
1 parent c6f875f commit 659f876

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717
the respective classes are available via autoloading, but continue to return objects from `Zend\Diactoros\`
1818
namespace otherwise.
1919

20+
## [1.11.0] - unreleased
21+
22+
- Allow to specify the hashing algorithm for WSSE authentication.
23+
2024
## [1.10.0] - 2020-11-11
2125

2226
- Added support for PHP 8.0.

src/Authentication/Wsse.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Message\Authentication;
44

55
use Http\Message\Authentication;
6+
use InvalidArgumentException;
67
use Psr\Http\Message\RequestInterface;
78

89
/**
@@ -22,25 +23,34 @@ final class Wsse implements Authentication
2223
*/
2324
private $password;
2425

26+
/**
27+
* @var string
28+
*/
29+
private $hashAlgorithm;
30+
2531
/**
2632
* @param string $username
2733
* @param string $password
34+
* @param string $hashAlgorithm To use a better hashing algorithm than the weak sha1, pass the algorithm to use, e.g. "sha512"
2835
*/
29-
public function __construct($username, $password)
36+
public function __construct($username, $password, $hashAlgorithm = 'sha1')
3037
{
3138
$this->username = $username;
3239
$this->password = $password;
40+
if (false === in_array($hashAlgorithm, hash_algos())) {
41+
throw new InvalidArgumentException(sprintf('Unaccepted hashing algorithm: %s', $hashAlgorithm));
42+
}
43+
$this->hashAlgorithm = $hashAlgorithm;
3344
}
3445

3546
/**
3647
* {@inheritdoc}
3748
*/
3849
public function authenticate(RequestInterface $request)
3950
{
40-
// TODO: generate better nonce?
4151
$nonce = substr(md5(uniqid(uniqid().'_', true)), 0, 16);
4252
$created = date('c');
43-
$digest = base64_encode(sha1(base64_decode($nonce).$created.$this->password, true));
53+
$digest = base64_encode(hash($this->hashAlgorithm, base64_decode($nonce).$created.$this->password, true));
4454

4555
$wsse = sprintf(
4656
'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',

src/CookieJar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class CookieJar implements \Countable, \IteratorAggregate
1111
{
1212
/**
13-
* @var \SplObjectStorage
13+
* @var \SplObjectStorage<object, mixed>
1414
*/
1515
private $cookies;
1616

src/Encoding/FilteredStream.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*/
1414
abstract class FilteredStream implements StreamInterface
1515
{
16-
const BUFFER_SIZE = 8192;
17-
1816
use StreamDecorator {
1917
rewind as private doRewind;
2018
seek as private doSeek;
2119
}
20+
const BUFFER_SIZE = 8192;
2221

2322
/**
2423
* @var callable

0 commit comments

Comments
 (0)