Skip to content

Commit 9b3ae07

Browse files
committed
Update xmlseclibs to 3.1.1 Update php-saml to 3.6.1
1 parent e82afe3 commit 9b3ae07

10 files changed

Lines changed: 150 additions & 30 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
xmlseclibs.php
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3+
05, Sep 2020, 3.1.1
4+
Features:
5+
- Support OAEP (iggyvolz)
6+
7+
Bug Fixes:
8+
- Fix AES128 (iggyvolz)
9+
10+
Improvements:
11+
- Fix tests for older PHP
12+
13+
22, Apr 2020, 3.1.0
14+
Features:
15+
- Support AES-GCM. Requires PHP 7.1. (François Kooman)
16+
17+
Improvements:
18+
- Fix Travis tests for older PHP versions.
19+
- Use DOMElement interface to fix some IDEs reporting documentation errors
20+
21+
Bug Fixes:
22+
- FIX missing InclusiveNamespaces PrefixList from Java + Apache WSS4J. (njake)
23+
324
06, Nov 2019, 3.0.4
425
Security Improvements:
526
- Insure only a single SignedInfo element exists within a signature during

onelogin-saml-sso/php/extlib/xmlseclibs/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ xmlseclibs is a library written in PHP for working with XML Encryption and Signa
55
The author of xmlseclibs is Rob Richards.
66

77
# 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)
8+
Master is currently the only actively maintained branch.
9+
* master/3.1: Added AES-GCM support requiring 7.1+
10+
* 3.0: Removes mcrypt usage requiring 5.4+ (5.6.24+ recommended for security reasons)
1011
* 2.0: Contains namespace support requiring 5.3+
1112
* 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+
1213

onelogin-saml-sso/php/extlib/xmlseclibs/src/XMLSecEnc.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace RobRichards\XMLSecLibs;
33

44
use DOMDocument;
5+
use DOMElement;
56
use DOMNode;
67
use DOMXPath;
78
use Exception;
@@ -10,7 +11,7 @@
1011
/**
1112
* xmlseclibs.php
1213
*
13-
* Copyright (c) 2007-2019, Robert Richards <rrichards@cdatazone.org>.
14+
* Copyright (c) 2007-2020, Robert Richards <rrichards@cdatazone.org>.
1415
* All rights reserved.
1516
*
1617
* Redistribution and use in source and binary forms, with or without
@@ -43,7 +44,7 @@
4344
* POSSIBILITY OF SUCH DAMAGE.
4445
*
4546
* @author Robert Richards <rrichards@cdatazone.org>
46-
* @copyright 2007-2019 Robert Richards <rrichards@cdatazone.org>
47+
* @copyright 2007-2020 Robert Richards <rrichards@cdatazone.org>
4748
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
4849
*/
4950

onelogin-saml-sso/php/extlib/xmlseclibs/src/XMLSecurityDSig.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* xmlseclibs.php
1313
*
14-
* Copyright (c) 2007-2019, Robert Richards <rrichards@cdatazone.org>.
14+
* Copyright (c) 2007-2020, Robert Richards <rrichards@cdatazone.org>.
1515
* All rights reserved.
1616
*
1717
* Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,7 @@
4444
* POSSIBILITY OF SUCH DAMAGE.
4545
*
4646
* @author Robert Richards <rrichards@cdatazone.org>
47-
* @copyright 2007-2019 Robert Richards <rrichards@cdatazone.org>
47+
* @copyright 2007-2020 Robert Richards <rrichards@cdatazone.org>
4848
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
4949
*/
5050

@@ -314,10 +314,22 @@ public function canonicalizeSignedInfo()
314314
if ($signInfoNode = $nodeset->item(0)) {
315315
$query = "./secdsig:CanonicalizationMethod";
316316
$nodeset = $xpath->query($query, $signInfoNode);
317+
$prefixList = null;
317318
if ($canonNode = $nodeset->item(0)) {
318319
$canonicalmethod = $canonNode->getAttribute('Algorithm');
320+
foreach ($canonNode->childNodes as $node)
321+
{
322+
if ($node->localName == 'InclusiveNamespaces') {
323+
if ($pfx = $node->getAttribute('PrefixList')) {
324+
$arpfx = array_filter(explode(' ', $pfx));
325+
if (count($arpfx) > 0) {
326+
$prefixList = array_merge($prefixList ? $prefixList : array(), $arpfx);
327+
}
328+
}
329+
}
330+
}
319331
}
320-
$this->signedInfo = $this->canonicalizeData($signInfoNode, $canonicalmethod);
332+
$this->signedInfo = $this->canonicalizeData($signInfoNode, $canonicalmethod, null, $prefixList);
321333
return $this->signedInfo;
322334
}
323335
}

onelogin-saml-sso/php/extlib/xmlseclibs/src/XMLSecurityKey.php

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* xmlseclibs.php
99
*
10-
* Copyright (c) 2007-2019, Robert Richards <rrichards@cdatazone.org>.
10+
* Copyright (c) 2007-2020, Robert Richards <rrichards@cdatazone.org>.
1111
* All rights reserved.
1212
*
1313
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@
4040
* POSSIBILITY OF SUCH DAMAGE.
4141
*
4242
* @author Robert Richards <rrichards@cdatazone.org>
43-
* @copyright 2007-2019 Robert Richards <rrichards@cdatazone.org>
43+
* @copyright 2007-2020 Robert Richards <rrichards@cdatazone.org>
4444
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
4545
*/
4646

@@ -50,14 +50,19 @@ class XMLSecurityKey
5050
const AES128_CBC = 'http://www.w3.org/2001/04/xmlenc#aes128-cbc';
5151
const AES192_CBC = 'http://www.w3.org/2001/04/xmlenc#aes192-cbc';
5252
const AES256_CBC = 'http://www.w3.org/2001/04/xmlenc#aes256-cbc';
53+
const AES128_GCM = 'http://www.w3.org/2009/xmlenc11#aes128-gcm';
54+
const AES192_GCM = 'http://www.w3.org/2009/xmlenc11#aes192-gcm';
55+
const AES256_GCM = 'http://www.w3.org/2009/xmlenc11#aes256-gcm';
5356
const RSA_1_5 = 'http://www.w3.org/2001/04/xmlenc#rsa-1_5';
5457
const RSA_OAEP_MGF1P = 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p';
58+
const RSA_OAEP = 'http://www.w3.org/2009/xmlenc11#rsa-oaep';
5559
const DSA_SHA1 = 'http://www.w3.org/2000/09/xmldsig#dsa-sha1';
5660
const RSA_SHA1 = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1';
5761
const RSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256';
5862
const RSA_SHA384 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384';
5963
const RSA_SHA512 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512';
6064
const HMAC_SHA1 = 'http://www.w3.org/2000/09/xmldsig#hmac-sha1';
65+
const AUTHTAG_LENGTH = 16;
6166

6267
/** @var array */
6368
private $cryptParams = array();
@@ -142,6 +147,30 @@ public function __construct($type, $params=null)
142147
$this->cryptParams['keysize'] = 32;
143148
$this->cryptParams['blocksize'] = 16;
144149
break;
150+
case (self::AES128_GCM):
151+
$this->cryptParams['library'] = 'openssl';
152+
$this->cryptParams['cipher'] = 'aes-128-gcm';
153+
$this->cryptParams['type'] = 'symmetric';
154+
$this->cryptParams['method'] = 'http://www.w3.org/2009/xmlenc11#aes128-gcm';
155+
$this->cryptParams['keysize'] = 16;
156+
$this->cryptParams['blocksize'] = 16;
157+
break;
158+
case (self::AES192_GCM):
159+
$this->cryptParams['library'] = 'openssl';
160+
$this->cryptParams['cipher'] = 'aes-192-gcm';
161+
$this->cryptParams['type'] = 'symmetric';
162+
$this->cryptParams['method'] = 'http://www.w3.org/2009/xmlenc11#aes192-gcm';
163+
$this->cryptParams['keysize'] = 24;
164+
$this->cryptParams['blocksize'] = 16;
165+
break;
166+
case (self::AES256_GCM):
167+
$this->cryptParams['library'] = 'openssl';
168+
$this->cryptParams['cipher'] = 'aes-256-gcm';
169+
$this->cryptParams['type'] = 'symmetric';
170+
$this->cryptParams['method'] = 'http://www.w3.org/2009/xmlenc11#aes256-gcm';
171+
$this->cryptParams['keysize'] = 32;
172+
$this->cryptParams['blocksize'] = 16;
173+
break;
145174
case (self::RSA_1_5):
146175
$this->cryptParams['library'] = 'openssl';
147176
$this->cryptParams['padding'] = OPENSSL_PKCS1_PADDING;
@@ -165,6 +194,18 @@ public function __construct($type, $params=null)
165194
}
166195
}
167196
throw new Exception('Certificate "type" (private/public) must be passed via parameters');
197+
case (self::RSA_OAEP):
198+
$this->cryptParams['library'] = 'openssl';
199+
$this->cryptParams['padding'] = OPENSSL_PKCS1_OAEP_PADDING;
200+
$this->cryptParams['method'] = 'http://www.w3.org/2009/xmlenc11#rsa-oaep';
201+
$this->cryptParams['hash'] = 'http://www.w3.org/2009/xmlenc11#mgf1sha1';
202+
if (is_array($params) && ! empty($params['type'])) {
203+
if ($params['type'] == 'public' || $params['type'] == 'private') {
204+
$this->cryptParams['type'] = $params['type'];
205+
break;
206+
}
207+
}
208+
throw new Exception('Certificate "type" (private/public) must be passed via parameters');
168209
case (self::RSA_SHA1):
169210
$this->cryptParams['library'] = 'openssl';
170211
$this->cryptParams['method'] = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1';
@@ -347,7 +388,7 @@ public function loadKey($key, $isFile=false, $isCert = false)
347388

348389
case'symmetric':
349390
if (strlen($this->key) < $this->cryptParams['keysize']) {
350-
throw new Exception('Key must contain at least 25 characters for this cipher');
391+
throw new Exception('Key must contain at least '.$this->cryptParams['keysize'].' characters for this cipher, contains '.strlen($this->key));
351392
}
352393
break;
353394

@@ -397,12 +438,22 @@ private function unpadISO10126($data)
397438
private function encryptSymmetric($data)
398439
{
399440
$this->iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cryptParams['cipher']));
400-
$data = $this->padISO10126($data, $this->cryptParams['blocksize']);
401-
$encrypted = openssl_encrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
441+
$authTag = null;
442+
if(in_array($this->cryptParams['cipher'], ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'])) {
443+
if (version_compare(PHP_VERSION, '7.1.0') < 0) {
444+
throw new Exception('PHP 7.1.0 is required to use AES GCM algorithms');
445+
}
446+
$authTag = openssl_random_pseudo_bytes(self::AUTHTAG_LENGTH);
447+
$encrypted = openssl_encrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA, $this->iv, $authTag);
448+
} else {
449+
$data = $this->padISO10126($data, $this->cryptParams['blocksize']);
450+
$encrypted = openssl_encrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
451+
}
452+
402453
if (false === $encrypted) {
403454
throw new Exception('Failure encrypting Data (openssl symmetric) - ' . openssl_error_string());
404455
}
405-
return $this->iv . $encrypted;
456+
return $this->iv . $encrypted . $authTag;
406457
}
407458

408459
/**
@@ -416,11 +467,24 @@ private function decryptSymmetric($data)
416467
$iv_length = openssl_cipher_iv_length($this->cryptParams['cipher']);
417468
$this->iv = substr($data, 0, $iv_length);
418469
$data = substr($data, $iv_length);
419-
$decrypted = openssl_decrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
470+
$authTag = null;
471+
if(in_array($this->cryptParams['cipher'], ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'])) {
472+
if (version_compare(PHP_VERSION, '7.1.0') < 0) {
473+
throw new Exception('PHP 7.1.0 is required to use AES GCM algorithms');
474+
}
475+
// obtain and remove the authentication tag
476+
$offset = 0 - self::AUTHTAG_LENGTH;
477+
$authTag = substr($data, $offset);
478+
$data = substr($data, 0, $offset);
479+
$decrypted = openssl_decrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA, $this->iv, $authTag);
480+
} else {
481+
$decrypted = openssl_decrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
482+
}
483+
420484
if (false === $decrypted) {
421485
throw new Exception('Failure decrypting Data (openssl symmetric) - ' . openssl_error_string());
422486
}
423-
return $this->unpadISO10126($decrypted);
487+
return null !== $authTag ? $decrypted : $this->unpadISO10126($decrypted);
424488
}
425489

426490
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* xmlseclibs.php
44
*
5-
* Copyright (c) 2007-2019, Robert Richards <rrichards@cdatazone.org>.
5+
* Copyright (c) 2007-2020, Robert Richards <rrichards@cdatazone.org>.
66
* All rights reserved.
77
*
88
* Redistribution and use in source and binary forms, with or without
@@ -35,12 +35,12 @@
3535
* POSSIBILITY OF SUCH DAMAGE.
3636
*
3737
* @author Robert Richards <rrichards@cdatazone.org>
38-
* @copyright 2007-2019 Robert Richards <rrichards@cdatazone.org>
38+
* @copyright 2007-2020 Robert Richards <rrichards@cdatazone.org>
3939
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
40-
* @version 3.0.4
40+
* @version 3.1.1
4141
*/
4242

43-
$xmlseclibs_srcdir = dirname(__FILE__) . '/src';
43+
$xmlseclibs_srcdir = dirname(__FILE__) . '/src/';
4444
require $xmlseclibs_srcdir . '/XMLSecurityKey.php';
4545
require $xmlseclibs_srcdir . '/XMLSecurityDSig.php';
4646
require $xmlseclibs_srcdir . '/XMLSecEnc.php';

onelogin-saml-sso/php/lib/Saml2/LogoutRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public function __construct(\OneLogin\Saml2\Settings $settings, $request = null,
122122
$nameIdSPNameQualifier,
123123
$nameIdFormat,
124124
$cert,
125-
$nameIdNameQualifier
125+
$nameIdNameQualifier,
126+
$security['encryption_algorithm']
126127
);
127128

128129
$sessionIndexStr = isset($sessionIndex) ? "<samlp:SessionIndex>{$sessionIndex}</samlp:SessionIndex>" : "";

onelogin-saml-sso/php/lib/Saml2/Settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ private function _addDefaultValues()
430430
$this->_security['digestAlgorithm'] = XMLSecurityDSig::SHA256;
431431
}
432432

433+
// EncryptionAlgorithm
434+
if (!isset($this->_security['encryption_algorithm'])) {
435+
$this->_security['encryption_algorithm'] = XMLSecurityKey::AES128_CBC;
436+
}
437+
433438
if (!isset($this->_security['lowercaseUrlencoding'])) {
434439
$this->_security['lowercaseUrlencoding'] = false;
435440
}

onelogin-saml-sso/php/lib/Saml2/Utils.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ public static function loadXML(DOMDocument $dom, $xml)
8282
assert($dom instanceof DOMDocument);
8383
assert(is_string($xml));
8484

85-
$oldEntityLoader = libxml_disable_entity_loader(true);
85+
$oldEntityLoader = null;
86+
if (PHP_VERSION_ID < 80000) {
87+
$oldEntityLoader = libxml_disable_entity_loader(true);
88+
}
8689

8790
$res = $dom->loadXML($xml);
8891

89-
libxml_disable_entity_loader($oldEntityLoader);
92+
if (PHP_VERSION_ID < 80000) {
93+
libxml_disable_entity_loader($oldEntityLoader);
94+
}
9095

9196
foreach ($dom->childNodes as $child) {
9297
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
@@ -141,9 +146,14 @@ public static function validateXML($xml, $schema, $debug = false, $schemaPath =
141146
$schemaFile = __DIR__ . '/schemas/' . $schema;
142147
}
143148

144-
$oldEntityLoader = libxml_disable_entity_loader(false);
149+
$oldEntityLoader = null;
150+
if (PHP_VERSION_ID < 80000) {
151+
$oldEntityLoader = libxml_disable_entity_loader(false);
152+
}
145153
$res = $dom->schemaValidate($schemaFile);
146-
libxml_disable_entity_loader($oldEntityLoader);
154+
if (PHP_VERSION_ID < 80000) {
155+
libxml_disable_entity_loader($oldEntityLoader);
156+
}
147157
if (!$res) {
148158
$xmlErrors = libxml_get_errors();
149159
syslog(LOG_INFO, 'Error validating the metadata: '.var_export($xmlErrors, true));
@@ -644,7 +654,7 @@ public static function getSelfRoutedURLNoQuery()
644654

645655
$pos = strpos($selfRoutedURLNoQuery, "?");
646656
if ($pos !== false) {
647-
$selfRoutedURLNoQuery = substr($selfRoutedURLNoQuery, 0, $pos-1);
657+
$selfRoutedURLNoQuery = substr($selfRoutedURLNoQuery, 0, $pos);
648658
}
649659

650660
return $selfRoutedURLNoQuery;
@@ -1046,12 +1056,13 @@ public static function formatFingerPrint($fingerprint)
10461056
* @param string|null $format SP Format
10471057
* @param string|null $cert IdP Public cert to encrypt the nameID
10481058
* @param string|null $nq IdP Name Qualifier
1059+
* @param string|null $encAlg Encryption algorithm
10491060
*
10501061
* @return string $nameIDElement DOMElement | XMLSec nameID
10511062
*
10521063
* @throws Exception
10531064
*/
1054-
public static function generateNameId($value, $spnq, $format = null, $cert = null, $nq = null)
1065+
public static function generateNameId($value, $spnq, $format = null, $cert = null, $nq = null, $encAlg = XMLSecurityKey::AES128_CBC)
10551066
{
10561067

10571068
$doc = new DOMDocument();
@@ -1071,14 +1082,18 @@ public static function generateNameId($value, $spnq, $format = null, $cert = nul
10711082
$doc->appendChild($nameId);
10721083

10731084
if (!empty($cert)) {
1074-
$seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type'=>'public'));
1085+
if ($encAlg == XMLSecurityKey::AES128_CBC) {
1086+
$seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type'=>'public'));
1087+
} else {
1088+
$seckey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type'=>'public'));
1089+
}
10751090
$seckey->loadKey($cert);
10761091

10771092
$enc = new XMLSecEnc();
10781093
$enc->setNode($nameId);
10791094
$enc->type = XMLSecEnc::Element;
10801095

1081-
$symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
1096+
$symmetricKey = new XMLSecurityKey($encAlg);
10821097
$symmetricKey->generateSessionKey();
10831098
$enc->encryptKey($seckey, $symmetricKey);
10841099

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"php-saml": {
3-
"version": "3.5.0",
4-
"released": "26/11/2020"
3+
"version": "3.6.1",
4+
"released": "02/03/2021"
55
}
66
}
77

0 commit comments

Comments
 (0)