Skip to content

Commit c0b29ab

Browse files
committed
Clean code. Make compatible with php7.2 . Fix tests. Update travis to test php 7.2. Update dependencies in composer
1 parent 19aefe2 commit c0b29ab

32 files changed

Lines changed: 1751 additions & 1567 deletions

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
language: php
22

33
php:
4+
- 5.4
45
- 5.6
56
- 7.0
67
- 7.1
8+
- 7.2
79

810
env:
911
- TRAVIS=true
@@ -21,7 +23,6 @@ before_script:
2123
script:
2224
- vendor/bin/phpunit --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml
2325
- php vendor/bin/phpcpd --exclude tests --exclude vendor .
24-
- php vendor/bin/phploc . --exclude vendor
2526
- php vendor/bin/phploc lib/.
2627
- mkdir -p tests/build/dependences
2728
- php vendor/bin/pdepend --summary-xml=tests/build/logs/dependence-summary.xml --jdepend-chart=tests/build/dependences/jdepend.svg --overview-pyramid=tests/build/dependences/pyramid.svg lib/.

README.md

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ and supported by OneLogin Inc.
1010
Warning
1111
-------
1212

13-
Update php-saml to 2.10.4, this version includes a security patch related to
14-
[signature validations on LogoutRequests/LogoutResponses](https://github.com/onelogin/php-saml/commit/949359f5cad5e1d085c4e5447d9aa8f49a6e82a1)
15-
16-
Update php-saml to 2.10.0, this version includes a security patch that contains extra validations that will prevent signature wrapping attacks. [CVE-2016-1000253](https://github.com/distributedweaknessfiling/DWF-Database-Artifacts/blob/ab8ae6e845eb506fbeb10a7e4ccb379f0b4222ca/DWF/2016/1000253/CVE-2016-1000253.json)
17-
18-
php-saml < v2.10.0 is vulnerable and allows signature wrapping!
19-
13+
This version is compatible with PHP 7.X and does not include xmlseclibs (you will need to install it via composer, dependency described in composer.json)
2014

2115
Security Guidelines
2216
-------------------
@@ -81,23 +75,20 @@ Installation
8175

8276
### Dependencies ###
8377

84-
* `php >= 5.3.3` and some core extensions like `php-xml`, `php-date`, `php-zlib`.
78+
* `php >= 5.4` and some core extensions like `php-xml`, `php-date`, `php-zlib`.
8579
* `openssl`. Install the openssl library. It handles x509 certificates.
86-
* `mcrypt`. Install that library and its php driver if you gonna handle
87-
encrypted data (`nameID`, `assertions`).
8880
* `gettext`. Install that library and its php driver. It handles translations.
8981
* `curl`. Install that library and its php driver if you plan to use the IdP Metadata parser.
9082

91-
Since [PHP 5.3 is officially unsupported](http://php.net/eol.php) we recommend you to use a newer PHP version.
92-
9383
### Code ###
9484

9585
#### Option 1. Download from github ####
9686

9787
The toolkit is hosted on github. You can download it from:
9888

99-
* Lastest release: https://github.com/onelogin/php-saml/releases/latest
100-
* Master repo: https://github.com/onelogin/php-saml/tree/master
89+
* https://github.com/onelogin/php-saml/releases
90+
91+
Search for 3.X.X releases
10192

10293
Copy the core of the library inside the php application. (each application has its
10394
structure so take your time to locate the PHP SAML toolkit in the best place).
@@ -112,6 +103,8 @@ In order to import the saml toolkit to your current php project, execute
112103
composer require onelogin/php-saml
113104
```
114105

106+
Remember to select the 3.X.X branch
107+
115108
After installation has completed you will find at the `vendor/` folder a new folder named `onelogin` and inside the `php-saml`. Make sure you are including the autoloader provided by composer. It can be found at `vendor/autoload.php`.
116109

117110
**Important** In this option, the x509 certs must be stored at `vendor/onelogin/php-saml/certs`
@@ -122,7 +115,7 @@ Your settings are at risk of being deleted when updating packages using `compose
122115
Compatibility
123116
-------------
124117

125-
This 3.X version only supports PHP 7.X..
118+
This 3.X.X supports PHP 7.X. but can be used with PHP >=5.4 as well (5.6.24+ recommended for security reasons).
126119

127120
Namespaces
128121
----------
@@ -147,7 +140,7 @@ Getting started
147140
### Knowing the toolkit ###
148141

149142
The new OneLogin SAML Toolkit contains different folders (`certs`, `endpoints`,
150-
`extlib`, `lib`, `demo`, etc.) and some files.
143+
`lib`, `demo`, etc.) and some files.
151144

152145
Let's start describing the folders:
153146

@@ -172,20 +165,10 @@ cert: `metadata.crt` and `metadata.key`.
172165
Use `sp_new.crt` if you are in a key rollover process and you want to
173166
publish that x509certificate on Service Provider metadata.
174167

175-
#### `extlib/` ####
176-
177-
This folder contains the 3rd party libraries that the toolkit uses. At the
178-
moment only uses the `xmlseclibs` (autor Robert Richards, BSD Licensed) which
179-
handle the sign and the encryption of xml elements.
180-
181-
182168
#### `lib/` ####
183169

184170
This folder contains the heart of the toolkit, the libraries:
185171

186-
* `Saml` folder contains a modified version of the toolkit v.1 and allows the
187-
old code to keep working. (This library is provided to maintain
188-
backward compatibility).
189172
* `Saml2` folder contains the new version of the classes and methods that
190173
are described in a later section.
191174

@@ -224,8 +207,6 @@ and support multiple languages.
224207
advanced_settings.php file which contains extra configuration info related to
225208
the security, the contact person, and the organization associated to the SP.
226209
* `_toolkit_loader.php` - This file load the toolkit libraries (The SAML2 lib).
227-
* `compatibility` - Import that file to make compatible your old code with the
228-
new toolkit (loads the SAML library).
229210

230211

231212
#### Miscellaneous ####
@@ -563,9 +544,13 @@ $auth = new OneLogin_Saml2_Auth($settingsInfo);
563544

564545
#### How load the library ####
565546

566-
In order to use the toolkit library you need to import the `_toolkit_loader.php`
567-
file located on the base folder of the toolkit. You can load this file in this
568-
way:
547+
548+
In order to use the toolkit library, if your project support composer you only
549+
need to install it with composer (See the installation section) and you are done.
550+
551+
552+
If your project doesn't use composer you need to import the `_toolkit_loader.php`
553+
file located on the base folder of the toolkit. You can load this file in this way:
569554

570555
```php
571556
<?php
@@ -577,17 +562,9 @@ require_once(TOOLKIT_PATH . '_toolkit_loader.php');
577562
After that line we will be able to use the classes (and their methods) of the
578563
toolkit (because the external and the Saml2 libraries files are loaded).
579564

580-
If you wrote the code of your SAML app for the version 1 of the PHP-SAML toolkit
581-
you will need to load the `compatibility.php`, file which loads the SAML library files,
582-
in addition to the the `_toolkit_loader.php`.
583-
584-
That SAML library uses the new classes and methods of the latest version of the
585-
toolkits but maintain the old classes, methods, and workflow of the old process
586-
to accomplish the same things.
587-
588-
We strongly recommend migrating your old code and use the new API of the
589-
new toolkit due there are a lot of new features that you can't handle with the
590-
old code.
565+
That toolkit depends on [xmlseclibs](https://github.com/robrichards/xmlseclibs) 3.X.X branch,
566+
you will need to get its code and place on your project and reuse the _toolkit_loader.php
567+
file to include xmlseclibs as well.
591568

592569

593570
#### Initiate SSO ####

_toolkit_loader.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
// (can conflicts other autoloaders)
55
// http://php.net/manual/en/language.oop5.autoload.php
66

7-
$libDir = dirname(__FILE__) . '/lib/Saml2/';
8-
9-
// Load composer
7+
// Load composer vendor folder if any
108
if (file_exists('vendor/autoload.php')) {
119
require 'vendor/autoload.php';
1210
}
1311

12+
/*
13+
// Load xmlseclibs
14+
15+
$xmlseclibsSrcDir = '';
16+
17+
include_once $xmlseclibsSrcDir.'/XMLSecEnc.php';
18+
include_once $xmlseclibsSrcDir.'/XMLSecurityDSig.php';
19+
include_once $xmlseclibsSrcDir.'/XMLSecurityKey.php';
20+
*/
21+
22+
23+
// Load php-saml
24+
$libDir = dirname(__FILE__) . '/lib/Saml2/';
25+
1426
$folderInfo = scandir($libDir);
1527

1628
foreach ($folderInfo as $element) {

composer.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616
"source": "https://github.com/onelogin/php-saml/"
1717
},
1818
"require": {
19-
"php": ">= 5.4",
20-
"robrichards/xmlseclibs": "^3.0.0",
21-
"ext-openssl": "*",
22-
"ext-dom": "*"
19+
"php": ">=5.4",
20+
"robrichards/xmlseclibs": ">=3.0"
2321
},
2422
"require-dev": {
25-
"phpunit/phpunit": "^5.7",
26-
"satooshi/php-coveralls": "1.0.1",
23+
"phpunit/phpunit": ">=4.8",
24+
"satooshi/php-coveralls": ">=1.0.2",
2725
"sebastian/phpcpd": "*",
2826
"phploc/phploc": "*",
29-
"pdepend/pdepend" : "1.1.0",
30-
"squizlabs/php_codesniffer": "2.*"
27+
"pdepend/pdepend" : ">=2.5.0"
3128
},
3229
"suggest": {
33-
"lib-openssl": "Install openssl lib in order to handle with x509 certs (require to support sign and encryption)",
30+
"ext-openssl": "Install openssl lib in order to handle with x509 certs (require to support sign and encryption)",
31+
"ext-curl": "Install curl lib to be able to use the IdPMetadataParser for parsing remote XMLs",
3432
"ext-gettext": "Install gettext and php5-gettext libs to handle translations"
3533
}
3634
}

lib/Saml2/Auth.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
<?php
2+
/**
3+
* This file is part of php-saml.
4+
*
5+
* (c) OneLogin Inc
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @package OneLogin
11+
* @author OneLogin Inc <saml-info@onelogin.com>
12+
* @license MIT https://github.com/onelogin/php-saml/blob/master/LICENSE
13+
* @link https://github.com/onelogin/php-saml
14+
*/
215

316
use RobRichards\XMLSecLibs\XMLSecurityKey;
417

518
/**
619
* Main class of OneLogin's PHP Toolkit
7-
*
820
*/
921
class OneLogin_Saml2_Auth
1022
{
@@ -201,11 +213,11 @@ public function processResponse($requestId = null)
201213
/**
202214
* Process the SAML Logout Response / Logout Request sent by the IdP.
203215
*
204-
* @param bool $keepLocalSession When false will destroy the local session, otherwise will keep it
205-
* @param string|null $requestId The ID of the LogoutRequest sent by this SP to the IdP
206-
* @param bool $retrieveParametersFromServer
207-
* @param callable $cbDeleteSession
208-
* @param bool $stay True if we want to stay (returns the url string) False to redirect
216+
* @param bool $keepLocalSession When false will destroy the local session, otherwise will keep it
217+
* @param string|null $requestId The ID of the LogoutRequest sent by this SP to the IdP
218+
* @param bool $retrieveParametersFromServer True if we want to use parameters from $_SERVER to validate the signature
219+
* @param callable $cbDeleteSession Method name to be executed to delete session
220+
* @param bool $stay True if we want to stay (returns the url string) False to redirect
209221
*
210222
* @return string|void
211223
*
@@ -438,12 +450,12 @@ public function login($returnTo = null, $parameters = array(), $forceAuthn = fal
438450
/**
439451
* Initiates the SLO process.
440452
*
441-
* @param string|null $returnTo The target URL the user should be returned to after logout.
442-
* @param array $parameters Extra parameters to be added to the GET
443-
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
444-
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
445-
* @param bool $stay True if we want to stay (returns the url string) False to redirect
446-
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
453+
* @param string|null $returnTo The target URL the user should be returned to after logout.
454+
* @param array $parameters Extra parameters to be added to the GET
455+
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
456+
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
457+
* @param bool $stay True if we want to stay (returns the url string) False to redirect
458+
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
447459
*
448460
* @return If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
449461
*
@@ -531,8 +543,8 @@ public function getLastRequestID()
531543
/**
532544
* Generates the Signature for a SAML Request
533545
*
534-
* @param string $samlRequest The SAML Request
535-
* @param string $relayState The RelayState
546+
* @param string $samlRequest The SAML Request
547+
* @param string $relayState The RelayState
536548
* @param string $signAlgorithm Signature algorithm method
537549
*
538550
* @return string A base64 encoded signature
@@ -550,8 +562,6 @@ public function buildRequestSignature($samlRequest, $relayState, $signAlgorithm
550562
);
551563
}
552564

553-
$key = $this->_settings->getSPkey();
554-
555565
$objKey = new XMLSecurityKey($signAlgorithm, array('type' => 'private'));
556566
$objKey->loadKey($key, false);
557567

lib/Saml2/AuthnRequest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
11
<?php
2+
/**
3+
* This file is part of php-saml.
4+
*
5+
* (c) OneLogin Inc
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @package OneLogin
11+
* @author OneLogin Inc <saml-info@onelogin.com>
12+
* @license MIT https://github.com/onelogin/php-saml/blob/master/LICENSE
13+
* @link https://github.com/onelogin/php-saml
14+
*/
215

316
/**
417
* SAML 2 Authentication Request
5-
*
618
*/
719
class OneLogin_Saml2_AuthnRequest
820
{
921

1022
/**
1123
* Object that represents the setting info
24+
*
1225
* @var OneLogin_Saml2_Settings
1326
*/
1427
protected $_settings;
1528

1629
/**
1730
* SAML AuthNRequest string
31+
*
1832
* @var string
1933
*/
2034
private $_authnRequest;
2135

2236
/**
2337
* SAML AuthNRequest ID.
38+
*
2439
* @var string
2540
*/
2641
private $_id;
2742

2843
/**
2944
* Constructs the AuthnRequest object.
3045
*
31-
* @param OneLogin_Saml2_Settings $settings Settings
32-
* @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
33-
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
34-
* @param bool $setNameIdPolicy When true the AuthNReuqest will set a nameIdPolicy
46+
* @param OneLogin_Saml2_Settings $settings Settings
47+
* @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
48+
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
49+
* @param bool $setNameIdPolicy When true the AuthNReuqest will set a nameIdPolicy
3550
*/
3651
public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = false, $isPassive = false, $setNameIdPolicy = true)
3752
{
@@ -93,7 +108,6 @@ public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = fal
93108

94109
$requestedAuthnStr = '';
95110
if (isset($security['requestedAuthnContext']) && $security['requestedAuthnContext'] !== false) {
96-
97111
$authnComparison = 'exact';
98112
if (isset($security['requestedAuthnContextComparison'])) {
99113
$authnComparison = $security['requestedAuthnContextComparison'];

lib/Saml2/Constants.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
2-
2+
/**
3+
* This file is part of php-saml.
4+
*
5+
* (c) OneLogin Inc
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @package OneLogin
11+
* @author OneLogin Inc <saml-info@onelogin.com>
12+
* @license MIT https://github.com/onelogin/php-saml/blob/master/LICENSE
13+
* @link https://github.com/onelogin/php-saml
14+
*/
15+
316
/**
417
* Constants of OneLogin PHP Toolkit
518
*

0 commit comments

Comments
 (0)