온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
     라인으로 공유



    before pay call 0088 from app

There is a lot that goes into being secure with user data now-a-days. I’ve been playing around with getting a node server setup on a project I am working on because it required Google Places. Google Places recommends that you have a server with a special key (which they provide) hit their servers on behalf of your users. So your servers are hit by your users, and then you ask Google for the data that is needed via your server. Because of this, I was looking into what I would need to have a working server to do what I want. I had never done any server programming before, but I know Javascript so I figured Node.js was a good choice. I had looked at Express for past projects, but never used it do to the restrictions of said projects. The reason I chose Express is because it is built on top of Node.js, but is really good for routing and endpoints (from what I took away when I read up on it).

For my testing purposes, everything I did was set up on my local computer, so I was using localhost as my web address. Because this was just a test for something I will deploy in the future, I didn’t want to test on production machines. My plan is to use DigitalOceanwhen the time comes. So let’s get started.

Getting a Basic Server Set Up

Let’s start with the basics. We will need an Express server that runs on Node. To do this, we will need to get the installer for Node.js. You can use any package manager you want for this, but I’m going to be lazy and say just run the installer. Just head over to Node.js’ website and download the version for your current computer. FAIR WARNING: I’m using OS X, and so Windows users you may have to do something different (Linux users should be fine).

Once you have installed Node, we want to make our first basic server. Here is what we are going to do:

  1. Create a folder to house our server files, doesn’t matter where it is. I keep all my projects in my ~/git directory.
  2. run npm init in the directory and follow the prompts.
  3. run npm install express to install Express.
  4. Create a new file. Let’s call it server.js. Open the file in your favorite text editor. I like Sublime.

Once we have our file, we have to declare our imports. We are going to need expresshttphttps, and fsexpress is what allows us to run the Express server and use any API that Express provides us. https tells our server that we accept secure connections, and what ports to listen in on (as well as options to reference keys and certs). And finally, fs is for file system access, since we will need to point our server to where the keys are.

Here is what our imports look like:

var express = require('express');
var http = require('http');
var https = require('https');
var fs = require('fs');

For starters, we just want a basic server. So to do so we are going to create a very basic http server that has no encryption so we can just test that our ports work. That is very easy to do in Express, it looks like this:

var server = express();

Once you have that, hop into your terminal, I like iTerm, and start your server using node server.js (make sure you are in the proper directory so server.js is seen). It should look like this: node_server.png

You can now navigate in your browser to http://localhost:8000. You will most likely get a blank page if you succeed because we haven’t told the server what to serve you once you get there. Let’s go tweak that. Add under your server code the following:

server.get('/', function (req, res) {
    res.send("Hello World!");

What the above function is telling the server is that when a GET request at /, it should send a response that says "Hello World!"req is the request object being sent, and res is the response object that we are getting ready to send back to the user.

Cool, you can save that, kill your server (that is Ctrl + C), and start it up again. Navigate to the same web address, and you should now see Hello World! displayed.

Creating your SSL Certificates

Awesome! You now have a running server. But! We want to keep our user data safe, so we need to take measures to make sure that we are providing a secure connection for users. So we are going to make an SSL key and certificate so we can verify secure connection with the browser. As a preface, I found the code on how to do this from StackOverflow. You can see the link here.

SSL generation is pretty straight forward, except when you do it wrong (like I did… many times). Thankfully, the post linked above shows how to do it in one line. In your terminal, in the directory we were working in before, type the following (please bear in mind XXX is number of days you want this certificate to be valid for):

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX

Something to note is that this is considered a self signed certificate. This means that no authority has validated it, and your browser will warn you about it when you access your page. This is fine for local testing, but for a production environment you should always have a legitimate certificate from a good provider.

We can break this code down just so we have an idea of what we are doing (fair warning, I ripped this from the StackOverflow link above):

  • req - utility used to request the certificate.
  • -x509 - tells the computer we want a self signed certificate and not to actually request one from a certificate authority.
  • -newkey - takes a paramater rsa:n-bits. It will generate a new key and certificate with RSA encryption of n-bits that are passed in. Here we are passing in the request for RSA of 2048 bits.
  • -keyout key.pem - puts out a key file that is the same name as the argument being passed to -keyout. In this case, we are generating a key file named key.pem.
  • -out cert.pem - puts out a file (in this case a certificate) with the name being passed to -out. Here we are certificate cert.pem.
  • -days XXX - how many days the certificate should be for. Defaults to 30 days.

Run this in your terminal, and you will be asked some questions reguarding your certificate during creation. Answer ALL of them. Make sure that when asked for the following:

Common Name (e.g. server FQDN or YOUR name) []:

You specifcy localhost. If you were rolling out to a production server, this would be the name of your server address. If you specifcy a passphrase, you will want to remember what it was so you can reference it later. When you are done, you can verify that you have your key and cert generated by typing ls in your terminal.

Enabling HTTPS on Express

Jumping back to our server.js, we are going to add a couple of lines to let the server know how to handle a secure request. First thing we want to do is create a JSON object that we pass with the key and cert in it.

var sslOptions = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')

If you had a passphrase, you will want to add passphrase: 'yourPassPhrase' to this object after the cert line. The only downside to this is that we want to read the file system synchronously, hense readFileSync() as our function. This could mean hold ups if this takes a long time, but in most cases you should be fine. Once you have that, we are going to reference the https object we created earlier. Under the http.createServer we are going to to use the same command.

https.createServer(sslOptions, server).listen(8443)

Here we are telling the server that if it is asked for an https connection on port 8443, it should use the ssl options we provided it and then respond as normal. So now if you save your file, you can restart your server in the terminal, and go to https://localhost:8443 in your browser and see your “Hello World!” web page. You will most likely be warned about how your certificate is not properly signed, just hit ok and proceed to the web page.

06/06/2016 - Revised with typo correction courtesy of Robert.

Written on October 8, 2015
59 리눅스 CentOS 6.5 SSL 구축 방법
2018-06-01 146
58 무료 SSL 인증서 SSL For Free
2018-05-26 177
57 도메인클럽 m 또는 www등의 서브도메인(a레코드) 추가는 어디서 할 수 있나요?
2018-05-25 189
56 Certificate Installation : Node.js in Linux
2018-05-25 168
55 online-csr-and-key-generator CSR 온라인 제너레이터 생성 만들기 Private key
2018-05-25 171
54 COMODO SSL SSL 인증서 구매 서버에 적용 순서
2018-05-25 185
53 인증서 취소 How to cancel an SSL certificate?
2018-05-25 186
52 Android SSL 프로그램 공인인증서 사설 인증서 ROOTCA Self-signed 인증서 에러 원인
2018-05-25 171
51 Retrofit is one of the most popular HTTP Client Library for Android 간결하고 요점정리
2018-05-23 182
50 SSL 프로그래밍 참고
2018-05-23 169
49 HTTPS 및 SSL을 사용한 보안 구글 문서
2018-05-23 214
48 Consuming APIs with Retrofit
2018-05-22 176
47 COMODO SSL Analyzer ip 도메인 모두 가능합니다
2018-05-22 172
46 OpenSSL 로 ROOT CA 생성 및 SSL 인증서 발급 순서 Self Signed Certificate
2018-05-22 190
45 OpenSSL 로 ROOT CA 생성 및 SSL 인증서 발급 설명좀 잘해놓은듯
2018-05-22 170
44 Android에 루트 CA 설치
2018-05-22 175
43 How to update OpenSSL on Debian testing
2018-05-22 171
42 신뢰되지 않는 인증서를 사용하여 SSL 구성
2018-05-22 191
41 OpenSSL tips and common commands
2018-05-22 168
40 How to get FREE SSL Certificate for Website (HTTPS) 인증서 무료로 받기
2018-05-22 183
39 retropit
2018-05-20 162
38 SSL test code
2018-05-20 184
37 HttpsURLConnection в ASyncTask https
2018-05-19 172
36 protected String doInBackground(String... strings) {
2018-05-19 175
35 Using Google Spread sheet as DataBase Part -2
2018-05-19 179
34 Android: HTTPS (SSL) connection using HttpsURLConnection
2018-05-19 186
33 HttpsUrlConnection, you can refer to my following sample code good
2018-05-19 177
32 how to use HttpsUrlConnection instead of DefaultHttpClient
2018-05-19 176
31 Https simple get request
2018-05-19 173
30 Base64 encoded value of [API-key]:[API-Secret] appending the "Basic " string in start.
2018-05-19 183
29 Class: https.Server
2018-05-19 182
28 HTTP2 server push in depth with node.js
2018-05-19 175
27 HSTS forces the client (browser accessing your server) to direct all traffic through HTTPS
2018-05-19 182
26 https ssl node js real code
2018-05-19 184
25 https 및 openssl 키값 decoding 확인 ssl tls
2018-05-19 176
24 TLS/SSL Concepts nodejs how to
2018-05-19 193
23 HTTPS Authorized Certs with Node.js
2018-05-19 175
22 How to Use SSL/TLS with Node.js Related Topics
2018-05-19 183
21 openssl website
2018-05-19 165
20 node js HTTPS server and client
2018-05-19 170
19 RESTful API with NodeJS/Express mysql
2018-05-19 179
18 Build a Rest API for Node & Mysql 2018 JWT
2018-05-19 190
Using SSL with Express 4 and Node.js
2018-05-19 176
16 https node js rest api express
2018-05-19 174
15 9 FREE Useful Online SSL/TLS Certificate Tools
2018-05-19 224
14 Do you know where your app’s secrets are?
2018-05-19 187
13 node js rest with express
2018-05-19 191
12 simple HTTPS JSON REST server using node.js
2018-05-19 166
11 5 Ways to Make HTTP Requests in Node.js
2018-05-19 180
10 express() detail easy doc
2018-05-19 163