Skip to content

Commit 23cef69

Browse files
committed
Added support for in-memory wallet (Issue #1671)
1 parent 660a144 commit 23cef69

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

doc/src/release_notes.rst

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

16+
#) Added support for in-memory wallet by adding a new parameter ``walletContent``
17+
of the type ``string`` which will let users pass the wallet content directly instead
18+
of storing and reading it up from a file.
19+
`Issue #1671 <https://github.com/oracle/node-oracledb/issues/
20+
1671>`__.
21+
1622
#) Added support to use ``IFILE`` parameter to embed custom
1723
network configuration files in the :ref:`tnsnames.ora <tnsadmin>` file.
1824

lib/oracledb.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ async function _verifyOptions(options, inCreatePool) {
177177
outOptions.walletLocation = options.walletLocation;
178178
}
179179

180+
//wallet content must be a string
181+
if (options.walletContent !== undefined) {
182+
errors.assertParamPropValue(typeof options.walletContent === 'string', 1,
183+
"walletContent");
184+
outOptions.walletContent = options.walletContent;
185+
}
186+
180187
// edition must be a string
181188
if (options.edition !== undefined) {
182189
errors.assertParamPropValue(typeof options.edition === 'string', 1,

lib/thin/pool.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ThinPoolImpl extends PoolImpl {
6464
this._usedConnectionList = new Set();
6565
this._password = params.password;
6666
this._walletPassword = params.walletPassword;
67+
this._walletContent = params.walletContent;
6768
this._obfuscatedPassword = [];
6869
this._obfuscatedWalletPassword = [];
6970
this._token = params.token;
@@ -88,6 +89,13 @@ class ThinPoolImpl extends PoolImpl {
8889
this._obfuscatedWalletPassword = obj.obfuscatedValue;
8990
this._userConfig.walletPassword = null;
9091
}
92+
// wallet content obfuscation
93+
if (this._walletContent !== undefined) {
94+
const obj = protocolUtil.setObfuscatedValue(this._walletContent);
95+
this._walletContent = obj.value;
96+
this._obfuscatedWalletContent = obj.obfuscatedValue;
97+
this._userConfig.walletConent = null;
98+
}
9199
// token obfuscation
92100
if (this._token !== undefined) {
93101
const obj = protocolUtil.setObfuscatedValue(this._token);
@@ -172,6 +180,13 @@ class ThinPoolImpl extends PoolImpl {
172180
this._obfuscatedWalletPassword);
173181
}
174182

183+
// deobfuscate wallet content
184+
if (clonedAttrs.walletContent === null) {
185+
clonedAttrs.walletContent =
186+
protocolUtil.getDeobfuscatedValue(this._walletContent,
187+
this._obfuscatedWalletContent);
188+
}
189+
175190
// deobfuscate token and private key
176191
// check for token expiry
177192
if (clonedAttrs.token === null) {

lib/thin/sqlnet/networkSession.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class NetworkSession {
301301
this.markerPkt = new Packet.MarkerPacket(this.sAtts.largeSDU);
302302
this.controlPkt = new Packet.ControlPacket();
303303
this.ntAdapter.largeSDU = this.sAtts.largeSDU;
304-
this.sAtts.nt.wallet = null;
304+
this.sAtts.clearWallet();
305305
this.sAtts.nt.walletPassword = null;
306306
return (true);
307307
}
@@ -328,6 +328,7 @@ class NetworkSession {
328328
this.ntAdapter.disconnect(constants.NSFIMM);
329329
this.ntAdapter = null;
330330
}
331+
this.sAtts.clearWallet();
331332
connected = false;
332333
savedErr = err;
333334
try {

lib/thin/sqlnet/sessionAtts.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class SessionAtts {
7777
if (typeof params.walletPassword === 'string') {
7878
this.nt.walletPassword = params.walletPassword;
7979
}
80+
if (typeof params.walletContent === 'string') {
81+
this.nt.wallet = params.walletContent;
82+
}
8083
if (params.expireTime > 0) {
8184
this.nt.expireTime = params.expireTime * 1000 * 60;
8285
}
@@ -135,6 +138,15 @@ class SessionAtts {
135138
});
136139
}
137140

141+
/**
142+
* Clear wallet
143+
*/
144+
clearWallet() {
145+
if (this.nt.wallet && Buffer.isBuffer(this.nt.wallet))
146+
this.nt.wallet.fill(0);
147+
this.nt.wallet = null;
148+
}
149+
138150
/**
139151
* Prepare attributes for connection, Generate Connection ID and read Wallet file
140152
*
@@ -151,7 +163,7 @@ class SessionAtts {
151163
}
152164
this.nt.connectionId = this.connectionId;
153165

154-
if (protocol && (protocol.toUpperCase() == "TCPS" && this.nt.walletFile)) {
166+
if (protocol && (protocol.toUpperCase() == "TCPS" && !this.nt.wallet && this.nt.walletFile)) {
155167
this.nt.wallet = await this.readWalletFile();
156168
}
157169

0 commit comments

Comments
 (0)