Skip to content

Commit 80f6d41

Browse files
committed
Update php-saml to 3.1.0. Make the code compatible
1 parent d505b7d commit 80f6d41

29 files changed

+3853
-2598
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2016 OneLogin, LLC
1+
Copyright (c) 2010-2019 OneLogin, LLC
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ This kind of WP hosting used to cache plugins and protect the wp-login.php view.
1111
You will need to contact them in order to disable the cache for this SAML plugin and also allow external HTTP POST to
1212
wp-login.php
1313

14+
### Security Improvements on 3.0.0 ###
15+
16+
Version 3.0.0 includes a security patch that will prevent DDOS by expansion of internally defined entities (XEE)
17+
That version also includes the use of php-saml 3.X so will be compatible with PHP 5.X and 7.X
18+
1419
### Security Improvements on 2.4.3 ###
1520

1621
Version 2.4.3 includes a security patch that contains extra validations that will prevent some kind of elaborated signature wrapping attacks and other security improvements. Previous versions are vulnerable so we highly recommended to upgrade to >= 2.4.3.

onelogin-saml-sso/php/_toolkit_loader.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,23 @@
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
********************************************************************************/
2929

30-
$libDir = dirname(__FILE__) . '/lib/Saml2/';
31-
$extlibDir = dirname(__FILE__) . '/extlib/';
30+
// Load xmlseclibs
31+
if (!class_exists("\RobRichards\XMLSecLibs\XMLSecurityKey")) {
32+
$xmlseclibsSrcDir = dirname(__FILE__).'/extlib/xmlseclibs/src';
3233

33-
// Load first external libs
34-
require_once($extlibDir . 'xmlseclibs/xmlseclibs.php');
34+
include_once $xmlseclibsSrcDir.'/XMLSecEnc.php';
35+
include_once $xmlseclibsSrcDir.'/XMLSecurityDSig.php';
36+
include_once $xmlseclibsSrcDir.'/XMLSecurityKey.php';
37+
include_once $xmlseclibsSrcDir.'/Utils/XPath.php';
38+
}
39+
40+
// Load php-saml
41+
$libDir = dirname(__FILE__).'/lib/Saml2/';
3542

3643
$folderInfo = scandir($libDir);
3744

3845
foreach ($folderInfo as $element) {
3946
if (is_file($libDir.$element) && (substr($element, -4) === '.php')) {
40-
require_once($libDir.$element);
47+
include_once $libDir.$element;
4148
}
4249
}

onelogin-saml-sso/php/configuration.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
exit;
66
}
77

8+
require_once "_toolkit_loader.php";
89
require_once "compatibility.php";
9-
require_once (dirname(__FILE__) . "/lib/Saml2/Constants.php");
10-
require_once (dirname(__FILE__) . "/extlib/xmlseclibs/xmlseclibs.php");
11-
1210

1311
function onelogin_saml_configuration_render() {
1412
$title = __("SSO/SAML Settings", 'onelogin-saml-sso');

onelogin-saml-sso/php/extlib/xmlseclibs/CHANGELOG.txt

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,79 @@
11
xmlseclibs.php
2-
??, ??? ????, 2.0.0
2+
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3+
15, Nov 2018, 3.0.3
4+
Bug Fixes:
5+
- Fix casing of class name. (Willem Stuursma-Ruwen)
6+
- Fix Xpath casing. (Tim van Dijen)
7+
8+
Improvements:
9+
- Make PCRE2 compliant. (Stefan Winter)
10+
- Add PHP 7.3 support. (Stefan Winter)
11+
12+
27, Sep 2018, 3.0.2
13+
Security Improvements:
14+
- OpenSSL is now a requirement rather than suggestion. (Slaven Bacelic)
15+
- Filter input to avoid XPath injection. (Jaime Pérez)
16+
17+
Bug Fixes:
18+
- Fix missing parentheses (Tim van Dijen)
19+
20+
Improvements:
21+
- Use strict comparison operator to compare digest values. (Jaime Pérez)
22+
- Remove call to file_get_contents that doesn't even work. (Jaime Pérez)
23+
- Document potentially dangerous return value behaviour. (Thijs Kinkhorst)
24+
25+
31, Aug 2017, 3.0.1
26+
Bug Fixes:
27+
- Fixed missing () in function call. (Dennis Væversted)
28+
29+
Improvements:
30+
- Add OneLogin to supported software.
31+
- Add .gitattributes to remove unneeded files. (Filippo Tessarotto)
32+
- Fix bug in example code. (Dan Church)
33+
- Travis: add PHP 7.1, move hhvm to allowed failures. (Thijs Kinkhorst)
34+
- Drop failing extract-win-cert test (Thijs Kinkhorst). (Thijs Kinkhorst)
35+
- Add comments to warn about return values of verify(). (Thijs Kinkhorst)
36+
- Fix tests to properly check return code of verify(). (Thijs Kinkhorst)
37+
- Restore support for PHP >= 5.4. (Jaime Pérez)
38+
39+
25, May 2017, 3.0.0
40+
Improvements:
41+
- Remove use of mcrypt (skymeyer)
42+
43+
08, Sep 2016, 2.0.1
44+
Bug Fixes:
45+
- Strip whitespace characters when parsing X509Certificate. fixes #84
46+
(klemen.bratec)
47+
- Certificate 'subject' values can be arrays. fixes #80 (Andreas Stangl)
48+
- HHVM signing node with ID attribute w/out namespace regenerates ID value.
49+
fixes #88 (Milos Tomic)
50+
51+
Improvements:
52+
- Fix typos and add some PHPDoc Blocks. (gfaust-qb)
53+
- Update lightSAML link. (Milos Tomic)
54+
- Update copyright dates.
55+
56+
31, Jul 2015, 2.0.0
57+
Features:
58+
- Namespace support. Classes now in the RobRichards\XMLSecLibs\ namespace.
59+
60+
Improvements:
61+
- Dropped support for PHP 5.2
62+
63+
31, Jul 2015, 1.4.1
64+
Bug Fixes:
65+
- Allow for large digest values that may have line breaks. fixes #62
66+
367
Features:
468
- Support for locating specific signature when multiple exist in
569
document. (griga3k)
670

71+
Improvements:
72+
- Add optional argument to XMLSecurityDSig to define the prefix to be used,
73+
also allowing for null to use no prefix, for the dsig namespace. fixes #13
74+
- Code cleanup
75+
- Depreciated XMLSecurityDSig::generate_GUID for XMLSecurityDSig::generateGUID
76+
777
23, Jun 2015, 1.4.0
878
Features:
979
- Support for PSR-0 standard.

onelogin-saml-sso/php/extlib/xmlseclibs/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2007-2013, Robert Richards <rrichards@cdatazone.org>.
1+
Copyright (c) 2007-2018, Robert Richards <rrichards@cdatazone.org>.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without
@@ -28,4 +28,4 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2828
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2929
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3030
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31-
POSSIBILITY OF SUCH DAMAGE.
31+
POSSIBILITY OF SUCH DAMAGE.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#xmlseclibs
2+
3+
xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.
4+
5+
The author of xmlseclibs is Rob Richards.
6+
7+
# Branches
8+
Both the master and the 2.0 branches are actively maintained.
9+
* master: Removes mcrypt usage requiring 5.4+ (5.6.24+ recommended for security reasons)
10+
* 2.0: Contains namespace support requiring 5.3+
11+
* 1.4: Contains auto-loader support while also maintaining backwards compatiblity with the older 1.3 version using the xmlseclibs.php file. Supports PHP 5.2+
12+
13+
# Requirements
14+
15+
xmlseclibs requires PHP version 5.4 or greater. **5.6.24+ recommended for security reasons**
16+
17+
18+
## How to Install
19+
20+
Install with [`composer.phar`](http://getcomposer.org).
21+
22+
```sh
23+
php composer.phar require "robrichards/xmlseclibs"
24+
```
25+
26+
27+
## Use cases
28+
29+
xmlseclibs is being used in many different software.
30+
31+
* [SimpleSAMLPHP](https://github.com/simplesamlphp/simplesamlphp)
32+
* [LightSAML](https://github.com/lightsaml/lightsaml)
33+
* [OneLogin](https://github.com/onelogin/php-saml)
34+
35+
## Basic usage
36+
37+
The example below shows basic usage of xmlseclibs, with a SHA-256 signature.
38+
39+
```php
40+
use RobRichards\XMLSecLibs\XMLSecurityDSig;
41+
use RobRichards\XMLSecLibs\XMLSecurityKey;
42+
43+
// Load the XML to be signed
44+
$doc = new DOMDocument();
45+
$doc->load('./path/to/file/tobesigned.xml');
46+
47+
// Create a new Security object
48+
$objDSig = new XMLSecurityDSig();
49+
// Use the c14n exclusive canonicalization
50+
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
51+
// Sign using SHA-256
52+
$objDSig->addReference(
53+
$doc,
54+
XMLSecurityDSig::SHA256,
55+
array('http://www.w3.org/2000/09/xmldsig#enveloped-signature')
56+
);
57+
58+
// Create a new (private) Security key
59+
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));
60+
/*
61+
If key has a passphrase, set it using
62+
$objKey->passphrase = '<passphrase>';
63+
*/
64+
// Load the private key
65+
$objKey->loadKey('./path/to/privatekey.pem', TRUE);
66+
67+
// Sign the XML file
68+
$objDSig->sign($objKey);
69+
70+
// Add the associated public key to the signature
71+
$objDSig->add509Cert(file_get_contents('./path/to/file/mycert.pem'));
72+
73+
// Append the signature to the XML
74+
$objDSig->appendSignature($doc->documentElement);
75+
// Save the signed XML
76+
$doc->save('./path/to/signed.xml');
77+
```
78+
79+
## How to Contribute
80+
81+
* [Open Issues](https://github.com/robrichards/xmlseclibs/issues)
82+
* [Open Pull Requests](https://github.com/robrichards/xmlseclibs/pulls)
83+
84+
Mailing List: https://groups.google.com/forum/#!forum/xmlseclibs
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace RobRichards\XMLSecLibs\Utils;
4+
5+
class XPath
6+
{
7+
const ALPHANUMERIC = '\w\d';
8+
const NUMERIC = '\d';
9+
const LETTERS = '\w';
10+
const EXTENDED_ALPHANUMERIC = '\w\d\s\-_:\.';
11+
12+
const SINGLE_QUOTE = '\'';
13+
const DOUBLE_QUOTE = '"';
14+
const ALL_QUOTES = '[\'"]';
15+
16+
17+
/**
18+
* Filter an attribute value for save inclusion in an XPath query.
19+
*
20+
* @param string $value The value to filter.
21+
* @param string $quotes The quotes used to delimit the value in the XPath query.
22+
*
23+
* @return string The filtered attribute value.
24+
*/
25+
public static function filterAttrValue($value, $quotes = self::ALL_QUOTES)
26+
{
27+
return preg_replace('#'.$quotes.'#', '', $value);
28+
}
29+
30+
31+
/**
32+
* Filter an attribute name for save inclusion in an XPath query.
33+
*
34+
* @param string $name The attribute name to filter.
35+
* @param mixed $allow The set of characters to allow. Can be one of the constants provided by this class, or a
36+
* custom regex excluding the '#' character (used as delimiter).
37+
*
38+
* @return string The filtered attribute name.
39+
*/
40+
public static function filterAttrName($name, $allow = self::EXTENDED_ALPHANUMERIC)
41+
{
42+
return preg_replace('#[^'.$allow.']#', '', $name);
43+
}
44+
}

0 commit comments

Comments
 (0)