k2hr3-api 1.0.42 → 2.0.1
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.
- package/config/k2hr3-init.sh.templ +4 -4
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -378
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
package/lib/k2hr3cryptutil.js
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* K2HR3 REST API
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2018 Yahoo Japan Corporation.
|
|
5
|
-
*
|
|
6
|
-
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
7
|
-
* common management information for the cloud.
|
|
8
|
-
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
9
|
-
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
10
|
-
* client system can dynamically read and modify these information.
|
|
11
|
-
*
|
|
12
|
-
* For the full copyright and license information, please view
|
|
13
|
-
* the license file that was distributed with this source code.
|
|
14
|
-
*
|
|
15
|
-
* AUTHOR: Takeshi Nakatani
|
|
16
|
-
* CREATE: Tue Oct 2 2018
|
|
17
|
-
* REVISION:
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var crypto = require('crypto');
|
|
24
|
-
var zlib = require('zlib');
|
|
25
|
-
var apiutil = require('./k2hr3apiutil');
|
|
26
|
-
|
|
27
|
-
// Debug logging objects
|
|
28
|
-
var r3logger = require('./dbglogging');
|
|
29
|
-
|
|
30
|
-
//---------------------------------------------------------
|
|
31
|
-
// Crypt for using in registering role member
|
|
32
|
-
//---------------------------------------------------------
|
|
33
|
-
// These utility functions are used by URL parameter for
|
|
34
|
-
// registering role member. The registering role member
|
|
35
|
-
// parameter is string which is encoded URI/JSON and encrypted.
|
|
36
|
-
// We use following functions for this logic.
|
|
37
|
-
//
|
|
38
|
-
function rawR3Encrypt(str, passphrase, algorithm)
|
|
39
|
-
{
|
|
40
|
-
if(!apiutil.isSafeString(str)){
|
|
41
|
-
r3logger.elog('The target string for encrypting is empty or not string.');
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
if(!apiutil.isSafeString(passphrase)){
|
|
45
|
-
r3logger.elog('The pass phrase string is empty or not string.');
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
if(!apiutil.isSafeString(algorithm)){
|
|
49
|
-
r3logger.elog('The algorithm cipher string is empty or not string.');
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
try{
|
|
53
|
-
// [NOTE] crypto.createCipher is deprecated
|
|
54
|
-
//
|
|
55
|
-
// Previously, the encoding was as follows, but this method is not used now.
|
|
56
|
-
// var cipherObj = crypto.createCipher(algorithm, passphrase);
|
|
57
|
-
// var cryptedStr = cipherObj.update(str, 'utf8', 'base64');
|
|
58
|
-
// cryptedStr += cipherObj.final('base64');
|
|
59
|
-
//
|
|
60
|
-
var initVector = crypto.randomBytes(16);
|
|
61
|
-
var pass2pbkdf = crypto.pbkdf2Sync(passphrase, initVector.toString(), 10000, 32, 'sha512');
|
|
62
|
-
var cipherObj = crypto.createCipheriv(algorithm, pass2pbkdf, initVector);
|
|
63
|
-
var cryptedMix = Buffer.concat([initVector, Buffer.from(':'), cipherObj.update(Buffer.from(str)), cipherObj.final()]);
|
|
64
|
-
var cryptedStr = cryptedMix.toString('base64');
|
|
65
|
-
|
|
66
|
-
// [NOTE]
|
|
67
|
-
// Use encodeURIComponent() instead of encodeURI() because we need to
|
|
68
|
-
// convert '/', '?', ':' characters.
|
|
69
|
-
return encodeURIComponent(cryptedStr);
|
|
70
|
-
}catch(exception){
|
|
71
|
-
r3logger.dlog(JSON.stringify(exception));
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function rawR3EncryptJSON(obj, passphrase, algorithm)
|
|
77
|
-
{
|
|
78
|
-
if(!apiutil.isSafeEntity(obj)){
|
|
79
|
-
r3logger.elog('The object is something wrong.');
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return rawR3Encrypt(JSON.stringify(obj), passphrase, algorithm);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function rawR3Decrypt(str, passphrase, algorithm)
|
|
86
|
-
{
|
|
87
|
-
if(!apiutil.isSafeString(str)){
|
|
88
|
-
r3logger.elog('The target string for encrypting is empty or not string.');
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
if(!apiutil.isSafeString(passphrase)){
|
|
92
|
-
r3logger.elog('The pass phrase string is empty or not string.');
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
if(!apiutil.isSafeString(algorithm)){
|
|
96
|
-
r3logger.elog('The algorithm cipher string is empty or not string.');
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
try{
|
|
101
|
-
// [NOTE]
|
|
102
|
-
// Use encodeURIComponent() instead of encodeURI() because we need to
|
|
103
|
-
// convert '/', '?', ':' characters.
|
|
104
|
-
var decodeStr = decodeURIComponent(str);
|
|
105
|
-
var decodeMix = Buffer.from(decodeStr, 'base64');
|
|
106
|
-
var decryptedStr;
|
|
107
|
-
|
|
108
|
-
if(decodeMix.slice(16, 17).toString() === ':'){
|
|
109
|
-
var initVector = decodeMix.slice(0, 16);
|
|
110
|
-
var pass2pbkdf = crypto.pbkdf2Sync(passphrase, initVector.toString(), 10000, 32, 'sha512');
|
|
111
|
-
var decipherObj = crypto.createDecipheriv(algorithm, pass2pbkdf, initVector);
|
|
112
|
-
var decryptedBuf= Buffer.concat([decipherObj.update(decodeMix.slice(17)), decipherObj.final()]);
|
|
113
|
-
decryptedStr = decryptedBuf.toString();
|
|
114
|
-
|
|
115
|
-
}else{
|
|
116
|
-
// [NOTE] Deprecated
|
|
117
|
-
// This is the case of the encoding used previously.
|
|
118
|
-
// For compatibility, only decoding is supported. Deprecated.
|
|
119
|
-
//
|
|
120
|
-
var cipherObj = crypto.createDecipher(algorithm, passphrase);
|
|
121
|
-
decryptedStr = cipherObj.update(decodeStr, 'base64', 'utf8');
|
|
122
|
-
decryptedStr += cipherObj.final('utf8');
|
|
123
|
-
}
|
|
124
|
-
return decryptedStr;
|
|
125
|
-
}catch(exception){
|
|
126
|
-
r3logger.dlog(JSON.stringify(exception));
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function rawR3DecryptJSON(str, passphrase, algorithm)
|
|
132
|
-
{
|
|
133
|
-
var decStr = rawR3Decrypt(str, passphrase, algorithm);
|
|
134
|
-
if(!apiutil.isSafeString(decStr)){
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
if(!apiutil.checkSimpleJSON(decStr)){
|
|
138
|
-
r3logger.elog('The decripted string(' + decStr + ') is not JSON string.');
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
return JSON.parse(decStr);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function rawR3Gzip(str, callback)
|
|
145
|
-
{
|
|
146
|
-
if(!apiutil.isSafeString(str)){
|
|
147
|
-
// not allow empty string('') too.
|
|
148
|
-
r3logger.elog('string parameter is empty.');
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if(!apiutil.isSafeEntity(callback)){
|
|
153
|
-
// sync type
|
|
154
|
-
var result = {
|
|
155
|
-
data: null,
|
|
156
|
-
length: 0
|
|
157
|
-
};
|
|
158
|
-
result.data = zlib.gzipSync(str);
|
|
159
|
-
result.length = result.data.length;
|
|
160
|
-
|
|
161
|
-
return result;
|
|
162
|
-
|
|
163
|
-
}else if('function' !== typeof callback){
|
|
164
|
-
// error
|
|
165
|
-
r3logger.elog('callback parameter is not function.');
|
|
166
|
-
return null;
|
|
167
|
-
}else{
|
|
168
|
-
// callback type
|
|
169
|
-
var _callback = callback;
|
|
170
|
-
|
|
171
|
-
zlib.gzip(str, function(error, binary){
|
|
172
|
-
if(error){
|
|
173
|
-
r3logger.elog('failed to compress(zip) string by ' + error.message);
|
|
174
|
-
return _callback(error);
|
|
175
|
-
}
|
|
176
|
-
var result = {
|
|
177
|
-
data: binary,
|
|
178
|
-
length: binary.length
|
|
179
|
-
};
|
|
180
|
-
return _callback(null, result);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function rawR3Gunzip(bin, callback)
|
|
186
|
-
{
|
|
187
|
-
if(!apiutil.isSafeEntity(bin) || !(bin instanceof Buffer)){
|
|
188
|
-
// not allow empty string('') too.
|
|
189
|
-
r3logger.elog('binary parameter is not instance of Buffer.');
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
if(!apiutil.isSafeEntity(callback)){
|
|
193
|
-
// sync type
|
|
194
|
-
return zlib.gunzipSync(bin).toString();
|
|
195
|
-
|
|
196
|
-
}else if('function' !== typeof callback){
|
|
197
|
-
// error
|
|
198
|
-
r3logger.elog('callback parameter is not function.');
|
|
199
|
-
return null;
|
|
200
|
-
}else{
|
|
201
|
-
// callback type
|
|
202
|
-
var _callback = callback;
|
|
203
|
-
|
|
204
|
-
zlib.gunzip(bin, function(error, binary){
|
|
205
|
-
if(error){
|
|
206
|
-
r3logger.elog('failed to decompress(unzip) binary by ' + error.message);
|
|
207
|
-
return _callback(error);
|
|
208
|
-
}
|
|
209
|
-
return binary.toString();
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
//---------------------------------------------------------
|
|
215
|
-
// Exports
|
|
216
|
-
//---------------------------------------------------------
|
|
217
|
-
exports.r3Encrypt = function(str, passphrase, algorithm)
|
|
218
|
-
{
|
|
219
|
-
return rawR3Encrypt(str, passphrase, algorithm);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
exports.r3EncryptJSON = function(obj, passphrase, algorithm)
|
|
223
|
-
{
|
|
224
|
-
return rawR3EncryptJSON(obj, passphrase, algorithm);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
exports.r3Decrypt = function(str, passphrase, algorithm)
|
|
228
|
-
{
|
|
229
|
-
return rawR3Decrypt(str, passphrase, algorithm);
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
exports.r3DecryptJSON = function(str, passphrase, algorithm)
|
|
233
|
-
{
|
|
234
|
-
return rawR3DecryptJSON(str, passphrase, algorithm);
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
exports.r3Gzip = function(str, callback)
|
|
238
|
-
{
|
|
239
|
-
return rawR3Gzip(str, callback);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
exports.r3Gunzip = function(bin, callback)
|
|
243
|
-
{
|
|
244
|
-
return rawR3Gunzip(bin, callback);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/*
|
|
248
|
-
* Local variables:
|
|
249
|
-
* tab-width: 4
|
|
250
|
-
* c-basic-offset: 4
|
|
251
|
-
* End:
|
|
252
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
253
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
254
|
-
*/
|