teradatasql 20.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 (59) hide show
  1. package/LICENSE +196 -0
  2. package/README.md +1447 -0
  3. package/THIRDPARTYLICENSE +40 -0
  4. package/lib/index.d.ts +14 -0
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.js +50 -0
  7. package/lib/index.js.map +1 -0
  8. package/lib/teradata-connection.d.ts +74 -0
  9. package/lib/teradata-connection.d.ts.map +1 -0
  10. package/lib/teradata-connection.js +280 -0
  11. package/lib/teradata-connection.js.map +1 -0
  12. package/lib/teradata-cursor.d.ts +58 -0
  13. package/lib/teradata-cursor.d.ts.map +1 -0
  14. package/lib/teradata-cursor.js +746 -0
  15. package/lib/teradata-cursor.js.map +1 -0
  16. package/lib/teradata-exceptions.d.ts +19 -0
  17. package/lib/teradata-exceptions.d.ts.map +1 -0
  18. package/lib/teradata-exceptions.js +52 -0
  19. package/lib/teradata-exceptions.js.map +1 -0
  20. package/lib/teradata-logging.d.ts +23 -0
  21. package/lib/teradata-logging.d.ts.map +1 -0
  22. package/lib/teradata-logging.js +79 -0
  23. package/lib/teradata-logging.js.map +1 -0
  24. package/lib/teradatasql.dll +0 -0
  25. package/lib/teradatasql.dylib +0 -0
  26. package/lib/teradatasql.so +0 -0
  27. package/package.json +33 -0
  28. package/samples/AGKRBatchInsert.js +38 -0
  29. package/samples/AGKRInsertSelect.js +28 -0
  30. package/samples/BatchInsPerf.js +47 -0
  31. package/samples/BatchInsert.js +17 -0
  32. package/samples/BatchInsertCSV.js +54 -0
  33. package/samples/CharPadding.js +31 -0
  34. package/samples/CommitRollback.js +31 -0
  35. package/samples/DecimalDigits.js +49 -0
  36. package/samples/DriverDatabaseVersion.js +14 -0
  37. package/samples/ElicitFile.js +19 -0
  38. package/samples/ExportCSVResult.js +54 -0
  39. package/samples/ExportCSVResults.js +60 -0
  40. package/samples/FakeExportCSVResults.js +82 -0
  41. package/samples/FakeResultSetCon.js +72 -0
  42. package/samples/FakeResultSetEsc.js +72 -0
  43. package/samples/FastExportCSV.js +102 -0
  44. package/samples/FastExportTable.js +76 -0
  45. package/samples/FastLoadBatch.js +152 -0
  46. package/samples/FastLoadCSV.js +116 -0
  47. package/samples/HelpSession.js +18 -0
  48. package/samples/IgnoreErrors.js +125 -0
  49. package/samples/InsertLob.js +62 -0
  50. package/samples/InsertXML.js +37 -0
  51. package/samples/LoadCSVFile.js +41 -0
  52. package/samples/LobLocators.js +57 -0
  53. package/samples/MetadataFromPrepare.js +23 -0
  54. package/samples/ParamDataTypes.js +70 -0
  55. package/samples/ShowCommand.js +31 -0
  56. package/samples/StoredProc.js +77 -0
  57. package/samples/TJEncryptPassword.js +270 -0
  58. package/samples/airports.csv +9 -0
  59. package/samples/udfinc.c +6 -0
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const teradatasql_1 = require("teradatasql");
23
+ const fs = __importStar(require("fs"));
24
+ const crypto = __importStar(require("crypto"));
25
+ function convertJavaNames(sName, nKeySizeInBits = 0, sMode = "") {
26
+ if (sName === "DES") {
27
+ sName = "des-" + sMode.toLowerCase();
28
+ }
29
+ else if (sName === "DESede") {
30
+ sName = "des-ede3-" + sMode.toLowerCase();
31
+ }
32
+ else if (sName === "AES") {
33
+ sName = "aes-" + nKeySizeInBits.toString() + "-" + sMode.toLowerCase();
34
+ }
35
+ return sName;
36
+ }
37
+ function createPasswordEncryptionKeyFile(sTransformation, sAlgorithm, sMatch, sMac, nKeySizeInBits, sPassKeyFileName) {
38
+ const nKeySizeInBytes = nKeySizeInBits / 8;
39
+ const abyKey = crypto.randomBytes(nKeySizeInBytes);
40
+ const nMacBlockSizeBytes = 64;
41
+ const abyMacKey = crypto.randomBytes(nMacBlockSizeBytes);
42
+ const sKeyHexDigits = abyKey.toString("hex");
43
+ const sMacKeyHexDigits = abyMacKey.toString("hex");
44
+ const fileData = "# Teradata SQL Driver password encryption key file\n" +
45
+ "version=1\n" +
46
+ "transformation=" +
47
+ sTransformation +
48
+ "\n" +
49
+ "algorithm=" +
50
+ sAlgorithm +
51
+ "\n" +
52
+ "match=" +
53
+ sMatch +
54
+ "\n" +
55
+ "key=" +
56
+ sKeyHexDigits +
57
+ "\n" +
58
+ "mac=" +
59
+ sMac +
60
+ "\n" +
61
+ "mackey=" +
62
+ sMacKeyHexDigits +
63
+ "\n";
64
+ const asTransformationParts = sTransformation.split("/");
65
+ if (asTransformationParts.length !== 3) {
66
+ console.log(">>> Invalid transformation: " + sTransformation);
67
+ process.exit(1);
68
+ }
69
+ fs.writeFileSync(sPassKeyFileName, fileData, { encoding: "latin1" });
70
+ return [abyKey, abyMacKey];
71
+ }
72
+ function createEncryptedPasswordFile(sTransformation, sAlgorithm, sMatch, sMac, sMode, nKeySizeInBits, abyKey, abyMacKey, sEncPassFileName, nCipherBlockSizeInBytes, sPassword) {
73
+ let abyPassword = Buffer.from(sPassword, "utf8");
74
+ const abyIV = crypto.randomBytes(nCipherBlockSizeInBytes);
75
+ const octetStringTag = 0x04;
76
+ let abyASN1EncodedIV = Buffer.allocUnsafe(2);
77
+ abyASN1EncodedIV[0] = octetStringTag;
78
+ abyASN1EncodedIV[1] = abyIV.length;
79
+ abyASN1EncodedIV = Buffer.concat([abyASN1EncodedIV, abyIV], abyASN1EncodedIV.length + abyIV.length);
80
+ const nPlaintextByteCount = (Math.floor(abyPassword.length / 512) + 1) * 512;
81
+ const nTrailerByteCount = nPlaintextByteCount - abyPassword.length;
82
+ const emptyBuffer = Buffer.alloc(nTrailerByteCount);
83
+ abyPassword = Buffer.concat([abyPassword, emptyBuffer], abyPassword.length + emptyBuffer.length);
84
+ const nodeAlgorithmName = convertJavaNames(sAlgorithm, nKeySizeInBits, sMode);
85
+ const cipher = crypto.createCipheriv(nodeAlgorithmName, abyKey, abyIV);
86
+ let abyEncryptedPassword = cipher.update(abyPassword);
87
+ const finalCipher = cipher.final();
88
+ abyEncryptedPassword = Buffer.concat([abyEncryptedPassword, finalCipher], abyEncryptedPassword.length + finalCipher.length);
89
+ const sEncryptedPasswordHexDigits = abyEncryptedPassword.toString("hex");
90
+ const sASN1EncodedIVHexDigits = abyASN1EncodedIV.toString("hex");
91
+ const abyTransformation = Buffer.from(sTransformation, "utf8");
92
+ const abyContentLength = abyEncryptedPassword.length + abyTransformation.length + abyASN1EncodedIV.length;
93
+ const abyContent = Buffer.concat([abyEncryptedPassword, abyTransformation, abyASN1EncodedIV], abyContentLength);
94
+ sMac = sMac.slice(4).toLowerCase();
95
+ const hmac = crypto.createHmac(sMac, abyMacKey);
96
+ hmac.update(abyContent);
97
+ const sHashHexDigits = hmac.digest("hex");
98
+ const fileData = "# Teradata SQL Driver encrypted password file\n" +
99
+ "version=1\n" +
100
+ "match=" +
101
+ sMatch +
102
+ "\n" +
103
+ "password=" +
104
+ sEncryptedPasswordHexDigits +
105
+ "\n" +
106
+ "params=" +
107
+ sASN1EncodedIVHexDigits +
108
+ "\n" +
109
+ "hash=" +
110
+ sHashHexDigits +
111
+ "\n";
112
+ fs.writeFileSync(sEncPassFileName, fileData, { encoding: "latin1" });
113
+ }
114
+ function loadPropertiesFile(sFileName) {
115
+ const properties = {};
116
+ const content = fs.readFileSync(sFileName, { encoding: "latin1" });
117
+ const lines = content.split("\n");
118
+ lines.forEach((line) => {
119
+ line = line.trim();
120
+ if (line.indexOf("#") !== 0) {
121
+ const asTokens = line.split("=", 2);
122
+ if (asTokens.length === 2) {
123
+ const sKey = asTokens[0];
124
+ const sValue = asTokens[1];
125
+ properties[sKey] = sValue;
126
+ }
127
+ }
128
+ });
129
+ return properties;
130
+ }
131
+ function decryptPassword(sPassKeyFileName, sEncPassFileName) {
132
+ const mapPassKey = loadPropertiesFile(sPassKeyFileName);
133
+ const mapEncPass = loadPropertiesFile(sEncPassFileName);
134
+ const algorithmString = "algorithm";
135
+ const hashString = "hash";
136
+ const keyString = "key";
137
+ const macString = "mac";
138
+ const mackeyString = "mackey";
139
+ const matchString = "match";
140
+ const paramsString = "params";
141
+ const passwordString = "password";
142
+ const transformationString = "transformation";
143
+ const versionString = "version";
144
+ if (mapPassKey[versionString] !== "1") {
145
+ console.log("Unrecognized version %s in file %s", mapPassKey[versionString], sPassKeyFileName);
146
+ process.exit(1);
147
+ }
148
+ if (mapEncPass[versionString] !== "1") {
149
+ console.log("Unrecognized version %s in file %s", mapPassKey[versionString], sEncPassFileName);
150
+ process.exit(1);
151
+ }
152
+ if (mapPassKey[matchString] !== mapEncPass[matchString]) {
153
+ console.log("Match value differs between files %s and %s", sPassKeyFileName, sEncPassFileName);
154
+ process.exit(1);
155
+ }
156
+ const sTransformation = mapPassKey[transformationString];
157
+ const sAlgorithm = mapPassKey[algorithmString];
158
+ const sKeyHexDigits = mapPassKey[keyString];
159
+ const sMACAlgorithm = mapPassKey[macString];
160
+ const sMacKeyHexDigits = mapPassKey[mackeyString];
161
+ const abyTransformation = Buffer.from(sTransformation, "utf8");
162
+ const abyKey = Buffer.from(sKeyHexDigits, "hex");
163
+ const abyMacKey = Buffer.from(sMacKeyHexDigits, "hex");
164
+ const abyEncryptedPassword = Buffer.from(mapEncPass[passwordString], "hex");
165
+ const abyASN1EncodedIV = Buffer.from(mapEncPass[paramsString], "hex");
166
+ const asTransformationParts = sTransformation.split("/");
167
+ const sMode = asTransformationParts[1];
168
+ if (sAlgorithm !== asTransformationParts[0]) {
169
+ console.log("Algorithm differs from transformation in file %s", sPassKeyFileName);
170
+ process.exit(1);
171
+ }
172
+ const abyContentLength = abyEncryptedPassword.length + abyTransformation.length + abyASN1EncodedIV.length;
173
+ const abyContent = Buffer.concat([abyEncryptedPassword, abyTransformation, abyASN1EncodedIV], abyContentLength);
174
+ const sMac = sMACAlgorithm.slice(4).toLowerCase();
175
+ const hmac = crypto.createHmac(sMac, abyMacKey);
176
+ hmac.update(abyContent);
177
+ const hashHexDigits = hmac.digest("hex");
178
+ const sHashHexDigits = mapEncPass[hashString];
179
+ if (hashHexDigits !== sHashHexDigits) {
180
+ console.log("Hash mismatch indicates possible tampering with file %s or %s", sPassKeyFileName, sEncPassFileName);
181
+ process.exit(1);
182
+ }
183
+ const nKeySizeInBytes = abyKey.length;
184
+ const nKeySizeInBits = nKeySizeInBytes * 8;
185
+ const nodeAlgorithmName = convertJavaNames(sAlgorithm, nKeySizeInBits, sMode);
186
+ const abyIV = abyASN1EncodedIV.slice(2, 2 + abyASN1EncodedIV[1]);
187
+ const decipher = crypto.createDecipheriv(nodeAlgorithmName, abyKey, abyIV);
188
+ const decrypted = decipher.update(abyEncryptedPassword);
189
+ const finalCipher = decipher.final();
190
+ const abyPassword = Buffer.concat([decrypted, finalCipher], decrypted.length + finalCipher.length);
191
+ const sPassword = abyPassword.slice(0, abyPassword.indexOf("\x00")).toString("utf8");
192
+ console.log("Decrypted password: %s", sPassword);
193
+ }
194
+ if (process.argv.length !== 10) {
195
+ console.log("Parameters: Transformation KeySizeInBits MAC PasswordEncryptionKeyFileName EncryptedPasswordFileName" + " Hostname Username Password");
196
+ process.exit(1);
197
+ }
198
+ const sTransformation = process.argv[2];
199
+ const sKeySizeInBits = process.argv[3];
200
+ const sMac = process.argv[4];
201
+ const sPassKeyFileName = process.argv[5];
202
+ const sEncPassFileName = process.argv[6];
203
+ const sHostname = process.argv[7];
204
+ const sUsername = process.argv[8];
205
+ let sPassword = process.argv[9];
206
+ const asTransformationParts = sTransformation.split("/");
207
+ if (asTransformationParts.length !== 3) {
208
+ console.log("Invalid transformation: " + sTransformation);
209
+ process.exit(1);
210
+ }
211
+ const sAlgorithm = asTransformationParts[0];
212
+ const sMode = asTransformationParts[1];
213
+ const sPadding = asTransformationParts[2];
214
+ if (["DES", "DESede", "AES"].indexOf(sAlgorithm) < 0) {
215
+ console.log("Unknown algorithm " + sAlgorithm);
216
+ process.exit(1);
217
+ }
218
+ if (["CBC", "CFB", "OFB"].indexOf(sMode) < 0) {
219
+ console.log("Unknown mode " + sMode);
220
+ process.exit(1);
221
+ }
222
+ if (["PKCS5Padding", "NoPadding"].indexOf(sPadding) < 0) {
223
+ console.log("Unknown padding " + sPadding);
224
+ process.exit(1);
225
+ }
226
+ if (["HmacSHA1", "HmacSHA256"].indexOf(sMac) < 0) {
227
+ console.log("Unknown MAC algorithm " + sMac);
228
+ process.exit(1);
229
+ }
230
+ if (!sPassword) {
231
+ console.log("Password cannot be zero length");
232
+ process.exit(1);
233
+ }
234
+ const nKeySizeInBits = parseInt(sKeySizeInBits, 10);
235
+ const match = Date.now().toString();
236
+ let nCipherBlockSizeInBytes = 0;
237
+ if (sAlgorithm === "AES") {
238
+ nCipherBlockSizeInBytes = 16;
239
+ }
240
+ else {
241
+ nCipherBlockSizeInBytes = 8;
242
+ }
243
+ const encryptKeys = createPasswordEncryptionKeyFile(sTransformation, sAlgorithm, match, sMac, nKeySizeInBits, sPassKeyFileName);
244
+ createEncryptedPasswordFile(sTransformation, sAlgorithm, match, sMac, sMode, nKeySizeInBits, encryptKeys[0], encryptKeys[1], sEncPassFileName, nCipherBlockSizeInBytes, sPassword);
245
+ decryptPassword(sPassKeyFileName, sEncPassFileName);
246
+ sPassword = "ENCRYPTED_PASSWORD(file:" + sPassKeyFileName + ",file:" + sEncPassFileName + ")";
247
+ const connParams = {
248
+ host: sHostname,
249
+ password: sPassword,
250
+ user: sUsername,
251
+ };
252
+ try {
253
+ const con = new teradatasql_1.TeradataConnection();
254
+ con.connect(connParams);
255
+ const cur = con.cursor();
256
+ cur.execute("select user, session");
257
+ const row = cur.fetchone();
258
+ console.log(row);
259
+ cur.close();
260
+ con.close();
261
+ }
262
+ catch (error) {
263
+ if (error instanceof teradatasql_1.OperationalError) {
264
+ console.log(error.message);
265
+ }
266
+ else {
267
+ console.log(error);
268
+ }
269
+ }
270
+ //# sourceMappingURL=TJEncryptPassword.js.map
@@ -0,0 +1,9 @@
1
+ Chicago,Midway,MDW
2
+ Chicago,O'Hare,ORD
3
+ London,Gatwick,LGW
4
+ London,Heathrow,LHR
5
+ London,Stansted,STN
6
+ New York City,John F. Kennedy,JFK
7
+ New York City,La Guardia,LGA
8
+ "Washington, D.C.",Dulles,IAD
9
+ "Washington, D.C.",Reagan,DCA
@@ -0,0 +1,6 @@
1
+ /* Copyright 2018 by Teradata Corporation. All rights reserved. */
2
+
3
+ void udfinc (int *i, int *result, char exception [6])
4
+ {
5
+ *result = *i + 1 ;
6
+ }