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

Usage of insecure hash functions: sha1 and md5 #6665

Open
Tracked by #6620
rdimaio opened this issue Apr 10, 2024 · 2 comments
Open
Tracked by #6620

Usage of insecure hash functions: sha1 and md5 #6665

rdimaio opened this issue Apr 10, 2024 · 2 comments
Assignees

Comments

@rdimaio
Copy link
Contributor

rdimaio commented Apr 10, 2024

Description

The following insecure hash functions are currently in use within Rucio:

The linter log below lists the uses identified by the linter, but there are other instances as well. For example, get_auth_token_user_pass expects a SHA1 hash of the password:

def get_auth_token_user_pass(account, username, password, appid, ip=None, vo='def', *, session: "Session"):
"""
Authenticate a Rucio account temporarily via username and password.
The token lifetime is 1 hour.
:param account: Account identifier as a string.
:param username: Username as a string.
:param password: SHA1 hash of the password as a string.
:param appid: The application identifier as a string.
:param ip: IP address of the client as a string.
:param vo: The VO to act on.
:param session: The database session in use.
:returns: A dict with token and expires_at entries.
"""
kwargs = {'account': account, 'username': username, 'password': password}
if not permission.has_permission(issuer=account, vo=vo, action='get_auth_token_user_pass', kwargs=kwargs, session=session):
raise exception.AccessDenied('User with identity %s can not log to account %s' % (username, account))
account = InternalAccount(account, vo=vo)
return authentication.get_auth_token_user_pass(account, username, password, appid, ip, session=session)

To do

In each instance of sha1 and md5 usages:

Linter log

❯ ruff check --select S324                                                                                                                                                                                                                                                                                               ─╯
lib/rucio/common/dumper/data_models.py:175:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
lib/rucio/common/utils.py:303:16: S324 Probable use of insecure hash functions in `hashlib`: `md5`
lib/rucio/core/did.py:98:20: S324 Probable use of insecure hash functions in `hashlib`: `md5`
lib/rucio/core/oidc.py:131:11: S324 Probable use of insecure hash functions in `hashlib`: `md5`
lib/rucio/daemons/auditor/hdfs.py:58:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
lib/rucio/daemons/auditor/srmdumps.py:249:9: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
lib/rucio/daemons/c3po/c3po.py:220:48: S324 Probable use of insecure hash functions in `hashlib`: `md5`
lib/rucio/rse/protocols/protocol.py:114:16: S324 Probable use of insecure hash functions in `hashlib`: `md5`
Found 8 errors.

Also other cases - e.g. get_auth_token_user_pass.

See also

Steps to reproduce

N/A

Rucio Version

No response

Additional Information

No response

@bari12
Copy link
Member

bari12 commented Apr 17, 2024

The majority of these are just for the lfn2pfn methods, there it should be fine. The oidc one which shows up is something to check though.

@dchristidis
Copy link
Contributor

The oidc one which shows up is something to check though.

A hash function is used to simplify avoiding they key restrictions of either dogpile.cache or Memcached (we could have devised a function that removes or replaces unacceptable characters instead). The payload that is hashed cannot be affected by a user, whether directly or indirectly. Given that MD5 is less expensive for the CPU, I don’t see sufficient motivation to replace it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants