Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support password hash #1543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class Account {
int getEncryptedLibraryVersion() const {
return serverInfo.encryptedLibraryVersion;
}

QString getEncryptedLibraryPwdHashAlgo() const {
return serverInfo.pwdHashAlgo;
}

QString getEncryptedLibraryPwdHashParams() const {
return serverInfo.pwdHashParams;
}

// require pro edtions and version at least at ...
// excluding OSS Version
bool isAtLeastProVersion(unsigned majorVersion, unsigned minorVersion, unsigned patchVersion) const {
Expand Down
38 changes: 36 additions & 2 deletions src/api/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ CreateRepoRequest::CreateRepoRequest(const Account& account,
int enc_version,
const QString& repo_id,
const QString& magic,
const QString& random_key)
const QString& random_key,
const QString& pwd_hash_algo,
const QString& pwd_hash_params,
const QString& pwd_hash)
: SeafileApiRequest(account.getAbsoluteUrl(kCreateRepoUrl),
SeafileApiRequest::METHOD_POST,
account.token)
Expand All @@ -270,6 +273,16 @@ CreateRepoRequest::CreateRepoRequest(const Account& account,
setFormParam("repo_id", repo_id);
setFormParam("magic", magic);
setFormParam("random_key", random_key);

if (!pwd_hash_algo.isEmpty()) {
setFormParam("pwd_hash_algo", pwd_hash_algo);
}
if (!pwd_hash_params.isEmpty()) {
setFormParam("pwd_hash_params", pwd_hash_params);
}
if (!pwd_hash.isEmpty()) {
setFormParam("pwd_hash", pwd_hash);
}
}

CreateRepoRequest::CreateRepoRequest(const Account& account,
Expand All @@ -279,7 +292,10 @@ CreateRepoRequest::CreateRepoRequest(const Account& account,
const QString& repo_id,
const QString& magic,
const QString& random_key,
const QString& salt)
const QString& salt,
const QString& pwd_hash_algo,
const QString& pwd_hash_params,
const QString& pwd_hash)
: SeafileApiRequest(account.getAbsoluteUrl(kCreateRepoUrl),
SeafileApiRequest::METHOD_POST,
account.token)
Expand All @@ -291,6 +307,16 @@ CreateRepoRequest::CreateRepoRequest(const Account& account,
setFormParam("magic", magic);
setFormParam("random_key", random_key);
setFormParam("salt", salt);

if (!pwd_hash_algo.isEmpty()) {
setFormParam("pwd_hash_algo", pwd_hash_algo);
}
if (!pwd_hash_params.isEmpty()) {
setFormParam("pwd_hash_params", pwd_hash_params);
}
if (!pwd_hash.isEmpty()) {
setFormParam("pwd_hash", pwd_hash);
}
}

void CreateRepoRequest::requestSuccess(QNetworkReply& reply)
Expand Down Expand Up @@ -759,6 +785,14 @@ void ServerInfoRequest::requestSuccess(QNetworkReply& reply)
ret.customBrand = dict["desktop-custom-brand"].toString();
}

if (dict.contains("encrypted_library_pwd_hash_algo")) {
ret.pwdHashAlgo = dict["encrypted_library_pwd_hash_algo"].toString();
}

if (dict.contains("encrypted_library_pwd_params")) {
ret.pwdHashParams = dict["encrypted_library_pwd_params"].toString();
}

emit success(ret);
}

Expand Down
10 changes: 8 additions & 2 deletions src/api/requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ class CreateRepoRequest : public SeafileApiRequest
int enc_version,
const QString& repo_id,
const QString& magic,
const QString& random_key);
const QString& random_key,
const QString& pwd_hash_algo,
const QString& pwd_hash_params,
const QString& pwd_hash);
// Constructor for seafile encryption v3
CreateRepoRequest(const Account& account,
const QString& name,
Expand All @@ -161,7 +164,10 @@ class CreateRepoRequest : public SeafileApiRequest
const QString& repo_id,
const QString& magic,
const QString& random_key,
const QString& salt);
const QString& salt,
const QString& pwd_hash_algo,
const QString& pwd_hash_params,
const QString& pwd_hash);

protected slots:
void requestSuccess(QNetworkReply& reply);
Expand Down
6 changes: 5 additions & 1 deletion src/api/server-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ServerInfo {
bool clientSSOViaLocalBrowser;
QString customBrand;
QString customLogo;
QString pwdHashAlgo;
QString pwdHashParams;

ServerInfo() :
majorVersion(0),
Expand All @@ -39,7 +41,9 @@ class ServerInfo {
fileSearch == rhs.fileSearch &&
disableSyncWithAnyFolder == rhs.disableSyncWithAnyFolder &&
customBrand == rhs.customBrand &&
customLogo == rhs.customLogo;
customLogo == rhs.customLogo &&
pwdHashAlgo == rhs.pwdHashAlgo &&
pwdHashParams == rhs.pwdHashParams;
}

bool operator!= (const ServerInfo &rhs) const {
Expand Down
13 changes: 11 additions & 2 deletions src/rpc/rpc-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,10 @@ int SeafileRpcClient::markFileLockState(const QString &repo_id,
int SeafileRpcClient::generateMagicAndRandomKey(int enc_version,
const QString &repo_id,
const QString &passwd,
const QString &pwd_hash_algo,
const QString &pwd_hash_params,
QString *magic,
QString *pwd_hash,
QString *random_key,
QString *salt)
{
Expand All @@ -879,10 +882,12 @@ int SeafileRpcClient::generateMagicAndRandomKey(int enc_version,
seafile_rpc_client_,
"seafile_generate_magic_and_random_key",
SEAFILE_TYPE_ENCRYPTION_INFO,
&error, 3,
&error, 5,
"int", enc_version,
"string", toCStr(repo_id),
"string", toCStr(passwd));
"string", toCStr(passwd),
"string", toCStr(pwd_hash_algo),
"string", toCStr(pwd_hash_params));
if (error) {
qWarning("failed to generate magic and random_key : %s\n", error->message);
g_error_free(error);
Expand All @@ -892,9 +897,11 @@ int SeafileRpcClient::generateMagicAndRandomKey(int enc_version,
char *c_magic = NULL;
char *c_random_key = NULL;
char *c_salt = NULL;
char *c_pwd_hash = NULL;
if (enc_version == 3 || enc_version == 4) {
g_object_get (obj,
"magic", &c_magic,
"pwd_hash", &c_pwd_hash,
"random_key", &c_random_key,
"salt", &c_salt,
NULL);
Expand All @@ -903,11 +910,13 @@ int SeafileRpcClient::generateMagicAndRandomKey(int enc_version,
} else {
g_object_get (obj,
"magic", &c_magic,
"pwd_hash", &c_pwd_hash,
"random_key", &c_random_key,
NULL);
}

*magic = QString(c_magic);
*pwd_hash = QString(c_pwd_hash);
*random_key = QString(c_random_key);

g_object_unref (obj);
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/rpc-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ class SeafileRpcClient : public QObject {
int generateMagicAndRandomKey(int enc_version,
const QString& repo_id,
const QString& passwd,
const QString& pwd_hash_algo,
const QString& pwd_hash_params,
QString *magic,
QString *pwd_hash,
QString *random_key,
QString *salt);

Expand Down
10 changes: 7 additions & 3 deletions src/ui/create-repo-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ void CreateRepoDialog::createAction()
// TODO: check server version is at least 4.3.x ?
QString repo_id = QUuid::createUuid().toString().mid(1, 36);
QString magic, random_key, salt;
QString pwd_hash_algo, pwd_hash_params, pwd_hash;

pwd_hash_algo = seafApplet->accountManager()->currentAccount().getEncryptedLibraryPwdHashAlgo();
pwd_hash_params = seafApplet->accountManager()->currentAccount().getEncryptedLibraryPwdHashAlgo();

int enc_version = seafApplet->accountManager()->currentAccount().getEncryptedLibraryVersion();

Expand All @@ -125,17 +129,17 @@ void CreateRepoDialog::createAction()
}

if (seafApplet->rpcClient()->generateMagicAndRandomKey(
enc_version, repo_id, passwd_, &magic, &random_key, &salt) < 0) {
enc_version, repo_id, passwd_, pwd_hash_algo, pwd_hash_params, &magic, &pwd_hash, &random_key, &salt) < 0) {
seafApplet->warningBox(tr("Failed to generate encryption key for this library"), this);
return;
}

if (enc_version == 3 || enc_version == 4) {
request_ = new CreateRepoRequest(
account_, name_, name_, enc_version, repo_id, magic, random_key, salt);
account_, name_, name_, enc_version, repo_id, magic, random_key, salt, pwd_hash_algo, pwd_hash_params, pwd_hash);
} else {
request_ = new CreateRepoRequest(
account_, name_, name_, enc_version, repo_id, magic, random_key);
account_, name_, name_, enc_version, repo_id, magic, random_key, pwd_hash_algo, pwd_hash_params, pwd_hash);
}
} else {
request_ = new CreateRepoRequest(account_, name_, name_, passwd_);
Expand Down