SSL, Express, Nodejs: Error: error:0909006C:PEM routines:get_name:no start line - node.js

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')
]

Related

Exception when using privateEncrypt/privateDecrypt with certain encrypted keys

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.

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.

installing and running browsershots

I tried to install Brwoswershots (https://github.com/spatie/browsershot) and I did this exactly by following the instructions on github.
Installing NodeJS and npm via yum
Installing browswershoots via composer: composer require
satie/browsershot
crated a file with
use Spatie\Browsershot\Browsershot;
$pathToImage="img/testasdf.png";
// an image will be saved
Browsershot::url('https://example.com')
->setScreenshotType('jpeg', 100)
->save($pathToImage);
It is on http://textblob.com/browsershots.php and brings the error.
Fatal error: Uncaught
Symfony\Component\Process\Exception\ProcessFailedException:
The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node
'/home/textblob/public_html/vendor/spatie/browsershot/src/../bin/browser.js'
'{"url":"https:\/\/example.com",
"action":"screenshot",
"options": {
"type":"jpeg",
"path":"img\/testasdf.png",
"quality":100,
"args":[],
"viewport":{"width":800,"height":600}
}
}'"
failed. Exit Code: 1(General error) Working directory:
/home/textblob/public_html
Output: ================ Error Output: ================
/home/textblob/public_html/vendor/spatie/browsershot/bin/browser.js:5
const getOutput = async (page, request) =>
{ ^ SyntaxError: Unexpected token ( at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMa in /home/textblob/public_html/vendor/spatie/browsershot/src/Browsershot.php
on line 565
I could solve this by downgrading to boxshot v2, witch works without puppeteer and so its not a fix, but working for me.

Getting an error when I run NPM live-server

Here's the server I'm using, https://www.npmjs.com/package/live-server. However, when I try to use ~/.live-server.json as the configuration file, I always fail... Here's what I have in the file, and it's very simple.
{
port: "8001"
}
Then I have this error when I run live-server
undefined:2
port: "8001"
^
SyntaxError: Unexpected token p
at Object.parse (native)
at Object.<anonymous> (/usr/local/lib/node_modules/live-server/live-server.js:17:20)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
I don't know why this is happening.
Property names in JSON must be quoted (JSON is not JavaScript):
{
"port": "8001"
}
It should be:
{
"port": 8001
}
Add explanation: well, in JSON, name should always double quoted, and value should also be double quoted, except number (if you double quote a number, it becomes a string). Like this:
{
"name1": "stringValue",
"name2": aNumber
}

Resources