Fix pgp uid decoding issue
This commit is contained in:
@@ -40,32 +40,37 @@ function run(arg)
|
||||
error('http error: ' .. url .. ' => ' .. resp['status'])
|
||||
else
|
||||
pubkey = pgp_pubkey_armored(resp['text'])
|
||||
-- print(pubkey)
|
||||
if last_err() then
|
||||
warn(last_err())
|
||||
clear_err()
|
||||
else
|
||||
-- print(pubkey)
|
||||
|
||||
emails = {}
|
||||
domain_matched = false
|
||||
local emails = {}
|
||||
local domain_matched = false
|
||||
|
||||
-- TODO: ensure at least one email matches our target domain
|
||||
if pubkey['uids'] then
|
||||
for j=1, #pubkey['uids'] do
|
||||
local m = regex_find("(.+) <([^< ]+@[^< ]+)>$", pubkey['uids'][j])
|
||||
if m then
|
||||
local email = m[3]:lower()
|
||||
emails[#emails+1] = {
|
||||
value=email,
|
||||
displayname=m[2],
|
||||
}
|
||||
-- TODO: ensure at least one email matches our target domain
|
||||
if pubkey['uids'] then
|
||||
for j=1, #pubkey['uids'] do
|
||||
local m = regex_find("(.+) <([^< ]+@[^< ]+)>$", pubkey['uids'][j])
|
||||
if m then
|
||||
local email = m[3]:lower()
|
||||
emails[#emails+1] = {
|
||||
value=email,
|
||||
displayname=m[2],
|
||||
}
|
||||
|
||||
if email:match('@' .. domain .. '$') then
|
||||
domain_matched = true
|
||||
if email:match('@' .. domain .. '$') then
|
||||
domain_matched = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if domain_matched then
|
||||
for j=1, #emails do
|
||||
db_add('email', emails[j])
|
||||
if domain_matched then
|
||||
for j=1, #emails do
|
||||
db_add('email', emails[j])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
9
modules/harness/pgp-stdin.lua
Normal file
9
modules/harness/pgp-stdin.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Description: Decode armored pgp key from stdin
|
||||
-- Version: 0.1.0
|
||||
-- License: GPL-3.0
|
||||
|
||||
function run()
|
||||
local pubkey = stdin_read_to_end()
|
||||
pubkey = pgp_pubkey_armored(pubkey)
|
||||
info(pubkey)
|
||||
end
|
||||
@@ -40,8 +40,9 @@ fn pgp_pubkey_lua(pubkey: &[u8]) -> Result<AnyLuaValue> {
|
||||
fingerprint = Some(fp);
|
||||
},
|
||||
Tag::UserID => {
|
||||
let body = String::from_utf8(body)?;
|
||||
uids.push_str(body);
|
||||
if let Ok(body) = String::from_utf8(body) {
|
||||
uids.push_str(body);
|
||||
}
|
||||
},
|
||||
Tag::Signature => {
|
||||
if let Ok(sig) = sloppy_rfc4880::signature::parse(&body) {
|
||||
|
||||
Reference in New Issue
Block a user