Last active
November 18, 2017 21:06
-
-
Save paragonie-scott/d37475b0bfc9bb437f0786188f2e9e2c to your computer and use it in GitHub Desktop.
Chronicle Test Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChronicleClient; | |
use GuzzleHttp\Client; | |
use ParagonIE\Chronicle\Chronicle; | |
use ParagonIE\ConstantTime\Base64UrlSafe; | |
use ParagonIE\Sapient\Adapter\Guzzle; | |
use ParagonIE\Sapient\CryptographyKeys\{ | |
SigningPublicKey, | |
SigningSecretKey | |
}; | |
use ParagonIE\Sapient\Sapient; | |
require_once 'vendor/autoload.php'; | |
$chronicle = \json_decode(\file_get_contents('server.json'), true); | |
$file = 'message.txt'; | |
$contents = \file_get_contents($file); | |
if (empty($contents)) { | |
exit(255); | |
} | |
$http = new Client(); | |
$sapient = new Sapient(new Guzzle($http)); | |
$request = $sapient->createSignedRequest( | |
'POST', | |
$chronicle['url'] . '/chronicle/publish', | |
$contents, | |
new SigningSecretKey( | |
Base64UrlSafe::decode($chronicle['my-secret-key']) | |
) | |
)->withAddedHeader( | |
'Chronicle-Client-Key-ID', | |
$chronicle['client-id'] | |
); | |
$response = $http->send($request); | |
$decoded = $sapient->decodeSignedJsonResponse( | |
$response, | |
new SigningPublicKey( | |
Base64UrlSafe::decode($chronicle['chronicle-public-key']) | |
) | |
); | |
var_dump($decoded); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"paragonie/sapient": "^1.0", | |
"guzzlehttp/guzzle": "^6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"url": "https://chronicle-public-test.paragonie.com", | |
"client-id": "", | |
"my-secret-key": "", | |
"my-public-key": "", | |
"chronicle-public-key": "3BK4hOYTWJbLV5QdqS-DFKEYOMKd-G5M9BvfbqG1ICI=" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment