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