Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'SSL not authorized' when using Let's Encrypt #45

Open
guymcswain opened this issue Jul 2, 2018 · 3 comments
Open

'SSL not authorized' when using Let's Encrypt #45

guymcswain opened this issue Jul 2, 2018 · 3 comments

Comments

@guymcswain
Copy link

guymcswain commented Jul 2, 2018

In blynk-nodejs, SslClient() the default options.certs_path points to server.crt in library and therefore options.ca maps to server.crt used for blynk-cloud.com. To enable SSL authorization via Mozilla CA, the options.ca must be null. I've tried options.certs_path pointing to a empty server.crt file but this returns options.ca === [ <Buffer > ], an empty buffer which evaluates to 'true'.

I have temporarily hard coded opts.ca = null to prevent overriding the Let's Encrypt authorization.

@guymcswain
Copy link
Author

guymcswain commented Jul 31, 2018

A bit more description of the problem along with a work-around:

Connect to blynk-cloud.com server:

const Auth = myAuthCodeString;
var options = {};  // no options needed to get default cert_path and server.crt
var blynk = new Blynk.Blynk(Auth, options);

In blynk-cloud.com case, blynk-nodejs.js module's internal variables are as follows:

self.ca:  [ '/path/to/blynk-library-js/certs/server.crt' ]
opts:  {
  "host": "blynk-cloud.com",
  "port": 8441,
  "servername": "blynk-cloud.com",
  "rejectUnauthorized": false,
  "family": 4,
  "ca": [
    {
      "type": "Buffer",
      "data": [
        45,
        45,
        …, // remaining cert bytes
        45,
        10
      ]
    }
  ]

Because the Blynk object calls tls.connect(opts, function() {…}, the opts.ca variable overrides the trusted CA certificates. (Incidentally, using self signed certificate for blynk-cloud.com seems less secure than it ought to be but that's another discussion.)

So, in the case of a blynk server running in your own domain using Let's Encrypt certificates there is no way to force Blynk object to call tls.connect() with opts.ca === null. In other words, there is no way to override the default CA override!

I have forked the library and have a workaround that modifies blynk-nodejs.js module as follows:

if (self.ca)   {
       if (Buffer.isBuffer(options.ca)) {
         opts.ca = options.ca;
       } else {
         opts.ca = self.ca.map(function(item){ 
          return fs.readFileSync(item); 
        }); 
+       if (opts.ca[0].toString() === '') opts.ca = null;   // added this line
      } 
    } 

To use the workaround you have to set options.certs_path = '/path/to/null/server.crt/file' and place an empty file named 'server.crt' at that location. It's not pretty but it works.

@pY4x3g
Copy link

pY4x3g commented Jul 26, 2019

Why is this issue not addressed in over a year? I have my own server and want to use SSL with lets encrypt certificates...

@QuadeHale
Copy link

QuadeHale commented Nov 6, 2019

I am having this same issue, and I finally came across this. Thank you so much @guymcswain for the fix.
The app was able to connect, non-SSL was able to connect, everything else works just fine. The only thing that would not work was SSL from an RPi with this library.

That one line, along with adding the certs_path key (to /home/pi in my case) and "touch ~/server.crt" worked instantly.
This should be fixed by now - it's been almost 18 months, and it's been difficult to find the answer to this problem.

For potential finding by google scrapers: SSL not authorized when using Let's Encrypt on Blynk local server with blynk-library.js for nodejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants