Commit 941597e7 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2545] (Lua) Incluir funcionalidade de construção de cadeia a partir...

[OPENBUS-2545] (Lua) Incluir funcionalidade de construção de cadeia a partir de prova externa ao OpenBus no núcleo
- Permitir que os tokens de autenticação externa possam ter tamanhos arbitrários.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/trunk@159133 ae0415b3-e90b-0410-900d-d0be9363c56b
parent e9f873a4
......@@ -18,7 +18,7 @@ local newthread = coroutine.create
local string = require "string"
local findstring = string.find
local repeatstr = string.rep
local repeatstring = string.rep
local substring = string.sub
local math = require "math"
......@@ -57,6 +57,8 @@ local is_NO_PERMISSION = sysex.is_NO_PERMISSION
local is_TRANSIENT = sysex.is_TRANSIENT
local is_COMM_FAILURE = sysex.is_COMM_FAILURE
local is_OBJECT_NOT_EXIST = sysex.is_OBJECT_NOT_EXIST
local server = require "openbus.util.server"
local blockencrypt = server.blockencrypt
local libidl = require "openbus.idl"
local libthrow = libidl.throw
......@@ -370,7 +372,8 @@ local function getLogin(self)
return login
end
local MaxEncryptedData = repeatstr("\255", EncryptedBlockSize-11)
local MaxEncryptionSize = EncryptedBlockSize-11
local MaxEncryptionData = repeatstring("\255", MaxEncryptionSize)
local function busaddress2component(orb, host, port, key)
local ref = "corbaloc::"..host..":"..port.."/"..key
......@@ -774,7 +777,7 @@ function Context:connectByReference(bus, props)
value = msg.UnableToObtainThePublicKey:tag{error=errmsg},
}
end
result, errmsg = result:encrypt(MaxEncryptedData)
result, errmsg = result:encrypt(MaxEncryptionData)
if result == nil then
InvalidPropertyValue{
property = "accesskey",
......@@ -872,7 +875,8 @@ function Context:importChain(token, domain)
minor = NoLoginCode,
}
end
local encrypted = buskey:encrypt(token)
local encrypted = assert(blockencrypt(buskey, "encrypt", MaxEncryptionSize, token))
local signed = AccessControl:signChainByToken(encrypted, domain)
return unmarshalJustSignedChain(self, conn, signed)
end
......
......@@ -14,6 +14,12 @@ local xpcall = _G.xpcall
local array = require "table"
local concat = array.concat
local string = require "string"
local substring = string.sub
local math = require "math"
local ceil = math.ceil
local io = require "io"
local openfile = io.open
local stderr = io.stderr
......@@ -105,6 +111,17 @@ function module.readprivatekey(path)
return nil, msg.UnableToReadPrivateKey:tag{ path = path, errmsg = errmsg }
end
function module.blockencrypt(key, operation, blocksize, stream)
local result = {}
for i = 1, ceil(#stream/blocksize) do
local block = substring(stream, 1+(i-1)*blocksize, i*blocksize)
local piece, errmsg = key[operation](key, block)
if piece == nil then return nil, errmsg end
result[#result+1] = piece
end
return concat(result)
end
function module.newSCS(params)
-- cria um componente SCS
local component = ComponentContext(params.orb, { -- component id
......
......@@ -21,23 +21,34 @@ assert(OpenBusContext.orb == orb)
local FakeEntity = "FakeEntity"
do log:TEST("Import chain from token")
for _, count in ipairs{0, 1, 10, 100} do
log:TEST("Import chain with "..count.." originators from token")
local conn = OpenBusContext:createConnection(bushost, busport, connprops)
conn:loginByPassword(user, password, domain)
local busid = conn.busid
local login = conn.login.id
local entity = conn.login.entity
local originators = {}
for i = 1, count do
originators[i] = "ExternalOriginator"..i
end
OpenBusContext:setDefaultConnection(conn)
local token = entity.."@"..login..": ExternalOriginator, ExternalCaller"
local prefix = #originators>0 and table.concat(originators, ", ")..", " or ""
local token = entity.."@"..login..": "..prefix.."ExternalCaller"
local imported = OpenBusContext:importChain(token, domain)
assert(imported.busid == busid)
assert(imported.target == entity)
assert(imported.caller.id == "<unknown>")
assert(imported.caller.entity == "ExternalCaller")
assert(imported.originators[1].id == "<unknown>")
assert(imported.originators[1].entity == "ExternalOriginator")
assert(#imported.originators == 1)
assert(#imported.originators == #originators)
for index, entity in ipairs(originators) do
assert(imported.originators[index].id == "<unknown>")
assert(imported.originators[index].entity == "ExternalOriginator"..index)
end
OpenBusContext:joinChain(imported)
local joined = OpenBusContext:makeChainFor(FakeEntity)
......@@ -47,11 +58,13 @@ do log:TEST("Import chain from token")
assert(joined.target == FakeEntity)
assert(joined.caller.id == login)
assert(joined.caller.entity == entity)
assert(joined.originators[2].id == "<unknown>")
assert(joined.originators[2].entity == "ExternalCaller")
assert(joined.originators[1].id == "<unknown>")
assert(joined.originators[1].entity == "ExternalOriginator")
assert(#joined.originators == 2)
assert(#joined.originators == 1+#originators)
for index, entity in ipairs(originators) do
assert(joined.originators[index].id == "<unknown>")
assert(joined.originators[index].entity == "ExternalOriginator"..index)
end
assert(joined.originators[1+#originators].id == "<unknown>")
assert(joined.originators[1+#originators].entity == "ExternalCaller")
OpenBusContext:setDefaultConnection(nil)
conn:logout()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment