Add php implementation

This commit is contained in:
Mikołaj Pich 2018-10-13 20:22:33 +02:00
parent 9ac32c33d5
commit 8f0b369347
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
8 changed files with 100 additions and 1 deletions

3
.gitignore vendored
View file

@ -60,3 +60,6 @@ typings/
# next.js build output
.next
.idea/
# php
vendor

23
composer.json Normal file
View file

@ -0,0 +1,23 @@
{
"name": "wulkanowy/uonet-request-signer",
"description": "UONET+ Request Signer",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Mikołaj Pich",
"email": "m.pich@outlook.com"
}
],
"require": {
"php": "^7.0"
},
"autoload": {
"files": [
"php/src/signer.php"
]
},
"scripts": {
"test": "php php/tests/signer_test.php"
}
}

19
composer.lock generated Normal file
View file

@ -0,0 +1,19 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "d1e5ca66a91f32aba91951d63ead0797",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.0"
},
"platform-dev": []
}

View file

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UONET+ Request Signer by Wulkanowy</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.7.5/forge.min.js" integrity="sha256-Nxwt1mmv6marltfJxJp/8QzIDEMTrGXI2fKG50K67ao=" crossorigin="anonymous"></script>
<script src="signer.js" defer></script>
<script src="js/signer.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.2/codemirror.min.js" integrity="sha256-uRIJ6Wfou5cTtmcCvQNA9lvsYl8sUbZXxnfG+P79ssY=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.2/mode/javascript/javascript.min.js" integrity="sha256-soPk2bgFhLwixxuyUzaWVadUMcVwWNE5JZwYdQhL4Xk=" crossorigin="anonymous"></script>
@ -58,6 +58,7 @@
<footer class="footer">
&copy; 2018 by <a href="https://wulkanowy.github.io">Wulkanowy</a> |
<a href="https://github.com/wulkanowy/uonet-request-signer">GitHub</a> |
<a href="https://github.com/wulkanowy/uonet-request-signer/blob/master/src/php">PHP implementation</a> |
<a href="https://github.com/VLO-GDA/uonet-sdk/blob/master/src/main/java/net/maciekmm/uonet/EncryptionUtils.java">Java implementation</a>
</footer>
<script>

17
php/README.md Normal file
View file

@ -0,0 +1,17 @@
# Uonet+ request signer for PHP
[![Total Downloads](https://poser.pugx.org/wulkanowy/uonet-request-signer/downloads?format=flat-square)](https://packagist.org/packages/wulkanowy/uonet-request-signer)
## Instalation
Via composer:
```bash
$ composer require wulkanowy/uonet-request-signer
```
## Tests
```bash
$ composer test
```

18
php/src/signer.php Normal file
View file

@ -0,0 +1,18 @@
<?php
namespace Wulkanowy\UonetRequestSigner;
function signContent(string $password, string $certificate, string $content)
{
openssl_pkcs12_read(base64_decode($certificate), $keystore, $password);
if (null === $keystore) {
throw new \RuntimeException('Invalid password');
}
$privateKey = openssl_pkey_get_private($keystore['pkey'], $password);
openssl_sign($content, $signature, $privateKey, OPENSSL_ALGO_SHA1);
return base64_encode($signature);
}

18
php/tests/signer_test.php Normal file
View file

@ -0,0 +1,18 @@
<?php
use function Wulkanowy\UonetRequestSigner\signContent;
require_once dirname(__DIR__).'/../vendor/autoload.php';
$password = '012345678901234567890123456789AB';
$certificate = 'MIIKYQIBAzCCChoGCSqGSIb3DQEHAaCCCgsEggoHMIIKAzCCBW8GCSqGSIb3DQEHAaCCBWAEggVcMIIFWDCCBVQGCyqGSIb3DQEMCgECoIIE+zCCBPcwKQYKKoZIhvcNAQwBAzAbBBSRxddtGxr1B3L4l6VE3c9VJ2uNtAIDAMNQBIIEyLpZHqyi1DevUp4RkJCJ3Da47HrAfOUdZ3aha2mGBoJa66Hd1zcQhe9KPllE12JhVbQHIjY/lkbrt7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AwIaBQAEFH8M34p8W3P5DQjPhHJ3h1c21OEVBBRrY106fqyzCCmc0jpKuoimwORPGQIDAYag';
$content = '{}';
$expectedSignature = 'PeEBjuVV4iI/bF5ljIBeTEhS/0htSsDsTQtExVYvX4dn9UJtZJZOYiVQZRLQHRv0sYmAufF9FqK/w+8wavUS0JdaehLewOAX/ppgxlyg3O1U/yYm7hwpGppoSh15M5hnFtBu7kEEJAb1akPACL64GEfAemfkyJVq5lab5W/1+oCQRdFePwLkrP1k8MQiMLYYPGY4+Sb/UEr4TmgahMwE9ZUVS+8NAxyi5sTwrejzvCl7/Z5o6mAtl5zFSxCgocKldVn/+A8z0/v87p4Zf5dgLCYcV+CLE+gEw22lFuBG3tnmfq3O4YBpg72RDvu5lYT0DLIHtUdibskB2GRNg3gDig==';
$requestSignatureValue = signContent($password, $certificate, $content);
if ($requestSignatureValue !== $expectedSignature) {
throw new AssertionError('Signatures not match');
}
echo 'Signatures match'.PHP_EOL;