7

Going crazy trying to solve error on Node.js while trying to contact Xero API.

I've used a bunch of combinations of '.cer' and '.crt' and '.pem'.

I've followed the advice of a number of StackOverflow posters.

Node.js https pem error: error:0906D06C:PEM routines:PEM_read_bio:no start line

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Error (native)
    at Sign.sign (crypto.js:327:26)
    at Xero.oa._createSignature (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/index.js:19:68)
    at exports.OAuth._getSignature (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:90:15)
    at exports.OAuth._prepareParameters (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:300:16)
    at exports.OAuth._performSecureRequest (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:309:31)
    at Xero.call (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/index.js:51:20)
    at /Users/BeardedMac/projects/clause/clause-mean-stack/routes/external.js:47:10
    at Layer.handle [as handle_request] (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/layer.js:95:5)
    at /Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:271:10)
    at expressInit (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/middleware/init.js:33:5)

Anyone out there have some insight?

The Xero API says it wants an X509 certificate...I'm not even making the call though.

Community
  • 1
  • 1
GeneralBear
  • 1,011
  • 3
  • 11
  • 35

2 Answers2

5

You need a PEM-encoded key as the xero module merely calls out to node's built-in crypto module to sign some data. Those types of keys start with

-----BEGIN RSA PRIVATE KEY-----

and end with

-----END RSA PRIVATE KEY-----

with base64-encoded data in between.

You can generate such a key using the openssl command-line utility:

openssl genrsa -out privateKey.pem 2048

Then read privateKey.pem in node like:

var fs = require('fs');
var privateKey = fs.readFileSync('/path/to/privateKey.pem');

// pass `privateKey` as the RSA private key to the `xero` module ...
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • I've used pem encoding, it does not seem to be working. I created my certificates using the openssl command-line options – GeneralBear Aug 01 '16 at 16:21
  • the api call from xero's node library asks you to enter an "RSA PRIVATE KEY"; I've used a number of filetypes of private keys, created by openssl, including crt, cer, and pem. Irrespective of which key I use, I get the same error. – GeneralBear Aug 01 '16 at 17:12
  • 1
    You might show the actual openssl commands you're using to generate the private key. – mscdex Aug 01 '16 at 17:13
  • 1
    this is the most recent: openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem – GeneralBear Aug 01 '16 at 17:15
  • 1
    I've updated my answer with an example `openssl` command line that should work. – mscdex Aug 01 '16 at 17:25
  • Thank you so much. Worked like a charm! – GeneralBear Aug 01 '16 at 17:28
-1

Check your certificate format. Carriage return(\r) and new line(\n) should be there in the .cer or .crt format. Postman expects this. This can be verified by opening it in notepad.

nanz
  • 1