/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Signing support, using libmd
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include "private.h"
/*
* Set this to a small number to debug sequence numbers
* that seem to get out of step.
*/
#ifdef DEBUG
#endif
/*
* Compute MD5 digest of packet data, using the stored MAC key.
*
* See similar code in the driver:
* and on the server side:
*/
static int
{
/*
* This union is a little bit of trickery to:
* (1) get the sequence number int aligned, and
* (2) reduce the number of digest calls, at the
* cost of a copying 32 bytes instead of 8.
* Both sides of this union are 2+32 bytes.
*/
union {
struct {
} r;
struct {
} s;
} smbhdr;
if (m->m_len < SMB_HDRLEN)
return (EIO);
return (EINVAL);
/*
* Make an aligned copy of the SMB header
* and fill in the sequence number.
*/
/*
* Compute the MAC: MD5(concat(Key, message))
*/
/* Digest the MAC Key */
/* Digest the (copied) SMB header */
/* Digest the rest of the first mbuf */
if (m->m_len > SMB_HDRLEN) {
m->m_len - SMB_HDRLEN);
}
m = m->m_next;
/* Digest rest of the SMB message. */
while (m) {
m = m->m_next;
}
/* Final */
/*
* Finally, store the signature.
* (first 8 bytes of the digest)
*/
if (signature)
return (0);
}
/*
* Sign a request with HMAC-MD5.
*/
void
{
int err;
/*
* Our mblk allocation ensures this,
* but just in case...
*/
if (m->m_len < SMB_HDRLEN)
return;
/*
* Signing is required, but we have no key yet
* fill in with the magic fake signing value.
* This happens with SPNEGO, NTLMSSP, ...
*/
return;
}
/*
* This will compute the MAC and store it
* directly into the message at sigloc.
*/
if (err) {
}
}
/*
* Verify reply signature.
*/
int
{
/*
* Note ct_mackey and ct_mackeylen gets initialized by
* smb_smb_ssnsetup. It's normal to have a null MAC key
* during extended security session setup.
*/
return (0);
/*
* Let caller deal with empty reply or short messages by
* returning zero. Caller will fail later, in parsing.
*/
if (m == NULL) {
DPRINT("empty reply");
return (0);
}
if (m->m_len < SMB_HDRLEN) {
DPRINT("short reply");
return (0);
}
if (err) {
/*
* If we can't compute a MAC, then there's
* no point trying other seqno values.
*/
return (EBADRPC);
}
/*
* Compare the computed signature with the
* one found in the message (at sigloc)
*/
return (0);
#ifdef DEBUG
/*
* of the sequence # has gotten a bit out of sync.
*/
break;
break;
}
}
if (fudge <= nsmb_signing_fudge) {
DPRINT("rseqno=%d, but %d would have worked",
}
#endif
return (EBADRPC);
}