Exception when using privateEncrypt/privateDecrypt with certain encrypted keys - node.js

Steps:
Create an public/private RSA key-pair by using either aes-128-ecb or
aes-128-ocb
Attempt to decrypt/encrypt something
Code:
const crypto = require("crypto");
let {privateKey, publicKey} = crypto.generateKeyPairSync("rsa", {
modulusLength: 2048,
publicKeyEncoding: {
type: "spki",
format: "pem"
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: "aes-128-ecb",
passphrase: "abcdef"
}
});
const encryptedString = crypto.privateEncrypt({
key: privateKey,
passphrase: "abcdef"
}, Buffer.from("The quick brown fox jumps over the lazy dog")).toString("base64");
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, "base64")).toString();
console.log(`Encrypted: ${encryptedString}`);
console.log(`Decrypted: ${decryptedString}`);
I can successfully encryption/decryption with the specified ciphers but it shows following error
node:internal/crypto/cipher:79
return method(data, format, type, passphrase, buffer, padding, oaepHash,
^
Error: error:060CC07A:digital envelope routines:EVP_CIPHER_asn1_to_param:cipher parameter error
at Object.privateEncrypt (node:internal/crypto/cipher:79:12)
at Object.<anonymous> (/home/pancho7532/Documents/AnotherBotXDDXD/rsaTest.js:25:32)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
opensslErrorStack: [
'error:060CC07A:digital envelope routines:EVP_CIPHER_asn1_to_param:cipher parameter error'
],
library: 'digital envelope routines',
function: 'EVP_CIPHER_asn1_to_param',
reason: 'cipher parameter error',
code: 'ERR_OSSL_EVP_CIPHER_PARAMETER_ERROR'
}

It took me a while to work this out, but seems to be an issue with the cipher property. Try using a different cipher.
I tried aes-256-ecb, aes-128-ecb and bf-ecb, none of them worked, then I tried aes-256-cbc, aes-128-cbc and bf-cbc and they all worked. I am not sure why but privateEncrypt() only seems to like all the same ciphers as generateKeyPairSync() does, specifically the "ecb" type.
With some Googling, it seems aes-128-cbc is generally considered better than aes-128-ecb, so maybe that is preferable anyway.

Related

AWS CDK: There can only be one default behavior across all sources

Background
I have a piece of cdk code that runs in a function. Each time through it creates a cloud front distribution. I want one instance to have a different value of behavior. This seems like a very simple thing, but I always get the error below that I do not understand.
Code
// 1. Default:
let behavior: cloudfront.Behavior = {isDefaultBehavior: true};
// Lambda Edge / Cloudfront Function Authentication...
if (subDomain == "monkey-ops") {
// 2. Cloudfront Function.
const cfFunct = new cloudfront.Function(this, 'id', {
functionName: 'http-auth-ops',
comment: 'http-auth for monkey-ops.monkeytronics.co.nz static site',
code: cloudfront.FunctionCode.fromFile({filePath: __dirname + '\\http-auth-ops-cf.js'})
});
behavior = {
isDefaultBehavior: false,
functionAssociations: [{
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
function: cfFunct
}]
};
// behavior = {isDefaultBehavior: true};
} else {
behavior = {isDefaultBehavior: true};
}
let cloudFrontDistribution = new cloudfront.CloudFrontWebDistribution(this, subDomain + 'Distribution', {
originConfigs: [
{
customOriginSource: {
domainName: s3Bucket.bucketWebsiteDomainName,
originProtocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY,
},
// behaviors : [ {isDefaultBehavior: true} ],
behaviors : [ behavior ],
}
],
viewerCertificate: cloudfront.ViewerCertificate.fromAcmCertificate(
tslCert,
{
aliases: [ subDomain + '.monkeytronics.co.nz' ],
// securityPolicy: cloudfront.SecurityPolicyProtocol.SSL_V3, // default
securityPolicy: cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
sslMethod: cloudfront.SSLMethod.SNI, // default
},
),
});
Error
Gives the following error, which I can't unpick...
Error: There can only be one default behavior across all sources. [ One default behavior per distribution ].
at new CloudFrontWebDistribution (D:\MonkeySource\2-Cloud\cdk_stacks\node_modules\aws-cdk-lib\aws-cloudfront\lib\web-distribution.js:1:6631)
at new StaticSite (D:\MonkeySource\2-Cloud\cdk_stacks\lib\factory\static-site\static-site-factory.ts:120:42)
at new SnWebStack (D:\MonkeySource\2-Cloud\cdk_stacks\lib\sn-web-stack.ts:57:7)
at Object.<anonymous> (D:\MonkeySource\2-Cloud\cdk_stacks\bin\cdk.ts:19:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module.m._compile (D:\MonkeySource\2-Cloud\cdk_stacks\node_modules\ts-node\src\index.ts:1056:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (D:\MonkeySource\2-Cloud\cdk_stacks\node_modules\ts-node\src\index.ts:1059:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
Subprocess exited with error 1
The error message is misleading. You are getting it because you have no default behavior configured.
{
isDefaultBehavior: true, // <-- This needs to be true for one behavior
functionAssociations: [{
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
function: cfFunct
}]
}
It means that you need to have only single default behavior.
But you can add multiple behaviors.
Cloudfront let's you create multiple behaviors and origins, which then can be used for multiple purposes.
Check the examples here
https://kuchbhilearning.blogspot.com/2022/10/add-cloudfront-behavior-and-origin.html
https://kuchbhilearning.blogspot.com/2022/10/api-gateway-and-cloud-front-in-same.html

Problem with pkg and crypto.generateKeyPairSync - "undefined is not a function"

I have a problem with the executable generated with pkg using generating RSA keys (crypto.generateKeyPairSync).
I am working on Windows 10 machine with:
node -v: v12.16.3
npm -v: 6.14.4
pkg -v: 4.4.8
The code:
const crypto = require('crypto')
try {
let { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'passphrase'
}
});
console.log(publicKey)
console.log(privateKey)
} catch (error) {
console.log(error)
}
The pkg command:
pkg -t node8-win-x64 . --output ./builds/crypto-test.exe
The result (error):
TypeError: undefined is not a function
at Object.<anonymous> (D:\snapshot\crypto-test\index.js:0:0)
at Module._compile (pkg/prelude/bootstrap.js:1320:22)
at Object.Module._extensions..js (module.js:662:10)
at Module.load (module.js:564:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (pkg/prelude/bootstrap.js:1375:12)
at startup (bootstrap_node.js:240:16)
at bootstrap_node.js:661:3
When I am using the same code without pkg - everything seems to work pefectly:
node .\index.js
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxImzEVPYGwjTwhps1BOh
8vlPMJTEViu7FfYJqYtkkBWXHtn+gAke3x+pe/eVOX2Zxg1qvuw6mYh+2q6UIrl2
MPs8TO5tGXcm7CTsncfp7iqIJZ4OiFl54Ea1eqWSF/wbU7QZRss4+HwqrYKYvtT0
aoIpSzKusgf57msj9Cl+c69M6h4YVENVMBY5t7Xm/jn69x9OytJ2nk+n5Ut8RYZK
+06krjSjsKIlglalBR1hjv+fYSu2pu4qeFD1kuMkwzN85xmv0cbFFWH38sDkyZKS
WB4X0DobwlDIIB0c02ZZmRPJZy0XUeQSM7GgVbIc7mL2aW1PO7Vse/5r0bhIYG9B
I+lf/B7B8iMErTZBxRvY2tLSAh7RE95DCor5tM55utsq8jhlZJUdBiHdmR8Dv064
cJthmBTbroe7WBP6FF6yqm51Xzq1welIuUm/PlxJ2ftr0/1dmeGJDJHJP3MaxwDt
C0nmD3BI7pmUsXYssxr9byp8De7sh6PSAjEtFmmWPWerOhfYKWDbpLXd2sDTzfvt
U19KptgVVrVPJOF7KY0B8q19x9m54ObqOSSJ/Y6ggBoQH3WcivqeRx4B3jIqQvXW
vdVhJoF3tK8Cfx1H+ZdFE4lNbCtrgbnbxm8gnR9SGZCGs8hqTftAxT4RDG2ZCW6Y
pYTpvQML6aJT/Z0AVOX5Cy8CAwEAAQ==
-----END PUBLIC KEY-----
-----BEGIN ENCRYPTED PRIV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7shse/TNZ7VvqLqxrr82oSj5FVcaYph
Oq1UoBi338n5iQEOeedPQZBELpTBqPKhKUqVfb9cDD8HOHgeMU2SZUBMRHp7P63Q
/ia5He9Zm/++7OD9r29yZi7sZ5B6DgOVrHhRJj+AhZJ0
-----END ENCRYPTED PRIVATE KEY-----
Can you guys help me with this issue? I spent hours trying to figure out how to fix this, but with no luck...
Thanks and greetings!
You are using node8-win-x64 in your package. But looks like your development machine is having v12 where it works.
Use v12 in your package.

SSL, Express, Nodejs: Error: error:0909006C:PEM routines:get_name:no start line

i tried to add certificates to my nodeJs, Express server like this:
cert: fs.readFileSync('/path/to/private.key'),
key: fs.readFileSync('/path/to/your_domain_name.crt'),
ca: [
fs.readFileSync('path/to/CA_root.crt'),
fs.readFileSync('path/to/ca_bundle_certificate.crt')
]
and i got this error
c.context.setKey(key, passphrase);
^
Error: error:0909006C:PEM routines:get_name:no start line
at Object.createSecureContext (_tls_common.js:151:17)
at Server.setSecureContext (_tls_wrap.js:1155:27)
at Server (_tls_wrap.js:1033:8)
at new Server (https.js:65:14)
at Object.createServer (https.js:89:10)
at Object.<anonymous> (********)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
library: 'PEM routines',
function: 'get_name',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'
}
does anyone faced this problem please?
Thanks by advance
Your may write wrong file name in cert and key section.
key: section need private key filename and cert: section need certification filename.
I switched your filename in cert and key section.
cert: fs.readFileSync('/path/to/your_domain_name.crt'),
key: fs.readFileSync('/path/to/private.key'),
ca: [
fs.readFileSync('path/to/CA_root.crt'),
fs.readFileSync('path/to/ca_bundle_certificate.crt')
]

Oracle DB connection with Node.js Getting "Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER."

I have installed Node JS version 12, cloned node-oracle db from github.
I have also set OCI_LIB_DIR Path as mentioned in this article.
module.exports = {
user : process.env.NODE_ORACLEDB_USER || "hr",
// Get the password from the environment variable
// NODE_ORACLEDB_PASSWORD. The password could also be a hard coded
// string (not recommended), or it could be prompted for.
// Alternatively use External Authentication so that no password is
// needed.
password : process.env.NODE_ORACLEDB_PASSWORD || abcd,
// For information on connection strings see:
// https://oracle.github.io/node-oracledb/doc/api.html#connectionstrings
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "jdbc:oracle:thin:#localhost:1521/orcl",
// Setting externalAuth is optional. It defaults to false. See:
// https://oracle.github.io/node-oracledb/doc/api.html#extauth
externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};
I have created a basic connection in SQL developer, would it help.
I have installed npm in node-oracledb and also set the username, but when I try to run the command "npm test" , It gives me the error
Deeksha ~/Desktop/nodewithoracle/node-oracledb (master)
$ npm test
> oracledb#4.1.0 test C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb
> mocha --opts test/opts/mocha.opts
C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1163
else throw err
^
Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER.
at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\test\dbconfig.js:48:9)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\850044533\Desktop\nodewithoracle\node-oracledb\test\notes.js:32:18)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:327:14)
at Mocha.run (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:804:10)
at Object.exports.singleRun (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:207:16)
at exports.runMocha (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:300:13)
at Object.exports.handler (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run.js:296:3)
at Object.runCommand (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\cli.js:63:6)
at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\bin\_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
npm ERR! Test failed. See above for more details.
set the credential environment variables to your DB credential values before you start Node.js. The error message says NODE_ORACLEDB_USER is not set.
Alternatively you can set the values directly in your getConnection() calls:
connection = await oracledb.getConnection({ user: 'hr', password: 'welcome', connectString: 'localhost/orcl' });
But be careful of hard coding passwords.
Use a valid connection string; a JDBC connection string is not usable (Node.js is not JDBC). See the node-oracledb doc JDBC and Oracle SQL Developer Connection Strings for how to determine what to use. Based on what you posted, you should use just localhost:1521/orcl.
Save yourself some time, and read the node-oracledb installation manual, the documentation, and the examples.

TypeError: Client is not a constructor - error at the latest version of kafka-node

Mosca gives this error:
TypeError: Client is not a constructor
at new KafkaAscoltatore (/home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/kafka_ascoltatore.js:59:26)
at Object.build (/home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/ascoltatori.js:77:12)
at /home/x/Desktop/broker/node_modules/mosca/lib/server.js:181:40
at makeCall (/home/x/Desktop/broker/node_modules/fastseries/series.js:117:7)
at ResultsHolder.release (/home/x/Desktop/broker/node_modules/fastseries/series.js:96:9)
at series (/home/x/Desktop/broker/node_modules/fastseries/series.js:39:14)
at Object.series (/home/x/Desktop/broker/node_modules/steed/steed.js:90:7)
at new Server (/home/x/Desktop/broker/node_modules/mosca/lib/server.js:171:9)
at Object.<anonymous> (/home/x/Desktop/broker/broker.js:118:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
Environment
Node version:v10.9.0
Kafka-node version:latest
Mosca version:latest
What I have tried
I opened /home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/kafka_ascoltatore.js
and after looking at the line below found out that the problem is related with kafka-node version:
this._opts.kafka = this._opts.kafka || require("kafka-node");
When I removed this._opts.kafka, it started to work fine. Then I printed both I figured out that the new version does not have Client constructor in it. Here is my print result:
this._opts.kafka (kafka-node v4.0.1 latest) returns HighLevelProducer which does not have Client, on the other hand require("kafka-node") (v0.5.9) returns HighLevelConsumer.
Code:
var backend = {
type: "kafka",
kafka: require('kafka-node'),
json: false,
connectionString: "IP:2181",
defaultEncoding: "utf8",
};
var moscaSettings = {
interfaces: [
{ type: "mqtt", port: PORT }
],
id: "mosca",
stats: false,
publishNewClient: false,
publishClientDisconnect: false,
publishSubscriptions: false,
backend: backend,
};
var server = new mosca.Server(moscaSettings); // Error pops here
I could make Kafka to work with older version as I mentioned above, but I think it would be only a quick fix, so I hope somebody can lead me with a proper solution.
The problem resulted from my using an example from the old version of kafka-node. When I replaced the code with the new example from the kafka-node GitHub, the problem was resolved.

Resources