|
|
527d9a |
From 3914106b613ad4f5f27a2d1b3fc8fc2efb41dec6 Mon Sep 17 00:00:00 2001
|
|
|
527d9a |
From: Alex Gaynor <alex.gaynor@gmail.com>
|
|
|
527d9a |
Date: Tue, 31 Jan 2023 08:33:54 -0500
|
|
|
527d9a |
Subject: [PATCH] Don't allow update_into to mutate immutable objects
|
|
|
527d9a |
|
|
|
527d9a |
---
|
|
|
527d9a |
src/cryptography/hazmat/backends/openssl/ciphers.py | 2 +-
|
|
|
527d9a |
tests/hazmat/primitives/test_ciphers.py | 8 ++++++++
|
|
|
527d9a |
2 files changed, 9 insertions(+), 1 deletion(-)
|
|
|
527d9a |
|
|
|
527d9a |
diff --git a/src/cryptography/hazmat/backends/openssl/ciphers.py b/src/cryptography/hazmat/backends/openssl/ciphers.py
|
|
|
527d9a |
index 1058de9..17abd3a 100644
|
|
|
527d9a |
--- a/src/cryptography/hazmat/backends/openssl/ciphers.py
|
|
|
527d9a |
+++ b/src/cryptography/hazmat/backends/openssl/ciphers.py
|
|
|
527d9a |
@@ -157,7 +157,7 @@ class _CipherContext:
|
|
|
527d9a |
data_processed = 0
|
|
|
527d9a |
total_out = 0
|
|
|
527d9a |
outlen = self._backend._ffi.new("int *")
|
|
|
527d9a |
- baseoutbuf = self._backend._ffi.from_buffer(buf)
|
|
|
527d9a |
+ baseoutbuf = self._backend._ffi.from_buffer(buf, require_writable=True)
|
|
|
527d9a |
baseinbuf = self._backend._ffi.from_buffer(data)
|
|
|
527d9a |
|
|
|
527d9a |
while data_processed != total_data_len:
|
|
|
527d9a |
diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py
|
|
|
527d9a |
index 02127dd..bf3b047 100644
|
|
|
527d9a |
--- a/tests/hazmat/primitives/test_ciphers.py
|
|
|
527d9a |
+++ b/tests/hazmat/primitives/test_ciphers.py
|
|
|
527d9a |
@@ -318,6 +318,14 @@ class TestCipherUpdateInto:
|
|
|
527d9a |
with pytest.raises(ValueError):
|
|
|
527d9a |
encryptor.update_into(b"testing", buf)
|
|
|
527d9a |
|
|
|
527d9a |
+ def test_update_into_immutable(self, backend):
|
|
|
527d9a |
+ key = b"\x00" * 16
|
|
|
527d9a |
+ c = ciphers.Cipher(AES(key), modes.ECB(), backend)
|
|
|
527d9a |
+ encryptor = c.encryptor()
|
|
|
527d9a |
+ buf = b"\x00" * 32
|
|
|
527d9a |
+ with pytest.raises((TypeError, BufferError)):
|
|
|
527d9a |
+ encryptor.update_into(b"testing", buf)
|
|
|
527d9a |
+
|
|
|
527d9a |
@pytest.mark.supported(
|
|
|
527d9a |
only_if=lambda backend: backend.cipher_supported(
|
|
|
527d9a |
AES(b"\x00" * 16), modes.GCM(b"\x00" * 12)
|
|
|
527d9a |
--
|
|
|
527d9a |
2.39.1
|
|
|
527d9a |
|