11# fabiang/sasl
22
33The PHP SASL Authentification Library.
4+ Full refactored version of the the original [ Auth_SASL2 Pear package] ( http://pear.php.net/package/Auth_SASL2/ ) .
5+
6+ Provides code to generate responses to common SASL mechanisms, including:
7+
8+ * Digest-MD5
9+ * Cram-MD5
10+ * Plain
11+ * Anonymous
12+ * Login (Pseudo mechanism)
13+ * SCRAM
414
515[ ![ PHP Version Require] ( https://poser.pugx.org/fabiang/sasl/require/php )] ( https://packagist.org/packages/fabiang/sasl )
616[ ![ Latest Stable Version] ( https://poser.pugx.org/fabiang/sasl/v/stable.svg )] ( https://packagist.org/packages/fabiang/sasl )
@@ -10,22 +20,17 @@ The PHP SASL Authentification Library.
1020[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/fabiang/sasl/badges/quality-score.png?b=develop )] ( https://scrutinizer-ci.com/g/fabiang/sasl/?branch=develop )
1121[ ![ Code Coverage] ( https://scrutinizer-ci.com/g/fabiang/sasl/badges/coverage.png?b=develop )] ( https://scrutinizer-ci.com/g/fabiang/sasl/?branch=develop )
1222
13- Provides code to generate responses to common SASL mechanisms, including:
14- * Digest-MD5
15- * Cram-MD5
16- * Plain
17- * Anonymous
18- * Login (Pseudo mechanism)
19- * SCRAM
23+ ## Security
2024
21- Full refactored version of the the original [ Auth_SASL2 Pear package] ( http://pear.php.net/package/Auth_SASL2/ ) .
25+ Please note that MD5- and SHA1-based authentication mechanism are considered insecure.
26+ Therefore you should prefer at least SCRAM-SHA-256 for ** non-secure connections (TLS)** when ever possible.
27+ For that reason Digest-MD5, Cram-MD5 and SCRAM-SHA-1 are deprecated and were removed in modern server software.
2228
2329## Installation
2430
25- The easiest way to install fabiang/sasl is by using Composer:
31+ The easiest way to install fabiang/sasl is by using [ Composer] ( https://getcomposer.org ) :
2632
2733```
28- curl -sS https://getcomposer.org/installer | php
2934composer require fabiang/sasl
3035```
3136
@@ -34,24 +39,31 @@ composer require fabiang/sasl
3439Use the factory method to create a authentication mechanism object:
3540
3641``` php
37- use Fabiang\Sasl\Sasl ;
42+ use Fabiang\SASL\SASL ;
3843
39- $factory = new Sasl;
40-
41- $mechanism = $factory->factory('SCRAM-SHA-1', array(
44+ $mechanism = SASL::SCRAM_SHA3_256->mechanism([
4245 'authcid' => 'username',
4346 'secret' => 'password',
4447 'authzid' => 'authzid', // optional. Username to proxy as
4548 'service' => 'servicename', // optional. Name of the service
4649 'hostname' => 'hostname', // optional. Hostname of the service
47- ) );
50+ ] );
4851
4952$response = $mechanism->createResponse();
5053```
5154
55+ Or create from string:
56+
57+ ``` php
58+ // throws Fabiang\SASL\Exception\UnsupportedMechanismException
59+ $mechanism = SASL::fromString('SCRAM-SHA3-256')->mechanism([
60+ // ...
61+ ]);
62+ ```
63+
5264Challenge-based authentication mechanisms implement the interface
53- ` Fabiang\Sasl \Authentication\ChallengeAuthenticationInterface ` .
54- For those mechanisms call the method again with the challenge:
65+ ` Fabiang\SASL \Authentication\ChallengeAuthenticationInterface ` .
66+ For those mechanisms call the method again with the challenge returned by the server :
5567
5668``` php
5769$response = $mechanism->createResponse($challenge);
@@ -64,7 +76,7 @@ $response = $mechanism->createResponse($challenge);
6476To verify the data returned by the server for SCRAM you can call:
6577
6678``` php
67- $mechanism->verify($data);
79+ $trusted = $ mechanism->verify($data);
6880```
6981
7082If the method returns false you should disconnect.
@@ -74,20 +86,21 @@ If the method returns false you should disconnect.
7486To enable [ downgrade protection for SCRAM] ( https://xmpp.org/extensions/xep-0474.html ) , you'll need to pass
7587the allowed authentication mechanisms and channel-binding types via options to the factory:
7688
77- ** Note** : Channel-binding is currently not supported [ due to limitations of PHP] ( https://github.com/php/php-src/issues/16766 ) .
89+ ** Note** : [ Channel-binding] ( https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism#Channel_binding )
90+ is currently not supported [ due to limitations of PHP] ( https://github.com/php/php-src/issues/16766 ) .
7891
7992``` php
80- $mechanism = $factory->factory('SCRAM-SHA-1', array(
93+ $authentication = AuthenticationMechanism::SCRAM_SHA_1->mechanism([
8194 'authcid' => 'username',
8295 'secret' => 'password',
8396 'authzid' => 'authzid', // optional. Username to proxy as
8497 'service' => 'servicename', // optional. Name of the service
8598 'hostname' => 'hostname', // optional. Hostname of the service
86- 'downgrade_protection' => array( // optional. When `null` downgrade protection string from server won't be validated
87- 'allowed_mechanisms' => array( 'SCRAM-SHA-1-PLUS', 'SCRAM-SHA-1') , // allowed mechanisms by the server
88- 'allowed_channel_bindings' => array( 'tls-unique', 'tls-exporter', 'tls-server-end-point') , // allowed channel-binding types by the server
89- ) ,
90- ) );
99+ 'downgrade_protection' => [ // optional. When `null` downgrade protection string from server won't be validated
100+ 'allowed_mechanisms' => [ 'SCRAM-SHA-1-PLUS', 'SCRAM-SHA-1'] , // allowed mechanisms by the server
101+ 'allowed_channel_bindings' => [ 'tls-unique', 'tls-exporter', 'tls-server-end-point'] , // allowed channel-binding types by the server
102+ ] ,
103+ ] );
91104```
92105
93106### Required options
@@ -96,15 +109,17 @@ List of options required by authentication mechanisms.
96109For mechanisms that are challenge-based you'll need to call ` createResponse() `
97110again and send the returned value to the server.
98111
99- | Mechanism | Authcid | Secret | Authzid | Service | Hostname | Challenge |
100- | ---------- | ------- | ------ | -------- | ------- | -------- | --------- |
101- | Anonymous | yes | no | no | no | no | no |
102- | Cram-MD5 | yes | yes | no | no | no | yes |
103- | Digest-MD5 | yes | yes | optional | yes | yes | yes |
104- | External | no | no | yes | no | no | no |
105- | Login | yes | yes | no | no | no | no |
106- | Plain | yes | yes | optional | no | no | no |
107- | SCRAM-* | yes | yes | optional | no | no | yes |
112+ | Mechanism | Authcid | Secret | Authzid | Service | Hostname | | Challenge |
113+ | ---------- | -------- | ------ | -------- | ------- | -------- | --- | --------- |
114+ | Anonymous | optional | no | no | no | no | | no |
115+ | Cram-MD5 | yes | yes | no | no | no | | yes |
116+ | Digest-MD5 | yes | yes | optional | yes | yes | | yes |
117+ | External | no | no | optional | no | no | | no |
118+ | Login | yes | yes | no | no | no | | no |
119+ | Plain | yes | yes | optional | no | no | | no |
120+ | SCRAM-* | yes | yes | optional | no | no | | yes |
121+
122+ Authcid = e.g. username, Secret = e.g. password
108123
109124## Unit tests
110125
0 commit comments