OStatus Magicsig adaptations to new phpseclib

Some constants have changed and the way to call RSA->sign(...) too.
This commit is contained in:
Mikael Nordfeldth 2016-06-17 23:43:24 +02:00
parent d8af92bda2
commit 1839082f95
1 changed files with 4 additions and 5 deletions

View File

@ -203,10 +203,10 @@ class Magicsig extends Managed_DataObject
return strtolower(hash('sha256', $this->toString(false, false)));
}
public function exportPublicKey($format=CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
public function exportPublicKey($type='PKCS1')
{
$this->publicKey->setPublicKey();
return $this->publicKey->getPublicKey($format);
return $this->publicKey->getPublicKey($type);
}
/**
@ -250,7 +250,6 @@ class Magicsig extends Managed_DataObject
public function loadKey($mod, $exp, $type = 'public')
{
$rsa = new \phpseclib\Crypt\RSA();
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->setHash($this->getHash());
$rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256);
$rsa->k = strlen($rsa->modulus->toBytes());
@ -266,7 +265,7 @@ class Magicsig extends Managed_DataObject
public function loadPublicKeyPKCS1($key)
{
$rsa = new \phpseclib\Crypt\RSA();
if (!$rsa->setPublicKey($key, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)) {
if (!$rsa->setPublicKey($key, 'PKCS1')) {
throw new ServerException('Could not load PKCS1 public key. We probably got this from a remote Diaspora node as the profile public key.');
}
$this->publicKey = $rsa;
@ -305,7 +304,7 @@ class Magicsig extends Managed_DataObject
*/
public function sign($bytes)
{
$sig = $this->privateKey->sign($bytes);
$sig = $this->privateKey->sign($bytes, \phpseclib\Crypt\RSA::PADDING_PKCS1);
if ($sig === false) {
throw new ServerException('Could not sign data');
}