// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/backing-dev.h>
#include <linux/writeback.h>
#include <linux/uio.h>
#include <linux/xattr.h>
#include <crypto/hash.h>
#include <crypto/aead.h>
#include <linux/random.h>
#include <linux/scatterlist.h>
#include "auth.h"
#include "glob.h"
#include <linux/fips.h>
#include <crypto/des.h>
#include "server.h"
#include "smb_common.h"
#include "connection.h"
#include "mgmt/user_session.h"
#include "mgmt/user_config.h"
#include "crypto_ctx.h"
#include "transport_ipc.h"
#include "../common/arc4.h"
/*
* Fixed format data defining GSS header and fixed string
* "not_defined_in_RFC4178@please_ignore".
* So sec blob data in neg phase could be generated statically.
*/
static char NEGOTIATE_GSS_HEADER[AUTH_GSS_LENGTH] = {
#ifdef CONFIG_SMB_SERVER_KERBEROS5
0x60, 0x5e, 0x06, 0x06, 0x2b, 0x06, 0x01, 0x05,
0x05, 0x02, 0xa0, 0x54, 0x30, 0x52, 0xa0, 0x24,
0x30, 0x22, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x12, 0x01, 0x02, 0x02, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x82, 0xf7, 0x12, 0x01, 0x02, 0x02,
0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
0x37, 0x02, 0x02, 0x0a, 0xa3, 0x2a, 0x30, 0x28,
0xa0, 0x26, 0x1b, 0x24, 0x6e, 0x6f, 0x74, 0x5f,
0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x5f,
0x69, 0x6e, 0x5f, 0x52, 0x46, 0x43, 0x34, 0x31,
0x37, 0x38, 0x40, 0x70, 0x6c, 0x65, 0x61, 0x73,
0x65, 0x5f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65
#else
0x60, 0x48, 0x06, 0x06, 0x2b, 0x06, 0x01, 0x05,
0x05, 0x02, 0xa0, 0x3e, 0x30, 0x3c, 0xa0, 0x0e,
0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0x37, 0x02, 0x02, 0x0a, 0xa3, 0x2a,
0x30, 0x28, 0xa0, 0x26, 0x1b, 0x24, 0x6e, 0x6f,
0x74, 0x5f, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65,
0x64, 0x5f, 0x69, 0x6e, 0x5f, 0x52, 0x46, 0x43,
0x34, 0x31, 0x37, 0x38, 0x40, 0x70, 0x6c, 0x65,
0x61, 0x73, 0x65, 0x5f, 0x69, 0x67, 0x6e, 0x6f,
0x72, 0x65
#endif
};
void ksmbd_copy_gss_neg_header(void *buf)
{
memcpy(buf, NEGOTIATE_GSS_HEADER, AUTH_GSS_LENGTH);
}
/**
* ksmbd_gen_sess_key() - function to generate session key
* @sess: session of connection
* @hash: source hash value to be used for find session key
* @hmac: source hmac value to be used for finding session key
*
*/
static int ksmbd_gen_sess_key(struct ksmbd_session *sess, char *hash,
char *hmac)
{
struct ksmbd_crypto_ctx *ctx;
int rc;
ctx = ksmbd_crypto_ctx_find_hmacmd5();
if (!ctx) {
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");