oracledb 5.5.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +1 -1875
  2. package/LICENSE.txt +8 -222
  3. package/NOTICE.txt +1 -1
  4. package/README.md +38 -30
  5. package/SECURITY.md +38 -0
  6. package/build/Release/oracledb-6.0.0-darwin-x64.node +0 -0
  7. package/build/Release/oracledb-6.0.0-darwin-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-6.0.0-js-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-6.0.0-linux-arm64.node +0 -0
  10. package/build/Release/oracledb-6.0.0-linux-arm64.node-buildinfo.txt +1 -0
  11. package/build/Release/oracledb-6.0.0-linux-x64.node +0 -0
  12. package/build/Release/oracledb-6.0.0-linux-x64.node-buildinfo.txt +1 -0
  13. package/build/Release/oracledb-6.0.0-win32-x64.node +0 -0
  14. package/build/Release/oracledb-6.0.0-win32-x64.node-buildinfo.txt +1 -0
  15. package/examples/README.md +113 -0
  16. package/examples/dbconfig.js +100 -0
  17. package/examples/example.js +156 -0
  18. package/index.js +26 -0
  19. package/lib/aqDeqOptions.js +146 -7
  20. package/lib/aqEnqOptions.js +59 -7
  21. package/lib/aqMessage.js +118 -7
  22. package/lib/aqQueue.js +242 -53
  23. package/lib/connection.js +1324 -465
  24. package/lib/constants.js +203 -0
  25. package/lib/dbObject.js +346 -32
  26. package/lib/errors.js +781 -0
  27. package/lib/impl/aqDeqOptions.js +197 -0
  28. package/lib/impl/aqEnqOptions.js +89 -0
  29. package/lib/impl/aqMessage.js +134 -0
  30. package/lib/impl/aqQueue.js +81 -0
  31. package/lib/impl/connection.js +529 -0
  32. package/lib/impl/dbObject.js +159 -0
  33. package/lib/impl/index.js +59 -0
  34. package/lib/impl/lob.js +85 -0
  35. package/lib/impl/pool.js +195 -0
  36. package/lib/impl/resultset.js +223 -0
  37. package/lib/impl/sodaCollection.js +174 -0
  38. package/lib/impl/sodaDatabase.js +81 -0
  39. package/lib/impl/sodaDocCursor.js +63 -0
  40. package/lib/impl/sodaDocument.js +98 -0
  41. package/lib/impl/sodaOperation.js +109 -0
  42. package/lib/lob.js +156 -68
  43. package/lib/oracledb.js +1047 -345
  44. package/lib/pool.js +654 -465
  45. package/lib/poolStatistics.js +23 -9
  46. package/lib/queryStream.js +14 -7
  47. package/lib/resultset.js +291 -183
  48. package/lib/settings.js +191 -0
  49. package/lib/sodaCollection.js +214 -201
  50. package/lib/sodaDatabase.js +107 -71
  51. package/lib/sodaDocCursor.js +44 -32
  52. package/lib/sodaDocument.js +76 -14
  53. package/lib/sodaOperation.js +131 -118
  54. package/lib/thin/connection.js +1038 -0
  55. package/lib/thin/dbObject.js +629 -0
  56. package/lib/thin/index.js +40 -0
  57. package/lib/thin/lob.js +188 -0
  58. package/lib/thin/pool.js +481 -0
  59. package/lib/thin/protocol/buffer.js +1040 -0
  60. package/lib/thin/protocol/capabilities.js +116 -0
  61. package/lib/thin/protocol/constants.js +764 -0
  62. package/lib/thin/protocol/encryptDecrypt.js +185 -0
  63. package/lib/thin/protocol/messages/auth.js +348 -0
  64. package/lib/thin/protocol/messages/base.js +475 -0
  65. package/lib/thin/protocol/messages/commit.js +56 -0
  66. package/lib/thin/protocol/messages/dataType.js +382 -0
  67. package/lib/thin/protocol/messages/execute.js +312 -0
  68. package/lib/thin/protocol/messages/fetch.js +60 -0
  69. package/lib/thin/protocol/messages/index.js +53 -0
  70. package/lib/thin/protocol/messages/lobOp.js +200 -0
  71. package/lib/thin/protocol/messages/logOff.js +53 -0
  72. package/lib/thin/protocol/messages/ping.js +56 -0
  73. package/lib/thin/protocol/messages/protocol.js +78 -0
  74. package/lib/thin/protocol/messages/rollback.js +56 -0
  75. package/lib/thin/protocol/messages/sessionRelease.js +60 -0
  76. package/lib/thin/protocol/messages/withData.js +811 -0
  77. package/lib/thin/protocol/oson.js +660 -0
  78. package/lib/thin/protocol/packet.js +520 -0
  79. package/lib/thin/protocol/protocol.js +202 -0
  80. package/lib/thin/protocol/utils.js +88 -0
  81. package/lib/thin/resultSet.js +122 -0
  82. package/lib/thin/sqlnet/connStrategy.js +175 -0
  83. package/lib/thin/sqlnet/constants.js +199 -0
  84. package/lib/thin/sqlnet/ezConnectResolver.js +488 -0
  85. package/lib/thin/sqlnet/navNodes.js +870 -0
  86. package/lib/thin/sqlnet/networkSession.js +620 -0
  87. package/lib/thin/sqlnet/ntTcp.js +525 -0
  88. package/lib/thin/sqlnet/nvStrToNvPair.js +783 -0
  89. package/lib/thin/sqlnet/packet.js +405 -0
  90. package/lib/thin/sqlnet/paramParser.js +205 -0
  91. package/lib/thin/sqlnet/sessionAtts.js +160 -0
  92. package/lib/thin/statement.js +301 -0
  93. package/lib/thin/util.js +289 -0
  94. package/lib/transformer.js +250 -0
  95. package/lib/types.js +357 -0
  96. package/lib/util.js +194 -110
  97. package/lib/version.js +36 -0
  98. package/package/README.md +33 -30
  99. package/package/install.js +89 -64
  100. package/package/prunebinaries.js +60 -12
  101. package/package.json +3 -3
  102. package/build/Release/oracledb-5.5.0-darwin-x64.node +0 -0
  103. package/build/Release/oracledb-5.5.0-darwin-x64.node-buildinfo.txt +0 -1
  104. package/build/Release/oracledb-5.5.0-linux-x64.node +0 -0
  105. package/build/Release/oracledb-5.5.0-linux-x64.node-buildinfo.txt +0 -1
  106. package/build/Release/oracledb-5.5.0-win32-x64.node +0 -0
  107. package/build/Release/oracledb-5.5.0-win32-x64.node-buildinfo.txt +0 -1
@@ -0,0 +1,185 @@
1
+ // Copyright (c) 2022, Oracle and/or its affiliates.
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // This software is dual-licensed to you under the Universal Permissive License
6
+ // (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7
+ // 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8
+ // either license.
9
+ //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
12
+ //
13
+ // Licensed under the Apache License, Version 2.0 (the "License");
14
+ // you may not use this file except in compliance with the License.
15
+ // You may obtain a copy of the License at
16
+ //
17
+ // https://www.apache.org/licenses/LICENSE-2.0
18
+ //
19
+ // Unless required by applicable law or agreed to in writing, software
20
+ // distributed under the License is distributed on an "AS IS" BASIS,
21
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ // See the License for the specific language governing permissions and
23
+ // limitations under the License.
24
+ //
25
+ //-----------------------------------------------------------------------------
26
+
27
+ 'use strict';
28
+
29
+ const Buffer = require('buffer').Buffer;
30
+ const crypto = require('crypto');
31
+
32
+ let algorithm = 'aes-256-cbc';
33
+ const _appendBuffer = Buffer.from([0x00, 0x01]);
34
+
35
+ /**
36
+ * A single Instance which handles all Encrypt, Decrypt,
37
+ * hash related to password verifiers.
38
+ */
39
+ class EncryptDecrypt {
40
+
41
+ // Key length is dependent on the algorithm. In this case for aes192, it is
42
+ // 24 bytes (192 bits).
43
+ _decrypt(key, val) {
44
+ const iv = Buffer.alloc(16, 0); // Initialization vector, same is used in server
45
+ const decipher = crypto.createDecipheriv(algorithm, key, iv);
46
+ decipher.setAutoPadding(false);
47
+ let decrypted = decipher.update(val);
48
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
49
+ return decrypted;
50
+ }
51
+
52
+ _encrypt(key, val, padding) {
53
+ let block_size = 16;
54
+ const iv = Buffer.alloc(block_size, 0);
55
+ let n = block_size - (val.length % block_size);
56
+ const nv = Buffer.alloc(n, n);
57
+ if (n > 0) {
58
+ if (padding) {
59
+ val += Buffer.alloc(n);
60
+ } else {
61
+ val = Buffer.concat([val, nv]);
62
+ }
63
+ }
64
+ const cipher = crypto.createCipheriv(algorithm, key, iv);
65
+ let encrypted = cipher.update(val);
66
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
67
+ if (!padding) {
68
+ encrypted = encrypted.slice(0, val.length);
69
+ }
70
+ val.fill(0);
71
+ return encrypted;
72
+ }
73
+
74
+ // Encrypt password and newPassword using comboKey
75
+ _setEncryptedPasswordBuffers(passwordBytes, newPasswordBytes, comboKey, authObj) {
76
+ let salt = Buffer.alloc(16);
77
+ crypto.randomFillSync(salt, 0, 16);
78
+ let temp = Buffer.concat([salt, passwordBytes]);
79
+ authObj.encodedPassword = this._encrypt(comboKey, temp);
80
+ temp.fill(0);
81
+ authObj.encodedPassword = authObj.encodedPassword.slice().toString('hex').toUpperCase();
82
+
83
+ if (newPasswordBytes) {
84
+ let newPasswordWithSalt = Buffer.concat([salt, newPasswordBytes]);
85
+ authObj.encodedNewPassword = this._encrypt(comboKey, newPasswordWithSalt);
86
+ newPasswordWithSalt.fill(0);
87
+ authObj.encodedNewPassword = authObj.encodedNewPassword.slice().toString('hex').toUpperCase();
88
+ }
89
+
90
+ // reset Buffers
91
+ passwordBytes.fill(0);
92
+ if (newPasswordBytes) {
93
+ newPasswordBytes.fill(0);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * updates authObject with required data.
99
+ *
100
+ * @param {object} sessionData The key/value pairs returned from OSESS key rpc
101
+ * @param {string} password Current Password of user
102
+ * @param {string} newPassword New password to be updated
103
+ * @param {boolean} verifier11G Verifier type 11g or not(12c)
104
+ */
105
+ updateVerifierData(sessionData, password, newPassword, verifier11G, authObj) {
106
+ let keyLen = 32;
107
+ let hashAlg = 'sha512';
108
+
109
+ let verifierData = Buffer.from(sessionData['AUTH_VFR_DATA'], 'hex');
110
+ let encodedServerKey = Buffer.from(sessionData['AUTH_SESSKEY'], 'hex');
111
+ let iterations = Number(sessionData['AUTH_PBKDF2_VGEN_COUNT']);
112
+ let passwordBytes = Buffer.from(password, 'utf8');
113
+ let passwordHash;
114
+ let passwordKey;
115
+
116
+ if (verifier11G) {
117
+ algorithm = 'aes-192-cbc';
118
+ keyLen = 24;
119
+ hashAlg = 'sha1';
120
+ let h = crypto.createHash(hashAlg);
121
+ h.update(passwordBytes);
122
+ h.update(verifierData);
123
+ let ph = h.digest();
124
+ passwordHash = Buffer.alloc(ph.length + 4);
125
+ ph.copy(passwordHash, 0, 0, ph.length);
126
+ } else {
127
+ algorithm = 'aes-256-cbc';
128
+ let temp = Buffer.from('AUTH_PBKDF2_SPEEDY_KEY', 'utf8');
129
+ let salt = Buffer.concat([verifierData, temp]);
130
+ passwordKey = crypto.pbkdf2Sync(passwordBytes, salt, iterations, 64, 'sha512');
131
+ let h = crypto.createHash(hashAlg);
132
+ h.update(passwordKey);
133
+ h.update(verifierData);
134
+ passwordHash = h.digest().slice(0, keyLen);
135
+ }
136
+
137
+ let newPasswordBytes;
138
+ if (newPassword) {
139
+ newPasswordBytes = Buffer.from(newPassword, 'utf8');
140
+ }
141
+ let sessionKeyParta = this._decrypt(passwordHash, encodedServerKey);
142
+ let sessionKeyPartb = Buffer.alloc(32);
143
+ crypto.randomFillSync(sessionKeyPartb, 0, 32);
144
+ let encodedClientKey = this._encrypt(passwordHash, sessionKeyPartb);
145
+ authObj.sessionKey = encodedClientKey.slice().toString('hex').toUpperCase().slice(0, 64);
146
+
147
+ iterations = Number(sessionData['AUTH_PBKDF2_SDER_COUNT']);
148
+ let mixingSalt = Buffer.from(sessionData['AUTH_PBKDF2_CSK_SALT'], 'hex');
149
+ let partABKey = Buffer.concat([sessionKeyPartb.slice(0, keyLen), sessionKeyParta.slice(0, keyLen)]);
150
+ let partABKeyStr = partABKey.toString('hex').toUpperCase();
151
+ let partABKeyBuffer = Buffer.from(partABKeyStr, 'utf8');
152
+ authObj.comboKey = crypto.pbkdf2Sync(partABKeyBuffer, mixingSalt, iterations, keyLen, 'sha512');
153
+
154
+ let salt = Buffer.alloc(16);
155
+ if (!verifier11G) {
156
+ crypto.randomFillSync(salt, 0, 16);
157
+ let temp = Buffer.concat([salt, passwordKey]);
158
+ authObj.speedyKey = this._encrypt(authObj.comboKey, temp);
159
+ authObj.speedyKey = authObj.speedyKey.slice(0, 80).toString('hex').toUpperCase();
160
+ }
161
+ this._setEncryptedPasswordBuffers(passwordBytes, newPasswordBytes, authObj.comboKey, authObj);
162
+ }
163
+
164
+ getEncryptedJSWPData(sessionKey, jdwpData) {
165
+ let buf = this._encrypt(sessionKey, jdwpData, true);
166
+
167
+ // Add a "01" at the end of the hex encrypted data to indicate the
168
+ // use of AES encryption
169
+ buf = buf.slice().toString('hex').toUpperCase();
170
+ buf = Buffer.concat([buf, _appendBuffer]);
171
+ return buf;
172
+ }
173
+
174
+ updatePasswordsWithComboKey(password, newPassword, comboKey, authObj) {
175
+ let passwordBytes = Buffer.from(password, 'utf8');
176
+ let newPasswordBytes;
177
+ if (newPassword) {
178
+ newPasswordBytes = Buffer.from(newPassword, 'utf8');
179
+ }
180
+ this._setEncryptedPasswordBuffers(passwordBytes, newPasswordBytes, comboKey, authObj);
181
+ }
182
+ }
183
+
184
+ let encryptDecryptInst = new EncryptDecrypt();
185
+ module.exports = encryptDecryptInst;
@@ -0,0 +1,348 @@
1
+ // Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // This software is dual-licensed to you under the Universal Permissive License
6
+ // (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7
+ // 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8
+ // either license.
9
+ //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
12
+ //
13
+ // Licensed under the Apache License, Version 2.0 (the "License");
14
+ // you may not use this file except in compliance with the License.
15
+ // You may obtain a copy of the License at
16
+ //
17
+ // https://www.apache.org/licenses/LICENSE-2.0
18
+ //
19
+ // Unless required by applicable law or agreed to in writing, software
20
+ // distributed under the License is distributed on an "AS IS" BASIS,
21
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ // See the License for the specific language governing permissions and
23
+ // limitations under the License.
24
+ //
25
+ //-----------------------------------------------------------------------------
26
+
27
+ 'use strict';
28
+
29
+ const constants = require("../constants.js");
30
+ const errors = require("../../../errors.js");
31
+ const os = require("os");
32
+ const process = require("process");
33
+ const ED = require("../encryptDecrypt.js");
34
+ const Message = require("./base.js");
35
+ const util = require("../../util.js");
36
+
37
+ const crypto = require('crypto');
38
+
39
+ /**
40
+ * Executes OSESSKEY and OAUTH RPC functions
41
+ *
42
+ * @class AuthMessage
43
+ * @extends {Message}
44
+ */
45
+ class AuthMessage extends Message {
46
+ /**
47
+ * Represents the data required for OAUTH and OSESSKEY rpc.
48
+ *
49
+ * @param {object} conn Connection object
50
+ * @param {object} config Dynamic Configuration like change password config after connection is established
51
+ */
52
+ constructor(conn, config) {
53
+ super(conn);
54
+ this.functionCode = constants.TNS_FUNC_AUTH_PHASE_ONE;
55
+ this.messageType = constants.TNS_MSG_TYPE_FUNCTION;
56
+ this.sessionData = {};
57
+ this.conn = conn;
58
+ this.sessionKey = "";
59
+ this.encodedPassword = "";
60
+ this.changePassword = false;
61
+ Object.defineProperty(this, 'password', {
62
+ enumerable: false,
63
+ value: config.password,
64
+ });
65
+ this.username = config.user;
66
+ if (this.username === undefined) {
67
+ this.username = "";
68
+ } else {
69
+ // trim leading and trailing spaces
70
+ this.username = this.username.trim();
71
+ }
72
+ this.schemaUser = '';
73
+ this.proxyUser = '';
74
+ this.proxyStatus = -1;
75
+ if (this.username.length !== 0) {
76
+ this.proxyStatusObj = util.checkProxyUserValidity(this.username);
77
+ if (this.proxyStatusObj.status === 0) {
78
+ this.proxyStatus = 0;
79
+ this.proxyUser = this.proxyStatusObj.proxyUser;
80
+ this.schemaUser = this.proxyStatusObj.schemaUser;
81
+ this.username = this.proxyUser;
82
+ }
83
+ }
84
+ this.newPassword = config.newPassword;
85
+ if (config.changePassword) {
86
+ // ChangePassword issued after login would use the same comboKey
87
+ // used in initial Login. We issue only OAUTH.
88
+ this.changePassword = true;
89
+ this.functionCode = constants.TNS_FUNC_AUTH_PHASE_TWO;
90
+ }
91
+ if (this.username) {
92
+ this.userByteLen = Buffer.byteLength(this.username); // Get utf8 encoded number of bytes
93
+ } else {
94
+ this.userByteLen = 0;
95
+ }
96
+ this.token = config.token;
97
+ if (this.token)
98
+ this.functionCode = constants.TNS_FUNC_AUTH_PHASE_TWO;
99
+ this.privateKey = config.privateKey;
100
+ if (this.privateKey) {
101
+ this.privateKey = '-----BEGIN PRIVATE KEY-----\n' + this.privateKey;
102
+ this.privateKey = this.privateKey + '\n' + '-----END PRIVATE KEY-----';
103
+ }
104
+ this.serviceName = this.conn.serviceName;
105
+ this.remoteAddress = this.conn.remoteAddress;
106
+ this.setAuthMode();
107
+ }
108
+
109
+ setAuthMode() {
110
+ if (!this.newPassword) {
111
+ this.authMode = constants.TNS_AUTH_MODE_LOGON;
112
+ }
113
+ if (this.conn.privilege & constants.SYSDBA) {
114
+ this.authMode |= constants.TNS_AUTH_MODE_SYSDBA;
115
+ }
116
+ if (this.conn.privilege & constants.SYSOPER) {
117
+ this.authMode |= constants.TNS_AUTH_MODE_SYSOPER;
118
+ }
119
+ if (this.conn.privilege & constants.SYSASM) {
120
+ this.authMode |= constants.TNS_AUTH_MODE_SYSASM;
121
+ }
122
+ if (this.conn.privilege & constants.SYSBKP) {
123
+ this.authMode |= constants.TNS_AUTH_MODE_SYSBKP;
124
+ }
125
+ if (this.conn.privilege & constants.SYSDG) {
126
+ this.authMode |= constants.TNS_AUTH_MODE_SYSDGD;
127
+ }
128
+ if (this.conn.privilege & constants.SYSKM) {
129
+ this.authMode |= constants.TNS_AUTH_MODE_SYSKMT;
130
+ }
131
+ if (this.conn.privilege & constants.SYSRAC) {
132
+ this.authMode |= constants.TNS_AUTH_MODE_SYSRAC;
133
+ }
134
+ if (this.privateKey) {
135
+ this.authMode |= constants.TNS_AUTH_MODE_IAM_TOKEN;
136
+ }
137
+ if (this.newPassword) {
138
+ this.authMode |= constants.TNS_AUTH_MODE_CHANGE_PASSWORD;
139
+ }
140
+ if (!this.token) {
141
+ this.authMode |= constants.TNS_AUTH_MODE_WITH_PASSWORD;
142
+ }
143
+ }
144
+
145
+ getAlterTimezoneStatement() {
146
+ let sign, tzRepr;
147
+ if (process.env.ORA_SDTZ) {
148
+ tzRepr = process.env.ORA_SDTZ;
149
+ } else {
150
+ const date = new Date();
151
+ const timezoneMinutes = date.getTimezoneOffset();
152
+ let tzHour = Math.trunc(timezoneMinutes / 60);
153
+ const tzMinutes = Math.abs((timezoneMinutes - tzHour * 60) % 60);
154
+ if (tzHour < 0) {
155
+ sign = '+'; // getTimezoneOffset() = localtime - timeUTC
156
+ tzHour = -tzHour;
157
+ } else {
158
+ sign = '-';
159
+ }
160
+ tzHour = tzHour.toLocaleString('en-US', {minimumIntegerDigits: 2});
161
+ tzRepr = `${sign}${tzHour}:${tzMinutes}`;
162
+ }
163
+ return `ALTER SESSION SET TIME_ZONE ='${tzRepr}'\x00`;
164
+ }
165
+
166
+ encode(buf) {
167
+ let verifier11G = false;
168
+ this.writeFunctionHeader(buf);
169
+ if (this.userByteLen > 0) {
170
+ buf.writeUInt8(1);
171
+ } else {
172
+ buf.writeUInt8(0);
173
+ }
174
+ buf.writeUB4(this.userByteLen);
175
+ buf.writeUB4(this.authMode);
176
+
177
+ if (this.functionCode === constants.TNS_FUNC_AUTH_PHASE_ONE) {
178
+ buf.writeUInt8(1);
179
+ buf.writeUB4(5);
180
+ buf.writeUInt8(0);
181
+ buf.writeUInt8(1);
182
+ if (this.userByteLen > 0) {
183
+ buf.writeBytesWithLength(Buffer.from(this.username));
184
+ }
185
+ buf.writeKeyValue("AUTH_TERMINAL", "unknown");
186
+ buf.writeKeyValue("AUTH_PROGRAM_NM", process.argv0);
187
+ buf.writeKeyValue("AUTH_MACHINE", os.hostname());
188
+ buf.writeKeyValue("AUTH_PID", process.pid.toString());
189
+ buf.writeKeyValue("AUTH_SID", os.userInfo().username);
190
+
191
+ } else {
192
+ let numPairs = 0;
193
+
194
+ if (this.changePassword) {
195
+ ED.updatePasswordsWithComboKey(this.password, this.newPassword, this.conn.comboKey, this);
196
+ numPairs = 2;
197
+ } else {
198
+ numPairs = 4;
199
+ if (this.token) {
200
+ numPairs += 1;
201
+ } else {
202
+ numPairs += 2;
203
+ if (this.verifierType === constants.TNS_VERIFIER_TYPE_11G_1 ||
204
+ this.verifierType === constants.TNS_VERIFIER_TYPE_11G_2) {
205
+ verifier11G = true;
206
+ } else if (this.verifierType !== constants.TNS_VERIFIER_TYPE_12C) {
207
+ errors.throwErr(errors.ERR_UNSUPPORTED_VERIFIER_TYPE,
208
+ this.verifierType.toString(16));
209
+ } else {
210
+ numPairs += 1;
211
+ }
212
+ ED.updateVerifierData(this.sessionData, this.password, this.newPassword, verifier11G, this);
213
+
214
+ // The comboKey is cached inside the conn which is used
215
+ // for changePassword issued on the connection
216
+ this.conn.comboKey = this.comboKey;
217
+ if (this.newPassword) {
218
+ numPairs += 1;
219
+ }
220
+ }
221
+
222
+ if (this.privateKey) {
223
+ numPairs += 2;
224
+ }
225
+ if (this.conn.connClass) {
226
+ numPairs += 1;
227
+ }
228
+ if (this.conn.purity) {
229
+ numPairs += 1;
230
+ }
231
+ if (this.conn.jdwpData) {
232
+ this.encryptedJDWPData = ED.getEncryptedJSWPData(this.sessionKey, this.conn.jdwpData);
233
+ numPairs += 1;
234
+ }
235
+ if (this.schemaUser.length !== 0) {
236
+ numPairs += 1;
237
+ }
238
+ }
239
+
240
+ buf.writeUInt8(1);
241
+ buf.writeUB4(numPairs);
242
+ buf.writeUInt8(1);
243
+ buf.writeUInt8(1);
244
+ if (this.userByteLen > 0)
245
+ buf.writeBytesWithLength(Buffer.from(this.username));
246
+ if (this.token) {
247
+ buf.writeKeyValue("AUTH_TOKEN", this.token);
248
+ } else {
249
+ if (!this.changePassword) {
250
+ buf.writeKeyValue("AUTH_SESSKEY", this.sessionKey, 1);
251
+ if (!verifier11G) {
252
+ buf.writeKeyValue("AUTH_PBKDF2_SPEEDY_KEY", this.speedyKey);
253
+ }
254
+ }
255
+ }
256
+ if (!this.changePassword) {
257
+ buf.writeKeyValue("SESSION_CLIENT_CHARSET", "873");
258
+ buf.writeKeyValue("SESSION_CLIENT_DRIVER_NAME", constants.DRIVER_NAME);
259
+ buf.writeKeyValue("SESSION_CLIENT_VERSION",
260
+ constants.CLIENT_VERSION.toString());
261
+ buf.writeKeyValue("AUTH_ALTER_SESSION", this.getAlterTimezoneStatement(), 1);
262
+ }
263
+ if (this.encodedPassword) {
264
+ buf.writeKeyValue("AUTH_PASSWORD", this.encodedPassword);
265
+ }
266
+ if (this.proxyStatus === 0) {
267
+ buf.writeKeyValue("PROXY_CLIENT_NAME", this.schemaUser);
268
+ }
269
+ if (this.encodedNewPassword) {
270
+ buf.writeKeyValue("AUTH_NEWPASSWORD", this.encodedNewPassword);
271
+ }
272
+ if (this.conn.connClass) {
273
+ buf.writeKeyValue("AUTH_KPPL_CONN_CLASS", this.conn.connClass);
274
+ }
275
+ if (this.conn.purity) {
276
+ buf.writeKeyValue("AUTH_KPPL_PURITY", '' + this.conn.purity);
277
+ }
278
+ if (this.privateKey) {
279
+ const currentDate = new Date();
280
+ const currentDateFormatted = currentDate.toGMTString();
281
+
282
+ let header = "date: " + currentDateFormatted + "\n" +
283
+ "(request-target): " + this.serviceName + "\n" +
284
+ "host: " + this.remoteAddress;
285
+
286
+ let signature = crypto.createSign('RSA-SHA256')
287
+ .update(header)
288
+ .sign(this.privateKey, 'base64');
289
+
290
+ buf.writeKeyValue("AUTH_HEADER", header);
291
+ buf.writeKeyValue("AUTH_SIGNATURE", signature);
292
+ }
293
+ if (this.conn.jdwpData) {
294
+ buf.writeKeyValue("AUTH_ORA_DEBUG_JDWP", this.encryptedJDWPData);
295
+ }
296
+
297
+ }
298
+ }
299
+
300
+ processReturnParameter(buf) {
301
+ let numParams = buf.readUB2();
302
+ for (let i = 0; i < numParams;i++) {
303
+ buf.skipUB4();
304
+ let key = buf.readStr(constants.TNS_CS_IMPLICIT);
305
+ let value = "";
306
+ let numBytes = buf.readUB4();
307
+ if (numBytes > 0) {
308
+ value = buf.readStr(constants.TNS_CS_IMPLICIT);
309
+ }
310
+ let flag = buf.readUB4();
311
+ if (key === "AUTH_VFR_DATA") {
312
+ this.verifierType = flag;
313
+ }
314
+ this.sessionData[key] = value;
315
+
316
+ }
317
+ if (this.functionCode === constants.TNS_FUNC_AUTH_PHASE_ONE) {
318
+ this.functionCode = constants.TNS_FUNC_AUTH_PHASE_TWO;
319
+ } else {
320
+ let versionNum;
321
+ let releaseNum;
322
+ let updateNum;
323
+ let portReleaseNum;
324
+ let portUpdateNum;
325
+
326
+ this.conn.sessionID = this.sessionData['AUTH_SESSION_ID'];
327
+ this.conn.serialNum = this.sessionData['AUTH_SERIAL_NUM'];
328
+ let fullVersionNum = Number(this.sessionData['AUTH_VERSION_NO']);
329
+ versionNum = (fullVersionNum >> 24) & 0xFF;
330
+ if (buf.caps.ttcFieldVersion >= constants.TNS_CCAP_FIELD_VERSION_18_1_EXT_1) {
331
+ releaseNum = (fullVersionNum >> 16) & 0xFF;
332
+ updateNum = (fullVersionNum >> 12) & 0x0F;
333
+ portReleaseNum = (fullVersionNum >> 4) & 0xFF;
334
+ portUpdateNum = fullVersionNum & 0x0F;
335
+ } else {
336
+ releaseNum = (fullVersionNum >> 20) & 0x0F;
337
+ updateNum = (fullVersionNum >> 12) & 0xFF;
338
+ portReleaseNum = (fullVersionNum >> 8) & 0x0F;
339
+ portUpdateNum = fullVersionNum & 0xFF;
340
+ }
341
+ this.conn.serverVersionString = versionNum + '.' + releaseNum + '.' + updateNum + '.' + portReleaseNum + '.' + portUpdateNum;
342
+ this.conn.serverVersion = versionNum * 100000000 + releaseNum * 1000000 + updateNum * 10000 + portReleaseNum * 100 + portUpdateNum * 1;
343
+ }
344
+ }
345
+
346
+ }
347
+
348
+ module.exports = AuthMessage;