diff options
author | aunsane <aunsane@gmail.com> | 2017-12-18 14:51:36 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-12-18 20:37:16 +0300 |
commit | 97254a71ba33edf4c829e4c4b0c4961c6348045f (patch) | |
tree | 83c4dc1b828dbce86ff68813defb2481ee178a09 /protocols/Tox/src | |
parent | 2626b146d53df3a5f9e7f8e9ed69c33a1145f9f3 (diff) |
Tox: enable profile encription (in test mode)
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 49 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.h | 9 |
2 files changed, 40 insertions, 18 deletions
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index a144eebee2..3beeb2d91c 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -64,18 +64,21 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) mir_free(data);
return false;
}
+ password = mir_utf8encodeW(pass_ptrT(passwordEditor.GetPassword()));
}
- uint8_t *encryptedData = (uint8_t*)mir_calloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
+ size_t decryptedSize = size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
+ uint8_t *decryptedData = (uint8_t*)mir_calloc(decryptedSize);
TOX_ERR_DECRYPTION coreDecryptError;
- if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError)) {
+ if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), decryptedData, &coreDecryptError)) {
ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
mir_free(data);
return false;
}
mir_free(data);
- data = encryptedData;
- size -= TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
+ data = decryptedData;
+ size = decryptedSize;
+ return true;
}
if (data) {
@@ -93,21 +96,26 @@ void CToxProto::SaveToxProfile(Tox *tox) mir_cslock locker(profileLock);
size_t size = tox_get_savedata_size(tox);
- uint8_t *data = (uint8_t*)mir_calloc(size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
+ uint8_t *data = (uint8_t*)mir_calloc(size);
tox_get_savedata(tox, data);
- /*pass_ptrA password(mir_utf8encodeW(pass_ptrT(getWStringA("Password"))));
+ pass_ptrA password(mir_utf8encodeW(pass_ptrT(getWStringA("Password"))));
if (password && mir_strlen(password))
{
TOX_ERR_ENCRYPTION coreEncryptError;
- if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), data, &coreEncryptError))
+ size_t encryptedSize = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
+ uint8_t *encryptedData = (uint8_t*)mir_calloc(encryptedSize);
+ if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreEncryptError))
{
debugLogA(__FUNCTION__": failed to encrypt tox profile");
mir_free(data);
+ mir_free(encryptedData);
return;
}
- size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
- }*/
+ mir_free(data);
+ data = encryptedData;
+ size = encryptedSize;
+ }
ptrW profilePath(GetToxProfilePath());
FILE *profile = _wfopen(profilePath, L"wb");
@@ -141,17 +149,28 @@ INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM) }
CToxPasswordEditor::CToxPasswordEditor(CToxProto *proto) :
- CToxDlgBase(proto, IDD_PASSWORD, false), ok(this, IDOK),
- password(this, IDC_PASSWORD), savePermanently(this, IDC_SAVEPERMANENTLY)
+ CToxDlgBase(proto, IDD_PASSWORD, false), m_ok(this, IDOK),
+ m_password(this, IDC_PASSWORD), m_savePermanently(this, IDC_SAVEPERMANENTLY)
{
- ok.OnClick = Callback(this, &CToxPasswordEditor::OnOk);
+ m_password.OnChange = Callback(this, &CToxPasswordEditor::OnOk);
+ m_ok.OnClick = Callback(this, &CToxPasswordEditor::OnOk);
+ m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()));
+}
+
+void CToxPasswordEditor::OnChange(CCtrlBase*)
+{
+ //m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()));
}
void CToxPasswordEditor::OnOk(CCtrlButton*)
{
- pass_ptrT tszPassword(password.GetText());
- if (savePermanently.Enabled())
+ pass_ptrT tszPassword(m_password.GetText());
+ if (m_savePermanently.Enabled())
m_proto->setWString("Password", tszPassword);
-
EndDialog(m_hwnd, 1);
}
+
+wchar_t* CToxPasswordEditor::GetPassword()
+{
+ return m_password.GetText();
+}
diff --git a/protocols/Tox/src/tox_profile.h b/protocols/Tox/src/tox_profile.h index 796f264d5b..6a0b31f1f5 100644 --- a/protocols/Tox/src/tox_profile.h +++ b/protocols/Tox/src/tox_profile.h @@ -4,16 +4,19 @@ class CToxPasswordEditor : public CToxDlgBase
{
private:
- CCtrlEdit password;
- CCtrlCheck savePermanently;
+ CCtrlEdit m_password;
+ CCtrlCheck m_savePermanently;
- CCtrlButton ok;
+ CCtrlButton m_ok;
protected:
+ void OnChange(CCtrlBase*);
void OnOk(CCtrlButton*);
public:
CToxPasswordEditor(CToxProto *proto);
+
+ wchar_t* GetPassword();
};
#endif //_TOX_PROFILE_H_
\ No newline at end of file |