/// <summary>Performs MAC signing of the SMB.</summary>
/// <remarks>
/// Performs MAC signing of the SMB. This is done as follows.
/// The signature field of the SMB is overwritted with the sequence number;
/// The MD5 digest of the MAC signing key + the entire SMB is taken;
/// The first 8 bytes of this are placed in the signature field.
/// </remarks>
/// <param name="data">The data.</param>
/// <param name="offset">The starting offset at which the SMB header begins.</param>
/// <param name="length">The length of the SMB data starting at offset.</param>
internal virtual void Sign(byte[] data,
int offset,
int length,
ServerMessageBlock request,
ServerMessageBlock response)
{
request.SignSeq = _signSequence;
if (response != null)
{
response.SignSeq = _signSequence + 1;
response.VerifyFailed = false;
}
try
{
Update(_macSigningKey, 0, _macSigningKey.Length);
int index = offset + SmbConstants.SignatureOffset;
for (int i = 0; i < 8; i++)
{
data[index + i] = 0;
}
ServerMessageBlock.WriteInt4(_signSequence, data, index);
Update(data, offset, length);
Array.Copy(Digest(), 0, data, index, 8);
if (_bypass)
{
_bypass = false;
Array.Copy(Runtime.GetBytesForString("BSRSPYL "),
0,
data,
index,
8);
}
}
catch (Exception ex)
{
if (Log.Level > 0)
{
Runtime.PrintStackTrace(ex, Log);
}
}
finally
{
_signSequence += 2;
}
}