From 57f635e02fa623e6df5ec518dec628c77e1a05c3 Mon Sep 17 00:00:00 2001 From: Boris Date: Tue, 15 Nov 2022 20:49:57 +0100 Subject: [PATCH] =?UTF-8?q?C'est=20le=20ma=C3=AEtre=20des=20clefs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Jaklis.class.php | 4 +++- lib/Keygen.class.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ login.php | 3 ++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/lib/Jaklis.class.php b/lib/Jaklis.class.php index 7950bc4..3bbd6e1 100644 --- a/lib/Jaklis.class.php +++ b/lib/Jaklis.class.php @@ -15,12 +15,14 @@ class Jaklis { private $msgLimit = 15; + private $pubsecDir = __DIR__ .'/../cache/pubsec/'; + private $userPubsecPath; public function __construct ($userPubkey, $mode = 'local') { - $this->userPubsecPath = __DIR__ .'/../cache/pubsec/'. $userPubkey .'.dunikey'; + $this->userPubsecPath = $this->pubsecDir . $userPubkey .'.dunikey'; if ($this->mode != 'local') { diff --git a/lib/Keygen.class.php b/lib/Keygen.class.php index e9e7d42..317eed0 100644 --- a/lib/Keygen.class.php +++ b/lib/Keygen.class.php @@ -2,9 +2,65 @@ class Keygen { + private $keygenPath = __DIR__ . '/../vendors/keygen/keygen'; + + private $pubsecDir = __DIR__ .'/../cache/pubsec/'; + + private $userPubsecPath; + public function __construct () { + } + public function getG1Pub ($salt, $pepper) { + + $salt = str_replace('"', '\"', $salt); + $pepper = str_replace('"', '\"', $pepper); + + $cmd = $this->keygenPath; + $cmd .= ' -f pubsec'; + $cmd .= ' -t duniter'; + $cmd .= ' "'. $salt .'"'; + $cmd .= ' "'. $pepper .'"'; + + $output=null; + $result_code=null; + exec($cmd, $output, $result_code); + + // die($cmd . '
'. print_r($output, true) . '
'. print_r($result_code, true)); + + if (empty($output) or empty($output[0])) { + + throw new Exception('Keygen me calcule pas (la G1 pub)'); + } + + return $output[0]; + } + + public function generatePubsec ($salt, $pepper) { + + $salt = str_replace('"', '\"', $salt); + $pepper = str_replace('"', '\"', $pepper); + + $userPubkey = $this->getG1Pub($salt, $pepper); + + $cmd = $this->keygenPath; + $cmd .= ' -f pubsec'; + $cmd .= ' -t duniter'; + $cmd .= ' "'. $salt .'"'; + $cmd .= ' "'. $pepper .'"'; + $cmd .= ' -o '. $this->pubsecDir . $userPubkey . '.dunikey'; + + $output=null; + $result_code=null; + exec($cmd, $output, $result_code); + + // die($cmd . '
'. print_r($result_code, true)); + + if ($result_code != 0) { + + throw new Exception('Keygen me calcule pas (la dunikey)'); + } } } diff --git a/login.php b/login.php index 40d56bd..d48e7f1 100644 --- a/login.php +++ b/login.php @@ -18,9 +18,10 @@ if (isset($_POST['salt'], $_POST['pepper'])) { try { $playerG1Id = $fred->donneMoiSaPutaindeG1Pub($_POST['salt'], $_POST['pepper']); + $keygen->generatePubsec($_POST['salt'], $_POST['pepper']); } catch (Exception $errMsg) { - + ErrorsHandler::kaput($errMsg); }