From 10d5e19d4c34fa3d8a72d51a41980aeca06032d8 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Sun, 23 Oct 2022 01:38:29 -0700 Subject: [PATCH 1/3] Replace SHA1 with SHA256 --- src/bb-library/Model/ClientPasswordResetTable.php | 2 +- src/bb-modules/Client/Api/Guest.php | 2 +- src/bb-modules/Invoice/Service.php | 2 +- src/bb-modules/Support/Service.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bb-library/Model/ClientPasswordResetTable.php b/src/bb-library/Model/ClientPasswordResetTable.php index 4445d1968..31c378751 100644 --- a/src/bb-library/Model/ClientPasswordResetTable.php +++ b/src/bb-library/Model/ClientPasswordResetTable.php @@ -46,7 +46,7 @@ class Model_ClientPasswordResetTable implements \Box\InjectionAwareInterface } $r->ip = $ip; - $r->hash = sha1(random_int(50, random_int(10, 99))); + $r->hash = hash('sha256', random_int(50, random_int(10, 99))); $r->updated_at = date('Y-m-d H:i:s'); $this->di['db']->store($r); diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index 45c78cbe9..620e89c28 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -184,7 +184,7 @@ class Guest extends \Api_Abstract throw new \Box_Exception('Email not found in our database'); } - $hash = sha1(time() . uniqid()); + $hash = hash('sha256', time().random_bytes(13)); $reset = $this->di['db']->dispense('ClientPasswordReset'); $reset->client_id = $c->id; diff --git a/src/bb-modules/Invoice/Service.php b/src/bb-modules/Invoice/Service.php index c35ff43fb..7a9af76c7 100644 --- a/src/bb-modules/Invoice/Service.php +++ b/src/bb-modules/Invoice/Service.php @@ -548,7 +548,7 @@ class Service implements InjectionAwareInterface $model->serie = $systemService->getParamValue('invoice_series'); $model->nr = $model->id; - $model->hash = sha1(uniqid()); + $model->hash = hash('sha256', random_bytes(13)); $taxtitle = ''; $taxService = $this->di['mod_service']('Invoice', 'Tax'); diff --git a/src/bb-modules/Support/Service.php b/src/bb-modules/Support/Service.php index c2785a5a6..6c93d576b 100644 --- a/src/bb-modules/Support/Service.php +++ b/src/bb-modules/Support/Service.php @@ -842,7 +842,7 @@ class Service implements \Box\InjectionAwareInterface } $ticket = $this->di['db']->dispense('SupportPTicket'); - $ticket->hash = sha1(random_bytes(13)); + $ticket->hash = hash('sha256', random_bytes(13)); $ticket->author_name = $data['name']; $ticket->author_email = $data['email']; $ticket->subject = $subject; @@ -1228,7 +1228,7 @@ class Service implements \Box\InjectionAwareInterface $this->di['events_manager']->fire(['event' => 'onBeforeAdminPublicTicketOpen', 'params' => $data]); $ticket = $this->di['db']->dispense('SupportPTicket'); - $ticket->hash = sha1(random_bytes(13)); + $ticket->hash = hash('sha256', random_bytes(13)); $ticket->author_name = $data['name']; $ticket->author_email = $data['email']; $ticket->subject = $data['subject']; From 7059118f8a027732373fd99c53bed5c9fd79f436 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Sun, 23 Oct 2022 01:46:56 -0700 Subject: [PATCH 2/3] Replace MD5 with SHA256 --- src/bb-modules/Invoice/Service.php | 2 +- src/bb-modules/Queue/Api/Admin.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/Invoice/Service.php b/src/bb-modules/Invoice/Service.php index 7a9af76c7..e4fdc1088 100644 --- a/src/bb-modules/Invoice/Service.php +++ b/src/bb-modules/Invoice/Service.php @@ -665,7 +665,7 @@ class Service implements InjectionAwareInterface $new = $this->di['db']->dispense('Invoice'); $new->client_id = $invoice->client_id; - $new->hash = md5(random_bytes(13)); + $new->hash = hash('sha256', random_bytes(13)); $new->status = \Model_Invoice::STATUS_REFUNDED; $new->currency = $invoice->currency; $new->approved = true; diff --git a/src/bb-modules/Queue/Api/Admin.php b/src/bb-modules/Queue/Api/Admin.php index b68f7ebd9..94b3d5377 100644 --- a/src/bb-modules/Queue/Api/Admin.php +++ b/src/bb-modules/Queue/Api/Admin.php @@ -128,7 +128,7 @@ class Admin extends \Api_Abstract $msg->queue_id = $q->id; $msg->handler = $handler; $msg->body = $body; - $msg->hash = md5($body); + $msg->hash = hash('sha256', $body); $msg->created_at = date('Y-m-d H:i:s'); $msg->updated_at = date('Y-m-d H:i:s'); @@ -294,7 +294,7 @@ class Admin extends \Api_Abstract foreach ($stmt1->fetchAll() as $data) { $stmt = $db->prepare($sql2); - $stmt->bindValue('handle', md5(random_bytes(23)), \PDO::PARAM_STR); + $stmt->bindValue('handle', hash('sha256', random_bytes(23)), \PDO::PARAM_STR); $stmt->bindValue('id', $data['id'], \PDO::PARAM_INT); $stmt->bindValue('timeout', $microtime); if ($stmt->execute()) { From 5dfa99a447e4b95df7e1928b11ee03a0dbe54f47 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Sun, 23 Oct 2022 01:59:22 -0700 Subject: [PATCH 3/3] Fix testTicketCreateForGuest Switched to SHA256 instead of SHA1, so the expected length is now 64 --- tests/bb-modules/Support/ServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bb-modules/Support/ServiceTest.php b/tests/bb-modules/Support/ServiceTest.php index 7473f5fe0..232a3057d 100644 --- a/tests/bb-modules/Support/ServiceTest.php +++ b/tests/bb-modules/Support/ServiceTest.php @@ -1433,7 +1433,7 @@ class ServiceTest extends \BBTestCase $result = $this->service->ticketCreateForGuest($data); $this->assertIsString($result); - $this->assertEquals(strlen($result), 40); + $this->assertEquals(strlen($result), 64); } public function testTicketCreateForClient()