Securing Debian Manual
Chapter 7 - Debian Security Infrastructure

7.1 The Debian Security Team

Debian has a Security Team, that handles security in the stable
distribution. Handling security means they keep track of vulnerabilities that
arise in software (watching forums such as Bugtraq, or vuln-dev) and determine
if the stable distribution is affected by it.

Also, the Debian Security Team is the contact point for problems that are
coordinated by upstream developers or organizations such as CERT which might affect multiple vendors.
That is, when problems are not Debian-specific. The contact point of the
Security Team is team@security.debian.org
which only the members of the security team read.

Sensitive information should be sent to the first address and, in some cases,
should be encrypted with the Debian Security Contact key (as found in the
Debian keyring).

Once a probable problem is received by the Security Team it will investigate if
the stable distribution is affected and if it is, a fix is made for
the source code base. This fix will sometimes include backporting the patch
made upstream (which usually is some versions ahead of the one distributed by
Debian). After testing of the fix is done, new packages are prepared and
published in the http://security.debian.org site so
they can be retrieved through apt (see Execute a security update, Section
4.2). At the same time a Debian Security Advisory (DSA) is
published on the web site and sent to public mailing lists including debian-security-announce
and Bugtraq.

7.2 Debian Security Advisories

Debian Security Advisories (DSAs) are made whenever a security vulnerability is
discovered that affects a Debian package. These advisories, signed by one of
the Security Team members, include information of the versions affected as well
as the location of the updates. This information is:

version number for the fix.

problem type.

whether it is remote or locally exploitable.

short description of the package.

description of the problem.

description of the exploit.

description of the fix.

DSAs are published both on Debian's
frontpage and in the Debian security pages.
Usually this does not happen until the website is rebuilt (every four hours) so
they might not be present immediately. The preferred channel is the
debian-security-announce mailing list.

Interested users can, however (and this is done in some Debian-related portals)
use the RDF channel to download automatically the DSAs to their desktop. Some
applications, such as Evolution (an email client and personal
information assistant) and Multiticker (a GNOME applet), can be
used to retrieve the advisories automatically. The RDF channel is available at
http://www.debian.org/security/dsa.rdf.

DSAs published on the website might be updated after being sent to the
public-mailing lists. A common update is adding cross references to security
vulnerability databases. Also, translations[51] of DSAs are not sent to the security mailing lists but are
directly included in the website.

7.2.2 CVE compatibility

Debian developers understand the need to provide accurate and up to date
information of the security status of the Debian distribution, allowing users
to manage the risk associated with new security vulnerabilities. CVE enables
us to provide standardized references that allow users to develop a CVE-enabled security
management process.

Debian believes that providing users with additional information related to
security issues that affect the Debian distribution is extremely important.
The inclusion of CVE names in advisories help users associate generic
vulnerabilities with specific Debian updates, which reduces the time spent
handling vulnerabilities that affect our users. Also, it eases the management
of security in an environment where CVE-enabled security tools -such as network
or host intrusion detection systems, or vulnerability assessment tools- are
already deployed regardless of whether or not they are based on the Debian
distribution.

Debian provides CVE names for all DSAs released since September 1998. All of
the advisories can be retrieved on the Debian web site, and announcements
related to new vulnerabilities include CVE names if available at the time of
their release. Advisories associated with a given CVE name can be searched
directly through the Debian Security Tracker (see below).

In some cases you might not find a given CVE name in published advisories, for
example because:

No Debian products are affected by that vulnerability.

There is not yet an advisory covering that vulnerability (the security issue
might have been reported as a security
bug but a fix has not been tested and uploaded).

An advisory was published before a CVE name was assigned to a given
vulnerability (look for an update at the web site).

7.3 Security Tracker

The central database of what the Debian security teams know about
vulnerabilities is the Debian Security Tracker.
It cross references packages, vulnerable and fixed versions for different
suites, CVE names, Debian bug numbers, DSA's and miscellaneous notes. It can
be searched, e.g. by CVE name to see which Debian packages are affected or
fixed, or by package to show unresolved security issues. The only information
missing from the tracker is confidential information that the security team
received under embargo.

The package debsecan uses the information in the tracker to report
to the administrator of a system which of the installed packages are
vulnerable, and for which updates are available to fix security issues.

7.4 Debian Security Build Infrastructure

Since Debian is currently supported in a large number of architectures,
administrators sometimes wonder if a given architecture might take more time to
receive security updates than another. As a matter of fact, except for rare
circumstances, updates are available to all architectures at the same time.

Packages in the security archive are autobuilt, just like the regular archive.
However, security updates are a little more different than normal uploads sent
by package maintainers since, in some cases, before being published they need
to wait until they can be tested further, an advisory written, or need to wait
for a week or more to avoid publicizing the flaw until all vendors have had a
reasonable chance to fix it.

Thus, the security upload archive works with the following procedure:

Someone finds a security problem.

Someone fixes the problem, and makes an upload to security-master.debian.org's
incoming (this someone is usually a Security Team member but can be
also a package maintainer with an appropriate fix that has contacted the
Security Team previously). The Changelog includes a testing-security
or stable-security as target distribution.

The upload gets checked and processed by a Debian system and moved into
queue/accepted, and the buildds are notified. Files in here can be accessed by
the security team and (somewhat indirectly) by the buildds.

Security-enabled buildds pick up the source package (prioritized over normal
builds), build it, and send the logs to the security team.

The security team reply to the logs, and the newly built packages are uploaded
to queue/unchecked, where they're processed by a Debian system, and moved into
queue/accepted.

When the security team find the source package acceptable (i.e., that it's been
correctly built for all applicable architectures and that it fixes the security
hole and doesn't introduce new problems of its own) they run a script which:

installs the package into the security archive.

updates the Packages, Sources and
Release files of security.debian.org in the usual way
(dpkg-scanpackages, dpkg-scansources, ...).

sets up a template advisory that the security team can finish off.

forwards the packages to the appropriate proposed-updates so that it can be
included in the real archive as soon as possible.

This procedure, previously done by hand, was tested and put through during the
freezing stage of Debian 3.0 woody (July 2002). Thanks to this infrastructure
the Security Team was able to have updated packages ready for the apache and
OpenSSH issues for all the supported (almost twenty) architectures in less than
a day.

7.4.1 Developer's guide to security updates

Debian developers that need to coordinate with the security team on fixing in
issue in their packages, can refer to the Developer's Reference section
Handling
security-related bugs.

7.5 Package signing in Debian

This section could also be titled "how to upgrade/update safely your
Debian GNU/Linux system" and it deserves its own section basically because
it is an important part of the Security Infrastructure. Package signing is an
important issue since it avoids tampering of packages distributed in mirrors
and of downloads with man-in-the-middle attacks. Automatic software update is
an important feature but it's also important to remove security threats that
could help the distribution of trojans and the compromise of systems during
updates[53].

Debian does not provide signed packages but provides a mechanism available
since Debian 4.0 (codename etch) to check for downloaded package's
integrity[54]. For more
information, see Secure apt, Section 7.5.2.

7.5.1 The current scheme for package signature checks

the Release file includes the MD5 sum of Packages.gz
(which contains the MD5 sums of packages) and will be signed. The signature is
one of a trusted source.

This signed Release file is downloaded by 'apt-get update' and
stored along with Packages.gz.

When a package is going to be installed, it is first downloaded, then the MD5
sum is generated.

The signed Release file is checked (signature ok) and it extracts
from it the MD5 sum for the Packages.gz file, the
Packages.gz checksum is generated and (if ok) the MD5 sum of the
downloaded package is extracted from it.

If the MD5 sum from the downloaded package is the same as the one in the
Packages.gz file the package will be installed, otherwise the
administrator will be alerted and the package will be left in the cache (so the
administrator can decide whether to install it or not). If the package is not
in the Packages.gz and the administrator has configured the system
to only install checked packages it will not be installed either.

By following the chain of MD5 sums apt is capable of verifying
that a package originates from a a specific release. This is less flexible
than signing each package one by one, but can be combined with that scheme too
(see below).

This scheme is fully
implemented in apt 0.6 and is available since the Debian 4.0
release. For more information see Secure apt, Section
7.5.2. Packages that provide a front-end to apt need to be modified to
adapt to this new feature; this is the case of aptitude which was
modified
to adapt to this scheme. Front-ends currently known to work properly with this
feature include aptitude and synaptic.

7.5.2 Secure apt

The apt 0.6 release, available since Debian 4.0 etch and later
releases, includes apt-secure (also known as secure apt)
which is a tool that will allow a system administrator to test the integrity of
the packages downloaded through the above scheme. This release includes the
tool apt-key for adding new keys to apt's keyring, which by
default includes only the current Debian archive signing key.

These changes are based on the patch for apt (available in
Bug
#203741) which provides this implementation.

This feature is still under development, if you believe you find bugs in it,
please, make first sure you are using the latest version (as this package might
change quite a bit before it is finally released) and, if running the latest
version, submit a bug against the apt package.

7.5.3 Per distribution release check

This section describes how the distribution release check mechanism works, it
was written by Joey Hess and is also available at the Debian Wiki.

7.5.3.1 Basic concepts

Here are a few basic concepts that you'll need to understand for the rest of
this section.

A checksum is a method of taking a file and boiling it down to a reasonably
short number that uniquely identifies the content of the file. This is a lot
harder to do well than it might seem, and the most commonly used type of
checksum, the MD5 sum, is in the process of being broken.

Public key cryptography is based on pairs of keys, a public key and a private
key. The public key is given out to the world; the private key must be kept a
secret. Anyone possessing the public key can encrypt a message so that it can
only be read by someone possessing the private key. It's also possible to use
a private key to sign a file, not encrypt it. If a private key is used to sign
a file, then anyone who has the public key can check that the file was signed
by that key. No one who doesn't have the private key can forge such a
signature.

These keys are quite long numbers (1024 to 2048 digits or longer), and to make
them easier to work with they have a key id, which is a shorter, 8 or 16 digit
number that can be used to refer to them.

gpg is the tool used in secure apt to sign files and check their
signatures.

apt-key is a program that is used to manage a keyring of gpg keys
for secure apt. The keyring is kept in the file
/etc/apt/trusted.gpg (not to be confused with the related but not
very interesting /etc/apt/trustdb.gpg). apt-key can
be used to show the keys in the keyring, and to add or remove a key.

7.5.3.2 Release checksums

A Debian archive contains a Release file, which is updated each
time any of the packages in the archive change. Among other things, the
Release file contains some MD5 sums of other files in the archive.
An excerpt of an example Release file:

These two checksums can be used to verify that you have downloaded a correct
copy of the Packages file, with a md5sum that matches the one in
the Release file. And when it downloads an individual package, it
can also check its md5sum against the content of the Packages
file. If apt fails at either of these steps, it will abort.

None of this is new in secure apt, but it does provide the foundation. Notice
that so far there is one file that apt doesn't have a way to check: The Release
file. Secure apt is all about making apt verify the Release file
before it does anything else with it, and plugging this hole, so that there is
a chain of verification from the package that you are going to install all the
way back to the provider of the package.

7.5.3.3 Verification of the Release file

To verify the Release file, a gpg signature is added for the
Release file. This is put in a file named
Release.gpg that is shipped alongside the Release
file. It looks something like this [56] , although only gpg actually looks at its contents
normally:

7.5.3.4 Check of Release.gpg by apt

Secure apt always downloads Release.gpg files when it's
downloading Release files, and if it cannot download the
Release.gpg, or if the signature is bad, it will complain, and
will make note that the Packages files that the
Release file points to, and all the packages listed therein, are
from an untrusted source. Here's how it looks during an apt-get
update:

W: GPG error: http://ftp.us.debian.org testing Release: The following signatures
couldn't be verified because the public key is not available: NO_PUBKEY 010908312D230C5F

Note that the second half of the long number is the key id of the key that apt
doesn't know about, in this case that's 2D230C5F.

If you ignore that warning and try to install a package later, apt will warn
again:

WARNING: The following packages cannot be authenticated!
libglib-perl libgtk2-perl
Install these packages without verification [y/N]?

If you say Y here you have no way to know if the file you're getting is the
package you're supposed to install, or if it's something else entirely that
somebody that can intercept the communication against the server[57] has arranged for you,
containing a nasty suprise.

Note that you can disable these checks by running apt with
--allow-unauthenticated.

It's also worth noting that newer versions of the Debian installer use the same
signed Release file mechanism during their debootstrap of the
Debian base system, before apt is available, and that the installer even uses
this system to verify pieces of itself that it downloads from the net. Also,
Debian does not currently sign the Release files on its CDs; apt
can be configured to always trust packages from CDs so this is not a large
problem.

7.5.3.5 How to tell apt what to trust

So the security of the whole system depends on there being a
Release.gpg file, which signs a Release file, and of
apt checking that signature using gpg. To check the signature, it
has to know the public key of the person who signed the file. These keys are
kept in apt's own keyring (/etc/apt/trusted.gpg), and managing the
keys is where secure apt comes in.

By default, Debian systems come preconfigured with the Debian archive key in
the keyring.

Here 4F368D5D is the key id, and notice that this key was only valid for a one
year period. Debian rotates these keys as a last line of defense against some
sort of security breach breaking a key.

That will make apt trust the official Debian archive, but if you
add some other apt repository to /etc/apt/sources.list, you'll
also have to give apt its key if you want apt to trust it. Once
you have the key and have verified it, it's a simple matter of running
apt-key add file to add it. Getting the key and verifying it are
the trickier parts.

7.5.3.6 Finding the key for a repository

The debian-archive-keyring package is used to distribute keys to
apt. Upgrades to this package can add (or remove) gpg keys for
the main Debian archive.

For other archives, there is not yet a standard location where you can find the
key for a given apt repository. There's a rough standard of putting the key up
on the web page for the repository or as a file in the repository itself, but
no real standard, so you might have to hunt for it.

The "gpg: no ultimately trusted keys found" warning means that gpg
was not configured to ultimately trust a specific key. Trust settings are part
of OpenPGPs Web-of-Trust which does not apply here. So there is no problem
with this warning. In typical setups the user's own key is ultimately trusted.

7.5.3.7 Safely adding a key

By adding a key to apt's keyring, you're telling apt to trust everything signed
by the key, and this lets you know for sure that apt won't install anything not
signed by the person who possesses the private key. But if you're sufficiently
paranoid, you can see that this just pushes things up a level, now instead of
having to worry if a package, or a Release file is valid, you can
worry about whether you've actually gotten the right key. Is the http://ftp-master.debian.org/ziyi_key_2006.asc
file mentioned above really Debian's archive signing key, or has it been
modified (or this document lies).

It's good to be paranoid in security, but verifying things from here is harder.
gpg has the concept of a chain of trust, which can start at
someone you're sure of, who signs someone's key, who signs some other key,
etc., until you get to the archive key. If you're sufficiently paranoid you'll
want to check that your archive key is signed by a key that you can trust, with
a trust chain that goes back to someone you know personally. If you want to do
this, visit a Debian conference or perhaps a local LUG for a key signing [59].

If you can't afford this level of paranoia, do whatever feels appropriate to
you when adding a new apt source and a new key. Maybe you'll want to mail the
person providing the key and verify it, or maybe you're willing to take your
chances with downloading it and assuming you got the real thing. The important
thing is that by reducing the problem to what archive keys to trust, secure apt
lets you be as careful and secure as it suits you to be.

7.5.3.8 Verifying key integrity

You can verify the fingerprint as well as the signatures on the key.
Retrieving the fingerprint can be done for multiple sources, you can check
The
Debian System Book, talk to Debian Developers on IRC, read the
mailing list where the key change will be announced or any other additional
means to verify the fingerprint. For example you can do this:

and then check
the trust path from your key (or a key you trust) to at least one of
the keys used to sign the archive key. If you are sufficiently paranoid you
will tell apt to trust the key only if you find an acceptable path:

$ gpg --export -a 2D230C5F | sudo apt-key add -
Ok

Note that the key is signed with the previous archive key, so theoretically you
can just build on your previous trust.

7.5.3.9 Debian archive key yearly rotation

As mentioned above, the Debian archive signing key is changed each year, in
January. Since secure apt is young, we don't have a great deal of experience
with changing the key and there are still rough spots.

In January 2006, a new key for 2006 was made and the Release file
began to be signed by it, but to try to avoid breaking systems that had the old
2005 key, the Release file was signed by that as well. The intent
was that apt would accept one signature or the other depending on the key it
had, but apt turned out to be buggy and refused to trust the file unless it had
both keys and was able to check both signatures. This was fixed in apt version
0.6.43.1. There was also confusion about how the key was distributed to users
who already had systems using secure apt; initially it was uploaded to the web
site with no announcement and no real way to verify it and users were forced to
download it by hand.

In January 2006, a new key for 2006 was made and the Release file began to be
signed by it, but to try to avoid breaking systems that had the old 2005 key,
the Release file was signed by that as well. In order to prevent
confusion on the best distribution mechanism for users who already have systems
using secure apt, the debian-archive-keyring package was introduced, which
manages apt keyring updates.

7.5.3.10 Known release checking problems

One not so obvious problem is that if your clock is very far off, secure apt
will not work. If it's set to a date in the past, such as 1999, apt will fail
with an unhelpful message such as this:

If it's set to a date too far in the future, apt will treat the keys as
expired.

Another problem you may encouter if using testing or unstable is that if you
have not run apt-get update lately and apt-get
install a package, apt might complain that it cannot be authenticated
(why does it do this?). apt-get update will fix this.

7.5.3.11 Manual per distribution release check

In case you want to add now the additional security checks and don't want or
cannot run the latest apt version[60] you can use the script below, provided by Anthony Towns.
This script can automatically do some new security checks to allow the user to
be sure that the software s/he's downloading matches the software Debian's
distributing. This stops Debian developers from hacking into someone's system
without the accountability provided by uploading to the main archive, or
mirrors mirroring something almost, but not quite like Debian, or mirrors
providing out of date copies of unstable with known security problems.

This sample code, renamed as apt-check-sigs, should be used in the
following way:

7.5.4 Release check of non Debian sources

Notice that, when using the latest apt version (with secure apt) no
extra effort should be required on your part unless you use non-Debian sources,
in which case an extra confirmation step will be required by apt-get. This is
avoided by providing Release and Release.gpg files in
the non-Debian sources. The Release file can be generated with
apt-ftparchive (available in apt-utils 0.5.0 and
later), the Release.gpg is just a detached signature. To generate
both follow this simple procedure:

7.5.5 Alternative per-package signing scheme

The additional scheme of signing each and every packages allows packages to be
checked when they are no longer referenced by an existing Packages
file, and also third-party packages where no Packages ever existed
for them can be also used in Debian but will not be default scheme.

This package signing scheme can be implemented using debsig-verify
and debsigs. These two packages can sign and verify embedded
signatures in the .deb itself. Debian already has the capability to do this
now, but there is no feature plan to implement the policy or other tools since
the archive signing scheme is prefered. These tools are available for users
and archive administrators that would rather use this scheme instead.

Latest dpkg versions (since 1.9.21) incorporate a patch
that provides this functionality as soon as debsig-verify is
installed.

NOTE: Currently /etc/dpkg/dpkg.cfg ships with
"no-debsig" as per default.

NOTE2: Signatures from developers are currently stripped when they enter off
the package archive since the currently preferred method is release checks as
described previously.