Skip to content

Commit

Permalink
http signature and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaz87 committed Oct 11, 2018
1 parent 07baf3f commit ebd5dd8
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 6 deletions.
37 changes: 37 additions & 0 deletions actions/say_hello.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
event: ["say_hello"]
priority: 1

local port = ctx.msg.path_segments[2]

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

ctx.msg is bound to request, isn't it?


local date = tostring(time.now())
local body = '{"title":"Hello Message","type":"msg","text":"Hello"}'

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

where does this get used?


--local signature_string = "date: " .. date .. "\n" .. body
signature_string = "a"

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

this is an important TODO

log.trace("signature string", signature_string)

-- from torchbear/src/lua_bindings/crypto/mod.rs at line 129
local key = crypto.sign.load_secret("+qEY1pRSYy7gTfJ58GLrDQTuhgiTf49Cy9yEgvix3vHGkq2b5t55E36RPtVYgnTn+2SF0Of8nEeVOyTvcvlnnQ==")

local signature = key:sign_detached(signature_string)

local signature_header = 'keyId="alice",algorithm="rsa-sha256",signature="' .. signature .. '"'

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

request_header_signature_value ?

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

key-id -> key-uuid

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

let's exclude algorithm

This comment has been minimized.

Copy link
@Arnaz87

Arnaz87 Oct 12, 2018

Author Collaborator

keyId is part of the http signature standard, can't be renamed if we are sopposed to follow the standard.
the algorithm can't be ignored either, is also required by the standard.

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 12, 2018

Member

algorithim="Ed25519"

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 12, 2018

Member

keyId -> key-uuid is a good change since we'll use uuid's instead of key "fingerprint" ids

This comment has been minimized.

Copy link
@Arnaz87

Arnaz87 Oct 12, 2018

Author Collaborator

You are not understanding, the standard demands a keyId field, we can have key-uuid and profile and whatever in any other header we want, but the signature header has to have keyId and only keyId


local response = ClientRequest.build()
:method("POST")
:uri("http://localhost:" .. port .. "/")
:headers({
["content-type"] = "application/json",
["date"] = date,
["signature"] = signature_header,
})

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

we also need key-uuid and signed-headers fields to hash with the those headers and body

key-uuid="uuid"
signed-headers="host date content-length" 
signature="Base64-string"
  • should key-uuid rather be profile?
  • these are included in signature of this header and the body

This comment has been minimized.

Copy link
@Arnaz87

Arnaz87 Oct 12, 2018

Author Collaborator

I think key-uuid should be profile or better identity, but keyId must to be included in the Signatue header anyway, we will duplicate information but whatever

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 12, 2018

Member

I don't want to follow the spec that way
I want key-uuid in separate header field, not a bundled Authorization field

This comment has been minimized.

Copy link
@Arnaz87

Arnaz87 Oct 12, 2018

Author Collaborator

Then we would be unnecessarily non-compilant. We can have key-uuid in a separate header field, but keyId is required.

:send_with_body(body)

--local inspect = require "inspect"

return {
headers = {
["content-type"] = "application/json",
},
body = '{"message":"said hello"}'
}
20 changes: 15 additions & 5 deletions actions/send_key_action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ if not private_key then
}
end

log.trace("Key exists")
local public_key
do
local file_content = fs.read_file("content/" .. public_uuid)
local header, content = split_yaml_header(file_content)
public_key = content
end

local port = req.path_segments[2]

print(private_key)
log.info("sending public key", public_key, "to port", port)

local new_todo = ClientRequest.build()
:method("POST")
:uri("http://localhost:3001/")
:headers({ ["content-type"] = "application/json" })
:send_with_body('{"title":"recieved key","type":"key","text":"' .. tostring(private_key) .. '"}')
:uri("http://localhost:" .. port .. "/")
:headers({
["content-type"] = "application/json",
["lighttouch-identity"] = "alice",

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

profile/key-uuid goes here

})
:send_with_body('{"title":"recieved key","type":"key","text":"' .. public_key .. '"}')

return {
headers = {
Expand Down
49 changes: 49 additions & 0 deletions actions/verify_signature.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
event: ["reqProcess"]

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

fix this in another change. lowercase

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

request-received?

priority: 1

-- TODO: the headers part of the signature header is being ignored.
-- every header listed in headers, separated with spaces, must be included

local header = req.headers["signature"]
log.trace("signature header", header)

if not header then log.info("Unsigned Request") return end

local keys = {
alice = "xpKtm+beeRN+kT7VWIJ05/tkhdDn/JxHlTsk73L5Z50="
}

local keyId, signature = header:match('keyId="(%a+)".+signature="([^"]+)"')
log.debug("keyId", keyId)
log.debug("signature", signature)

--[=[
local sig_parts = {}
for _, part in ipairs(header:split(",")) do
local ps = part:split("=")
-- remove start and end quotes (doesn't handle escape sequences)
sig_parts[ps[1]] = ps[2]:sub(2, -2)
end
log.trace("signature parts")
for k, v in pairs(sig_parts) do
log.debug(k, v)
end
local signature = sig_parts.signature
]=]

local key = crypto.sign.load_public(keys[keyId])
log.trace("public key for", keyId, key)

local signature_string = "date: " .. req.headers.date .. "\n" .. req.body_raw
signature_string = "a"
log.trace("signature string", signature_string)

local is_valid = key:verify_detached(signature_string, signature)
if is_valid then
log.info("request signature is valid")
else
log.warn("invalid request signature")

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

s/warn/info

This comment has been minimized.

Copy link
@naturallymitchell

naturallymitchell Oct 11, 2018

Member

which host did it - client, profile, key-id
what was it about

This comment has been minimized.

Copy link
@Arnaz87

Arnaz87 Oct 12, 2018

Author Collaborator

If the signature was invalid it should error IMO. I don't understand the second comment

end

1 change: 1 addition & 0 deletions events.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
key_generation_request
witness_request
send_key
say_hello
6 changes: 6 additions & 0 deletions rules/say_hello_rule.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if req.method == "GET"
and #req.path_segments == 2
and req.path_segments[1] == "say_hello"
then
events["say_hello"]:trigger()
end
2 changes: 1 addition & 1 deletion rules/send_key_rule.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if req.method == "GET"
and #req.path_segments == 1
and #req.path_segments == 2
and req.path_segments[1]:match("send_key") -- TODO: make it a known type, not just any word
then
events["send_key"]:trigger(req)
Expand Down

5 comments on commit ebd5dd8

@naturallymitchell
Copy link
Member

@naturallymitchell naturallymitchell commented on ebd5dd8 Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_signature.action
(executes before lighttouch-api/create_document_local.action)

  • first action strip trusted header
  • put trusted header on if it checks out with any key

lighttouch-api/create_document_local.action puts content in content/profile-key-id/

@naturallymitchell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_signature should move to lighttouch-api
creating new keys should stay here and have a web interface
sending keys to friends should stay here as an action, hopefully at some point there will be a repl or better yet a lighttouch-admin for doing this stuff, the url scheme pays of anyway
/admin/keys/ ?

@Arnaz87
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_signature needs to know where to get the public key according to keyId, how would we do that lighttouch-keys?

there should be a sign_request action somewhere as well, where should that go?

@naturallymitchell
Copy link
Member

@naturallymitchell naturallymitchell commented on ebd5dd8 Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shows where the content moves
jazzdotdev-packages/json-interface#4

and in content/[key-uuid]/ <- content from us, eg keys

@naturallymitchell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profile has a name field

key has a type: box/seal , kind: pub/priv , and uuid of profile

content/home/[uuid of review] - says that profile is good

Please sign in to comment.