Skip to contentSkip to conversation

Make NTLMv2 as auth mech within NTLMSSP and enable signing using crypto shash APIs

PATCH New [email protected] 1 participant 1 message Aug 5, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make NTLMv2 as auth mech within NTLMSSP and enable signing using crypto shash APIs

Make ntlmv2 as an authentication mechanism within ntlmssp instead of ntlmv1.
Parse type 2 response in ntlmssp negotiation to pluck AV pairs and use them to calculate ntlmv2 response token. Also, assign domain name from the sever response in type 2 packet of ntlmssp and use that (netbios) domain name in calculation of response.

Enable cifs/smb signing using rc4 and hmac-sha256.

Changed name of the structure mac_key to session_key to reflect the type of key it holds.

Use kernel crypto_shash_* APIs instead of the equivalent cifs functions.

Quoted 1 line

From 42320e9889118b93bb747859b5d47af0803da378 Mon Sep 17 00:00:00 2001

From: Shirish Pargaonkar <[email protected]>
Date: Wed, 4 Aug 2010 22:58:42 -0500
Subject: [PATCH] Make ntlmv2 as auth mech and enable signing using crypto_shash APIs

---
 fs/smb2/connect.c     |   11 ++-
 fs/smb2/ntlmssp.c     |  154 ++++++++++++-------
 fs/smb2/ntlmssp.h     |   13 ++
 fs/smb2/smb2encrypt.c |  418 +++++++++++++++++++++++++++++++++----------------
 fs/smb2/smb2glob.h    |   20 ++-
 fs/smb2/smb2pdu.c     |    2 +-
 fs/smb2/smb2pdu.h     |   16 ++-
 fs/smb2/smb2proto.h   |   11 +-
 fs/smb2/transport.c   |    6 +-
 9 files changed, 442 insertions(+), 209 deletions(-)
fs/smb2/connect.c +10 -1
index 97909a0..f515fee 100644
@@ -430,6 +430,7 @@ smb2_put_smb_ses(struct smb2_ses *ses)
 		SMB2_logoff(xid, ses);
 		_free_xid2(xid);
 	}
+	smb2_crypto_hash_release(server);
 	smb2_ses_info_free(ses);
 	smb2_put_tcp_session(server);
 }
@@ -1606,12 +1607,20 @@ smb2_mount(struct super_block *sb, struct smb2_sb_info *smb2_sb,
 			pSMB2_ses = NULL;
 			goto mount_out;
 		}
+		rc = smb2_crypto_hash_allocate(pSMB2_ses->server);
+		if (rc) {
+			sERROR(1, "could not setup hash structures rc %d", rc);
+			goto mount_out;
+		}
+
 		down(&pSMB2_ses->ses_sem);
 		rc = smb2_setup_session(xid, pSMB2_ses,
 				smb2_sb->local_nls);
 		up(&pSMB2_ses->ses_sem);
-		if (rc)
+		if (rc) {
+			smb2_crypto_hash_release(pSMB2_ses->server);
 			goto mount_out;
+		}
 	}
 
 	sFYI(1, "about to search for tcon matching %s", vol_info->UNC);
fs/smb2/ntlmssp.c +99 -55

205 lines not on this page · raw message

fs/smb2/ntlmssp.h +13 -0
index 22db991..97c040c 100644
@@ -70,6 +70,19 @@
 /* OpenGroup and to make the code more closely match the standard in */
 /* appearance */
 
+/* Define AV Pair Field IDs */
+#define NTLMSSP_AV_EOL			0
+#define NTLMSSP_AV_NB_COMPUTER_NAME	1
+#define NTLMSSP_AV_NB_DOMAIN_NAME	2
+#define NTLMSSP_AV_DNS_COMPUTER_NAME	3
+#define NTLMSSP_AV_DNS_DOMAIN_NAME	4
+#define NTLMSSP_AV_DNS_TREE_NAME	5
+#define NTLMSSP_AV_FLAGS		6
+#define NTLMSSP_AV_TIMESTAMP		7
+#define NTLMSSP_AV_RESTRICTION		8
+#define NTLMSSP_AV_TARGET_NAME		9
+#define NTLMSSP_AV_CHANNEL_BINDINGS	10
+
 typedef struct _SECURITY_BUFFER {
 	__le16 Length;
 	__le16 MaximumLength;
fs/smb2/smb2encrypt.c +282 -136

547 lines not on this page · raw message

fs/smb2/smb2glob.h +17 -3
index ec39583..a53bc07 100644
@@ -23,6 +23,9 @@
 #include <linux/slow-work.h>
 #include "smb2_fs_sb.h"
 #include "smb2acl.h"
+#include <crypto/internal/hash.h>
+#include <linux/scatterlist.h>
+
 /*
  * The sizes of various internal tables and strings
  */
@@ -81,13 +84,13 @@ enum protocol_enum {
  */
 #define SMB2_SESS_KEY_SIZE (24)
 
-struct mac_key {
+struct session_key {
 	unsigned int len;
 	union {
 		char ntlm[SMB2_SESS_KEY_SIZE + 16];
 		char krb5[SMB2_SESS_KEY_SIZE + 16]; /* BB: length correct? */
 		struct {
-			char key[16];
+			unsigned char key[16];
 			struct ntlmv2_resp resp;
 		} ntlmv2;
 	} data;
@@ -104,6 +107,14 @@ struct smb2_cred {
 	struct smb2_ace *aces;
 };
 
+struct ntlmssp_auth {
+	__u32 client_flags;
+	__u32 server_flags;
+	unsigned char ciphertext[SMB2_CPHTXT_SIZE];
+	struct crypto_shash *hmacsha256;
+	struct crypto_shash *hmacmd5;
+};
+
 /*
  *****************************************************************
  * Except the SMB2 PDUs themselves all the
@@ -164,9 +175,12 @@ struct tcp_srv_inf {
 	int time_adj;  /* Adjust for difference in server time zone in sec */
 	__u64 current_mid;         /* multiplex id - rotating counter */
 	char crypt_key[SMB2_CRYPTO_KEY_SIZE];
+	unsigned int tilen; /* length of the target info blob */
+	unsigned char *tiblob; /* target info blob in challenge response */
 	/* 16th byte of RFC1001 workstation name is always null */
 	char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
-	struct mac_key mac_signing_key;
+	struct session_key session_key;
+	struct ntlmssp_auth ntlmssp;
 	char ntlmv2_hash[16];
 	unsigned long lstrp; /* when we got last response from this server */
 };
fs/smb2/smb2pdu.c +1 -1
index 6640446..87c23af 100644
@@ -745,7 +745,7 @@ ssetup_ntlmssp_authenticate:
 		}
 	} else if (phase == NtLmAuthenticate) {
 		pSMB2->hdr.SessionId = ses->suid;
-		ntlmssp_blob = kmalloc(sizeof(struct _NEGOTIATE_MESSAGE) + 500,
+		ntlmssp_blob = kmalloc(5 * sizeof(struct _AUTHENTICATE_MESSAGE),
 					GFP_KERNEL);
 		blob_length = build_ntlmssp_auth_blob(ntlmssp_blob, ses,
 						      nls_cp);
fs/smb2/smb2pdu.h +13 -3
index 8ca4206..965f4f0 100644
@@ -723,6 +723,18 @@ struct ioctl_rsp {
  */
 #define SMB2_CRYPTO_KEY_SIZE (8)
 
+#define SMB2_SESS_KEY_SIZE (24)
+#define SMB2_CLIENT_CHALLENGE_SIZE (8)
+#define SMB2_SERVER_CHALLENGE_SIZE (8)
+#define SMB2_HMAC_MD5_HASH_SIZE (16)
+#define SMB2_CPHTXT_SIZE (16)
+#define SMB2_NTLMV2_SESSKEY_SIZE (16)
+#define SMB2_NTHASH_SIZE (16)
+#define SMB2_SIGNATURE_SIZE (16)
+#define SMB2_HMACSHA256_SIZE (32)
+
+
+
 /* format of NLTMv2 Response ie "case sensitive password" hash when NTLMv2 */
 
 #define NTLMSSP_SERVER_TYPE	1
@@ -734,7 +746,7 @@ struct ioctl_rsp {
 struct ntlmssp2_name {
 	__le16 type;
 	__le16 length;
-/*	char   name[length]; */
+	unsigned char value[1];
 } __attribute__((packed));
 
 struct ntlmv2_resp {
@@ -744,8 +756,6 @@ struct ntlmv2_resp {
 	__le64  time;
 	__u64  client_chal; /* random */
 	__u32  reserved2;
-	struct ntlmssp2_name names[2];
-	/* array of name entries could follow ending in minimum 4 byte struct */
 } __attribute__((packed));
 
 
fs/smb2/smb2proto.h +5 -6
index e55a7d3..1ad4265 100644
@@ -76,8 +76,7 @@ extern int smb2_sendrcv_blocking(const unsigned int xid, struct smb2_tcon *tcon,
 			struct smb2_hdr *out_buf,
 			int *pbytes_returned);
 extern int sign_smb2(struct kvec *iov, int n_vec, struct tcp_srv_inf *);
-extern int smb2_verify_signature(struct smb2_hdr *,
-				 const struct mac_key *mac_key);
+extern int smb2_verify_signature(struct smb2_hdr *, struct tcp_srv_inf *);
 extern int smb2_demultiplex_thread(struct tcp_srv_inf *server);
 extern int smb2_reconnect(struct tcp_srv_inf *server);
 extern int smb2_setup_session(unsigned int xid, struct smb2_ses *pses_info,
@@ -132,11 +131,11 @@ extern int build_spnego_ntlmssp_blob(char **security_blob, int ntlmssp_blob_len,
 				     char *ntlmssp_blob);
 extern void SMB2encrypt(unsigned char *passwd, const unsigned char *c8,
 			unsigned char *p24, const struct nls_table *cp);
-extern int smb2_calculate_mac_key(struct mac_key *key, const char *rn,
-				  const char *password,
-				  const struct nls_table *cp);
-void smb2_setup_ntlmv2_rsp(struct smb2_ses *ses, char *resp_buf,
+extern int smb2_setup_ntlmv2_rsp(struct smb2_ses *ses, char *resp_buf,
 			   const struct nls_table *nls_cp);
+extern int calc_seckey(struct tcp_srv_inf *);
+extern int smb2_crypto_hash_allocate(struct tcp_srv_inf *);
+extern void  smb2_crypto_hash_release(struct tcp_srv_inf *);
 /* smb2des.c */
 extern void smb2_E_P16(unsigned char *p14, unsigned char *p16);
 extern void smb2_E_P24(unsigned char *p21, const unsigned char *c8,
fs/smb2/transport.c +2 -4
index fc8af87..8e25a2e 100644
@@ -670,8 +670,7 @@ pending_loop:
 
 	if ((receive_len > 24) &&
 	    (ses->server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED)) {
-		rc = smb2_verify_signature(out_buf,
-					   &ses->server->mac_signing_key);
+		rc = smb2_verify_signature(out_buf, ses->server);
 		if (rc)
 			sERROR(1, "Unexpected SMB2 signature");
 	}
@@ -856,8 +855,7 @@ smb2_sendrcv2(const unsigned int xid, struct smb2_ses *ses,
 		/* convert the length into a more usable form */
 		if ((receive_len > 24) &&
 		    (ses->server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED)) {
-			rc = smb2_verify_signature(midq->resp_buf,
-						&ses->server->mac_signing_key);
+			rc = smb2_verify_signature(midq->resp_buf, ses->server);
 			if (rc) {
 				sERROR(1, "Unexpected SMB signature");
 				/* BB FIXME add code to kill session */
Signature · 1 line
1.6.0.2