Skip to content

Commit 8377cca

Browse files
committed
Fixed bug when connecting to databses using older 11g password verifiers
1 parent f7b336d commit 8377cca

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ node-oracledb `v6.0.2 <https://github.com/oracle/node-oracledb/compare/v6.0.1...
1111
Thin Mode Changes
1212
+++++++++++++++++
1313

14+
#) Fixed bug connecting to databases with older 11g password verifiers.
15+
1416
#) Fixed bug when the length of a chunk inside a chunked read spans packets.
1517
`Issue #1576 <https://github.com/oracle/node-oracledb/issues/1576>`__.
1618

lib/thin/protocol/encryptDecrypt.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,30 @@ class EncryptDecrypt {
138138
if (newPassword) {
139139
newPasswordBytes = Buffer.from(newPassword, 'utf8');
140140
}
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');
141+
const sessionKeyParta = this._decrypt(passwordHash, encodedServerKey);
142+
const sessionKeyPartb = Buffer.alloc(sessionKeyParta.length);
143+
crypto.randomFillSync(sessionKeyPartb);
144+
const encodedClientKey = this._encrypt(passwordHash, sessionKeyPartb);
145+
146+
if (sessionKeyParta.length === 48) {
147+
authObj.sessionKey = encodedClientKey.slice().toString('hex').toUpperCase().slice(0, 96);
148+
const buf = Buffer.alloc(24);
149+
for (let i = 16; i <= 40; i++) {
150+
buf[i - 16] = sessionKeyParta[i] ^ sessionKeyPartb[i];
151+
}
152+
const part1 = crypto.createHash("md5").update(buf.subarray(0, 16)).digest();
153+
const part2 = crypto.createHash("md5").update(buf.subarray(16)).digest();
154+
authObj.comboKey = Buffer.concat([part1, part2]).slice(0, keyLen);
155+
} else {
156+
authObj.sessionKey = encodedClientKey.slice().toString('hex').toUpperCase().slice(0, 64);
157+
const mixingSalt = Buffer.from(sessionData['AUTH_PBKDF2_CSK_SALT'], 'hex');
158+
iterations = Number(sessionData['AUTH_PBKDF2_SDER_COUNT']);
159+
const partABKey = Buffer.concat([sessionKeyPartb.slice(0, keyLen), sessionKeyParta.slice(0, keyLen)]);
160+
const partABKeyStr = partABKey.toString('hex').toUpperCase();
161+
const partABKeyBuffer = Buffer.from(partABKeyStr, 'utf8');
162+
authObj.comboKey = crypto.pbkdf2Sync(partABKeyBuffer, mixingSalt,
163+
iterations, keyLen, 'sha512');
164+
}
153165

154166
let salt = Buffer.alloc(16);
155167
if (!verifier11G) {

0 commit comments

Comments
 (0)