Lazy
Lazy

Reputation: 1837

Express and SSL usage

I've purchased a Comodo SSL certificate to make SSL server with express. I have these files.

AddTrustExternalCARoot.crt
COMODORSAAddTrustCA.crt
COMODORSADomainValidationSecureServerCA.crt
mysite.com.key
mysite.com.csr
mysite_com.crt

According to a lot of documents I need .pem files. But nobody is saying what is that .pem files?

var options = {
  key: fs.readFileSync('/key.pem'),
  cert: fs.readFileSync('/cert.pem'),
  ca: fs.readFileSync('/ca.pem')
};

It'd be great if there is a tutorial.

Upvotes: 1

Views: 1038

Answers (2)

ice13berg
ice13berg

Reputation: 713

Try this answer. PEM is just a format than other SSL formats, and is very common.

Comodo may have already provided you a .pem file, but just named it .crt.
OR you may be able to request a .pem file in place of a DER-formatted file.
OR, you can use OpenSSL to convert from one format to another.

openssl rsa -inform DER -outform PEM -in mysite.com.key -out mysite.com.key.pem
openssl x509 -inform DER -outform PEM -in mysite.com.crt -out mysite.com.crt.pem

Upvotes: 1

Muhammad Ali
Muhammad Ali

Reputation: 2014

Simply start ssl OR simple way to use PEM NPM

var https = require('https'),
connect = require('connect'),
fs = require("fs");
var port = 3000;
var options = {
key: fs.readFileSync('/key.pem'),
cert: fs.readFileSync('/cert.pem'),
ca: fs.readFileSync('/ca.pem')
};
var app = express();
/* express setting */
server = require('https').createServer(options, app),
server.listen(port);

PEM npm is easiest way to start node server with SSL like

$> npm install pem

var https = require('https'),
pem = require('pem'),
express = require('express');

pem.createCertificate({days:1, selfSigned:true}, function(err, keys){
var app = express();


https.createServer({key: keys.serviceKey, cert: keys.certificate}, app).listen(443);
});

Upvotes: 0

Related Questions