-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Kerin
committed
May 3, 2018
0 parents
commit 3b681e5
Showing
16 changed files
with
885 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/test export-ignore | ||
/.gitignore export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/README.md export-ignore | ||
/Makefile export-ignore |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License | ||
|
||
Copyright 2018 The BitWasp developers | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
_GENERATE_DIR=./src/ | ||
|
||
ifdef GENERATE_DIR | ||
_GENERATE_DIR=$(GENERATE_DIR) | ||
endif | ||
|
||
phpcs: pretest | ||
vendor/bin/phpcs --standard=PSR2 -n src test/unit/ | ||
|
||
phpcbf: pretest | ||
vendor/bin/phpcbf --standard=PSR2 -n src test/unit/ | ||
|
||
pretest: | ||
if [ ! -d vendor ] || [ ! -f composer.lock ]; then composer install; else echo "Already have dependencies"; fi | ||
if [ ! -d build ]; then mkdir build; fi | ||
|
||
phpunit-ci-unit: pretest | ||
php vendor/bin/phpunit -c phpunit.xml --coverage-text --coverage-clover=build/coverage.clover | ||
|
||
phpunit-ci-integration: pretest | ||
php vendor/bin/phpunit -c phpunit.device.xml --coverage-text --coverage-clover=build/coverage.clover | ||
|
||
ocular: | ||
if [ ! -f ocular.phar ]; then wget https://scrutinizer-ci.com/ocular.phar; fi | ||
|
||
scrutinizer: ocular | ||
php ocular.phar code-coverage:upload --format=php-clover build/coverage.clover | ||
|
||
clean: clean-env clean-deps | ||
|
||
clean-env: | ||
rm -rf ocular.phar | ||
rm -rf build | ||
|
||
clean-deps: | ||
rm -rf vendor/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "bitwasp/pinentry", | ||
"type": "library", | ||
"description": "Interface to gpgtools pinentry for PHP applications", | ||
"keywords": ["pinentry", "gpgtools", "password"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Thomas Kerin" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"BitWasp\\PinEntry\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"BitWasp\\Test\\PinEntry\\": "test/unit" | ||
} | ||
}, | ||
"require": { | ||
"guzzlehttp/streams": "^3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.0.0", | ||
"squizlabs/php_codesniffer": "^3.2", | ||
"phpstan/phpstan": "^0.9.2" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
bootstrap="vendor/autoload.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="All tests"> | ||
<directory>test/unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitWasp\PinEntry; | ||
|
||
class Command | ||
{ | ||
const SETDESC = 'SETDESC'; | ||
const SETPROMPT = 'SETPROMPT'; | ||
const SETKEYINFO = 'SETKEYINFO'; | ||
const SETREPEAT = 'SETREPEAT'; | ||
const SETTITLE = 'SETTITLE'; | ||
const SETERROR = 'SETERROR'; | ||
const SETOK = 'SETOK'; | ||
const SETNOTOK = 'SETNOTOK'; | ||
const SETCANCEL = 'SETCANCEL'; | ||
const SETREPEATERROR = 'SETREPEATERROR'; | ||
const SETTIMEOUT = 'SETTIMEOUT'; | ||
const SETQUALITYBAR = 'SETQUALITYBAR'; | ||
const SETQUALITYBAR_TT = 'SETQUALITYBAR_TT'; | ||
|
||
private $cmd; | ||
private $param; | ||
|
||
public function __construct(string $command, $param) | ||
{ | ||
$this->cmd = $command; | ||
$this->param = $param; | ||
} | ||
|
||
public function getCommand(): string | ||
{ | ||
return $this->cmd; | ||
} | ||
|
||
public function getParam() | ||
{ | ||
return $this->param; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitWasp\PinEntry\Exception; | ||
|
||
class PinEntryException extends \Exception | ||
{ | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitWasp\PinEntry\Exception; | ||
|
||
class RemotePinEntryException extends PinEntryException | ||
{ | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Exception; | ||
|
||
use BitWasp\PinEntry\Exception\RemotePinEntryException; | ||
|
||
class UnexpectedResponseException extends RemotePinEntryException | ||
{ | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitWasp\PinEntry; | ||
|
||
use BitWasp\PinEntry\Exception\PinEntryException; | ||
use BitWasp\PinEntry\Process\ProcessInterface; | ||
|
||
class PinEntry | ||
{ | ||
/** | ||
* @var ProcessInterface | ||
*/ | ||
private $process; | ||
|
||
public function __construct( | ||
ProcessInterface $process | ||
) { | ||
$msg = $process->waitFor("OK"); | ||
|
||
if ($msg !== "OK Pleased to meet you\n") { | ||
throw new PinEntryException("Unexpected start of pinnetry protocol"); | ||
} | ||
$this->process = $process; | ||
} | ||
|
||
public function getInfo(string $type): string | ||
{ | ||
$this->process->send("GETINFO {$type}\n"); | ||
$msg = $this->process->waitFor("D"); | ||
return $msg; | ||
} | ||
|
||
public function getPin(Request $request): string | ||
{ | ||
foreach ($request->getCommands() as $command => $param) { | ||
$this->process->send("{$command} {$param}\n"); | ||
$this->process->waitFor("OK"); | ||
} | ||
|
||
foreach ($request->getOptions() as $option => $value) { | ||
$this->process->send("OPTION {$option} {$value}\n"); | ||
$this->process->waitFor("OK"); | ||
} | ||
|
||
$this->process->send("GETPIN\n"); | ||
$msg = $this->process->waitFor("D"); | ||
return $msg; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitWasp\PinEntry\Process; | ||
|
||
class DebugDecorator implements ProcessInterface | ||
{ | ||
/** | ||
* @var ProcessInterface | ||
*/ | ||
private $process; | ||
|
||
public function __construct(ProcessInterface $process) | ||
{ | ||
$this->process = $process; | ||
} | ||
|
||
public function close(): bool | ||
{ | ||
echo sprintf("%s(%s)\n", __METHOD__); | ||
return $this->process->close(); | ||
} | ||
|
||
public function recv(): string | ||
{ | ||
$recv = $this->process->recv(); | ||
return $recv; | ||
} | ||
|
||
public function waitFor(string $text) | ||
{ | ||
echo sprintf("%s(%s)\n", __METHOD__, trim($text)); | ||
$recv = $this->process->waitFor($text); | ||
echo sprintf("%s(%s) received\n%s\n", __METHOD__, trim($text), $recv); | ||
return $recv; | ||
} | ||
|
||
public function send(string $data) | ||
{ | ||
echo sprintf("%s(%s)\n", __METHOD__, trim($data)); | ||
$send = $this->process->send($data); | ||
return $send; | ||
} | ||
} |
Oops, something went wrong.