Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions SMBLibrary.Tests/Client/SMB2ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,37 @@
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Threading;

namespace SMBLibrary.Tests.Client
{
[TestClass]
public class SMB2ClientTests
{
private int m_serverPort;
{
// ensure that multiple tests run at the same instant in time receive different port numbers
// by incrementing the port number for each test
private static readonly int minPort = 1025;
private static readonly int maxPort = 65535;
private static int m_serverPort = minPort + new Random().Next(maxPort - minPort);

private TcpListener m_tcpListener;
private bool m_clientConnected;

private static int GetNextPortNumber()
{
var next = Interlocked.Increment(ref m_serverPort);

if (next > maxPort)
next = minPort;

return next;
}

[TestInitialize]
public void Initialize()
{
m_serverPort = 1000 + new Random().Next(50000);
m_tcpListener = new TcpListener(IPAddress.Loopback, m_serverPort);
m_tcpListener = new TcpListener(IPAddress.Loopback, GetNextPortNumber());
m_tcpListener.Start();
}

Expand Down
2 changes: 1 addition & 1 deletion SMBLibrary.Tests/NTFileStore/NTDirectoryFileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SMBLibrary.Tests
[TestClass]
public class NTDirectoryFileSystemTests : NTFileStoreTests
{
private static readonly string TestDirectoryPath = @"C:\Tests";
private static readonly string TestDirectoryPath = Path.Combine(Path.GetTempPath(), "SMBLibraryTests");

static NTDirectoryFileSystemTests()
{
Expand Down
4 changes: 2 additions & 2 deletions SMBLibrary/Authentication/NTLM/Helpers/NTLMCryptography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static byte[] ComputeServerSignKey(byte[] exportedSessionKey)
return ComputeSignKey(exportedSessionKey, false);
}

private static byte[] ComputeSignKey(byte[] exportedSessionKey, bool isClient)
public static byte[] ComputeSignKey(byte[] exportedSessionKey, bool isClient)
{
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/524cdccb-563e-4793-92b0-7bc321fce096
string str;
Expand Down Expand Up @@ -312,7 +312,7 @@ public static byte[] ComputeServerSealKey(byte[] exportedSessionKey)
return ComputeSealKey(exportedSessionKey, false);
}

private static byte[] ComputeSealKey(byte[] exportedSessionKey, bool isClient)
public static byte[] ComputeSealKey(byte[] exportedSessionKey, bool isClient)
{
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/524cdccb-563e-4793-92b0-7bc321fce096
string str;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
/* Copyright (C) 2014-2026 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
*
* You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation,
Expand Down Expand Up @@ -78,6 +78,13 @@ public override NTStatus GetChallengeMessage(out object context, byte[] negotiat
byte[] serverChallenge = GenerateServerChallenge();
context = new AuthContext(serverChallenge);

ChallengeMessage challengeMessage = CreateChallengeMessage(negotiateMessage, serverChallenge);
challengeMessageBytes = challengeMessage.GetBytes();
return NTStatus.SEC_I_CONTINUE_NEEDED;
}

protected virtual ChallengeMessage CreateChallengeMessage(NegotiateMessage negotiateMessage, byte[] serverChallenge)
{
ChallengeMessage challengeMessage = new ChallengeMessage();
// https://msdn.microsoft.com/en-us/library/cc236691.aspx
challengeMessage.NegotiateFlags = NegotiateFlags.TargetTypeServer |
Expand Down Expand Up @@ -147,8 +154,7 @@ public override NTStatus GetChallengeMessage(out object context, byte[] negotiat
challengeMessage.ServerChallenge = serverChallenge;
challengeMessage.TargetInfo = AVPairUtils.GetAVPairSequence(Environment.MachineName, Environment.MachineName);
challengeMessage.Version = NTLMVersion.Server2003;
challengeMessageBytes = challengeMessage.GetBytes();
return NTStatus.SEC_I_CONTINUE_NEEDED;
return challengeMessage;
}

public override NTStatus Authenticate(object context, byte[] authenticateMessageBytes)
Expand Down
2 changes: 1 addition & 1 deletion SMBLibrary/SMBLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net20;net40;netstandard2.0</TargetFrameworks>
<AssemblyName>SMBLibrary</AssemblyName>
<Version>1.5.6.1</Version>
<Version>1.5.6.2</Version>
<NoWarn>1573;1591</NoWarn>
<RootNamespace>SMBLibrary</RootNamespace>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand Down