Skip to content

Commit e4b5b7e

Browse files
committed
Merge branch 'master' into v4_phpseclibs
2 parents 0bca690 + 2f8c755 commit e4b5b7e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/XMLSecurityKey.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class XMLSecurityKey
6666
const RSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256';
6767
const RSA_SHA384 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384';
6868
const RSA_SHA512 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512';
69+
const ECDSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256';
6970
const HMAC_SHA1 = 'http://www.w3.org/2000/09/xmldsig#hmac-sha1';
7071
const RSA_SHA256_MGF1 = 'http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1';
7172
const AUTHTAG_LENGTH = 16;
@@ -250,6 +251,17 @@ public function __construct($type, $params=null)
250251
}
251252
}
252253
throw new Exception('Certificate "type" (private/public) must be passed via parameters');
254+
case (self::ECDSA_SHA256):
255+
$this->cryptParams['library'] = 'phpseclib';
256+
$this->cryptParams['method'] = 'http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256';
257+
$this->cryptParams['digest'] = 'SHA256';
258+
if (is_array($params) && ! empty($params['type'])) {
259+
if ($params['type'] == 'public' || $params['type'] == 'private') {
260+
$this->cryptParams['type'] = $params['type'];
261+
break;
262+
}
263+
}
264+
throw new Exception('Certificate "type" (private/public) must be passed via parameters');
253265
case (self::RSA_SHA384):
254266
$this->cryptParams['library'] = 'phpseclib';
255267
$this->cryptParams['method'] = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384';
@@ -618,6 +630,12 @@ public function signData($data)
618630
case 'phpseclib':
619631
$passphrase = $this->passphrase !== '' ? $this->passphrase : false;
620632
$private = PublicKeyLoader::load($this->key, $passphrase);
633+
if ($this->type === self::ECDSA_SHA256) {
634+
return $private
635+
->withHash($this->cryptParams['digest'])
636+
->withSignatureFormat('IEEE')
637+
->sign($data);
638+
}
621639
return $this->configureRSAKey($private)->sign($data);
622640
case (self::HMAC_SHA1):
623641
return hash_hmac("sha1", $data, $this->key, true);
@@ -646,6 +664,13 @@ public function verifySignature($data, $signature)
646664
case 'phpseclib':
647665
try {
648666
$public = PublicKeyLoader::load($this->key);
667+
if ($this->type === self::ECDSA_SHA256) {
668+
$result = $public
669+
->withHash($this->cryptParams['digest'])
670+
->withSignatureFormat('IEEE')
671+
->verify($data, $signature);
672+
return $result === true ? 1 : 0;
673+
}
649674
$result = $this->configureRSAKey($public)->verify($data, $signature);
650675
return $result === true ? 1 : 0;
651676
} catch (Exception $e) {

0 commit comments

Comments
 (0)