-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfido_server.js
84 lines (71 loc) · 2.66 KB
/
fido_server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const path = require("path");
var https = require('https');
var fs = require('fs');
var express = require("express");
var mysql = require("mysql");
var crypto = require('crypto');
const request = require("request");
/*mysql에 접근 가능한 사용자 확인 여부
var connection = mysql.createConnection({//local db
host: "127.0.0.1", //localhost
user: "root",
password: "password12#",
database: "fido",
port: "3306"
});
*/
var connection = mysql.createConnection({
host: "52.79.236.167",
user: "root",
password: "1234",
database: "fido",
port: "3306"
});
connection.connect();
var key = fs.readFileSync('./keys/bankfido.pem', 'utf-8');
var certificate = fs.readFileSync('./keys/bankfido.crt', 'utf-8');
var credentials = { key: key, cert: certificate };
var app = express();
app.use(express.urlencoded({ extended: false }));//form에서 데이터를 받아오자!
app.use(express.json());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, "public"))); //to use static asset
/*========================= 지문 등록 프로세스 ======================================*/
//10&11.hido에서 CI,publicKeyB를 json으로 받아와서 DB에 추가
app.get("/registration/key", function(req, res){
var CI = req.body.CI;
var publicKeyB = req.body.publicKeyB;
if(CI!=null && publicKeyB != null){
var sql = "INSERT INTO fido (`CI`, `publicKeyB`) VALUES (?,?)";
connection.query(sql, [CI,publicKeyB], function (error, results) {
if (error) throw error;
else {
console.log('publicKeyB 등록완료');
}
})
}else{
console.log("CI or publicKeyB 없음");
}
});
/*========================= 지문 인증 프로세스 ======================================*/
// 7.FIDO 서버에서 CI를 받아서 검색해서, HIDO 서버에 PublicKeyB 전송
app.post("/auth", function (req, res) {
var CI = req.body.CI;//hido에서 넘어오는 값
if(CI!=null){
var sql = "SELECT * FROM fido WHERE CI = ?";
connection.query(sql, [CI], function (error, results) {
if (error) throw error;
else {
var publicKeyB = results[0].publicKeyB;
var jsonData = { "publicKeyB": publicKeyB, "CI": CI };
res.send(jsonData);
}
})
}else{
console.log("CI 없음");
}
});
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(443);
console.log('Server running');