sbool getAuthorOfSignedText_debug; sS getAuthorOfSignedText(S signed) { ret pairB(getAuthorOfSignedText2(signed)); } // returns pair(purported author, verified author) static PairS getAuthorOfSignedText2(S signed) { try { L 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; } }