This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eid_service.js
153 lines (141 loc) · 4.56 KB
/
eid_service.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Type: Microservice
Version: 0.0.1a
Description: Microservice to interface Cititen eID with the rest of the system
**/
/*
TODO:
- Monitor Service
- Pin failed response
- Prepare a remote folder in secpack with the cards serial number
- Register a person with type_human.json schema and upload it to secpack as type_human.json
*/
var express = require('express');
var axios = require('axios');
let axeCFG = { timeout: 1000 };
var app = express();
let port = 3001;
var pcsc = require('./eid_pcsc_reader_monitor');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.listen(port, function () {
console.log('Startup complete. Listening on port '+port);
});
pcsc.registerReader(
function() {
//send status of card inserted
axios.post('http://localhost/notify', {
notification: 'eid_service',
message: 'CARD_INSERTED'
},axeCFG).then(function (response) {
//console.log(response.data);
})
.catch(function (error) {
//console.log(error);
});
},
function() {
axios.post('http://localhost/notify', {
notification: 'eid_service',
message: 'CARD_REMOVED'
},axeCFG).then(function (response) {
//console.log(response.data);
})
.catch(function (error) {
//console.log(error);
})
}
);
app.get('/exists', function(req, res) {
pcsc.checkCard().then(result => {
if (result == 0) {
axios.post('http://localhost/notify', {
notification: 'eid_service',
message: 'CARD_NOT_EXISTS'
},axeCFG).then(function (response) {
//console.log(response.data);
res.send({"ok" : "request_done"});
})
.catch(function (error) {
//console.log(error);
});
}
else {
axios.post('http://localhost/notify', {
notification: 'eid_service',
message: 'CARD_EXISTS'
},axeCFG).then(function (response) {
//console.log(response.data);
res.send({"ok" : "request_done"});
})
.catch(function (error) {
//console.log(error);
});
}
}).catch(function (error) {
console.error(error)
});
})
app.get('/identity/:PIN_ID', function(req, res) {
if (pcsc.getReader().card_present == true) {
if (req.params.PIN_ID !== '') {
pcsc.readIdentity(req.params.PIN_ID).then(address => {
res.send(address);
});
}
else {
res.send({"error" : "no_identity_pin_given"});
}
}
else {
res.send({"error" : "no_card_present"});
}
});
app.get('/address/:PIN_ADDRESS', function(req, res) {
if (pcsc.getReader().card_present == true) {
if (req.params.PIN_ADDRESS !== '') {
pcsc.readAddress(req.params.PIN_ADDRESS).then(address => {
res.send(address);
});
}
else {
res.send({"error" : "no_address_pin_given"});
}
}
else {
res.send({"error" : "no_card_present"});
}
});
app.post('/register/:PIN_ID/:PIN_ADD' ,function(req, res) {
if (pcsc.getReader().card_present == true) {
pcsc.readIdentity(req.params.PIN_ID).then(ident => {
pcsc.readAddress(req.params.PIN_ADD).then(address => {
pcsc.registerCard(ident,address)
res.send({"ok" : "request_done"});
});
});
}
else {
res.send({"error" : "no_card_present"});
}
});
app.get('/status',function(req, res) {
if (!pcsc.getReader()) res.send({"error": "no_card_reader"});
else {
res.send(pcsc.getReader());
}
});
/*metodos
Ao inserir o cartão de cidadão
- O web interface pede o PIN da Identificação
- Ao receber a Identificação é invocado o método ident com o serialDocumentNumber
- O servidor pergunta ao secPack se este serialDocumentNumber existe.
- Se existir
- Dá as boas vindas ao utilizador no web interface
- ...
- Se não existir
- Dá as boas vindas ao utilizador no web interface
- No web interface fazer o reset do formulário de pin