sbool getAuthorOfSignedText_debug; sS getAuthorOfSignedText(S signed) { ret pairB(getAuthorOfSignedText2(signed)); } // returns pair(purported author, verified author) static PairS getAuthorOfSignedText2(S signed) { try { L<S> lines = toLines(signed); S authorLine = nextToLast(lines); S sigLine = last(lines); if (getAuthorOfSignedText_debug) print("authorLine: " + authorLine); S text = fromLines(dropLast(lines)); //print("Verifying text: " + l(text) + " - " + quote(text)); if (!startsWith(authorLine, "-")) null; S author = dropPrefix("-", authorLine); author = beforeComma(author); // drop date etc. if (!isComputerID(author)) fail("Not a computer ID: " + author); //print("Possible author: " + author); S publicKey = getPublicKeyOfComputer(author); if (publicKey == null) fail("Computer " + author + " has to publish a public key."); if (!startsWith(sigLine, "sig: ")) null; S sig = dropPrefix("sig: ", sigLine); if (!PKI.verifySignature(PKI.publicKeyFromString(publicKey), PKI.signatureFromString(sig), toUtf8(text))) { print("Signature doesn't verify (key: ..." + publicKey + ")"); print("Sig: " + sig); print("Text:"); printIndent(">> ", text); ret pair(author, null); } ret pair(author, author); } catch (RuntimeException e) { printShortException(e); null; } }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001567 |
Snippet name: | getAuthorOfSignedText [author = computer ID] |
Eternal ID of this version: | #1001567/19 |
Text MD5: | f778363668abf658ab9e0d791e0078b6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-06-09 15:25:26 |
Source code size: | 1436 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 791 / 1088 |
Version history: | 18 change(s) |
Referenced in: | #1001583 - isSignedWithKey #1001858 - getAuthorOfSignedJava #1002427 - Accellerating 629 (SPIKE) #1004861 - locallyVerifyUserStatement #1006654 - Standard functions list 2 (LIVE, continuation of #761) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |