인증서 생성

openssl genrsa -des3 -passout pass:패스워드 -out server.pass.key 2048

openssl rsa -passin pass:패스워드 -in server.pass.key -out server.key

rm server.pass.key

openssl req -new -key server.key -out server.csr -subj '/C=KO/ST=None/L=None/O=None/CN=bloodguy'

openssl x509 -req -sha256 -days 36500 -in server.csr -signkey server.key -out server.crt

// 여기까지 하면 server.key와 server.crt 파일이 생성됨

 

 

server.js

const fs = require('fs'); 
const https = require('https');
 
const opt = {
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt')
}; 
 
https.createServer(opt, (req, res) => {
    res.end('hello world\n');
}).listen(443);

 

 

client.js

// bypass self-signed certificate
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  
const https = require('https');
  
https.get('https://HOSTNAME:PORT', (res) => {
    console.log('statusCode:', res.statusCode);
    console.log('headers:', res.headers);
  
    res.on('data', (d) => {
        process.stdout.write(d);
    });
}).on('error', (e) => {
    console.log(e);
});

 

 

 

 

Posted by bloodguy
,