1524bc
From 3c64a236dfecbe396766ec0e8d326443358d4ab3 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Mon, 4 Nov 2019 17:01:50 +0100
1524bc
Subject: [PATCH 192/208] lib:crypto: Add samba_gnutls_weak_crypto()
1524bc
1524bc
Signed-off-by: Andreas Schneider <asn@samba.org>
1524bc
---
1524bc
 lib/crypto/gnutls_helpers.h     |  7 +++++
1524bc
 lib/crypto/gnutls_weak_crypto.c | 48 +++++++++++++++++++++++++++++++++
1524bc
 lib/crypto/wscript_build        |  1 +
1524bc
 3 files changed, 56 insertions(+)
1524bc
 create mode 100644 lib/crypto/gnutls_weak_crypto.c
1524bc
1524bc
diff --git a/lib/crypto/gnutls_helpers.h b/lib/crypto/gnutls_helpers.h
1524bc
index d6000c7b316..a985c028e9d 100644
1524bc
--- a/lib/crypto/gnutls_helpers.h
1524bc
+++ b/lib/crypto/gnutls_helpers.h
1524bc
@@ -92,4 +92,11 @@ int samba_gnutls_arcfour_confounded_md5(const DATA_BLOB *key_input1,
1524bc
 					DATA_BLOB *data,
1524bc
 					enum samba_gnutls_direction encrypt);
1524bc
 
1524bc
+/**
1524bc
+ * @brief Check if weak crypto is allowed.
1524bc
+ *
1524bc
+ * @return true if weak crypo is allowed, false otherwise.
1524bc
+ */
1524bc
+bool samba_gnutls_weak_crypto_allowed(void);
1524bc
+
1524bc
 #endif /* _GNUTLS_HELPERS_H */
1524bc
diff --git a/lib/crypto/gnutls_weak_crypto.c b/lib/crypto/gnutls_weak_crypto.c
1524bc
new file mode 100644
1524bc
index 00000000000..68ce588243f
1524bc
--- /dev/null
1524bc
+++ b/lib/crypto/gnutls_weak_crypto.c
1524bc
@@ -0,0 +1,48 @@
1524bc
+/*
1524bc
+ * Copyright (c) 2019      Andreas Schneider <asn@samba.org>
1524bc
+ *
1524bc
+ * This program is free software: you can redistribute it and/or modify
1524bc
+ * it under the terms of the GNU General Public License as published by
1524bc
+ * the Free Software Foundation, either version 3 of the License, or
1524bc
+ * (at your option) any later version.
1524bc
+ *
1524bc
+ * This program is distributed in the hope that it will be useful,
1524bc
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1524bc
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1524bc
+ * GNU General Public License for more details.
1524bc
+ *
1524bc
+ * You should have received a copy of the GNU General Public License
1524bc
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
1524bc
+ */
1524bc
+
1524bc
+#include "includes.h"
1524bc
+#include "lib/crypto/gnutls_helpers.h"
1524bc
+
1524bc
+#include <gnutls/crypto.h>
1524bc
+#include <gnutls/gnutls.h>
1524bc
+
1524bc
+bool samba_gnutls_weak_crypto_allowed(void)
1524bc
+{
1524bc
+	gnutls_cipher_hd_t cipher_hnd = NULL;
1524bc
+	gnutls_datum_t key = {
1524bc
+		.data = discard_const_p(unsigned char, "SystemLibraryDTC"),
1524bc
+		.size = 16,
1524bc
+	};
1524bc
+	int rc;
1524bc
+
1524bc
+	/*
1524bc
+	 * If RC4 is not allowed to be initialzed then weak crypto is not
1524bc
+	 * allowed.
1524bc
+	 */
1524bc
+	rc = gnutls_cipher_init(&cipher_hnd,
1524bc
+				GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+				&key,
1524bc
+				NULL);
1524bc
+	if (rc == GNUTLS_E_UNWANTED_ALGORITHM) {
1524bc
+		return false;
1524bc
+	}
1524bc
+
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
+
1524bc
+	return true;
1524bc
+}
1524bc
diff --git a/lib/crypto/wscript_build b/lib/crypto/wscript_build
1524bc
index eb67af63f26..e5766042541 100644
1524bc
--- a/lib/crypto/wscript_build
1524bc
+++ b/lib/crypto/wscript_build
1524bc
@@ -10,6 +10,7 @@ bld.SAMBA_SUBSYSTEM('GNUTLS_HELPERS',
1524bc
                     source='''
1524bc
                     gnutls_error.c
1524bc
                     gnutls_arcfour_confounded_md5.c
1524bc
+                    gnutls_weak_crypto.c
1524bc
                     ''',
1524bc
                     deps='gnutls samba-errors');
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc