Urgent.News

What's breaking now, across thousands of outlets.

Tech

pdfsig said my edited signed PDF was still valid, so I compare ByteRange with the file size

I appended one line of text to the page content of a signed PDF, then ran pdfsig on it. It printed "Signature is Valid". pyHanko looked at the same file and called it an illegal modification. Both are right about different things, and that gap is why I ended up writing a small check that compares a signature's ByteRange with the file size. Some context. Our upload service compresses PDFs before…

I appended a line of text to the signed PDF, then ran pdfsig on it, which printed "Signature is Valid". I also used pyHanko on the same file and it called it an illegal modification. Both are correct about different things, which explains why I ended up writing a check that compares a signature's ByteRange with the file size. Our upload service compresses PDFs before storing them, and recently, signed contracts started being sent through it.

Before allowing compression to touch those contracts, I wanted to know if the file carried a signature and if anything changed after signing. The validators check different things. pdfsig verifies the hash over the signed bytes, and if those bytes didn't change, it says valid. pyHanko also checks what comes after the signature. The issue comes when the file size doesn't match the last signed byte.

If they're the same, the signature covers everything. If the ByteRange end is smaller, bytes were added after signing. If it's larger, the file was rewritten and the signature dictionary was copied over with stale numbers. To compare the ByteRange end with the file size, I wrote a function called signature_coverage. It checks if the last signed byte equals the file size, if bytes were appended, or if the file was past the end of the file (EOF).

I ran this check on three incremental files and a rewritten copy. All the incremental files came back as "appended", and the rewritten copy came back as "past EOF". Two outputs return an empty list, meaning the signature used to be there but was deleted. This check helps determine if an uploaded file has a valid signature and if any modifications were made after signing.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Quy Uớc Đặt Tên (Naming Conventions) Trong Java

Quy ước đặt tên là một tập hợp các quy tắc thống nhất về cách đặt tên cho các thành phần ngôn ngữ như class, biến, phương thức, v.v. trong Java.

  • Java naming conventions standardize language components like classes and variables.
  • CamelCase used for variables, methods, and classes; PascalCase for classes and interfaces.
  • Consistency, meaningfulness, and readability are benefits of following naming conventions.

DishReactions is a free, offline app that records customer reactions per order and shows a live chart of which dish gets the best reviews.

*This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle What I Built DishReactions — a local-first app for small restaurants that records customer reaction on every…

  • DishReactions is a free, offline app for small restaurants
  • Records customer reactions (1-5 stars, emojis) per order
  • Live chart shows dish with highest average rating

🚀 Big update

🚀 Grosse mise à jour sur coddyrun.fr ! Ces dernières semaines, le site a beaucoup changé. Voici tout ce qui vous attend 👇 ⚔️ NOUVEAU : les Défis Un problème à résoudre en CoddyRun, proposé par un…

  • CoddyRun introduces Challenges for problem-solving with community submissions.
  • Real-time chat and public profiles enable interaction and sharing among users.
  • Over 340 FAQ entries and 54 collectible badges enhance user engagement.

More from Sunday 18 October →