Skip to content

Commit fa99979

Browse files
committed
Enable Fast Authentication for the latest Oracle Database release
1 parent 48d0baf commit fa99979

File tree

8 files changed

+38
-72
lines changed

8 files changed

+38
-72
lines changed

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ node-oracledb `v6.5.0 <https://github.com/oracle/node-oracledb/compare/v6.4.0...
1313
Thin Mode Changes
1414
++++++++++++++++++
1515

16+
#) Added support for Oracle Database 23c feature that can improve the
17+
performance of connection creation by reducing the number of
18+
round trips required for all connections created.
19+
1620
#) Error ``NJS-149: the bind variable placeholder "%s" cannot be used
1721
both before and after the RETURNING clause in a DML RETURNING statement``
1822
is now raised when the same bind variable placeholder name is used both

lib/thin/connection.js

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ const finalizationRegistry = new global.FinalizationRegistry((heldValue) => {
5050
class TDSBuffer extends BaseBuffer {
5151
}
5252

53-
const connectionCookies = new Map();
54-
5553
class ThinConnectionImpl extends ConnectionImpl {
5654

5755
/**
@@ -596,26 +594,6 @@ class ThinConnectionImpl extends ConnectionImpl {
596594
return (this._pool) ? true : false;
597595
}
598596

599-
//---------------------------------------------------------------------------
600-
// getConnectionCookieByUUID()
601-
//
602-
// It fetches from map which keeps keyname as UUID+ServiceName.
603-
// UUID identifies the CDB instance and ServiceName identifies the
604-
// entity within a PDB which uniquely identifies a pdb instance.
605-
//---------------------------------------------------------------------------
606-
getConnectionCookieByUUID(uuid) {
607-
let cookie;
608-
if (uuid) {
609-
const key = uuid + ((this.serviceName) ? this.serviceName : this.sid);
610-
cookie = connectionCookies.get(key);
611-
if (!cookie) {
612-
cookie = {};
613-
connectionCookies.set(key, cookie);
614-
}
615-
}
616-
return cookie;
617-
}
618-
619597
/**
620598
*
621599
* @param {object} params Configuration of the connection
@@ -705,37 +683,19 @@ class ThinConnectionImpl extends ConnectionImpl {
705683
}
706684

707685
try {
708-
const cookie = this.getConnectionCookieByUUID(this.nscon.dbUUID);
709-
this.nscon.dbUUID = null;
710686
const protocolMessage = new messages.ProtocolMessage(this);
711687
const dataTypeMessage = new messages.DataTypeMessage(this);
712688
const authMessage = new messages.AuthMessage(this, params);
713-
let sentCookie = false;
714-
if (cookie && cookie.populated) {
715-
const cookieMessage = new messages.ConnectionCookieMessage(this);
716-
cookieMessage.cookie = cookie;
717-
cookieMessage.protocolMessage = protocolMessage;
718-
cookieMessage.dataTypeMessage = dataTypeMessage;
719-
cookieMessage.authMessage = authMessage;
720-
await this._protocol._processMessage(cookieMessage);
721-
sentCookie = true;
689+
if (this.nscon.supportsFastAuth) {
690+
const fastAuthMessage = new messages.FastAuthMessage(this);
691+
fastAuthMessage.protocolMessage = protocolMessage;
692+
fastAuthMessage.dataTypeMessage = dataTypeMessage;
693+
fastAuthMessage.authMessage = authMessage;
694+
await this._protocol._processMessage(fastAuthMessage);
722695
} else {
723696
await this._protocol._processMessage(protocolMessage);
724-
}
725-
if (!sentCookie || !cookie.populated) {
726697
await this._protocol._processMessage(dataTypeMessage);
727-
// Does OSESSKEY for non-token Authentication else OAUTH
728698
await this._protocol._processMessage(authMessage);
729-
if (cookie && !cookie.populated) {
730-
cookie.protocolVersion = protocolMessage.serverVersion;
731-
cookie.serverBanner = protocolMessage.serverBanner;
732-
cookie.charsetID = this._protocol.caps.charSetID;
733-
cookie.ncharsetID = this._protocol.caps.nCharsetId;
734-
cookie.flags = protocolMessage.serverFlags;
735-
cookie.compileCaps = Buffer.from(protocolMessage.serverCompileCaps);
736-
cookie.runtimeCaps = Buffer.from(protocolMessage.serverRunTimeCaps);
737-
cookie.populated = true;
738-
}
739699
}
740700
if (!params.token) { // non-token Authentication
741701
await this._protocol._processMessage(authMessage); // OAUTH

lib/thin/protocol/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ module.exports = {
433433
TNS_MSG_TYPE_ONEWAY_FN: 26,
434434
TNS_MSG_TYPE_IMPLICIT_RESULTSET: 27,
435435
TNS_MSG_TYPE_RENEGOTIATE: 28,
436-
TNS_MSG_TYPE_COOKIE: 30,
436+
TNS_MSG_TYPE_FAST_AUTH: 34,
437437

438438
// parameter keyword numbers,
439439
TNS_KEYWORD_NUM_CURRENT_SCHEMA: 168,
@@ -669,6 +669,7 @@ module.exports = {
669669
TNS_TDU: 65535,
670670
TNS_MAX_CONNECT_DATA: 230,
671671
TNS_MAX_UROWID_LENGTH: 3950,
672+
TNS_SERVER_CONVERTS_CHARS: 0x01, // server does charset conversion
672673

673674
// drcp release mode
674675
DRCP_DEAUTHENTICATE: 0x00000002,

lib/thin/protocol/messages/connectionCookie.js renamed to lib/thin/protocol/messages/fastAuth.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023 Oracle and/or its affiliates.
1+
// Copyright (c) 2023, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -31,37 +31,38 @@ const Message = require("./base.js");
3131

3232
/**
3333
* Executes a Fast Negotiation RPC function.
34-
* It sends Protocol Negotiation, Cookie Message, Datatype Negotiation
34+
* It sends Protocol Negotiation, Datatype Negotiation
3535
* and OSESS Key RPC in single round trip.
3636
*
37-
* @class ConnectionCookieMessage
37+
* @class FastAuthMessage
3838
* @extends {Message}
3939
*/
40-
class ConnectionCookieMessage extends Message {
40+
class FastAuthMessage extends Message {
4141

4242
/**
43-
* Serializes the ConnectionCookieMessage function arguments
43+
* Serializes the FastAuthMessage function arguments
4444
*
4545
* @param {object} buf input arguments
4646
*/
4747
encode(buf) {
48+
buf.writeUInt8(constants.TNS_MSG_TYPE_FAST_AUTH);
49+
buf.writeUInt8(1); // Fast Auth version
50+
buf.writeUInt8(constants.TNS_SERVER_CONVERTS_CHARS); // flag 1
51+
buf.writeUInt8(0); // flag 2
4852
this.protocolMessage.encode(buf);
49-
buf.writeUInt8(constants.TNS_MSG_TYPE_COOKIE);
50-
buf.writeUInt8(1); // cookie version
51-
buf.writeUInt8(this.cookie.protocolVersion);
52-
buf.writeUInt16LE(this.cookie.charsetID);
53-
buf.writeUInt8(this.cookie.flags);
54-
buf.writeUInt16LE(this.cookie.ncharsetID);
55-
buf.writeBytesWithLength(this.cookie.serverBanner);
56-
buf.writeBytesWithLength(this.cookie.compileCaps);
57-
buf.writeBytesWithLength(this.cookie.runtimeCaps);
53+
buf.writeUInt16BE(0); // server charset (unused)
54+
buf.writeUInt8(0); // server charset flag (unused)
55+
buf.writeUInt16BE(0); // server ncharset (unused)
56+
buf.caps.ttcFieldVersion = constants.TNS_CCAP_FIELD_VERSION_19_1_EXT_1;
57+
buf.writeUInt8(buf.caps.ttcFieldVersion);
5858
this.dataTypeMessage.encode(buf);
5959
this.authMessage.encode(buf);
60+
buf.caps.ttcFieldVersion = constants.TNS_CCAP_FIELD_VERSION_MAX;
6061
}
6162

6263
processMessage(buf, messageType) {
6364
if (messageType === constants.TNS_MSG_TYPE_RENEGOTIATE) {
64-
this.cookie.populated = false;
65+
this.reNegotiate = true;
6566
} else if (messageType === constants.TNS_MSG_TYPE_PROTOCOL) {
6667
this.protocolMessage.processMessage(buf, messageType);
6768
} else if (messageType === constants.TNS_MSG_TYPE_DATA_TYPES) {
@@ -73,4 +74,4 @@ class ConnectionCookieMessage extends Message {
7374

7475
}
7576

76-
module.exports = ConnectionCookieMessage;
77+
module.exports = FastAuthMessage;

lib/thin/protocol/messages/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ const PingMessage = require('./ping.js');
3737
const ProtocolMessage = require('./protocol.js');
3838
const RollbackMessage = require('./rollback.js');
3939
const SessionReleaseMessage = require('./sessionRelease.js');
40-
const ConnectionCookieMessage = require('./connectionCookie.js');
40+
const FastAuthMessage = require('./fastAuth.js');
4141

4242
module.exports = {
4343
AuthMessage,
4444
CommitMessage,
45-
ConnectionCookieMessage,
45+
FastAuthMessage,
4646
DataTypeMessage,
4747
ExecuteMessage,
4848
FetchMessage,

lib/thin/sqlnet/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = {
108108
TNS_VERSION_DESIRED: 319,
109109
TNS_VERSION_MINIMUM: 300,
110110
TNS_VERSION_MIN_UUID: 319,
111+
TNS_VERSION_MIN_DATA_FLAGS: 318,
111112
TNS_UUID_OFFSET: 45,
112113

113114
/* Accept Packet */
@@ -143,6 +144,7 @@ module.exports = {
143144
// Accept flag2
144145
NSPACOOB: 0x00000001, // OOB support check at connection time
145146
NSGPCHKSCMD: 0x01000000, // Support for Poll and Check logic
147+
TNS_ACCEPT_FLAG_FAST_AUTH: 0x10000000, // Support Fast Auth
146148

147149
/* Redirect packet */
148150
NSPRDLEN: 8, // Length of redirect data

lib/thin/sqlnet/networkSession.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ class NetworkSession {
355355
break;
356356
case constants.NSPTAC: /* ACCEPT */
357357
Packet.AcceptPacket(packet, this.sAtts);
358-
this.dbUUID = packet.dbUUID;
359-
packet.dbUUID = null;
358+
if (packet.flags & constants.TNS_ACCEPT_FLAG_FAST_AUTH) {
359+
this.supportsFastAuth = true;
360+
}
360361
break;
361362
case constants.NSPTRF: /* REFUSE */
362363
this.refusePkt = new Packet.RefusePacket(packet);

lib/thin/sqlnet/packet.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,8 @@ function AcceptPacket(packet, sAtts) {
246246
this.flag0 = packet.buf.readUInt8(constants.NSPACFL0);
247247
this.flag1 = packet.buf.readUInt8(constants.NSPACFL1);
248248

249-
/* UUID - CDB Instance ID */
250-
if (sAtts.version >= constants.TNS_VERSION_MIN_UUID) {
251-
packet.dbUUID = packet.buf.subarray(constants.TNS_UUID_OFFSET,
252-
constants.TNS_UUID_OFFSET + 16);
253-
packet.dbUUID = packet.dbUUID.toString('base64');
249+
if (sAtts.version >= constants.TNS_VERSION_MIN_DATA_FLAGS) {
250+
packet.flags = packet.buf.readUInt32BE(constants.NSPACFL2);
254251
}
255252
}
256253

0 commit comments

Comments
 (0)