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

feat: Decrypt input secrets if there are some #45

Merged
merged 10 commits into from
Feb 3, 2023

Conversation

drobnikj
Copy link
Member

@drobnikj drobnikj commented Feb 1, 2023

@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-platform Issues with this label are in the ownership of the platform team. label Feb 1, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

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!

Copy link
Member

@fnesveda fnesveda left a comment

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.

tests/unit/test_crypto.py Outdated Show resolved Hide resolved
tests/unit/test_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
src/apify/_crypto.py Outdated Show resolved Hide resolved
@drobnikj
Copy link
Member Author

drobnikj commented Feb 1, 2023

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

Co-authored-by: František Nesveda <[email protected]>
Copy link
Contributor

@github-actions github-actions bot left a comment

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!

Copy link
Contributor

@github-actions github-actions bot left a comment

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
src/apify/actor.py Outdated Show resolved Hide resolved
src/apify/actor.py Outdated Show resolved Hide resolved
src/apify/consts.py Show resolved Hide resolved
src/apify/_utils.py Outdated Show resolved Hide resolved
password_bytes,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA1()),
algorithm=hashes.SHA1(),
Copy link
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

Copy link
Member Author

@drobnikj drobnikj Feb 2, 2023

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.

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
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?

Copy link
Member Author

@drobnikj drobnikj Feb 2, 2023

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
Member

Choose a reason for hiding this comment

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

ok, fair enough

label=None,
),
)
return {
Copy link
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
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
Member

Choose a reason for hiding this comment

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

ok

Returns:
str: Decrypted value.
"""
encrypted_password_bytes = base64.b64decode(encrypted_password.encode('utf-8'))
Copy link
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
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.

src/apify/_crypto.py Show resolved Hide resolved
@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-platform Issues with this label are in the ownership of the platform 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