Skip to content

Add deprecated Legacy_Auth authentication method #1231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
45 changes: 45 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient.Tests/LegacyClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/

//$Authors = Osincev Daniil

using System.Text;
using FirebirdSql.Data.Client.Managed.Legacy;
using FirebirdSql.Data.TestsBase;
using NUnit.Framework;

namespace FirebirdSql.Data.FirebirdClient.Tests;

[NoServerCategory]
public class LegacyClientTests
{
[Test]
public void ClientProofProducesExpectedHash()
{
var client = new LegacyClient();
var result = client.ClientProof("masterkey");
var hash = Encoding.ASCII.GetString(result);
Assert.AreEqual("QP3LMZ/MJh.", hash);
}

[Test]
public void ClientProofNullReturnsStar()
{
var client = new LegacyClient();
var result = client.ClientProof(null);
var hash = Encoding.ASCII.GetString(result);
Assert.AreEqual("*", hash);
}
}
10 changes: 9 additions & 1 deletion src/FirebirdSql.Data.FirebirdClient/Client/Managed/AuthBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Threading.Tasks;
using FirebirdSql.Data.Client.Managed.Srp;
using FirebirdSql.Data.Client.Managed.Sspi;
using FirebirdSql.Data.Client.Managed.Legacy;
using FirebirdSql.Data.Common;
using WireCryptOption = FirebirdSql.Data.Client.Managed.Version13.WireCryptOption;

Expand All @@ -33,6 +34,7 @@ sealed class AuthBlock
Srp256Client _srp256;
SrpClient _srp;
SspiHelper _sspi;
Legacy.LegacyClient _legacy;

public GdsConnection Connection { get; }
public string User { get; }
Expand All @@ -57,6 +59,7 @@ public AuthBlock(GdsConnection connection, string user, string password, WireCry
_srp256 = new Srp256Client();
_srp = new SrpClient();
_sspi = new SspiHelper();
_legacy = new LegacyClient();

Connection = connection;
User = user;
Expand Down Expand Up @@ -96,7 +99,7 @@ public byte[] UserIdentificationData()
var specificData = Encoding.UTF8.GetBytes(_srp256.PublicKeyHex);
WriteMultiPartHelper(result, IscCodes.CNCT_specific_data, specificData);

var plugins = string.Join(",", new[] { _srp256.Name, _srp.Name });
var plugins = string.Join(",", new[] { _srp256.Name, _srp.Name, _legacy.PluginName });
var pluginsBytes = Encoding.UTF8.GetBytes(plugins);
result.WriteByte(IscCodes.CNCT_plugin_list);
result.WriteByte((byte)pluginsBytes.Length);
Expand Down Expand Up @@ -282,6 +285,10 @@ public void Start(byte[] serverData, string acceptPluginName, bool isAuthenticat
SessionKey = _srp.SessionKey;
SessionKeyName = _srp.SessionKeyName;
}
else if (AcceptPluginName.Equals(_legacy.PluginName, StringComparison.Ordinal))
{
ClientData = _legacy.ClientProof(Password);
}
else if (AcceptPluginName.Equals(_sspi.Name, StringComparison.Ordinal))
{
if (hasServerData)
Expand All @@ -307,6 +314,7 @@ void ReleaseAuth()
_srp = null;
_sspi?.Dispose();
_sspi = null;
_legacy = null;
}

static void WriteMultiPartHelper(Stream stream, byte code, byte[] data)
Expand Down
Loading