Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 3 min read

A SHA-256 checksum file from Uniface - and why sha256sum -c did not read it

The customer app from the series Building a customer app in Uniface 10 can export all customers as one JSON file. Stage 30 gave the admin form three buttons for it: full JSON export, write checksum, verify checksum. Tes

The customer app from the series Building a customer app in Uniface 10 can export all customers as one JSON file. Stage 30 gave the admin form three buttons for it: full JSON export, write checksum, verify checksum.

Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).

Hashing a file

entry FILE_HASH
params
    string pFileName : IN
    string pHash : OUT
    string pError : OUT
endparams
variables
    raw vData
endvariables
    pHash = ""
    pError = ""
    if ($lfileexists(pFileName) != 1)
        pError = $concat("The file ", pFileName, " does not exist.")
        return -1
    endif
    fileload/raw pFileName, vData
    if ($status < 0)
        pError = $concat("The file ", pFileName, " could not be read (error ", $procerror, ").")
        return -1
    endif
    pHash = $lowercase($encode("HEX", $encode("SHA256", vData)))
    return 0
end

fileload/raw reads the bytes without any character conversion, $encode("SHA256", ...) hashes them, $encode("HEX", ...) turns the result into 64 hex characters.

Writing the checksum file

public operation WRITE_CHECKSUM
params
    string pFileName : IN
    string pHash : OUT
    string pError : OUT
endparams
variables
    string vName, vLine, vFile
endvariables
    pHash = ""
    pError = ""
    activate "RIGHTS_SVC".REQUIRE("EDIT", pError)
    if ($status < 0)
        return -1
    endif
    call FILE_HASH(pFileName, pHash, pError)
    if ($status < 0)
        return -1
    endif
    call BASE_NAME(pFileName, vName)
    vLine = "%%(pHash)  %%(vName)%%^"
    vFile = "%%(pFileName).sha256"
    call WRITE_FILE_NOBOM(vLine, vFile, pError)
    if ($status < 0)
        pHash = ""
        return -1
    endif
    return 0
end

The line has the format of sha256sum: hash, two spaces, file name. %%^ is the line break in a Uniface string.

Verifying

public operation VERIFY_CHECKSUM
params
    string pFileName : IN
    boolean pOk : OUT
    string pError : OUT
endparams
variables
    string vFile, vText, vExpected, vHash
endvariables
    pOk = 0
    pError = ""
    activate "RIGHTS_SVC".REQUIRE("READ", pError)
    if ($status < 0)
        return -1
    endif
    vFile = "%%(pFileName).sha256"
    if ($lfileexists(vFile) != 1)
        pError = $concat("The checksum file ", vFile, " does not exist.")
        return -1
    endif
    fileload vFile, vText, "UTF-8"
    if ($status < 0 | $length(vText) < 64)
        pError = $concat("The checksum file ", vFile, " could not be read.")
        return -1
    endif
    vExpected = $lowercase(vText[1:64])
    call FILE_HASH(pFileName, vHash, pError)
    if ($status < 0)
        return -1
    endif
    pOk = (vHash = vExpected)
    return 0
end

The check only reads the first 64 characters, so it does not care about the rest of the line.

Click test

  • "Full JSON export": "3 customer(s) written to .../full_export.json."
  • "Write checksum": the hash appeared in the result field. A second tool on the same file (sha256sum and Python's hashlib) printed the same 64 characters.
  • "Verify checksum": "The checksum matches: the file is unchanged."
  • One space appended to the JSON file with a script, "Verify checksum" again: "The checksum does not match: the file was changed."
  • The original file was copied back; its SHA-256 was the written value again.

The surprise: sha256sum -c

The idea of the format was that the file can also be checked without the app. With GNU coreutils 8.32:

$ sha256sum -c full_export.json.sha256
sha256sum: full_export.json: FAILED open or read
'full_export.json'$'\r': No such file or directory
sha256sum: WARNING: 1 listed file could not be read

A look at the bytes showed why: the line ends with \r\n. The service ends the line with %%^ and writes it with lfiledump/nobom ... "UTF-8"; on Windows the file had CR LF at the end, and sha256sum takes the CR as part of the file name.

Removing the CR on the reading side works:

$ tr -d '\r' < full_export.json.sha256 | sha256sum -c -
full_export.json: OK

And it still detects a change: for a copy of the file with one extra byte and a checksum line in the same CR LF format, the same command reported FAILED and exited with 1.

Notes

  • The service is unchanged for now. The cleaner fix is a checksum line without CR; the variant that writes a bare LF from ProcScript is not tested yet, so it is not shown here.
  • The checksum protects against accidental changes, not against someone who can change both files. For that the hash would have to be stored somewhere else or signed.
  • fileload/raw matters: hashing a string that was loaded with a character set conversion would hash something else than the bytes on disk.
๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.