7.5. 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 [47]

FIXME: probably the Internet Explorer vulnerability handling. certificate chains has an impact on security updates on Microsoft Windows.

Debian does not provide signed packages but provides a mechanism available since Debian 4.0 (codename etch) to check for downloaded package’s integrity[48]. For more information, see 第 7.5.2 节 “Secure apt”.

This issue is better described in the http://www.cryptnet.net/fdp/crypto/strong_distro.html by V. Alex Brennen.

7.5.1. The current scheme for package signature checks

当前使用 apt 进行软件包签名检测的计划是:

  • 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.

下边的 MD5 sums apt 可以完成对于源自某个发行版的单个的软件包的校检. 这与对每个软件包签名相比不太灵活, 也许会与这个计划结合(参见下面).

This scheme is http://lists.debian.org/debian-devel/2003/debian-devel-200312/msg01986.html in apt 0.6 and is available since the Debian 4.0 release. For more information see 第 7.5.2 节 “Secure apt”. 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 http://lists.debian.org/debian-devel/2005/03/msg02641.html to adapt to this scheme. Front-ends currently known to work properly with this feature include aptitude and synaptic.

在Debian]中的软件包签名已经被讨论了相当一段时间了, 更多信息参见: http://www.debian.org/News/weekly/2001/8/http://www.debian.org/News/weekly/2000/11/.

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 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=203741) which provides this implementation.

Secure apt works by checking the distribution through the Release file, as discussed in 第 7.5.3 节 “Per distribution release check”. Typically, this process will be transparent to the administrator although you will need to intervene every year[49] to add the new archive key when it is rotated, for more information on the steps an administrator needs to take a look at 第 7.5.3.7 节 “Safely adding a key”.

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.

You can find more information at http://wiki.debian.org/SecureApt and the official documentation: http://www.enyo.de/fw/software/apt-secure/ and http://www.syntaxpolice.org/apt-secure/.

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 http://wiki.debian.org/SecureApt.

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:

  1. MD5Sum:
  2. 6b05b392f792ba5a436d590c129de21f 3453 Packages
  3. 1356479a23edda7a69f24eb8d6f4a14b 1131 Packages.gz
  4. 2a5167881adc9ad1a8864f281b1eb959 1715 Sources
  5. 88de3533bf6e054d1799f8e49b6aed8b 658 Sources.gz

The Release files also include SHA-1 checksums, which will be useful once MD5 sums become fully broken, however apt doesn’t use them yet.

Now if we look inside a Packages file, we’ll find more MD5 sums, one for each package listed in it. For example:

  1. Package: uqm
  2. Priority: optional
  3. ...
  4. Filename: unstable/uqm_0.4.0-1_i386.deb
  5. Size: 580558
  6. MD5sum: 864ec6157c1eea88acfef44d0f34d219

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 [50] , although only gpg actually looks at its contents normally:

  1. -----BEGIN PGP SIGNATURE-----
  2. Version: GnuPG v1.4.1 (GNU/Linux)
  3.  
  4. iD8DBQBCqKO1nukh8wJbxY8RAsfHAJ9hu8oGNRAl2MSmP5+z2RZb6FJ8kACfWvEx
  5. UBGPVc7jbHHsg78EhMBlV/U=
  6. =x6og
  7. -----END PGP SIGNATURE-----

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:

  1. W: GPG error: http://ftp.us.debian.org testing Release: The following signatures
  2. 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:

  1. WARNING: The following packages cannot be authenticated!
  2. libglib-perl libgtk2-perl
  3. 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[51] 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.

  1. # apt-key list
  2. /etc/apt/trusted.gpg
  3. --------------------
  4. pub 1024D/4F368D5D 2005-01-31 [expires: 2006-01-31]
  5. uid Debian Archive Automatic Signing Key (2005) <ftpmaster@debian.org>

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 Debian archive signing key is available at http://ftp-master.debian.org/ziyi_key_2006.asc (replace 2006 with current year).[52]

gpg itself has a standard way to distribute keys, using a keyserver that gpg can download a key from and add it to its keyring. For example:

  1. $ gpg --keyserver pgpkeys.mit.edu --recv-key 2D230C5F
  2. gpg: requesting key 2D230C5F from hkp server pgpkeys.mit.edu
  3. gpg: key 2D230C5F: public key "Debian Archive Automatic Signing Key (2006) <ftpm
  4. aster@debian.org>" imported
  5. gpg: Total number processed: 1
  6. gpg: imported: 1

You can then export that key from your own keyring and feed it to apt-key:

  1. $ gpg -a --export 2D230C5F | sudo apt-key add -
  2. gpg: no ultimately trusted keys found
  3. OK

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 [53].

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 http://debiansystem.info/readers/changes/547-ziyi-key-2006, 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:

  1. $ GET http://ftp-master.debian.org/ziyi_key_2006.asc | gpg --import
  2. gpg: key 2D230C5F: public key "Debian Archive Automatic Signing Key (2006)
  3. <ftpmaster&debian.org>" imported
  4. gpg: Total number processed: 1
  5. gpg: imported: 1
  6. $ gpg --check-sigs --fingerprint 2D230C5F
  7. pub 1024D/2D230C5F 2006-01-03 [expires: 2007-02-07]
  8. Key fingerprint = 0847 50FC 01A6 D388 A643 D869 0109 0831 2D23 0C5F
  9. uid Debian Archive Automatic Signing Key (2006) <ftpmaster@debian.org>
  10. sig!3 2D230C5F 2006-01-03 Debian Archive Automatic Signing Key
  11. (2006) <ftpmaster@debian.org>
  12. sig! 2A4E3EAA 2006-01-03 Anthony Towns <aj@azure.humbug.org.au>
  13. sig! 4F368D5D 2006-01-03 Debian Archive Automatic Signing Key
  14. (2005) <ftpmaster@debian.org>
  15. sig! 29982E5A 2006-01-04 Steve Langasek <vorlon@dodds.net>
  16. sig! FD6645AB 2006-01-04 Ryan Murray <rmurray@cyberhqz.com>
  17. sig! AB2A91F5 2006-01-04 James Troup <james@nocrew.org>

and then http://www.debian.org/doc/manuals/securing-debian-howto/ch7.en.html#s-deb-pack-sign 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:

  1. $ gpg --export -a 2D230C5F | sudo apt-key add -
  2. 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:

  1. W: GPG error: http://archive.progeny.com sid Release: Unknown error executing gpg

Although apt-key list will make the problem plain:

  1. gpg: key 2D230C5F was created 192324901 seconds in the future (time warp or clock problem)
  2. gpg: key 2D230C5F was created 192324901 seconds in the future (time warp or clock problem)
  3. pub 1024D/2D230C5F 2006-01-03
  4. uid Debian Archive Automatic Signing Key (2006) <ftpmaster@debian.org>

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[54] 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.

示例代码,将其命名为 apt-check-sigs, 可以通过下边的方法使用:

  1. # apt-get update
  2. # apt-check-sigs
  3. (...results...)
  4. # apt-get dist-upgrade

首先, 您需要:

  • get the keys the archive software uses to sign Release files, http://ftp-master.debian.org/ziyi_key_2006.asc and add them to ~/.gnupg/trustedkeys.gpg (which is what gpgv uses by default).

    1. gpg --no-default-keyring --keyring trustedkeys.gpg --import ziyi_key_2006.asc
  • 删除 /etc/apt/sources.list 中所有没有正常使用 “dists” 的行, 或者修改脚本,以便对它们有效.

  • be prepared to ignore the fact that Debian security updates don’t have signed Release files, and that Sources files don’t have appropriate checksums in the Release file (yet).

  • 准备用正确的公钥检查对应的源码.

这是 apt-check-sigs 的示例代码,最新的版本可从 http://people.debian.org/~ajt/apt-check-sigs 处获取. 此代码当前为 beta 版, 更多信息参见 http://lists.debian.org/debian-devel/2002/debian-devel-200207/msg00421.html.

  1. #!/bin/bash
  2.  
  3. # Copyright (c) 2001 Anthony Towns <ajt@debian.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14.  
  15. rm -rf /tmp/apt-release-check
  16. mkdir /tmp/apt-release-check || exit 1
  17. cd /tmp/apt-release-check
  18.  
  19. >OK
  20. >MISSING
  21. >NOCHECK
  22. >BAD
  23.  
  24. arch=`dpkg --print-installation-architecture`
  25.  
  26. am_root () {
  27. [ `id -u` -eq 0 ]
  28. }
  29.  
  30. get_md5sumsize () {
  31. cat "$1" | awk '/^MD5Sum:/,/^SHA1:/' |
  32. MYARG="$2" perl -ne '@f = split /\s+/; if ($f[3] eq $ENV{"MYARG"}) {
  33. print "$f[1] $f[2]\n"; exit(0); }'
  34. }
  35.  
  36. checkit () {
  37. local FILE="$1"
  38. local LOOKUP="$2"
  39.  
  40. Y="`get_md5sumsize Release "$LOOKUP"`"
  41. Y="`echo "$Y" | sed 's/^ *//;s/ */ /g'`"
  42.  
  43. if [ ! -e "/var/lib/apt/lists/$FILE" ]; then
  44. if [ "$Y" = "" ]; then
  45. # No file, but not needed anyway
  46. echo "OK"
  47. return
  48. fi
  49. echo "$FILE" >>MISSING
  50. echo "MISSING $Y"
  51. return
  52. fi
  53. if [ "$Y" = "" ]; then
  54. echo "$FILE" >>NOCHECK
  55. echo "NOCHECK"
  56. return
  57. fi
  58. X="`md5sum < /var/lib/apt/lists/$FILE | cut -d\ -f1` `wc -c < /var/lib
  59. /apt/lists/$FILE`"
  60. X="`echo "$X" | sed 's/^ *//;s/ */ /g'`"
  61. if [ "$X" != "$Y" ]; then
  62. echo "$FILE" >>BAD
  63. echo "BAD"
  64. return
  65. fi
  66. echo "$FILE" >>OK
  67. echo "OK"
  68. }
  69.  
  70. echo
  71. echo "Checking sources in /etc/apt/sources.list:"
  72. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  73. echo
  74. (echo "You should take care to ensure that the distributions you're downloading
  75. "
  76. echo "are the ones you think you are downloading, and that they are as up to"
  77. echo "date as you would expect (testing and unstable should be no more than"
  78. echo "two or three days out of date, stable-updates no more than a few weeks"
  79. echo "or a month)."
  80. ) | fmt
  81. echo
  82.  
  83. cat /etc/apt/sources.list |
  84. sed 's/^ *//' | grep '^[^#]' |
  85. while read ty url dist comps; do
  86. if [ "${url%%:*}" = "http" -o "${url%%:*}" = "ftp" ]; then
  87. baseurl="${url#*://}"
  88. else
  89. continue
  90. fi
  91.  
  92. echo "Source: ${ty} ${url} ${dist} ${comps}"
  93.  
  94. rm -f Release Release.gpg
  95. lynx -reload -dump "${url}/dists/${dist}/Release" >/dev/null 2>&1
  96. wget -q -O Release "${url}/dists/${dist}/Release"
  97.  
  98. if ! grep -q '^' Release; then
  99. echo " * NO TOP-LEVEL Release FILE"
  100. >Release
  101. else
  102. origline=`sed -n 's/^Origin: *//p' Release | head -1`
  103. lablline=`sed -n 's/^Label: *//p' Release | head -1`
  104. suitline=`sed -n 's/^Suite: *//p' Release | head -1`
  105. codeline=`sed -n 's/^Codename: *//p' Release | head -1`
  106. dateline=`grep "^Date:" Release | head -1`
  107. dscrline=`grep "^Description:" Release | head -1`
  108. echo " o Origin: $origline/$lablline"
  109. echo " o Suite: $suitline/$codeline"
  110. echo " o $dateline"
  111. echo " o $dscrline"
  112.  
  113. if [ "${dist%%/*}" != "$suitline" -a "${dist%%/*}" != "$codeline" ]; then
  114. echo " * WARNING: asked for $dist, got $suitline/$codeline"
  115. fi
  116.  
  117. lynx -reload -dump "${url}/dists/${dist}/Release.gpg" >/dev/null 2>&1
  118. wget -q -O Release.gpg "${url}/dists/${dist}/Release.gpg"
  119.  
  120. gpgv --status-fd 3 Release.gpg Release 3>&1 >/dev/null 2>&1 | sed -n "s/^\[GNUPG:\] //p" | (okay=0; err=""; while read gpgcode rest; do
  121. if [ "$gpgcode" = "GOODSIG" ]; then
  122. if [ "$err" != "" ]; then
  123. echo " * Signed by ${err# } key: ${rest#* }"
  124. else
  125. echo " o Signed by: ${rest#* }"
  126. okay=1
  127. fi
  128. err=""
  129. elif [ "$gpgcode" = "BADSIG" ]; then
  130. echo " * BAD SIGNATURE BY: ${rest#* }"
  131. err=""
  132. elif [ "$gpgcode" = "ERRSIG" ]; then
  133. echo " * COULDN'T CHECK SIGNATURE BY KEYID: ${rest %% *}"
  134. err=""
  135. elif [ "$gpgcode" = "SIGREVOKED" ]; then
  136. err="$err REVOKED"
  137. elif [ "$gpgcode" = "SIGEXPIRED" ]; then
  138. err="$err EXPIRED"
  139. fi
  140. done
  141. if [ "$okay" != 1 ]; then
  142. echo " * NO VALID SIGNATURE"
  143. >Release
  144. fi)
  145. fi
  146. okaycomps=""
  147. for comp in $comps; do
  148. if [ "$ty" = "deb" ]; then
  149. X=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/binary-${arch}/Release" | sed 's,//*,_,g'`" "${comp}/binary-${arch}/Release")
  150. Y=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/binary-${arch}/Packages" | sed 's,//*,_,g'`" "${comp}/binary-${arch}/Packages")
  151. if [ "$X $Y" = "OK OK" ]; then
  152. okaycomps="$okaycomps $comp"
  153. else
  154. echo " * PROBLEMS WITH $comp ($X, $Y)"
  155. fi
  156. elif [ "$ty" = "deb-src" ]; then
  157. X=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/source/Release" | sed 's,//*,_,g'`" "${comp}/source/Release")
  158. Y=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/source/Sources" | sed 's,//*,_,g'`" "${comp}/source/Sources")
  159. if [ "$X $Y" = "OK OK" ]; then
  160. okaycomps="$okaycomps $comp"
  161. else
  162. echo " * PROBLEMS WITH component $comp ($X, $Y)"
  163. fi
  164. fi
  165. done
  166. [ "$okaycomps" = "" ] || echo " o Okay:$okaycomps"
  167. echo
  168. done
  169.  
  170. echo "Results"
  171. echo "~~~~~~~"
  172. echo
  173.  
  174. allokay=true
  175.  
  176. cd /tmp/apt-release-check
  177. diff <(cat BAD MISSING NOCHECK OK | sort) <(cd /var/lib/apt/lists && find . -type f -maxdepth 1 | sed 's,^\./,,g' | grep '_' | sort) | sed -n 's/^> //p' >UNVALIDATED
  178.  
  179. cd /tmp/apt-release-check
  180. if grep -q ^ UNVALIDATED; then
  181. allokay=false
  182. (echo "The following files in /var/lib/apt/lists have not been validated."
  183. echo "This could turn out to be a harmless indication that this script"
  184. echo "is buggy or out of date, or it could let trojaned packages get onto"
  185. echo "your system."
  186. ) | fmt
  187. echo
  188. sed 's/^/ /' < UNVALIDATED
  189. echo
  190. fi
  191.  
  192. if grep -q ^ BAD; then
  193. allokay=false
  194. (echo "The contents of the following files in /var/lib/apt/lists does not"
  195. echo "match what was expected. This may mean these sources are out of date,"
  196. echo "that the archive is having problems, or that someone is actively"
  197. echo "using your mirror to distribute trojans."
  198. if am_root; then
  199. echo "The files have been renamed to have the extension .FAILED and"
  200. echo "will be ignored by apt."
  201. cat BAD | while read a; do
  202. mv /var/lib/apt/lists/$a /var/lib/apt/lists/${a}.FAILED
  203. done
  204. fi) | fmt
  205. echo
  206. sed 's/^/ /' < BAD
  207. echo
  208. fi
  209.  
  210. if grep -q ^ MISSING; then
  211. allokay=false
  212. (echo "The following files from /var/lib/apt/lists were missing. This"
  213. echo "may cause you to miss out on updates to some vulnerable packages."
  214. ) | fmt
  215. echo
  216. sed 's/^/ /' > MISSING
  217. echo
  218. fi
  219.  
  220. if grep -q ^ NOCHECK; then
  221. allokay=false
  222. (echo "The contents of the following files in /var/lib/apt/lists could not"
  223. echo "be validated due to the lack of a signed Release file, or the lack"
  224. echo "of an appropriate entry in a signed Release file. This probably"
  225. echo "means that the maintainers of these sources are slack, but may mean"
  226. echo "these sources are being actively used to distribute trojans."
  227. if am_root; then
  228. echo "The files have been renamed to have the extension .FAILED and"
  229. echo "will be ignored by apt."
  230. cat NOCHECK | while read a; do
  231. mv /var/lib/apt/lists/$a /var/lib/apt/lists/${a}.FAILED
  232. done
  233. fi) | fmt
  234. echo
  235. sed 's/^/ /' > NOCHECK
  236. echo
  237. fi
  238.  
  239. if $allokay; then
  240. echo 'Everything seems okay!'
  241. echo
  242. fi
  243.  
  244. rm -rf /tmp/apt-release-check

You might need to apply the following patch for sid since md5sum adds an ‘-‘ after the sum when the input is stdin:

  1. @@ -37,7 +37,7 @@
  2. local LOOKUP=”$2

  3.     Y="`get_md5sumsize Release "$LOOKUP"`"
      • Y=”echo "$Y" | sed 's/^ *//;s/ */ /g'
        • Y=”echo "$Y" | sed 's/-//;s/^ *//;s/ */ /g'

        • if [ ! -e “/var/lib/apt/lists/$FILE ]; then

        •     if [ "$Y" = "" ]; then
        • @@ -55,7 +55,7 @@

        •     return
        • fi

        • X=”md5sum &lt; /var/lib/apt/lists/$FILE wc -c &lt; /var/lib/apt/lists/$FILE

      •  
          • X=”echo "$X" | sed 's/^ *//;s/ */ /g'
            • X=”echo "$X" | sed 's/-//;s/^ *//;s/ */ /g'
            • if [ $X != $Y ]; then
                  echo "$FILE" &gt;&gt;BAD
            •     echo "BAD"

          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:

          1. $ rm -f dists/unstable/Release
          2. $ apt-ftparchive release dists/unstable > dists/unstable/Release
          3. $ gpg --sign -ba -o dists/unstable/Release.gpg dists/unstable/Release

          7.5.5. 可供选种的软包签名方案

          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 http://lists.debian.org/debian-dpkg/2001/debian-dpkg-200103/msg00024.html that provides this functionality as soon as debsig-verify is installed.

          注: 当前 /etc/dpkg/dpkg.cfg 引入 “no-debsig” 为缺省值.

          注2: 来自开发者的签名署名当它们进入软包的时候被剥离, 因为当前首选的方法还是使用前边描述的那种方法.


          [47] Some operating systems have already been plagued with automatic-updates problems such as the http://www.cunap.com/~hardingr/projects/osx/exploit.html.

          [48] Older releases, such as Debian 3.1 sarge can use this feature by using backported versions of this package management tool

          [49] Until an automatic mechanism is developed.

          [50] Technically speaking, this is an ASCII-armored detached gpg signature.

          [51] Or has poisoned your DNS, or is spoofing the server, or has replaced the file in the mirror you are using, etc.

          [52] “ziyi” is the name of the tool used for signing on the Debian servers, the name is based on the name of a http://en.wikipedia.org/wiki/Zhang_Ziyi.

          [53] Not all apt repository keys are signed at all by another key. Maybe the person setting up the repository doesn’t have another key, or maybe they don’t feel comfortable signing such a role key with their main key. For information on setting up a key for a repository see 第 7.5.4 节 “Release check of non Debian sources”.

          [54] Either because you are using the stable, sarge, release or an older release or because you don’t want to use the latest apt version, although we would really appreciate testing of it.