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