-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (46 loc) · 1.5 KB
/
index.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
var Socket = require('./Socket.js')
var crypto = require('./crypto.js')
var certificate = require('./certificate.js')
module.exports.listen = function(ext_ip, port, key, cb) {
var server = new Socket(port)
server.listen(ext_ip, key.cert, key.signing, key.boxing, false)
server.on('create', cb)
return server
}
module.exports.client = function(ip, port, domain_service) {
var client = new Socket()
if (arguments.length >= 3) {
client.setDomainService(ip, port, domain_service)
}
return client
}
module.exports.domainservice = function(ext_ip, port, key, cb) {
var server = new Socket(port)
server.listen(ext_ip, key.cert, key.signing, key.boxing, true)
server.on('requestCert', function(bident, cert_cb) {
var ident = certificate.Identity.fromBuffer(bident)
if (ident.matches(server.ephemeral_certificate)) {
cert_cb(null, server.certificate.toBuffer(), server.ephemeral_certificate.toBuffer())
} else {
cb(ident, cert_cb)
}
})
return server
}
module.exports.nameservice = function(ext_ip, port, key, cb) {
var server = new Socket(port)
server.listen(ext_ip, key.cert, key.signing, key.boxing, false)
server.on('giveCert', cb)
return server
}
module.exports.generate_servercert = function(hostname) {
var signing = crypto.make_signing_keypair()
var boxing = crypto.make_keypair()
var cert = certificate.Cert.makeSign(signing.private, signing.public, boxing.public, hostname)
return {
cert: cert,
signing: signing,
boxing: boxing
}
}
module.exports.generate_clientkey = crypto.make_keypair