Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Decrypt input secrets if there are some#45

Merged
drobnikj merged 10 commits into
masterapify/apify-sdk-python:masterfrom
feat/secret_input_supportapify/apify-sdk-python:feat/secret_input_supportCopy head branch name to clipboard
Feb 3, 2023
Merged

feat: Decrypt input secrets if there are some#45
drobnikj merged 10 commits into
masterapify/apify-sdk-python:masterfrom
feat/secret_input_supportapify/apify-sdk-python:feat/secret_input_supportCopy head branch name to clipboard

Conversation

@drobnikj

@drobnikj drobnikj commented Feb 1, 2023

Copy link
Copy Markdown
Member

@github-actions github-actions Bot added this to the 56th sprint - Platform team milestone Feb 1, 2023
@github-actions github-actions Bot added the t-core-services Issues with this label are in the ownership of the core services team. label Feb 1, 2023

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Pull Request Tookit has failed!

Pull request is neither linked to an issue or epic nor labeled as adhoc!

@fnesveda fnesveda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

I just had some suggestions about the function signatures, and I found some typos.

Comment thread tests/unit/test_crypto.py Outdated
Comment thread tests/unit/test_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
Comment thread src/apify/_crypto.py Outdated
@drobnikj

drobnikj commented Feb 1, 2023

Copy link
Copy Markdown
Member Author

Yeah, I really need a spell checker in my vs code 😄 sorry about that.

Co-authored-by: František Nesveda <fnesveda@users.noreply.github.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Pull Request Tookit has failed!

Pull request is neither linked to an issue or epic nor labeled as adhoc!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Pull Request Tookit has failed!

Pull request is neither linked to an issue or epic nor labeled as adhoc!

@drobnikj
drobnikj requested a review from fnesveda February 1, 2023 17:04
Comment thread src/apify/actor.py Outdated
Comment thread src/apify/actor.py Outdated
Comment thread src/apify/consts.py
Comment thread src/apify/_utils.py Outdated
Comment thread src/apify/_crypto.py
password_bytes,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA1()),
algorithm=hashes.SHA1(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHA-1 is a deprecated hash algorithm that has practical known collision attacks. You are strongly discouraged from using it. Existing applications should strongly consider moving away.

https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#cryptography.hazmat.primitives.hashes.SHA1

@drobnikj drobnikj Feb 2, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it is deprecated for the encryption, but in this case, we are using sha1 for padding and it is not the issue. In short, sha1 is there used for generating a hash which fills the block of the message for encryption. It is quite complex stuff, but the message itself together with the hash is then encrypted using the public key(RSA). There is a nice picture and explanation of how OAEP works.
The sha1 is used to This combination(MGF1 + SHA1 for padding) for RSA encryption OAEP (RSA_PKCS1_OAEP_PADDING) is recommended by open SSL, and it is used for example in node js by default. As it is used in node js by default.

Comment thread src/apify/_crypto.py
password_bytes = key_bytes + initialized_vector_bytes

# NOTE: Auth Tag is appended to the end of the encrypted data, it has length of 16 bytes and ensures integrity of the data.
cipher = Cipher(algorithms.AES(key_bytes), modes.GCM(initialized_vector_bytes, min_tag_length=ENCRYPTION_AUTH_TAG_LENGTH))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min_tag_length (int) – The minimum length tag must be. By default this is 16, meaning tag truncation is not allowed. Allowing tag truncation is strongly discouraged for most applications.

min_tag_length is 16 by default, why override with 16?

@drobnikj drobnikj Feb 2, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure that default will change the decryption still work. We are strictly setting tag to 16 chars in length same as in node js version of this method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, fair enough

Comment thread src/apify/_crypto.py
label=None,
),
)
return {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you .decode('utf-8') here? Do you need the values as strings or?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I need the value as a string. The function is aligned with the same one from JS for better accountability. Basically, we didn't use this function in python yet. The function is there mainly for testing and maybe for the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread src/apify/_crypto.py
Returns:
str: Decrypted value.
"""
encrypted_password_bytes = base64.b64decode(encrypted_password.encode('utf-8'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you didn't decode in encrypt, you can omit encode here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true. But the encrypted secret(password and value) is stored in input JSON, and the base64 string is better for handling as it has a subset of characters and we can easily match it.

Comment thread src/apify/_crypto.py
@drobnikj
drobnikj requested a review from jirimoravcik February 2, 2023 09:17
@drobnikj
drobnikj merged commit 6eb1630 into master Feb 3, 2023
@drobnikj
drobnikj deleted the feat/secret_input_support branch February 3, 2023 09:23
@fnesveda fnesveda added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-core-services Issues with this label are in the ownership of the core services team. validated Issues that are resolved and their solutions fulfill the acceptance criteria.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.