From e2f853d5f05b24f32c743ec744bb6b7f142c616d Mon Sep 17 00:00:00 2001 From: "Jeremy W. Sherman" Date: Sun, 1 Aug 2021 21:11:00 -0400 Subject: [PATCH] feat: express client support for UTF-8 in LOGIN7 Update connection featureExtAck token handling to not assume every such token must have fedauth data. [#1143] --- src/connection.ts | 4 ++-- src/login7-payload.ts | 12 ++++++++++++ test/unit/login7-payload-test.js | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 2a8b5bf72..f3375f610 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -3614,10 +3614,10 @@ Connection.prototype.STATE = { this.loginError = ConnectionError(`Active Directory authentication acknowledgment for ${authentication.type} authentication method includes extra data`); this.loggedIn = false; } - } else if (token.fedAuth === undefined) { + } else if (token.fedAuth === undefined && token.utf8Support === undefined) { this.loginError = ConnectionError('Received acknowledgement for unknown feature'); this.loggedIn = false; - } else { + } else if (token.fedAuth) { this.loginError = ConnectionError('Did not request Active Directory authentication, but received the acknowledgment'); this.loggedIn = false; } diff --git a/src/login7-payload.ts b/src/login7-payload.ts index b2a2b3d32..d7bcf52dd 100644 --- a/src/login7-payload.ts +++ b/src/login7-payload.ts @@ -1,4 +1,5 @@ import { sprintf } from 'sprintf-js'; +import { versions } from './tds-versions'; const FLAGS_1 = { ENDIAN_LITTLE: 0x00, @@ -411,6 +412,17 @@ class Login7Payload { } } + if (this.tdsVersion >= versions['7_4']) { + // Signal UTF-8 support: Value 0x0A, bit 0 must be set to 1. Added in TDS 7.4. + const UTF8_SUPPORT_FEATURE_ID = 0x0a; + const UTF8_SUPPORT_CLIENT_SUPPORTS_UTF8 = 0x01; + const buf = Buffer.alloc(6); + buf.writeUInt8(UTF8_SUPPORT_FEATURE_ID, 0); + buf.writeUInt32LE(1, 1); + buf.writeUInt8(UTF8_SUPPORT_CLIENT_SUPPORTS_UTF8, 5); + buffers.push(buf); + } + buffers.push(Buffer.from([FEATURE_EXT_TERMINATOR])); return Buffer.concat(buffers); diff --git a/test/unit/login7-payload-test.js b/test/unit/login7-payload-test.js index 6295ec0db..a1e866131 100644 --- a/test/unit/login7-payload-test.js +++ b/test/unit/login7-payload-test.js @@ -132,7 +132,7 @@ describe('Login7Payload', function() { describe('for a login payload with active directory authentication', function() { it('generates the expected data', function() { const payload = new Login7Payload({ - tdsVersion: 0x72090002, + tdsVersion: 0x74000004, packetSize: 1024, clientProgVer: 0, clientPid: 12345, @@ -175,7 +175,7 @@ describe('Login7Payload', function() { 2 + 2 + (2 * payload.changePassword.length) + 4 + // cbSSPILong 4 + // Extension offset - 1 + 1 + 4 + 1 + 1; // Feature ext + 1 + (1 + 4 + 1) + (1 + 4 + 1) + 1; // Feature ext - v7.4 includes UTF8_SUPPORT unlike prior versions assert.lengthOf(data, expectedLength); });