unable to use #google-cloud/kms nodejs module to decrypt secret - google-cloud-kms

Code:
contents = encryptedWebhookSecret[0].toString();
console.log(typeof contents);
console.log(contents);
const formattedName = kmsClient.cryptoKeyPath(PROJECT, 'global', KEYRING, KEY);
const kmsDecryptRequest = {
name: formattedName,
ciphertext: contents //encryptedWebhookSecret
};
console.log("Decrypting webhook secret...");
return kmsClient.decrypt(kmsDecryptRequest);
encryptedWebhookSecret is the result of a download() operation using #google-cloud/storage client. this returns a [Buffer], which I cast to a string. I log the encrypted string, it's value is correct. I can download the encrypted secret using gsutil from the command line and gcloud kms decrypt works fine.
This error seems like it is saying the string is not encoded properly (should it not be utf8?).
The values for PROJECT, KEYRING, and KEY have been double and triple checked and are correct.
Error:
ERROR: Error: invalid encoding at Error (native) at Object.decode (/user_code/node_modules/#google-cloud/kms/node_modules/#protobufjs/base64/index.js:105:19) at Type.DecryptRequest$fromObject [as fromObject] (eval at Codegen (/user_code/node_modules/#google-cloud/kms/node_modules/#protobufjs/codegen/index.js:50:33), <anonymous>:12:15) at Type.fromObject (/user_code/node_modules/#google-cloud/kms/node_modules/protobufjs/src/type.js:538:25) at serialize (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/protobuf_js_6_common.js:70:23) at Object.final_requester.sendMessage (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/client_interceptors.js:802:37) at InterceptingCall._callNext (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/client_interceptors.js:418:43) at InterceptingCall.sendMessage (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/client_interceptors.js:460:8) at InterceptingCall._callNext (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/client_interceptors.js:424:12) at InterceptingCall.sendMessage (/user_code/node_modules/#google-cloud/kms/node_modules/grpc/src/client_interceptors.js:460:8)
EDIT: When I try using a base64 encoding, I get "TypeError: Key must be a buffer at TypeError (native) at new Hmac (crypto.js:93:16) at Object.Hmac (crypto.js:91:12) at isRequestValid (/user_code/index.js:81:8) at decryptWebhookSecret.then (/user_code/index.js:119:21)".

The Node client library requires that plaintexts and ciphertexts be submitted as Buffers. Which is easy enough-- you'll just do ciphertext: Buffer.from(contents) in your sample above.

The issue was that ciphertext needs to be base64 encoded.

Related

Error: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

I am working on SQfLite database. I am trying to save data but getting an error during saving data. I am using Chrome to check my output. The error is No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider). Here is a code which i think having a problem.
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "student.db");
return await openDatabase(path, version: 1, onCreate: _onCreate);
Here is a code for inserting data:
Database? db = await instance.database;
var id = await db!.insert('student', data);
I am using Chrome for checking output, may be this is a reason for error or whatever reason please guide me.
Plugins added
sqflite: ^2.0.2+1
get: ^4.6.5
path_provider: ^2.0.11
the error is:
Error: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
at Object.throw_ [as throw] (http://localhost:65116/dart_sdk.js:5067:11)
at MethodChannel._invokeMethod (http://localhost:65116/packages/flutter/src/services/restoration.dart.lib.js:1560:21)
at _invokeMethod.next ()
at http://localhost:65116/dart_sdk.js:40571:33
at _RootZone.runUnary (http://localhost:65116/dart_sdk.js:40441:59)
at _FutureListener.thenAwait.handleValue (http://localhost:65116/dart_sdk.js:35363:29)
at handleValueCallback (http://localhost:65116/dart_sdk.js:35931:49)
at _Future._propagateToListeners (http://localhost:65116/dart_sdk.js:35969:17)
at [_completeWithValue] (http://localhost:65116/dart_sdk.js:35817:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:65116/dart_sdk.js:35838:35)
at Object._microtaskLoop (http://localhost:65116/dart_sdk.js:40708:13)
at _startMicrotaskLoop (http://localhost:65116/dart_sdk.js:40714:13)
at http://localhost:65116/dart_sdk.js:36191:9

OutOfMemoryException while extracting OBJ

I have a Revit file and I am trying to extract geometry of it (OBJ file)(master view activated as I need space volumes)
I am calling GetDerivativeManifestAsync method from DerivativesApi class from Autodesk.Forge
await derivative.GetDerivativeManifestAsync(urn, derivativeUrn);
However I am getting System.OutOfMemoryException thrown from forge client.
Reason: Autodesk.Forge.Client.ApiException: Error calling GetDerivativeManifest: Exception of type 'System.OutOfMemoryException' was thrown.
Why does it happen and how can I solve it?
Thank you
It might mean that the OBJ file is too large for your computer to handle. Please use this API of Forge Dotnet SDK to check the file size:
IDictionary<string, string> headers = derivative.GetDerivativeManifestHeaders(urn, derivativeUrn);
long fileSize = Convert.ToInt32(headers["Content-Length"]);
Console.WriteLine ("\t size: " + fileSize); //!<<< in bytes

Node Rest Client Response Error

Can I handle a non-JSON response in node-rest-client POST method?
This is the error and response i'm getting:
response: [PURGED], error: [SyntaxError: Unexpected token P in JSON at
position 0]
Can I somehow avoid getting an error? The function does what is requested.
I suppose creating a custom parser is a solution? I don't understand how to achieve it though.
You need to add a "mimetypes" attribute to your client options.
For example, something like this should enable you to handle XML as well as JSON responses:
const Client = require('node-rest-client').Client;
var client = new Client({mimetypes:{
json:["application/json","application/json;charset=utf-8"],
xml:["application/xml","application/xml;charset=utf-8"]
}});
client.post(...)

Error with node-redis: Deprecated: The SET command contains a argument of type Object

I'm using the connect-redis-crypto module (https://github.com/jas-/connect-redis-crypto
) which is built for encrypting redis session data on top of connect-redis(https://github.com/tj/connect-redis). My redis version is 3.2.8.
I am running into error node-redis: Deprecated: The SET command contains a argument of type Object. Based on the larger error message, it seems to come from trying to parse the string [object Object] when it is not a JSON string. I put nested objects that hold user information on req.session which directly gets stored (and ideally encrypted) in redis.
From some sources I learned nested objects in Redis are not allowed which might cause this error, but I believe this library stores data as JSON to allow for nested objects. connect-redis works fine for me, but when this connect-redis-crypto library tries to JSON parse encrypted data it throws me this particular error.
Would really appreciate your help!
node_redis: Deprecated: The SET command contains a argument of type Object.
This is converted to "[object Object]" by using .toString() now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
8 May 18:24:48 - ---NEW REQUEST---
REQUEST : GET /api/somePath/client
QUERY : {}
BODY : {}
data [object Object]
err SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Command.callback (/Users/Documents/web-AOT/server/node_modules/connect-redis-crypto/lib/connect-redis.js:262:35)
at normal_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:721:21)
at RedisClient.return_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:819:9)
at JavascriptRedisParser.returnReply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:192:18)
at JavascriptRedisParser.execute (/Users/Documents/web-AOT/server/node_modules/redis-parser/lib/parser.js:560:12)
at Socket.<anonymous> (/Users/Documents/web-AOT/server/node_modules/redis/index.js:274:27)
at emitOne (events.js:96:13)
at Socket.emit (events.js:189:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:551:20)
The solution is here
You have to wrap your object in JSON.stringify and then remember to JSON.parse the response when you query the key later.
// set
client.set(
"key",
JSON.stringify(
{
example: {
field: "testing",
field1: 333
},
field: 123
}, () => {}
)
);
// get
client.get("key", (err, data) => {
console.log(JSON.parse(data));
});
Actually I was able to fix the error by making tweaks via the forked library. :)
If anyone ever runs into this error...
https://github.com/rjlee7/connect-redis-crypto

Ember error when json response root key is singular

I am getting an Ember error when the response json root is singular.
json response:
{"subscription": {"id": "1"}}
error:
Assertion failed: Your server returned a hash with the key subscription but you have no mapping for it
model:
App.Subscription
If I pass a plural root key subscriptions in the json response, it works fine. I don't think I should have to do this though since the singular version is default behavior for active
_model_serializers if there is only one resource to send.
Is this a bug in Ember or should I be doing something for this to be supported?
What might help is to define plurals on your adapter. So in the case of a model called App.Subscription this could look like this:
App.Adapter = DS.RESTAdapter.extend();
App.Adapter.configure('plurals', { "subscription": "subscription" });
Edit
As for the .json one possible solution might be to hook into the buildURL function of your RESTAdapter and adding the .json suffix yourself. This could look something like this:
App.Adapter = DS.RESTAdapter.extend({
buildURL: function(record, suffix) {
var url = this._super(record, suffix);
return url + ".json";
}
})
This would make a request to http://localhost:4000//subscription.json
Hope it helps.