summaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2019-03-18 16:24:54 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-08-21 09:57:30 +0000
commit025f6a135f930264ddcf1cd1b9e1004464618194 (patch)
tree508f9dfda2580015bf0e609232b2caf94fc60cb3 /auth
parent3b27fd8a490f29cbc94b8ac377b3a2cb6db7598c (diff)
downloadsamba-025f6a135f930264ddcf1cd1b9e1004464618194.tar.gz
auth:gensec: Use GnuTLS AES CFB8 in netsec_do_seal()
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'auth')
-rw-r--r--auth/gensec/schannel.c95
1 files changed, 94 insertions, 1 deletions
diff --git a/auth/gensec/schannel.c b/auth/gensec/schannel.c
index 78d559b803d..18e2ed6cd36 100644
--- a/auth/gensec/schannel.c
+++ b/auth/gensec/schannel.c
@@ -33,9 +33,12 @@
#include "librpc/gen_ndr/dcerpc.h"
#include "param/param.h"
#include "auth/gensec/gensec_toplevel_proto.h"
-#include "lib/crypto/aes.h"
#include "libds/common/roles.h"
+#ifndef HAVE_GNUTLS_AES_CFB8
+#include "lib/crypto/aes.h"
+#endif
+
#include "lib/crypto/gnutls_helpers.h"
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
@@ -258,6 +261,95 @@ static NTSTATUS netsec_do_seal(struct schannel_state *state,
bool forward)
{
if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
+#ifdef HAVE_GNUTLS_AES_CFB8
+ gnutls_cipher_hd_t cipher_hnd = NULL;
+ uint8_t sess_kf0[16] = {0};
+ gnutls_datum_t key = {
+ .data = sess_kf0,
+ .size = sizeof(sess_kf0),
+ };
+ uint32_t iv_size =
+ gnutls_cipher_get_iv_size(GNUTLS_CIPHER_AES_128_CFB8);
+ uint8_t _iv[iv_size];
+ gnutls_datum_t iv = {
+ .data = _iv,
+ .size = iv_size,
+ };
+ uint32_t i;
+ int rc;
+
+ for (i = 0; i < key.size; i++) {
+ key.data[i] = state->creds->session_key[i] ^ 0xf0;
+ }
+
+ ZERO_ARRAY(_iv);
+
+ memcpy(iv.data + 0, seq_num, 8);
+ memcpy(iv.data + 8, seq_num, 8);
+
+ rc = gnutls_cipher_init(&cipher_hnd,
+ GNUTLS_CIPHER_AES_128_CFB8,
+ &key,
+ &iv);
+ if (rc < 0) {
+ DBG_ERR("ERROR: gnutls_cipher_init: %s\n",
+ gnutls_strerror(rc));
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (forward) {
+ rc = gnutls_cipher_encrypt(cipher_hnd,
+ confounder,
+ 8);
+ if (rc < 0) {
+ DBG_ERR("ERROR: gnutls_cipher_encrypt: %s\n",
+ gnutls_strerror(errno));
+ gnutls_cipher_deinit(cipher_hnd);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ /*
+ * Looks like we have to reuse the initial IV which is
+ * cryptographically wrong!
+ */
+ gnutls_cipher_set_iv(cipher_hnd, iv.data, iv.size);
+ rc = gnutls_cipher_encrypt(cipher_hnd,
+ data,
+ length);
+ if (rc < 0) {
+ DBG_ERR("ERROR: gnutls_cipher_encrypt: %s\n",
+ gnutls_strerror(errno));
+ gnutls_cipher_deinit(cipher_hnd);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ } else {
+ rc = gnutls_cipher_decrypt(cipher_hnd,
+ confounder,
+ 8);
+ if (rc < 0) {
+ DBG_ERR("ERROR: gnutls_cipher_decrypt: %s\n",
+ gnutls_strerror(errno));
+ gnutls_cipher_deinit(cipher_hnd);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ /*
+ * Looks like we have to reuse the initial IV which is
+ * cryptographically wrong!
+ */
+ gnutls_cipher_set_iv(cipher_hnd, iv.data, iv.size);
+ rc = gnutls_cipher_decrypt(cipher_hnd,
+ data,
+ length);
+ if (rc < 0) {
+ DBG_ERR("ERROR: gnutls_cipher_decrypt: %s\n",
+ gnutls_strerror(errno));
+ gnutls_cipher_deinit(cipher_hnd);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ }
+ gnutls_cipher_deinit(cipher_hnd);
+#else /* NOT HAVE_GNUTLS_AES_CFB8 */
AES_KEY key;
uint8_t iv[AES_BLOCK_SIZE];
uint8_t sess_kf0[16];
@@ -279,6 +371,7 @@ static NTSTATUS netsec_do_seal(struct schannel_state *state,
aes_cfb8_encrypt(confounder, confounder, 8, &key, iv, AES_DECRYPT);
aes_cfb8_encrypt(data, data, length, &key, iv, AES_DECRYPT);
}
+#endif /* HAVE_GNUTLS_AES_CFB8 */
} else {
gnutls_cipher_hd_t cipher_hnd;
uint8_t _sealing_key[16];