Skip to content

Commit 47e9cbb

Browse files
committed
Proper handling when WireCrypt is disabled on server.
1 parent 8965f55 commit 47e9cbb

4 files changed

Lines changed: 44 additions & 15 deletions

File tree

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/AuthBlock.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public async Task<IResponse> ProcessContAuthResponse(IXdrReader xdr, AsyncWrappi
149149
else if (response is GenericResponse genericResponse)
150150
{
151151
ServerKeys = genericResponse.Data;
152-
IsAuthenticated = true;
153152
Complete();
154153
}
155154
else
@@ -232,11 +231,17 @@ public void Start(byte[] serverData, string acceptPluginName, bool isAuthenticat
232231
}
233232
}
234233

235-
void Complete()
234+
public void Complete()
235+
{
236+
IsAuthenticated = true;
237+
ReleaseAuth();
238+
}
239+
240+
void ReleaseAuth()
236241
{
237242
_srp256 = null;
238243
_srp = null;
239-
_sspi.Dispose();
244+
_sspi?.Dispose();
240245
_sspi = null;
241246
}
242247

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/GdsConnection.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ await Xdr.ReadBoolean(async).ConfigureAwait(false),
192192
break;
193193
}
194194

195-
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
196-
await Xdr.Flush(async).ConfigureAwait(false);
197-
await AuthBlock.ProcessWireCryptResponse(Xdr, this, async).ConfigureAwait(false);
195+
if (AuthBlock.ServerKeys.Any())
196+
{
197+
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
198+
await Xdr.Flush(async).ConfigureAwait(false);
199+
await AuthBlock.ProcessWireCryptResponse(Xdr, this, async).ConfigureAwait(false);
200+
}
198201
}
199202
}
200203

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version13/GdsDatabase.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//$Authors = Hajime Nakagami, Jiri Cincura (jiri@cincura.net)
1717

1818
using System.IO;
19+
using System.Linq;
1920
using System.Text;
2021
using System.Threading.Tasks;
2122
using FirebirdSql.Data.Common;
@@ -46,16 +47,21 @@ public override async Task Attach(DatabaseParameterBufferBase dpb, string databa
4647
response = await AuthBlock.ProcessContAuthResponse(Xdr, async).ConfigureAwait(false);
4748
response = await ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
4849
}
49-
await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false);
50+
var genericResponse = (GenericResponse)response;
51+
await base.ProcessAttachResponse(genericResponse, async).ConfigureAwait(false);
5052

51-
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
52-
await Xdr.Flush(async).ConfigureAwait(false);
53-
await AuthBlock.ProcessWireCryptResponse(Xdr, _connection, async).ConfigureAwait(false);
53+
if (genericResponse.Data.Any())
54+
{
55+
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
56+
await Xdr.Flush(async).ConfigureAwait(false);
57+
await AuthBlock.ProcessWireCryptResponse(Xdr, _connection, async).ConfigureAwait(false);
58+
}
5459
}
5560
else
5661
{
5762
response = await ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
5863
await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false);
64+
AuthBlock.Complete();
5965
}
6066
AuthBlock.WireCryptValidate(IscCodes.PROTOCOL_VERSION13);
6167
}
@@ -109,16 +115,21 @@ public override async Task CreateDatabase(DatabaseParameterBufferBase dpb, strin
109115
response = await AuthBlock.ProcessContAuthResponse(Xdr, async).ConfigureAwait(false);
110116
response = await ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
111117
}
112-
await ProcessCreateResponse((GenericResponse)response, async).ConfigureAwait(false);
118+
var genericResponse = (GenericResponse)response;
119+
await ProcessCreateResponse(genericResponse, async).ConfigureAwait(false);
113120

114-
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
115-
await Xdr.Flush(async).ConfigureAwait(false);
116-
await AuthBlock.ProcessWireCryptResponse(Xdr, _connection, async).ConfigureAwait(false);
121+
if (genericResponse.Data.Any())
122+
{
123+
await AuthBlock.SendWireCryptToBuffer(Xdr, async).ConfigureAwait(false);
124+
await Xdr.Flush(async).ConfigureAwait(false);
125+
await AuthBlock.ProcessWireCryptResponse(Xdr, _connection, async).ConfigureAwait(false);
126+
}
117127
}
118128
else
119129
{
120130
response = await ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
121131
await ProcessCreateResponse((GenericResponse)response, async).ConfigureAwait(false);
132+
AuthBlock.Complete();
122133
}
123134
}
124135
catch (IOException ex)

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version13/GdsServiceManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//$Authors = Carlos Guzman Alvarez, Jiri Cincura (jiri@cincura.net)
1717

1818
using System.IO;
19+
using System.Linq;
1920
using System.Threading.Tasks;
2021
using FirebirdSql.Data.Common;
2122

@@ -45,16 +46,25 @@ public override async Task Attach(ServiceParameterBufferBase spb, string dataSou
4546
response = await Connection.AuthBlock.ProcessContAuthResponse(Database.Xdr, async).ConfigureAwait(false);
4647
response = await (Database as GdsDatabase).ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
4748
}
48-
await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false);
49+
var genericResponse = (GenericResponse)response;
50+
await base.ProcessAttachResponse(genericResponse, async).ConfigureAwait(false);
4951

5052
await Connection.AuthBlock.SendWireCryptToBuffer(Database.Xdr, async).ConfigureAwait(false);
5153
await Database.Xdr.Flush(async).ConfigureAwait(false);
5254
await Connection.AuthBlock.ProcessWireCryptResponse(Database.Xdr, Connection, async).ConfigureAwait(false);
55+
56+
if (genericResponse.Data.Any())
57+
{
58+
await Database.AuthBlock.SendWireCryptToBuffer(Database.Xdr, async).ConfigureAwait(false);
59+
await Database.Xdr.Flush(async).ConfigureAwait(false);
60+
await Database.AuthBlock.ProcessWireCryptResponse(Database.Xdr, Connection, async).ConfigureAwait(false);
61+
}
5362
}
5463
else
5564
{
5665
response = await (Database as GdsDatabase).ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false);
5766
await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false);
67+
Database.AuthBlock.Complete();
5868
}
5969
}
6070
catch (IscException)

0 commit comments

Comments
 (0)