"Finite Field Arithmetic." Chapter 20C: Support for 'Clearsigned' GPG texts in "Litmus."

This article is part of a series of hands-on tutorials introducing FFA, or the Finite Field Arithmetic library. FFA differs from the typical "Open Sores" abomination, in that -- rather than trusting the author blindly with their lives -- prospective users are expected to read and fully understand every single line. In exactly the same manner that you would understand and pack your own parachute. The reader will assemble and test a working FFA with his own hands, and at the same time grasp the purpose of each moving part therein.

You will need:

Add the above vpatches and seals to your V-set, and press to ffa_ch20c_litmus_clearsigned.kv.vpatch.

As of Chapter 20C, the versions of Peh and FFA are 250 and 253, respectively. FFA and Peh themselves have not changed from Chapter 19.

Compile Peh:

cd ffacalc
gprbuild

... and install it to a path visible in your shell (e.g. /usr/bin.)


Litmus now supports GPG "clearsigned" texts. Compatibility with the program given in the previous chapter is retained. The "clearsigned" mode of operation is selected simply by invoking the script with two arguments instead of the usual three:


litmus.sh:

.......
 
# Whether we are working on a 'clearsigned text'
CLEARSIGN_MODE=false
 
# Set up in the selected mode:
case $ARGCOUNT in
    2) # If given two arguments, verify a 'clearsigned' text file:
        CLEARSIGN_MODE=true
        # The processed payload will end up in a temporary file:
        DATAFILE=$(mktemp) || { echo "Failed to create temp file!" >&2; \
            exit $RET_EGGOG; }
        # On exit, if in 'clearsign' mode, remove temporary file with payload:
        trap remove_temp_file EXIT
        # Expect 'Canonical Text Signature' in GPG sig packet turd
        expect_sig_class=1
        ;;
    3) # Verify Detached Signature on given Data File (third argument is path):
        # The given Data file to be verified against the Signature
        DATAFILE=$3 # i.e. path given on command line
        # Expect 'Detached Binary Signature' in GPG sig packet turd
        expect_sig_class=0
        ;;
    *) # If invalid arg count -- print usage and abort:
        echo "Usage: $0 publickey.peh signature.sig datafile"
        echo "   or: $0 publickey.peh clearsigned.txt"
        exit $RET_EGGOG
        ;;
esac
.......


RFC4880 (the document GPG nominally conforms to) specifies certain transformations required to obtain the hashable payload from the document (e.g. imposition of MSDOS-style line endings) which were implemented as follows:


litmus.sh:

.......
 
# If we are operating on a 'clearsigned' text file, $DATAFILE will be
# an empty temporary file, and the payload is to be extracted to it,
 
.......
 
if [ $CLEARSIGN_MODE == true ]
then
    # Find position of 'clearsign' payload start marker:
    CLEAR_MARKER="\-\-\-\-\-BEGIN PGP SIGNED MESSAGE\-\-\-\-\-"
    start_clr=$(grep -m 1 -n "$CLEAR_MARKER" $SIGFILE | cut -d ':' -f1)
 
    # If payload start marker was not found:
    if [ "$start_clr" == "" ]
    then
        eggog_broken_clearsigned
    fi
 
    # Discard the start marker:
    start_clr=$(($start_clr + 1))
 
    # The payload ends with the line preceding the sig start:
    end_clr=$((start_ln - 2))
 
    # Find any 'Hash:' headers:
    start_body=$(tail -n "+$start_clr" $SIGFILE | \
        grep -v -n -m 1 "^Hash:" | cut -d ':' -f1)
 
    # Skip the above headers and mandatory empty line:
    start_clr=$(($start_clr + $start_body))
 
    # If there is no payload, or the markers are misplaced, abort:
    if [ $start_clr -ge $end_clr ]
    then
        eggog_broken_clearsigned
    fi
 
    # Extract the 'clearsign' payload to the temporary file:
    cat $SIGFILE | sed -n "$start_clr,$end_clr p" | \
        sed 's/[ \t]*$//; s/^- //' | \
        awk '{printf("%s\r\n",$0)}' \
            > $DATAFILE
 
    # Remove the trailing CR,LF ending:
    truncate -s -2 $DATAFILE
 
    # After this, proceed exactly like with 'detached' sigs, but
    # with the expected 'class' being 1 rather than 0.
fi
 
.......


To verify a "clearsigned" message, invoke Litmus with two arguments: the public key, followed by the input file, e.g.:

./litmus.sh asciilifeform.peh asciilifeform-clearsigned.txt

... which will yield the output:

VALID GPG RSA signature from asciilifeform <stas@loper-os.org>


~To be continued!~

This entry was written by Stanislav , posted on Saturday January 11 2020 , filed under Ada, Bitcoin, Cold Air, Computation, Cryptography, FFA, Friends, Mathematics, SoftwareArchaeology, SoftwareSucks . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

2 Responses to “"Finite Field Arithmetic." Chapter 20C: Support for 'Clearsigned' GPG texts in "Litmus."”

  • shinohai says:

    Built and tested:


    /home/shinohai/devel/Ada # ./litmus.sh wot/asciilifeform.peh asciilifeform-clearsigned.txt
    VALID GPG RSA signature from asciilifeform

    Verified clearsigned things from alf, BingoBoingo, and spyked just fine. Litmus test warned perfectly of the sigs from the sad list published previously.

    ffa_ch20c_litmus_clearsigned.kv.vpatch.shinohai.sig

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJg+le85nelwEv2C6SnWIPMGx00wFAl4bSuAACgkQSnWIPMGx
    00yliA/7BDS3HUjgEM/4V4cVzDTaHg9Ux6HEPqzYdnKO/FxNgHSNt1CrrK/Yd9HV
    OIF88qmAWJhuwv5AIjkpuEb+wLmVwNXsdJwl08gsz3ex1f04mC9mok1++Ehepv08
    V96cu3Dpek239Ul/FHwp9AXW2wuzgotM4BgeH7ItPIjoacy00aya8Tyl4gLyOKb3
    lZd/hVbiV5yI5KQx8/l8nrnhEMdcRz/TAcvOgCIk+QiyPwgR/TvAMO8bkKxg+1Rw
    7ba3gMRhmM2foDRL/KpsWzRnlgh63oEelsmTXA+VjLGHHejl8Up7dgDVQjTaNTrc
    8JITxVZHxZXb1xPOyEP5J4KfgH2sYt5N2dgbeojN1Vek9zfzEHfp6FZzjriI2lcQ
    mXSVuYdaIzh0iN1cyodYRV312/BgAhPnWD6DU56LRqQcqVAK44aHAhPRlWfGUVWZ
    JBaXeCkpw9ciVjriB9WW3kPHPP44FWodkxw2nNLqC5eqd+D5u9WMock0M+DW2u6C
    zEE/h+n8yONd7qRLJ04s8ylVwkuYL4YcFBza7XpwbdcCB6SGSqS1ndhKiTyjNATp
    uRAZjdxAS8SZ0NY3eR1NiN5vh4MJrIE1y1aAU/IjJ/7aLaU2azZeXZ7MIuoF9Hwz
    EWTCLyO6bG8KSiZ5NWAyGWEKTxiKp9uSV2YhZRNyt9vAAhoxfkM=
    =NI0T
    -----END PGP SIGNATURE-----

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" highlight="">


MANDATORY: Please prove that you are human:

30 xor 34 = ?

What is the serial baud rate of the FG device ?


Answer the riddle correctly before clicking "Submit", or comment will NOT appear! Not in moderation queue, NOWHERE!