1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-23 11:47:39 +00:00

network group wip + virtual dirs + better trust

This commit is contained in:
kepler155c@gmail.com
2019-04-08 09:30:47 -04:00
parent 9413785248
commit 70733ab4f2
8 changed files with 92 additions and 31 deletions

View File

@@ -1,20 +1,18 @@
local Config = require('config')
local config = { }
local Security = { }
function Security.verifyPassword(password)
Config.load('os', config)
return config.password and password == config.password
local current = Security.getPassword()
return current and password == current
end
function Security.hasPassword()
return not not config.password
return not not Security.getPassword()
end
function Security.getSecretKey()
Config.load('os', config)
local config = Config.load('os')
if not config.secretKey then
config.secretKey = math.random(100000, 999999)
Config.update('os', config)
@@ -23,7 +21,6 @@ function Security.getSecretKey()
end
function Security.getPublicKey()
local exchange = {
base = 11,
primeMod = 625210769
@@ -47,14 +44,13 @@ function Security.getPublicKey()
end
function Security.updatePassword(password)
Config.load('os', config)
local config = Config.load('os')
config.password = password
Config.update('os', config)
end
function Security.getPassword()
Config.load('os', config)
return config.password
return Config.load('os').password
end
return Security

View File

@@ -105,7 +105,7 @@ end
function Socket.connect(host, port)
if not device.wireless_modem then
return false, 'Wireless modem not found'
return false, 'Wireless modem not found', 'NOMODEM'
end
local socket = newSocket(host == os.getComputerID())
@@ -138,15 +138,19 @@ function Socket.connect(host, port)
_G.transport.open(socket)
return socket
elseif msg.type == 'NOPASS' then
socket:close()
return false, 'Password not set on target', 'NOPASS'
elseif msg.type == 'REJE' then
socket:close()
return false, 'Password not set on target or not trusted'
return false, 'Trust not established', 'NOTRUST'
end
end
until e == 'timer' and id == timerId
socket:close()
return false, 'Connection timed out'
return false, 'Connection timed out', 'TIMEOUT'
end
local function trusted(msg, port)
@@ -190,7 +194,15 @@ function Socket.server(port)
socket.wseq = msg.wseq
socket.rseq = msg.rseq
if trusted(msg, port) then
if not Security.hasPassword() then
socket.transmit(socket.dport, socket.sport, {
type = 'NOPASS',
dhost = socket.dhost,
shost = socket.shost,
})
socket:close()
elseif trusted(msg, port) then
socket.connected = true
socket.transmit(socket.dport, socket.sport, {
type = 'CONN',
@@ -201,14 +213,15 @@ function Socket.server(port)
_G.transport.open(socket)
return socket
end
socket.transmit(socket.dport, socket.sport, {
type = 'REJE',
dhost = socket.dhost,
shost = socket.shost,
})
socket:close()
else
socket.transmit(socket.dport, socket.sport, {
type = 'REJE',
dhost = socket.dhost,
shost = socket.shost,
})
socket:close()
end
end
end
end