Fix pgp uid decoding issue

This commit is contained in:
kpcyrd
2019-09-14 23:39:21 +02:00
parent a89cefc48f
commit 9057fd666f
3 changed files with 36 additions and 21 deletions

View File

@@ -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

View 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

View File

@@ -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) {