1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-15 18:37:33 +01:00
phpseclib/tests/Unit/File/X509/SPKACTest.php

99 lines
3.7 KiB
PHP
Raw Normal View History

2014-06-04 07:11:57 +02:00
<?php
/**
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2014 Jim Wigginton
2014-06-04 07:11:57 +02:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib3\File\X509;
use phpseclib3\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->assertIsArray($spkac);
2014-06-04 07:11:57 +02:00
$spkac = $x509->loadSPKAC('SPKAC=' . $test);
$this->assertIsArray($spkac);
2014-06-04 07:11:57 +02:00
$this->assertTrue(
$x509->validateSignature(),
'Failed asserting that the signature is valid'
);
$pubKey = $x509->getPublicKey();
$this->assertIsString("$pubKey");
2014-06-04 07:11:57 +02:00
}
public function testSaveSPKAC()
{
$privatekey = RSA::createKey(512)
->withPadding(RSA::SIGNATURE_PKCS1)
->withHash('sha1');
2014-06-04 07:11:57 +02:00
2014-12-10 01:53:05 +01:00
$x509 = new X509();
$x509->setPrivateKey($privatekey);
2014-06-04 07:11:57 +02:00
$x509->setChallenge('...');
$spkac = $x509->signSPKAC();
$this->assertIsArray($spkac);
2014-06-04 07:11:57 +02:00
$this->assertIsString($x509->saveSPKAC($spkac));
2014-06-04 07:11:57 +02:00
2014-12-10 01:53:05 +01:00
$x509 = new X509();
$x509->setPrivateKey($privatekey);
2014-06-04 07:11:57 +02:00
$spkac = $x509->signSPKAC();
$this->assertIsArray($spkac);
2014-06-04 07:11:57 +02:00
$this->assertIsString($x509->saveSPKAC($spkac));
2014-06-04 07:11:57 +02:00
}
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'
);
}
}