diff --git a/common/rpc-service.c b/common/rpc-service.c index cdff149..54cbd3e 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -3056,6 +3056,7 @@ seafile_create_enc_repo (const char *repo_id, const char *random_key, const char *salt, int enc_version, + int key_iter, GError **error) { if (!repo_id || !repo_name || !repo_desc || !owner_email) { @@ -3069,6 +3070,7 @@ seafile_create_enc_repo (const char *repo_id, repo_id, repo_name, repo_desc, owner_email, magic, random_key, salt, enc_version, + key_iter, error); return ret; } diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index c9717b6..0b445a0 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -923,6 +923,7 @@ seafile_create_enc_repo (const char *repo_id, const char *random_key, const char *salt, int enc_version, + int key_iter, GError **error); char * diff --git a/lib/rpc_table.py b/lib/rpc_table.py index e10bb2f..0f6c139 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -66,6 +66,7 @@ func_table = [ [ "string", ["string", "string", "string", "string", "string", "string", "int64", "int"] ], [ "string", ["string", "string", "string", "string", "string", "string", "string"] ], [ "string", ["string", "string", "string", "string", "string", "string", "string", "int"] ], + [ "string", ["string", "string", "string", "string", "string", "string", "string", "int", "int"] ], [ "string", ["string", "string", "string", "string", "string", "string", "string", "int64"] ], [ "string", ["string", "string", "string", "string", "string", "string", "string", "string", "string"] ], [ "string", ["string", "int", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "int", "string"] ], diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 6559c2d..1413f8e 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -11,8 +11,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass create_repo = seafile_create_repo - @searpc_func("string", ["string", "string", "string", "string", "string", "string", "string", "int"]) - def seafile_create_enc_repo(repo_id, name, desc, owner_email, magic, random_key, salt, enc_version): + @searpc_func("string", ["string", "string", "string", "string", "string", "string", "string", "int", "int"]) + def seafile_create_enc_repo(repo_id, name, desc, owner_email, magic, random_key, salt, enc_version, key_iter): pass create_enc_repo = seafile_create_enc_repo diff --git a/python/seaserv/api.py b/python/seaserv/api.py index ece5270..691b65c 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -89,8 +89,8 @@ class SeafileAPI(object): def create_repo(self, name, desc, username, passwd=None, enc_version=2, storage_id=None): return seafserv_threaded_rpc.create_repo(name, desc, username, passwd, enc_version) - def create_enc_repo(self, repo_id, name, desc, username, magic, random_key, salt, enc_version): - return seafserv_threaded_rpc.create_enc_repo(repo_id, name, desc, username, magic, random_key, salt, enc_version) + def create_enc_repo(self, repo_id, name, desc, username, magic, random_key, salt, enc_version, key_iter=1000): + return seafserv_threaded_rpc.create_enc_repo(repo_id, name, desc, username, magic, random_key, salt, enc_version, key_iter) def get_repos_by_id_prefix(self, id_prefix, start=-1, limit=-1): """ diff --git a/server/repo-mgr.c b/server/repo-mgr.c index 5ab928b..815316d 100644 --- a/server/repo-mgr.c +++ b/server/repo-mgr.c @@ -3744,6 +3744,7 @@ create_repo_common (SeafRepoManager *mgr, const char *random_key, const char *salt, int enc_version, + int key_iter, GError **error) { SeafRepo *repo = NULL; @@ -3780,6 +3781,14 @@ create_repo_common (SeafRepoManager *mgr, return -1; } } + if (enc_version >= 5) { + if (key_iter <= 0) { + seaf_warning ("Bad key iteration times.\n"); + g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, + "Bad key iteration times"); + return -1; + } + } repo = seaf_repo_new (repo_id, repo_name, repo_desc); @@ -3793,7 +3802,7 @@ create_repo_common (SeafRepoManager *mgr, if (enc_version >= 3) memcpy (repo->salt, salt, 64); if (enc_version >= 5) { - repo->key_iter = seaf->key_iter; + repo->key_iter = key_iter; } repo->version = CURRENT_REPO_VERSION; @@ -3877,10 +3886,10 @@ seaf_repo_manager_create_new_repo (SeafRepoManager *mgr, int rc; if (passwd) rc = create_repo_common (mgr, repo_id, repo_name, repo_desc, owner_email, - magic, random_key, salt, enc_version, error); + magic, random_key, salt, enc_version, seaf->key_iter, error); else rc = create_repo_common (mgr, repo_id, repo_name, repo_desc, owner_email, - NULL, NULL, NULL, -1, error); + NULL, NULL, NULL, -1, -1, error); if (rc < 0) goto bad; @@ -3909,6 +3918,7 @@ seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr, const char *random_key, const char *salt, int enc_version, + int key_iter, GError **error) { if (!repo_id || !is_uuid_valid (repo_id)) { @@ -3926,7 +3936,7 @@ seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr, } if (create_repo_common (mgr, repo_id, repo_name, repo_desc, owner_email, - magic, random_key, salt, enc_version, error) < 0) + magic, random_key, salt, enc_version, key_iter, error) < 0) return NULL; if (seaf_repo_manager_set_repo_owner (mgr, repo_id, owner_email) < 0) { diff --git a/server/repo-mgr.h b/server/repo-mgr.h index 5bbef72..08e7526 100644 --- a/server/repo-mgr.h +++ b/server/repo-mgr.h @@ -514,6 +514,7 @@ seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr, const char *random_key, const char *salt, int enc_version, + int key_iter, GError **error); /* Give a repo and a path in this repo, returns a list of commits, where every diff --git a/server/seaf-server.c b/server/seaf-server.c index 46c0b31..87d9f17 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -227,7 +227,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_create_enc_repo, "seafile_create_enc_repo", - searpc_signature_string__string_string_string_string_string_string_string_int()); + searpc_signature_string__string_string_string_string_string_string_string_int_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_get_commit,