![]() |
Security, encryption and trusted documents | ![]() |
TeXmacs documents are not just passive data: they may contain Scheme code, through the extern primitive, through hyperlinks and action tags whose target is a script, through observers attached to loci, and through the scripts of interactive widgets. Documents may also contain confidential material which should be stored encrypted on disk. This chapter describes the mechanisms which TeXmacs provides for both concerns:
the notion of trusted (“secure”) documents and the checker secure? which decides whether a piece of Scheme code coming from an untrusted document may be evaluated;
the interface with GnuPG, which allows to encrypt regions of a document for a list of recipients or with a passphrase, and to encrypt whole documents with a passphrase;
the wallet, an encrypted store for passphrases, and its optional connection to the keychain of the operating system;
the generation of passwords and salts, used by the TeXmacs server.
The cryptography of the client/server system (TLS, certificates, password hashing on the server) is described in the chapters on the server and on the protocol, and is not repeated here.
The two concerns are handled by independent code:
is implemented partly in C++ and partly in Scheme. A document is trusted if its file name lies below one of the directories of $TEXMACS_SECURE_PATH (is_secure,
System/Classes/url.cpp
). The typesetter records this in the environment (edit_env_rep::secure); code coming from untrusted documents is passed to the Scheme predicate secure? (
kernel/texmacs/tm-secure.scm
), which accepts an expression only if it calls functions declared secure. The user preference security (“accept no scripts”, “prompt on scripts”, “accept all scripts”) decides what happens to the other expressions.
is implemented entirely in Scheme, in
progs/security/
, on top of the external program gpg. The only hooks in C++ are the call of tree-export-encrypted in export_tree (
Texmacs/Data/new_buffer.cpp
) and the generic evaluate_system routine which runs gpg with passphrases sent through pipes. The markup for encrypted regions is defined in
packages/standard/std-security.ts
. All encryption features are disabled unless the preference experimental encryption is on and a gpg executable is found.
Paths below are relative to
src/TeXmacs/progs/
for Scheme files and to
src/src/
for C++ files.
kernel/texmacs/tm-secure.scm
The checker secure?, secure-eval and the list of primitive functions which are declared secure.
kernel/texmacs/tm-define.scm
The option :secure of tm-define.
System/Classes/url.cpp,
System/Boot/init_texmacs.cpp
The predicate is_secure and the default value of $TEXMACS_SECURE_PATH.
Typeset/Env/env_exec.cpp,
Style/Evaluate/evaluate_rewrite.cpp,
Typeset/Concat/concat_active.cpp
The checks on extern and on observers, and the transmission of the trust status to links.
link/link-navigate.scm
The execution of scripts which are the target of a link or an action (execute-script).
texmacs/texmacs/tm-server.scm
The preference security and set-script-status.
security/gpg/gpg-base.scm
The interface to gpg: key generation, key listing, import and export, encryption and decryption, passphrase encryption, collected public keys.
security/gpg/gpg-edit.scm
Encrypted regions in documents, encryption of whole buffers, the save and load hooks.
security/gpg/gpg-widgets.scm,
security/gpg/gpg-menu.scm
Dialogs (key manager, passphrase prompts, recipient selection), menus and preferences.
security/gpg/gpg-wallet.scm,
security/wallet/
The wallet.
security/keychain/
Access to the keychain of macOS (security command) and Windows (winwallet helper).
security/password.scm
Generation of passwords and salts.
packages/standard/std-security.ts
Rendering of the encrypted and decrypted regions; the packages packages/customize/encryption/gpg-info-level-*.ts choose how much information about the recipients is displayed.