Commit f6597408 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2711] (Lua) A chave pública do barramento deve ser distribuída num certificado X.509

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/trunk@159143 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 941597e7
......@@ -34,6 +34,8 @@ local pubkey = require "lce.pubkey"
local newkey = pubkey.create
local decodeprvkey = pubkey.decodeprivate
local decodepubkey = pubkey.decodepublic
local x509 = require "lce.x509"
local decodecertificate = x509.decode
local table = require "loop.table"
local copy = table.copy
......@@ -287,9 +289,13 @@ end
local function intiateLogin(self)
local AccessControl = getCoreFacet(self, "AccessControl", AccessControlRepId)
local buskey, errmsg = decodepubkey(AccessControl:_get_buskey())
local certificate, errmsg = decodecertificate(AccessControl:_get_certificate())
if certificate == nil then
ServiceFailure{message=msg.InvalidBusCertificate:tag{message=errmsg}}
end
local buskey, errmsg = certificate:getpubkey()
if buskey == nil then
ServiceFailure{message=msg.InvalidBusKey:tag{message=errmsg}}
ServiceFailure{message=msg.UnableToObtainBusKey:tag{message=errmsg}}
end
return AccessControl, buskey
end
......
......@@ -79,36 +79,32 @@ function module.readfrom(path, mode)
return nil, msg.UnableToReadFileContents:tag{ path = path, errmsg = errmsg }
end
local readfrom = module.readfrom
function module.readpublickey(path)
local file, errmsg = io.open(path, "rb")
if file ~= nil then
local encoded, errmsg = readfrom(path)
if encoded ~= nil then
local certificate
certificate, errmsg = file:read("*a")
file:close()
certificate, errmsg = decodecertificate(encoded)
if certificate then
certificate, errmsg = decodecertificate(certificate)
if certificate then
local key
key, errmsg = certificate:getpubkey()
if key then return key end
end
local key
key, errmsg = certificate:getpubkey()
if key then return key, encoded end
errmsg = msg.UnableToObtainPublicKey:tag{ path = path, errmsg = errmsg }
end
errmsg = msg.UnableToDecodeCertificate:tag{ path = path, errmsg = errmsg }
end
return nil, msg.UnableToReadPublicKey:tag{ path = path, errmsg = errmsg }
return nil, errmsg
end
function module.readprivatekey(path)
local file, errmsg = io.open(path, "rb")
if file ~= nil then
local key
key, errmsg = file:read("*a")
file:close()
if key then
key, errmsg = decodeprivatekey(key)
if key then return key end
end
local key, errmsg = readfrom(path)
if key ~= nil then
key, errmsg = decodeprivatekey(key)
if key then return key end
errmsg = msg.UnableToDecodePrivateKey:tag{ path = path, errmsg = errmsg }
end
return nil, msg.UnableToReadPrivateKey:tag{ path = path, errmsg = errmsg }
return nil, errmsg
end
function module.blockencrypt(key, operation, blocksize, stream)
......
......@@ -13,8 +13,8 @@ local validid = uuid.isvalid
local hash = require "lce.hash"
local sha256 = hash.sha256
local pubkey = require "lce.pubkey"
local decodepubkey = pubkey.decodepublic
local x509 = require "lce.x509"
local decodecertificate = x509.decode
local idl = require "openbus.core.idl"
local loadIDL = idl.loadto
......@@ -170,7 +170,7 @@ function connectToBus(host, port, orb)
return {
id = assert(AccessControl:_get_busid()),
key = assert(decodepubkey(AccessControl:_get_buskey())),
key = assert(assert(decodecertificate(AccessControl:_get_certificate())):getpubkey()),
component = bus,
AccessControl = AccessControl,
OfferRegistry = OfferRegistry,
......
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