eduardoboucas / staticman

💪 User-generated content for Git-powered websites
https://staticman.net
MIT License
2.42k stars 541 forks source link

Error thrown from NodeRSA.js:178 "Empty key given" when attempting to start the server #128

Open micmart opened 7 years ago

micmart commented 7 years ago

I followed your steps on https://github.com/eduardoboucas/staticman:

  1. Clone the repository and install the dependencies via npm
  2. Create a development config file from the sample file.
  3. Edit the newly-created config file with your GitHub access token, SSH private key and the port to run the server.
  4. I additionally run export NODE_ENV=development
  5. Start the server.

When I start the server I get the following error:

martm106-3AH03Y:staticman martm106$ npm start

> staticman@2.0.0 prestart /Users/martm106/Dev/staticman
> if [ ! -d node_modules ]; then npm install; fi

> staticman@2.0.0 start /Users/martm106/Dev/staticman
> node index.js

/Users/martm106/Dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178
            throw Error("Empty key given");
            ^

Error: Empty key given
    at NodeRSA.module.exports.NodeRSA.importKey (/Users/martm106/Dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178:19)
    at Object.<anonymous> (/Users/martm106/Dev/staticman/controllers/encrypt.js:8:5)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at new StaticmanAPI (/Users/martm106/Dev/staticman/server.js:13:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! staticman@2.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the staticman@2.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/martm106/.npm/_logs/2017-07-26T13_49_18_210Z-debug.log

Any hint how to resolve?

Node v8.2.1 MacOS Sierra v10.12.5

flyinggrizzly commented 6 years ago

@micmart this one threw me for a while. For development, put your environment variables into .env, and try adding

const env = require('dotenv').config()

to the top of index.js, and adding "dotenv":"^4.0.0" topackage.json`

You probably won't want that in production though. Better to just export the environment variables directly there.

aptfx commented 6 years ago

I have the same problem. RSA private key is in config.development.js but starting in development mode gives:

> node index.js

/home/jo/dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178
            throw Error("Empty key given");
            ^

Error: Empty key given
    at NodeRSA.module.exports.NodeRSA.importKey (/home/jo/dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178:19)
aptfx commented 6 years ago

Found the problem. I had a JSON syntax error in the config.development.js. This got muffled away in a try {} catch (e) {}

shoreviewanalytics commented 5 years ago

I have the same problem. RSA private key is in config.development.js but starting in development mode gives:

> node index.js

/home/jo/dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178
            throw Error("Empty key given");
            ^

Error: Empty key given
    at NodeRSA.module.exports.NodeRSA.importKey (/home/jo/dev/staticman/node_modules/node-rsa/src/NodeRSA.js:178:19)

Wondering how you fixed? I get the same error and don't see an issue with the json syntax.

shoreviewanalytics commented 5 years ago

I'm unable to start staticman after following steps noted above. Here's my debug log.

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ] 2 info using npm@3.5.2 3 info using node@v8.10.0 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle staticman@2.0.0~prestart: staticman@2.0.0 6 verbose lifecycle staticman@2.0.0~prestart: unsafe-perm in lifecycle true 7 verbose lifecycle staticman@2.0.0~prestart: PATH: /usr/share/npm/bin/node-gyp-bin:/opt/staticman/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin 8 verbose lifecycle staticman@2.0.0~prestart: CWD: /opt/staticman 9 silly lifecycle staticman@2.0.0~prestart: Args: [ '-c', 'if [ ! -d node_modules ]; then npm install; fi' ] 10 silly lifecycle staticman@2.0.0~prestart: Returned: code: 0 signal: null 11 info lifecycle staticman@2.0.0~start: staticman@2.0.0 12 verbose lifecycle staticman@2.0.0~start: unsafe-perm in lifecycle true 13 verbose lifecycle staticman@2.0.0~start: PATH: /usr/share/npm/bin/node-gyp-bin:/opt/staticman/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin 14 verbose lifecycle staticman@2.0.0~start: CWD: /opt/staticman 15 silly lifecycle staticman@2.0.0~start: Args: [ '-c', 'node index.js' ] 16 silly lifecycle staticman@2.0.0~start: Returned: code: 1 signal: null 17 info lifecycle staticman@2.0.0~start: Failed to exec start script 18 verbose stack Error: staticman@2.0.0 start: node index.js 18 verbose stack Exit status 1 18 verbose stack at EventEmitter. (/usr/share/npm/lib/utils/lifecycle.js:232:16) 18 verbose stack at emitTwo (events.js:126:13) 18 verbose stack at EventEmitter.emit (events.js:214:7) 18 verbose stack at ChildProcess. (/usr/share/npm/lib/utils/spawn.js:24:14) 18 verbose stack at emitTwo (events.js:126:13) 18 verbose stack at ChildProcess.emit (events.js:214:7) 18 verbose stack at maybeClose (internal/child_process.js:925:16) 18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) 19 verbose pkgid staticman@2.0.0 20 verbose cwd /opt/staticman 21 error Linux 4.15.0-36-generic 22 error argv "/usr/bin/node" "/usr/bin/npm" "start" 23 error node v8.10.0 24 error npm v3.5.2 25 error code ELIFECYCLE 26 error staticman@2.0.0 start: node index.js 26 error Exit status 1 27 error Failed at the staticman@2.0.0 start script 'node index.js'. 27 error Make sure you have the latest version of node.js and npm installed. 27 error If you do, this is most likely a problem with the staticman package, 27 error not with npm itself. 27 error Tell the author that this fails on your system: 27 error node index.js 27 error You can get information on how to open an issue for this project with: "npm-debug.log" 49L, 2967C 1,1 Top

shoreviewanalytics commented 5 years ago

@micmart this one threw me for a while. For development, put your environment variables into .env, and try adding

const env = require('dotenv').config()

to the top of index.js, and adding "dotenv":"^4.0.0" topackage.json`

You probably won't want that in production though. Better to just export the environment variables directly there.

How did you push staticman to a dokku server? I'm getting the error "Empty key given" when I try to push using dokku. Any thoughts on what I need to do to fix? Thanks!

justinrummel commented 5 years ago

Is there any updates on this, I'm stuck at the same spot.

shoreviewanalytics commented 5 years ago

If recall right, its an issue with rsaPrivateKey in the config file. I used a command line tool to check my syntax.

On Mon, Feb 11, 2019, 1:52 PM Justin Rummel <notifications@github.com wrote:

Is there any updates on this, I'm stuck at the same spot.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eduardoboucas/staticman/issues/128#issuecomment-462509302, or mute the thread https://github.com/notifications/unsubscribe-auth/AivBM-fQAFt7iodM3OH5YqK9T_CKhXUnks5vMeYEgaJpZM4Oj92g .

justinrummel commented 5 years ago

Thanks for the quick reply @shoreviewanalytics, however, it just leaves more questions. What was wrong w/ the config file? What command line tool did you use to check the syntax? I have something like the below (fake data):


{
  "githubToken": "5091869e2c124aa7ad7a592bf8114a8b",
  "rsaPrivateKey": "-----BEGIN RSA PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEArJ+ZlUKOPHILf3hfzTo/fqlnu9koIQBK05Z3Q2NqwlKRBqYT3sH9
IZXpMxkzHt5W0Nkvk/cNwqK7dEXAweXfPN11XvzZKaXEYrBbUIUBiw5v8NfEGJRnxY0UQy
9iLehUAungExEWQphlVArDzPXQiYXetX9yMZ6ITnDs3VhcMZE901l9wfKFj6l2yv67qGjp
yeHWNcV88MDkdKZqGU3wSNnPhOA9obo8vOJqio+CReNHQPCMyBkw+0s1FeSyzUKYWqognI
SPluQYqMpnXkrqd7ipukMxSe0ag5kEgGxYwk+E8ZLMgUpE+5CcKVFwbMM0TPkSGbfuvUdI
STg2jk2ZIwAAA8BQIjjNUCI4zQAAAAdzc2gtcnNhAAABAQCsn5mVQo48cgt/eF/NOj9+qW
e72SghAErTlndDY2rCUpEGphPewf0hlekzGTMe3lbQ2S+T9w3Cort0RcDB5d883XVe/Nkp
pcRisFtQhQGLDm/w18QYlGfFjRRDL2It6FQC6eATERZCmGV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hoeoFrh3w0Tb6G
IOEJEr/8T6IgLwEAAAAJZGVsZXRlLW1lAQI=
-----END RSA PRIVATE KEY-----",
  "port": 443
}
justinrummel commented 5 years ago

OK, couple of notes for future people. YES, the rsaPrivateKey is just one line (not over serval lines like you would expect). Also, for whatever reason I could not bind against port 443, but 8443 allowed me to start.

sadmin@staticman:~/staticman$ npm start

> staticman@2.0.0 prestart /home/sadmin/staticman
> if [ ! -d node_modules ]; then npm install; fi

> staticman@2.0.0 start /home/sadmin/staticman
> node index.js

Staticman API running on port 8443
shoreviewanalytics commented 5 years ago

Cool, I have a post on my blog on how to setup your own instance. Please have a look, leave a comment. It took me days to figure it out! 😁

https://shoreviewanalytics.github.io/Staticman-API-Dokku-Deployment/

On Tue, Feb 12, 2019, 12:01 PM Justin Rummel <notifications@github.com wrote:

OK, couple of notes for future people. YES, the rsaPrivateKey is just one line (not over serval lines like you would expect). Also, for whatever reason I could not bind against port 443, but 8443 allowed me to start.

sadmin@staticman:~/staticman$ npm start

staticman@2.0.0 prestart /home/sadmin/staticman if [ ! -d node_modules ]; then npm install; fi

staticman@2.0.0 start /home/sadmin/staticman node index.js

Staticman API running on port 8443

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eduardoboucas/staticman/issues/128#issuecomment-462912288, or mute the thread https://github.com/notifications/unsubscribe-auth/AivBM7EZOohugHRiXG22q5M467rB5pbkks5vMx21gaJpZM4Oj92g .

justinrummel commented 5 years ago

Thanks @shoreviewanalytics ! I'll go through your documentation over the weekend

justinrummel commented 5 years ago

hello @shoreviewanalytics unfortunately still not getting anything to work. Used Digital Ocean and created my own Dokku on Ubuntu 18 LTD and I'm always getting stuck somewhere on /app/node_modules/node-rsa/src/NodeRSA.js. I feel like your directions are more notes for yourself vs. directions, especially for someone who has ZERO experience with Dokku.

shoreviewanalytics commented 5 years ago

Hi Justin,

Unfortunately, I don't really remember more than the notes I took on how I did it. My explanation is far from a step by step, so I agree with you that it is really just my notes on the process. You can try the following for config.production.json. Please be sure that the .json is valid by using a validator and make sure that you don't wrap the rsaPrivatKey either. Where I say "insert public key here all on one line, no wrapping" is where you put your key.

{ "githubToken": "", "rsaPrivateKey": "-----BEGIN RSA PUBLIC KEY-----insert public key here all on one line, no wrapping==-----END RSA PUBLIC KEY-----", "port": 80 }

On Sat, Mar 2, 2019 at 12:53 PM Justin Rummel notifications@github.com wrote:

hello @shoreviewanalytics https://github.com/shoreviewanalytics unfortunately still not getting anything to work. Used Digital Ocean and created my own Dokku on Ubuntu 18 LTD and I'm always getting stuck somewhere on /app/node_modules/node-rsa/src/NodeRSA.js. I feel like your directions are more notes for yourself vs. directions, especially for someone who has ZERO experience with Dokku.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eduardoboucas/staticman/issues/128#issuecomment-468943518, or mute the thread https://github.com/notifications/unsubscribe-auth/AivBMxLTA1sR54dy0VxUH9n69USOVIqqks5vSrqTgaJpZM4Oj92g .

dertuxmalwieder commented 2 years ago

Unfortunately, that does not fix the problem for me.