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

st2api encrypt of £ (and other utf-8 chars) fails with python stacktrace #4513

Closed
dswebbthg opened this issue Jan 23, 2019 · 3 comments · Fixed by #4528
Closed

st2api encrypt of £ (and other utf-8 chars) fails with python stacktrace #4513

dswebbthg opened this issue Jan 23, 2019 · 3 comments · Fixed by #4528
Labels
Milestone

Comments

@dswebbthg
Copy link
Contributor

SUMMARY

Provide a quick summary of your bug or feature request.

ISSUE TYPE

Pick one below and delete the rest:

  • Bug Report
STACKSTORM VERSION

Paste the output of st2 --version:
root@stackstorm-ha-st2client-68fdcb57f-xnxkv:/opt/stackstorm# st2 --version
st2 3.0dev (9577ff9), on Python 3.6.7

OS / ENVIRONMENT / INSTALL METHOD

kubernetes using ubuntu 18.04 using helm

STEPS TO REPRODUCE

root@stackstorm-ha-st2client-68fdcb57f-xnxkv:/opt/stackstorm# st2 key set --scope=system --encrypt test '£'
ERROR: 400 Client Error: Bad Request
MESSAGE: The length of the provided data is not a multiple of the block length. for url: http://stackstorm-ha-st2api:9101/keys/test

During handling of the above exception, another exception occurred:

error log from the st2api container

2019-01-23 16:06:14,301 ERROR [-] Failed to call controller function "put" for operation "st2api.controllers.v1.keyvalue:key_value_pair_controller.put": The length of the provided data is not a multiple of the block length.
Traceback (most recent call last):
File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2api/controllers/v1/keyvalue.py", line 301, in put
kvp_db = KeyValuePairAPI.to_model(kvp)
File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/models/api/keyvalue.py", line 175, in to_model
value = symmetric_encrypt(KeyValuePairAPI.crypto_key, value)
File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/crypto.py", line 186, in symmetric_encrypt
return cryptography_symmetric_encrypt(encrypt_key=encrypt_key, plaintext=plaintext)
File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/crypto.py", line 237, in cryptography_symmetric_encrypt
ciphertext_bytes = encryptor.update(data) + encryptor.finalize()
File "/opt/stackstorm/st2/lib/python3.6/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 159, in finalize
data = self._ctx.finalize()
File "/opt/stackstorm/st2/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 173, in finalize
"The length of the provided data is not a multiple of "
ValueError: The length of the provided data is not a multiple of the block length.

EXPECTED RESULTS

we should be able to encrypt the £ sign

ACTUAL RESULTS

http 400 and a python stacktrace on the api

@dswebbthg
Copy link
Contributor Author

make that utf-8 special characters

@dswebbthg dswebbthg changed the title st2api encrypt of £ fails with python stacktrace st2api encrypt of £ (and other utf-8 chars) fails with python stacktrace Jan 23, 2019
nickbaum added a commit to nickbaum/st2 that referenced this issue Jan 30, 2019
WARNING: I'm no crypto expert, so please review with care.

I ran into this same issue when trying to encrypt utf-8 text:

StackStorm#4513

I believe the problem is that the plaintext is padded before it's encoded, and the encoding changes the length of the data.

Moving the encoding before the padding seems to resolve the issue.
@nickbaum
Copy link

Update: the tests failed for that pull request, I added a comment describing the issue but don't have a solution yet.

@Kami
Copy link
Member

Kami commented Jan 31, 2019

Thanks for reporting this issue and sorry for the delay.

We will have a look as soon as we get a chance.

Kami added a commit that referenced this issue Jan 31, 2019
handle unicode (utf-8) data.

Previously we didn't correctly convert string to bytes before padding
data which resulted in incorrectly padded data (incorrect length) so the
actual encryption step failed.

Thanks to @dswebbthg for reporting this issue.

Resolves #4513.
@Kami Kami closed this as completed in #4528 Feb 1, 2019
@Kami Kami added this to the 2.10.2 milestone Feb 1, 2019
Kami added a commit that referenced this issue Feb 18, 2019
handle unicode (utf-8) data.

Previously we didn't correctly convert string to bytes before padding
data which resulted in incorrectly padded data (incorrect length) so the
actual encryption step failed.

Thanks to @dswebbthg for reporting this issue.

Resolves #4513.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants