From 321f83d805b6f506ae092383f6abda748e07c7cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 22 May 2019 17:12:24 -0400
Subject: [PATCH] registration: daemon should sign the name in lowercase

Because the signature is now fixed and sign(Name) != sign(name),
the daemon should sign the name in lowercase because it will
try to register the name in lowercase.

Change-Id: If5f786f241fedb83d65015ac7edf0cacd66f4d2d
---
 src/jamidht/jamiaccount.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index ad4fbf9677..a49ec709b7 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -1666,10 +1666,12 @@ void
 JamiAccount::registerName(const std::string& password, const std::string& name)
 {
     std::string signedName;
+    auto nameLowercase {name};
+    std::transform(nameLowercase.begin(), nameLowercase.end(), nameLowercase.begin(), ::tolower);
     std::string publickey;
     try {
         auto privateKey = readArchive(password).id.first;
-        signedName = base64::encode(privateKey->sign(Blob(name.begin(), name.end())));
+        signedName = base64::encode(privateKey->sign(Blob(nameLowercase.begin(), nameLowercase.end())));
         publickey = privateKey->getPublicKey().toString();
     } catch (const std::exception& e) {
         JAMI_ERR("[Account %s] can't export account: %s", getAccountID().c_str(), e.what());
@@ -1677,7 +1679,7 @@ JamiAccount::registerName(const std::string& password, const std::string& name)
         return;
     }
 
-    nameDir_.get().registerName(ringAccountId_, name, ethAccount_, [acc=getAccountID(), name, w=weak()](NameDirectory::RegistrationResponse response){
+    nameDir_.get().registerName(ringAccountId_, nameLowercase, ethAccount_, [acc=getAccountID(), name, w=weak()](NameDirectory::RegistrationResponse response){
         int res = (response == NameDirectory::RegistrationResponse::success)      ? 0 : (
                   (response == NameDirectory::RegistrationResponse::invalidName)  ? 2 : (
                   (response == NameDirectory::RegistrationResponse::alreadyTaken) ? 3 : 4));
-- 
GitLab