2014-06-04 05:11:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
2014-12-09 23:02:44 +00:00
|
|
|
* @copyright 2014 Jim Wigginton
|
2014-06-04 05:11:57 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\File\X509;
|
|
|
|
use phpseclib3\Crypt\RSA;
|
2014-06-04 05:11:57 +00:00
|
|
|
|
2014-06-05 14:23:22 +00:00
|
|
|
class Unit_File_X509_SPKACTest extends PhpseclibTestCase
|
2014-06-04 05:11:57 +00:00
|
|
|
{
|
|
|
|
public function testLoadSPKAC()
|
|
|
|
{
|
2014-06-05 14:23:22 +00: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 05:11:57 +00:00
|
|
|
|
2014-12-10 00:53:05 +00:00
|
|
|
$x509 = new X509();
|
2014-06-04 05:11:57 +00:00
|
|
|
|
|
|
|
$spkac = $x509->loadSPKAC($test);
|
|
|
|
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsArray($spkac);
|
2014-06-04 05:11:57 +00:00
|
|
|
|
|
|
|
$spkac = $x509->loadSPKAC('SPKAC=' . $test);
|
|
|
|
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsArray($spkac);
|
2014-06-04 05:11:57 +00:00
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$x509->validateSignature(),
|
|
|
|
'Failed asserting that the signature is valid'
|
|
|
|
);
|
|
|
|
|
|
|
|
$pubKey = $x509->getPublicKey();
|
|
|
|
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsString("$pubKey");
|
2014-06-04 05:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveSPKAC()
|
|
|
|
{
|
2019-06-24 02:51:38 +00:00
|
|
|
$privatekey = RSA::createKey(512)
|
|
|
|
->withPadding(RSA::SIGNATURE_PKCS1)
|
|
|
|
->withHash('sha1');
|
2014-06-04 05:11:57 +00:00
|
|
|
|
2014-12-10 00:53:05 +00:00
|
|
|
$x509 = new X509();
|
2016-04-30 21:23:35 +00:00
|
|
|
$x509->setPrivateKey($privatekey);
|
2014-06-04 05:11:57 +00:00
|
|
|
$x509->setChallenge('...');
|
|
|
|
|
|
|
|
$spkac = $x509->signSPKAC();
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsArray($spkac);
|
2014-06-04 05:11:57 +00:00
|
|
|
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsString($x509->saveSPKAC($spkac));
|
2014-06-04 05:11:57 +00:00
|
|
|
|
2014-12-10 00:53:05 +00:00
|
|
|
$x509 = new X509();
|
2018-02-15 11:29:14 +00:00
|
|
|
$x509->setPrivateKey($privatekey);
|
2014-06-04 05:11:57 +00:00
|
|
|
|
|
|
|
$spkac = $x509->signSPKAC();
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsArray($spkac);
|
2014-06-04 05:11:57 +00:00
|
|
|
|
2020-12-12 21:11:04 +00:00
|
|
|
$this->assertIsString($x509->saveSPKAC($spkac));
|
2014-06-04 05:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBadSignatureSPKAC()
|
|
|
|
{
|
2014-06-05 14:23:22 +00: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 05:11:57 +00:00
|
|
|
|
2014-12-10 00:53:05 +00:00
|
|
|
$x509 = new X509();
|
2014-06-04 05:11:57 +00: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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|