Skip to content

Commit

Permalink
update create enc repo
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam committed Sep 13, 2024
1 parent ef0e3c9 commit cc70721
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 49 deletions.
20 changes: 10 additions & 10 deletions seahub/api2/endpoints/admin/group_owned_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,36 @@ def post(self, request, group_id):

repo_id = seafile_api.add_group_owned_repo(group_id, repo_name,
permission, password, enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None,
storage_id=storage_id)
else:
# STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING'
if org_id and org_id > 0:
repo_id = seafile_api.org_add_group_owned_repo(
org_id, group_id, repo_name, permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.add_group_owned_repo(
group_id, repo_name, permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
if org_id and org_id > 0:
repo_id = seafile_api.org_add_group_owned_repo(
org_id, group_id, repo_name, permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.add_group_owned_repo(group_id, repo_name,
permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

# for activities
username = request.user.username
Expand Down
8 changes: 4 additions & 4 deletions seahub/api2/endpoints/group_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ def post(self, request, group_id):

repo_id = seafile_api.create_org_repo(repo_name, '', username, org_id, password,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.create_repo(repo_name, '', username, password,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

repo = seafile_api.get_repo(repo_id)
share_dir_to_group(repo, '/', username, username, group_id,
Expand Down
4 changes: 2 additions & 2 deletions seahub/api2/endpoints/group_owned_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def post(self, request, group_id, org_id):
permission,
password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None,
storage_id=storage_id)
else:
# STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING'
Expand Down
57 changes: 32 additions & 25 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,14 @@ def repo_download_info(request, repo_id, gen_sync_token=True):
'repo_version': repo_version,
'head_commit_id': repo.head_cmmt_id,
'permission': seafile_api.check_permission_by_path(repo_id, '/', email)
}
}

if settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO:
info_json.update({
'pwd_hash': repo.pwd_hash or "",
'pwd_hash_algo': repo.pwd_hash_algo or "",
'pwd_hash_params': repo.pwd_hash_params or "",
})

if is_pro_version() and ENABLE_STORAGE_CLASSES:
info_json['storage_name'] = repo.storage_name
Expand Down Expand Up @@ -1144,8 +1151,8 @@ def _create_repo(self, request, repo_name, repo_desc, username, org_id):
repo_id = seafile_api.create_org_repo(repo_name,
repo_desc, username, org_id, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
if is_pro_version() and ENABLE_STORAGE_CLASSES:

Expand All @@ -1161,22 +1168,22 @@ def _create_repo(self, request, repo_name, repo_desc, username, org_id):
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None,
storage_id=storage_id)
else:
# STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING'
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

if passwd and ENABLE_RESET_ENCRYPTED_REPO_PASSWORD:
add_encrypted_repo_secret_key_to_database(repo_id, passwd)
Expand Down Expand Up @@ -1335,8 +1342,8 @@ def post(self, request, format=None):
repo_id = seafile_api.create_org_repo(repo_name, repo_desc,
username, org_id, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
repo = seafile_api.get_repo(repo_id)
seafile_api.set_org_inner_pub_repo(org_id, repo.id, permission)
else:
Expand All @@ -1354,22 +1361,22 @@ def post(self, request, format=None):
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None,
storage_id=storage_id)
else:
# STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING'
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

repo = seafile_api.get_repo(repo_id)
seafile_api.add_inner_pub_repo(repo.id, permission)
Expand Down Expand Up @@ -4923,8 +4930,8 @@ def post(self, request, group, format=None):
repo_id = seafile_api.create_org_repo(repo_name, repo_desc,
username, org_id, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

repo = seafile_api.get_repo(repo_id)
seafile_api.add_org_group_repo(repo_id, org_id, group.id,
Expand All @@ -4944,21 +4951,21 @@ def post(self, request, group, format=None):
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd, storage_id,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
# STORAGE_CLASS_MAPPING_POLICY == 'REPO_ID_MAPPING'
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
repo_id = seafile_api.create_repo(repo_name,
repo_desc, username, passwd,
enc_version=settings.ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)

repo = seafile_api.get_repo(repo_id)
seafile_api.set_group_repo(repo.id, group.id, username, permission)
Expand Down
6 changes: 4 additions & 2 deletions seahub/api2/views_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def get(self, request, format=None):
info['encrypted_library_version'] = settings.ENCRYPTED_LIBRARY_VERSION
else:
info['encrypted_library_version'] = 2
info['encrypted_library_pwd_hash_algo'] = settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO
info['encrypted_library_pwd_hash_params'] = settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS

if settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO:
info['encrypted_library_pwd_hash_algo'] = settings.ENCRYPTED_LIBRARY_PWD_HASH_ALGO
info['encrypted_library_pwd_hash_params'] = settings.ENCRYPTED_LIBRARY_PWD_HASH_PARAMS

features = ['seafile-basic']

Expand Down
4 changes: 2 additions & 2 deletions seahub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@
ENABLE_ENCRYPTED_LIBRARY = True
ENCRYPTED_LIBRARY_VERSION = 2

ENCRYPTED_LIBRARY_PWD_HASH_ALGO = "pbkdf2_sha256"
ENCRYPTED_LIBRARY_PWD_HASH_PARAMS = "1000" # iteration count
ENCRYPTED_LIBRARY_PWD_HASH_ALGO = ""
ENCRYPTED_LIBRARY_PWD_HASH_PARAMS = ""

# enable reset encrypt library's password when user forget password
ENABLE_RESET_ENCRYPTED_REPO_PASSWORD = False
Expand Down
8 changes: 4 additions & 4 deletions seahub/utils/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def add_group_owned_repo(self, group_id, repo_name, password, permission,
return seafile_api.org_add_group_owned_repo(
org_id, group_id, repo_name, permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS)
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None)
else:
return seafile_api.add_group_owned_repo(
group_id, repo_name, permission, password,
enc_version=ENCRYPTED_LIBRARY_VERSION,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS,
pwd_hash_algo=ENCRYPTED_LIBRARY_PWD_HASH_ALGO or None,
pwd_hash_params=ENCRYPTED_LIBRARY_PWD_HASH_PARAMS or None,
storage_id=storage_id)

def delete_group_owned_repo(self, group_id, repo_id, org_id=None):
Expand Down

0 comments on commit cc70721

Please sign in to comment.