Skip to content

Commit

Permalink
feat: express client support for UTF-8 in LOGIN7
Browse files Browse the repository at this point in the history
Update connection featureExtAck token handling to not assume every such token
must have fedauth data.

[#1143]
  • Loading branch information
jeremy-w committed Aug 13, 2021
1 parent c91258e commit e2f853d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/login7-payload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sprintf } from 'sprintf-js';
import { versions } from './tds-versions';

const FLAGS_1 = {
ENDIAN_LITTLE: 0x00,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/login7-payload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit e2f853d

Please sign in to comment.