Modern PDF security
Command Line – PDF Security
PDFs, the preferred format for file sharing, only offer primitive privacy and security measures. With these command-line tools, you can help your PDFs meet modern security requirements.
First released in 1992, the Portable Document Format (PDF) shows no signs of disappearing. The format has become a business standard and the preferred format for sending files to a print shop. Closely related to PostScript (PS), PDF has the advantages of ensuring that files are seen exactly as the user intended and of eliminating concerns about the supported formats or available fonts on the recipient's word processor. Yet for all these advantages, the PDF format comes from an era less concerned with privacy and security. It does include privacy and security permissions, but these are primitive by modern standards. In fact, these tools are literally a joke. As I have heard several times, PDFs exist in one of two states: compromised and about to be compromised. Fortunately, the means exist to address issues that the PDF format itself does not. In addition to the countless scripts available for editing PDF content and structure, there are also a growing number that enhance privacy and security.
PDF password protection continues to be used for the simple reason that it is widely available. LibreOffice users, for example, can set it by selecting File | Export As | Export As PDF… | Security. From this path, a password can be set to open a PDF file, as well as grant permission for if and how the file can be printed, edited, or copied. These settings will control a PDF file's use by unsophisticated users, but they are no match for modern cracking tools. Aside from the laxness with which many users handle security, if the file is read in an environment in which the reader can control permissions (i.e., in most modern operating systems), the password protection is easily and quickly bypassed [1]. LibreOffice itself provides stronger protection with the option of using a digital signature or a personal GPG key by selecting File | Export As | Export As PDF… | PDF Options | Digital Signatures (Figure 1). While this option guarantees the sender's identity, it does not cover every circumstance.
Depending on your purpose, you may want to use one of the scripts found in the repositories of Debian and other major distributions. Some of these scripts can carry out numerous functions, but here I will only detail their privacy and security functions. Note that several have no man page, instead offering only a brief help option, which should be enough to figure out their use.
pdfcrack
Whenever passwords are used, some users are bound to forget them. These users provide a legitimate reason for an administrative tool such as pdfcrack
[2], although these tools are, of course, open to abuse. You can use pdfcrack
in two ways: with a search string using the option --charset STRING
(-c STRING
) (Figure 2) or with --wordlist=FILE
(-w=FILE
). Using a wordlist – any number of which are available online – is generally the most efficient, unless you have some idea of what the password might be, and you can use regular expressions to set a search range. The search can be further limited by skipping passwords with fewer characters than a limit defined with --minpw NUMBER
(-n NUMBER
) or omitting any password length greater than the number defined with --maxpw=NUMBER
(-m NUMBER
). Yet another way to limit the attempt is to use --owner
(-o
). The initial letter case can also be ignored using --permutate
(-s
), an option that is presumably intended at some point to search for a permutation of a password (e.g., search and searching) simultaneously. However, that functionality remains to be implemented.
poppler-utils
The poppler-utils package [3] is a collection of several of the most common tools for PDF manipulation. When checking a file for privacy or security, you can use a number of these tools to list or extract various objects to be sure that you check them: pdfdetach
for embedded files, pdfimages
for images, pdftotext
to read the contents easily, and pdfinfo
for document extraction. However, for security, the most useful poppler-utils tool is pdfsig
(Figure 3), which verifies digital signatures by searching for the NSS certificate database in the default Firefox profile, as well as searching /etc/pki/nssdb
. In addition, pdfsig
shows each signer's identity plus the time and date of the signature. Unfortunately, it is not set up to check GPG private and public keys.
QPDF
Contrary to the impression you sometimes get from the Internet, QPDF [4] is not primarily intended to crack PDF files. More accurately, qpdf
, a multipurpose command, converts one type of a PDF file into another. Among its functions are linearization (optimization for the web); creation of new files; rotating, merging, and splitting files; and selecting a range of pages to copy to a new file. Decryption and encryption are only part of QPDF's functions, offering enhanced permissions and higher security than PDF's default permissions. The --help
option displays a help page similar to a man page.
QPDF can be compiled with several different options for encryption [5]. The command can be run using --password=PASSWORD
. If a file has more than one password, the option must be used for each password, unless all are the same. Complete decryption is as easy as --decrypt
, but encryption can be more complicated. The simplest way is to copy settings from another file with --copy-encryption=FILE
, which creates a new file even if the original's password is not known. More often, though, --encrypt OPTIONS
is used. An encrypted file can be created with:
qpdf --encrypt KEY-LENGTH KEY-LENGTH-FLAGS FILE qpdf --encrypt USER-PASSWORD OWNER-PASSWORD KEY-LENGTH-- ./INPUT.PDF ./OUTPUT.pdf
This command creates the output file with no output to the screen. KEY-LENGTH
can be 40, 128, or 256, with each key length offering different flags before the input file, as described in the --help
option, as well as extra security. For example, a key length of 40 allows the default permissions included in the PDF standard (ISO 32000). A key length of 128 includes all the options of a key length of 40, plus permissions for other alterations, such as permissions for forms or the use of AES encryption. To these permissions, a length of 256 adds support for V4 and the deprecated RC5 encryption. All these options and flags can be used with --password-mode
, which sets how passwords should be read: literally, as UTF-8 encoded, hex-encoded, or automatically as needed. Any of these options can be used with QPDF's other options, to create, for example, an encrypted file with rotated pages or only a selection of pages.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.