'Computer/javascript'에 해당되는 글 23건

  1. 2013.02.06 [node.js] HTTPS 이용하기
반응형

* HTTPS Server는 HTTP Server와 유사하게 이용 가능하다. 앞의 TLS 처럼 options 값을 주고 https 모듈을 이용하면 된다.

var fs=require('fs');

var https=require('https');

var options={

        key:fs.readFileSync('./server_key.pem'),

        cert:fs.readFileSync('./server_cert.pem'),

        ca:fs.readFileSync('./client_cert.pem'),

        requestCert:true,

        rejectUnauthorized:true

};

var server=https.createServer(options,function(req,res){

        res.writeHead(200,{'Content-Type':'text/plain'});

        res.end('Hello World');

        console.log('authorized:',req.socket.authorized);

        console.log('client certificate:',req.socket.getPeerCertificate());

});

var port=4001;

var address='192.168.0.80';

server.listen(port,address,function(){

        console.log('Server is listening on port',server.address().port);

});


* HTTPS Client
- 사례

var fs=require('fs');

var https=require('https');
var options={
        host:'google.com',
        method:'GET',
        path:'/'
};
var request=https.request(options,function(res){
        console.log('authorized:',res.socket.authorized);
        console.log('certificate:',res.socket.getPeerCertificate());
});
request.end();


- 실행 결과
$ node ex1302064.js 
authorized: true
certificate: { subject: 
   { C: 'US',
     ST: 'California',
     L: 'Mountain View',
     O: 'Google Inc',
     CN: '*.google.com' },
  issuer: { C: 'US', O: 'Google Inc', CN: 'Google Internet Authority' },
  subjectaltname: 'DNS:*.google.com, DNS:*.android.com, DNS:*.appengine.google.com, DNS:*.cloud.google.com, DNS:*.google-analytics.com, DNS:*.google.ca, DNS:*.google.cl, DNS:*.google.co.in, DNS:*.google.co.jp, DNS:*.google.co.uk, DNS:*.google.com.ar, DNS:*.google.com.au, DNS:*.google.com.br, DNS:*.google.com.co, DNS:*.google.com.mx, DNS:*.google.com.tr, DNS:*.google.com.vn, DNS:*.google.de, DNS:*.google.es, DNS:*.google.fr, DNS:*.google.hu, DNS:*.google.it, DNS:*.google.nl, DNS:*.google.pl, DNS:*.google.pt, DNS:*.googleapis.cn, DNS:*.googlecommerce.com, DNS:*.gstatic.com, DNS:*.urchin.com, DNS:*.url.google.com, DNS:*.youtube-nocookie.com, DNS:*.youtube.com, DNS:*.ytimg.com, DNS:android.com, DNS:g.co, DNS:goo.gl, DNS:google-analytics.com, DNS:google.com, DNS:googlecommerce.com, DNS:urchin.com, DNS:youtu.be, DNS:youtube.com',
  modulus: 'A74B85B280E594036FCA4AE56CA97180A167F7B946E826B5E9BD594F7BDD1A5068C73ADF7315CEA86900D42709A9CDE1D16E2DC6A3E93BD6AA9463831A6427BFFE8790D4E6B8E489A876231513E0276B380AFA1FB1EC710AEC34FF0D9C1CA7D6470FEC706C2A6B8990F5DE58E94EAE4D6FF0F1CA7D72C07A799428FE850158C9',
  exponent: '10001',
  valid_from: 'Jan  3 12:13:31 2013 GMT',
  valid_to: 'Jun  7 19:43:27 2013 GMT',
  fingerprint: '4B:B7:CC:81:2C:B9:00:3A:75:97:10:27:43:61:0B:93:D9:7C:3C:19',
  ext_key_usage: [ '1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2' ] }

반응형
Posted by alias
,