92 lines
2.6 KiB
Diff
92 lines
2.6 KiB
Diff
From f20d681243aed9c4e2c1a669cb04964b380413f3 Mon Sep 17 00:00:00 2001
|
|
From: Andreas Schneider <asn@samba.org>
|
|
Date: Fri, 22 Feb 2019 12:59:13 +0100
|
|
Subject: [PATCH 056/187] lib:crypto: Use GnuTLS RC4 in py_crypto
|
|
|
|
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
|
|
(cherry picked from commit fc4ae06001fbb0045318a8cec7af6af81241c60e)
|
|
---
|
|
lib/crypto/py_crypto.c | 34 +++++++++++++++++++++++++++++-----
|
|
lib/crypto/wscript_build | 7 +++----
|
|
2 files changed, 32 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/lib/crypto/py_crypto.c b/lib/crypto/py_crypto.c
|
|
index 13e2569945d..c85cd2c13d2 100644
|
|
--- a/lib/crypto/py_crypto.c
|
|
+++ b/lib/crypto/py_crypto.c
|
|
@@ -21,13 +21,18 @@
|
|
#include <Python.h>
|
|
#include "includes.h"
|
|
#include "python/py3compat.h"
|
|
-#include "lib/crypto/arcfour.h"
|
|
+
|
|
+#include <gnutls/gnutls.h>
|
|
+#include <gnutls/crypto.h>
|
|
|
|
static PyObject *py_crypto_arcfour_crypt_blob(PyObject *module, PyObject *args)
|
|
{
|
|
- DATA_BLOB data, key;
|
|
+ DATA_BLOB data;
|
|
PyObject *py_data, *py_key, *result;
|
|
TALLOC_CTX *ctx;
|
|
+ gnutls_cipher_hd_t cipher_hnd = NULL;
|
|
+ gnutls_datum_t key;
|
|
+ int rc;
|
|
|
|
if (!PyArg_ParseTuple(args, "OO", &py_data, &py_key))
|
|
return NULL;
|
|
@@ -51,10 +56,29 @@ static PyObject *py_crypto_arcfour_crypt_blob(PyObject *module, PyObject *args)
|
|
return PyErr_NoMemory();
|
|
}
|
|
|
|
- key.data = (uint8_t *)PyBytes_AsString(py_key);
|
|
- key.length = PyBytes_Size(py_key);
|
|
+ key = (gnutls_datum_t) {
|
|
+ .data = (uint8_t *)PyBytes_AsString(py_key),
|
|
+ .size = PyBytes_Size(py_key),
|
|
+ };
|
|
|
|
- arcfour_crypt_blob(data.data, data.length, &key);
|
|
+ rc = gnutls_cipher_init(&cipher_hnd,
|
|
+ GNUTLS_CIPHER_ARCFOUR_128,
|
|
+ &key,
|
|
+ NULL);
|
|
+ if (rc < 0) {
|
|
+ talloc_free(ctx);
|
|
+ PyErr_Format(PyExc_OSError, "encryption failed");
|
|
+ return NULL;
|
|
+ }
|
|
+ rc = gnutls_cipher_encrypt(cipher_hnd,
|
|
+ data.data,
|
|
+ data.length);
|
|
+ gnutls_cipher_deinit(cipher_hnd);
|
|
+ if (rc < 0) {
|
|
+ talloc_free(ctx);
|
|
+ PyErr_Format(PyExc_OSError, "encryption failed");
|
|
+ return NULL;
|
|
+ }
|
|
|
|
result = PyBytes_FromStringAndSize((const char*) data.data, data.length);
|
|
talloc_free(ctx);
|
|
diff --git a/lib/crypto/wscript_build b/lib/crypto/wscript_build
|
|
index 2ad8dfe2cd0..46b0e084328 100644
|
|
--- a/lib/crypto/wscript_build
|
|
+++ b/lib/crypto/wscript_build
|
|
@@ -28,7 +28,6 @@ bld.SAMBA_SUBSYSTEM('TORTURE_LIBCRYPTO',
|
|
)
|
|
|
|
bld.SAMBA_PYTHON('python_crypto',
|
|
- source='py_crypto.c',
|
|
- deps='LIBCRYPTO',
|
|
- realname='samba/crypto.so'
|
|
- )
|
|
+ source='py_crypto.c',
|
|
+ deps='gnutls talloc',
|
|
+ realname='samba/crypto.so')
|
|
--
|
|
2.23.0
|
|
|