2014-06-04 07:11:57 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
2014-12-10 00:02:44 +01:00
|
|
|
* @copyright 2014 Jim Wigginton
|
2014-06-04 07:11:57 +02:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-12-10 01:53:05 +01:00
|
|
|
use phpseclib\File\X509;
|
2014-12-17 01:16:54 +01:00
|
|
|
use phpseclib\Crypt\RSA;
|
2014-06-04 07:11:57 +02:00
|
|
|
|
2014-06-05 16:23:22 +02:00
|
|
|
class Unit_File_X509_SPKACTest extends PhpseclibTestCase
|
2014-06-04 07:11:57 +02:00
|
|
|
{
|
|
|
|
public function testLoadSPKAC()
|
|
|
|
{
|
2014-06-05 16:23:22 +02:00
|
|
|
$test = 'MIICQDCCASgwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQChgo9mWzQm3TSwGgpZnIc54' .
|
|
|
|
'TZ8gYpfAO/AI0etvyWDqnFfdNCUQsqxTdSi6/rtrJdLGBsszRGrRIc/0JqmjM+jCHGYutLeo4xwgr' .
|
|
|
|
'a3HAZrWDypL5IlRWnLmLA4U/qGXCXNSk+9NrJl39X3IDA8o/aOJyr9iMUJMvswcWjVjPom3NhAgmJ' .
|
|
|
|
'ZwW0vUEMw9zszExpiRnGSO5XXntQW2qvfzo+J3NzS3BBbKxEmTsfOLHextcXeFQUaBQHXB/WOtweW' .
|
|
|
|
'Y/Bd4iZ8ETmhal28g1HWVcTFPD+V+KPRFeARlVEW6JmcJucW2WdJlBGKXXXPEfdHrDS3OgD/eDWfM' .
|
|
|
|
'JE4mChZ/icxAgMBAAEWADANBgkqhkiG9w0BAQQFAAOCAQEAUMvIKhlSgEgbC081b/FJwh6mbuVgYN' .
|
|
|
|
'ZV37Ts2WjrHoDFlabu9WXU8xzgaXct3sO51vJM5I36rY4UPyc6w3y9dLaamEwKUoWnpHG8mlXs2JG' .
|
|
|
|
'GEUOvxh5z9yfk/2ZmdCVBlKnU1LDB+ZDyNyNh5B0YULrJKw9e0jV+ymP7srwUSBcdUfZh1KEKGVIN' .
|
|
|
|
'Uv4J3GuL8V63E2unWCHGRPw4EmFVTbWpgMx96XR7p/pMavu6/pVKgYQqWLOmEeOK+dmT/QVon28d5' .
|
|
|
|
'dmeL7aWrpP+3x3L0A9cATksracQX676XogdAEXJ59fcr/S5AGw1TFErbyBbfyeAWvzDZIXeMXpb9h' .
|
|
|
|
'yNtA==';
|
2014-06-04 07:11:57 +02:00
|
|
|
|
2014-12-10 01:53:05 +01:00
|
|
|
$x509 = new X509();
|
2014-06-04 07:11:57 +02:00
|
|
|
|
|
|
|
$spkac = $x509->loadSPKAC($test);
|
|
|
|
|
|
|
|
$this->assertInternalType('array', $spkac);
|
|
|
|
|
|
|
|
$spkac = $x509->loadSPKAC('SPKAC=' . $test);
|
|
|
|
|
|
|
|
$this->assertInternalType('array', $spkac);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$x509->validateSignature(),
|
|
|
|
'Failed asserting that the signature is valid'
|
|
|
|
);
|
|
|
|
|
|
|
|
$pubKey = $x509->getPublicKey();
|
|
|
|
|
|
|
|
$this->assertInternalType('string', "$pubKey");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveSPKAC()
|
|
|
|
{
|
2014-12-17 01:16:54 +01:00
|
|
|
$privKey = new RSA();
|
2014-06-04 07:22:46 +02:00
|
|
|
extract($privKey->createKey());
|
2016-04-10 18:25:31 +02:00
|
|
|
$privKey->loadKey($privatekey);
|
2014-06-04 07:11:57 +02:00
|
|
|
|
2014-12-10 01:53:05 +01:00
|
|
|
$x509 = new X509();
|
2016-04-10 18:25:31 +02:00
|
|
|
$x509->setPrivateKey($privKey);
|
2014-06-04 07:11:57 +02:00
|
|
|
$x509->setChallenge('...');
|
|
|
|
|
|
|
|
$spkac = $x509->signSPKAC();
|
|
|
|
$this->assertInternalType('array', $spkac);
|
|
|
|
|
|
|
|
$this->assertInternalType('string', $x509->saveSPKAC($spkac));
|
|
|
|
|
2014-12-10 01:53:05 +01:00
|
|
|
$x509 = new X509();
|
2014-06-04 07:22:46 +02:00
|
|
|
$x509->setPrivateKey($privKey);
|
2014-06-04 07:11:57 +02:00
|
|
|
|
|
|
|
$spkac = $x509->signSPKAC();
|
|
|
|
$this->assertInternalType('array', $spkac);
|
|
|
|
|
|
|
|
$this->assertInternalType('string', $x509->saveSPKAC($spkac));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBadSignatureSPKAC()
|
|
|
|
{
|
2014-06-05 16:23:22 +02:00
|
|
|
$test = 'MIICQDCCASgwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQChgo9mWzQm3TSwGgpZnIc54' .
|
|
|
|
'TZ8gYpfAO/AI0etvyWDqnFfdNCUQsqxTdSi6/rtrJdLGBsszRGrRIc/0JqmjM+jCHGYutLeo4xwgr' .
|
|
|
|
'a3HAZrWDypL5IlRWnLmLA4U/qGXCXNSk+9NrJl39X3IDA8o/aOJyr9iMUJMvswcWjVjPom3NhAgmJ' .
|
|
|
|
'ZwW0vUEMw9zszExpiRnGSO5XXntQW2qvfzo+J3NzS3BBbKxEmTsfOLHextcXeFQUaBQHXB/WOtweW' .
|
|
|
|
'Y/Bd4iZ8ETmhal28g1HWVcTFPD+V+KPRFeARlVEW6JmcJucW2WdJlBGKXXXPEfdHrDS3OgD/eDWfM' .
|
|
|
|
'JE4mChZ/icxAgMBAAEWADANBgkqhkiG9w0BAQQFAAOCAQEAUMvIKhlSgEgbC081b/FJwh6mbuVgYN' .
|
|
|
|
'ZV37Ts2WjrHoDFlabu9WXU8xzgaXct3sO51vJM5I36rY4UPyc6w3y9dLaamEwKUoWnpHG8mlXs2JG' .
|
|
|
|
'GEUOvxh5z9yfk/2ZmdCVBlKnU1LDB+ZDyNyNh5B0YULrJKw9e0jV+ymP7srwUSBcdUfZh1KEKGVIN' .
|
|
|
|
'Uv4J3GuL8V63E2unWCHGRPw4EmFVTbWpgMx96XR7p/pMavu6/pVKgYQqWLOmEeOK+dmT/QVon28d5' .
|
|
|
|
'dmeL7aWrpP+3x3L0A9cATksracQX676XogdAEXJ59fcr/S5AGw1TFErbyBbfyeAWvzDZIXeMXpb9h' .
|
|
|
|
'yNtA==';
|
2014-06-04 07:11:57 +02:00
|
|
|
|
2014-12-10 01:53:05 +01:00
|
|
|
$x509 = new X509();
|
2014-06-04 07:11:57 +02:00
|
|
|
|
|
|
|
$spkac = $x509->loadSPKAC($test);
|
|
|
|
|
|
|
|
$spkac['publicKeyAndChallenge']['challenge'] = 'zzzz';
|
|
|
|
|
|
|
|
$x509->loadSPKAC($x509->saveSPKAC($spkac));
|
|
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
$x509->validateSignature(),
|
|
|
|
'Failed asserting that the signature is invalid'
|
|
|
|
);
|
2016-04-10 18:25:31 +02:00
|
|
|
|
2014-06-04 07:11:57 +02:00
|
|
|
}
|
|
|
|
}
|