File: infrastructure.sgml.svn-base

package info (click to toggle)
harden-doc 3.13.3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,908 kB
  • ctags: 25
  • sloc: sh: 789; makefile: 174; xml: 105; perl: 86
file content (1281 lines) | stat: -rw-r--r-- 56,417 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
<!-- CVS revision of this document "$Revision: 1.28 $"  -->

<chapt>Debian Security Infrastructure

<sect id="debian-sec-team">The Debian Security Team

<p>Debian has a Security Team, made up of five members and two
secretaries who handle security in the <em>stable</em>
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 <em>stable</em>
distribution is affected by it.

<p>Also, the Debian Security Team is the contact point for problems
that are coordinated by upstream developers or organizations such as
<url id="http://www.cert.org" name="CERT"> which might affect multiple
vendors. That is, when problems are not Debian-specific. There are two
contact points with the Security Team:

<list>

<item><url id="mailto:team@security.debian.org"
name="team@security.debian.org"> which only the members of the
security team read. 

<item><url id="mailto:security@debian.org" name="security@debian.org">
which is read by all Debian developers (including the security
team). Mails sent to this list are not published in the Internet (it's
not a public mailing list).

</list>

<p>Sensitive information should be sent to the first address and, in
some cases, should be encrypted with the Debian Security Contact key
(key ID 363CCD95).

<p>Once a probable problem is received by the Security Team it will
investigate if the <em>stable</em> 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 <url
id="security-master.debian.org"> site so they can be retrieved through
<prgn>apt</prgn> (see <ref id="security-update">). At the same time a
<em>Debian Security Advisory</em> (DSA) is published on the web site
and sent to public mailing lists including <url
id="http://lists.debian.org/debian-security-announce"
name="debian-security-announce"> and Bugtraq.

<p>Some other frequently asked questions on the Debian Security Team can be
found at <ref id="debian-sec-team-faq">.


<sect id="dsa">Debian Security Advisories

<p>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 and their MD5 sums. This information is:

<list>
<item>version number for the fix.
<item>problem type.
<item>whether it is remote or locally exploitable.
<item>short description of the package.
<item>description of the problem.
<item>description of the exploit.
<item>description of the fix.
</list>


<p>DSAs are published both in <url id="http://www.debian.org/"
name="Debian's mainserver frontpage"> and in the <url
id="http://www.debian.org/security/" name="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.

<p>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
<prgn>Evolution</prgn> (an email client and personal information
assistant) and <prgn>Multiticker</prgn> (a GNOME applet), can be used
to retrieve the advisories automatically. The RDF channel is available
at <url id="http://www.debian.org/security/dsa.rdf">.

<p>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<footnote>Translations are available in up to ten different
languages.</footnote> of DSAs are not sent to the security mailing
lists but are directly included in the website.

<sect1 id="crossreference">Vulnerability cross references

<p>Debian provides a fully <url
id="http://www.debian.org/security/crossreferences"
name="crossreferenced table"> including all the references available
for all the advisories published since 1998. This table is provided to
complement the <url
id="http://cve.mitre.org/cve/refs/refmap/source-DEBIAN.html"
name="reference map available at CVE">. 

<P>You will notice that this table provides references to
security databases such as <url id="http://www.securityfocus.com/bid"
name="Bugtraq">,
<url id="http://www.cert.org/advisories/" name="CERT/CC Advisories">
and <url id="http://www.kb.cert.org/vuls" name="US-CERT Vulnerability
Notes Database"> as well as CVE names (see below). These references
are provided for convenience use, but only CVE references are
periodically reviewed and included. This feature was added to the
website on June 2002.

<p>One of the advantages of adding cross references to these
vulnerability databases is that:

<list>
<item>it makes it easier for Debian users to see and track which
general (published) advisories have already been covered by Debian. 

<item>system administrators can learn more about the vulnerability and
its impact by following the cross references.

<item>this information can be used to cross-check output from
vulnerability scanners that include references to CVE to remove false
positives (see <ref id="vulnasses-false-positive">).

</list>
</sect1>

<sect1 id="cve-compatible">CVE compatibility

<P>Debian Security Advisories were <url
id="http://www.debian.org/security/CVE-certificate.jpg" name="declared
CVE-Compatible"><footnote>The full <url
id="http://cve.mitre.org/compatible/phase2/SPI_Debian.html"
name="capability questionnaire"> is available at CVE</footnote> in
February 24, 2004.

<p>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 <url
id="http://www.cve.mitre.org/compatible/enterprise.html"
name="CVE-enabled security management process">.

<p>The <url id="http://cve.mitre.org" name="Common Vulnerabilities and
Exposures (CVE)"> project is maintained by the MITRE Corporation and
provides a list of standardized names for vulnerabilities and security
exposures.

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

<p>Debian started adding CVE names to DSAs in June 2002, and now
provides CVE names for all DSAs released since September 1998 after a
review process started on August 2002. 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 <url id="http://search.debian.org/" name="search engine">.

<p>Users who want to search for a particular CVE name can use the web
search engine available in debian.org to retrieve advisories available
(in English and translated to other languages) associated with CVE
names. A search can be made for a specific name (like advisory <url
id="http://search.debian.org/?q=advisory+%22CAN-2002-0001%22&amp;ps=50&amp;o=1&amp;m=all"
name="CAN-2002-0001">) or for partial names (like all the 2002
candidates included in advisories search for <url
id="http://search.debian.org/?q=advisory+%22CAN-2002%22&amp;ps=50&amp;o=1&amp;m=all"
name="CAN-2002">). Notice that you need to enter the word "advisory"
together with the CVE name in order to retrieve only security
advisories.

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

<list>
   <item> No Debian products are affected by that vulnerability.
   <item> There is not yet an advisory covering that vulnerability
   (the security issue might have been reported as a <url
   id="http://bugs.debian.org/cgi-bin/pkgreport.cgi?tag=security"
   name="security bug"> but a fix has not been tested and uploaded).
   <item> An advisory was published before a CVE name was assigned to a
   given vulnerability (look for an update at the web site).
</list>
</sect1>

</sect>

<sect>Debian Security Build Infrastructure

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

<p>While previously the task to build security updates was done by
hand, it is currently not (as Anthony Towns describes in 
<url id="http://lists.debian.org/debian-devel-announce/2002/debian-devel-announce-200206/msg00002.html" name="a mail">
sent to the debian-devel-announce mailing list dated 8th June
2002).

<p>Packages uploaded by the security team (to <url
id="ftp://security-master.debian.org:/org/security.debian.org/queue/unchecked"> or
<url id="ftp://security-master.debian.org/pub/SecurityUploadQueue">)
with an appropriate patch are checked for signatures withing fifteen
minutes of being uploaded. Once this is done they get added to the
list of the autobuilders (which no longer do a daily archive
run). Thus, packages can get automatically built for <em>all</em>
architectures thirty minutes or an hour or so after they're uploaded.
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. 

<p>Thus, the security upload archive works with the following
procedure (called <em>"Accepted-Autobuilding"</em>):

<list>

<item>Someone finds a security problem.
     
<item>Someone fixes the problem, and makes an upload to
      security-master.debian.org's incoming (this <em>someone</em> 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 <em>testing-security</em>
      or <em>stable-security</em> as target distribution.

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

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

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

<item>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:

<list>
<item>installs the package into the security archive.

<item>updates the <file>Packages</file>, <file>Sources</file> and <file>Release</file> files of
security.debian.org in the usual way (<prgn>dpkg-scanpackages</prgn>,
<prgn>dpkg-scansources</prgn>, ...).

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

<item>(optionally) forwards the packages to the appropriate
proposed-updates so that it can be included in the real archive as
soon as possible.

</list>

</list>

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


<sect1>Developer's guide to security updates

<p>This mail was sent by Wichert Akkerman to the <url
id="http://lists.debian.org/debian-devel-announce/2002/debian-devel-announce-200206/msg00004.html"
name="Debian-devel-announce mailing list"> in order to describe Debian
developer's behavior for handling security problems in their
packages. It is published here both for the benefit of developers as
well as for users to understand better how security is handled in Debian.

<p>FIXME: Please note that the up to date reference for this information is
the <url id="http://www.debian.org/doc/manuals/developers-reference/ch-pkgs#bug-security" name="Debian Developer's Reference">, this section will be
removed in the near future.

<sect2>Coordinating with the security team

<p>If a developer learns of a security problem, either in his package
or someone else's he should always contact the security team (at
team@security.debian.org). They keep track of outstanding security
problems, can help maintainers with security problems or fix them
themselves, are responsible for sending security advisories and
maintaining security.debian.org.

<p>Please note that security advisories are only done for release
distributions, not for testing, unstable (see <ref id="sec-unstable">)
or older distributions (see <ref id="sec-older">).

<sect2>Learning of security problems

<p>There are a few ways a developer can learn of a security problem:

<list>
<item>he notices it on a public forum (mailing list, website, etc.).
<item>someone files a bugreport (the <em>Security</em> tag should be
used, or added by the developer).
<item>someone informs him via private email.
</list>

<p>In the first two cases the information is public and it is important
to have a fix as soon as possible. In the last case however it might
not be public information. In that case there are a few possible options
for dealing with the problem:

<list>

<item>if it is a trivial problem (like insecure temporary files) there is no
  need to keep the problem a secret and a fix should be made and
  released.

<item>if the problem is severe (remote exploitable, possibility to gain root
  privileges) it is preferable to share the information with other
  vendors and coordinate a release. The security team keeps contacts
  with the various organizations and individuals and can take care of
  that.

</list>

<p>In all cases if the person who reports the problem asks to not
disclose the information that should be respected, with the obvious
exception of informing the security team (the developer should make
sure he tells the security team that the information cannot be
disclosed).

<p>Please note that if secrecy is needed the developer can also not
upload a fix to unstable (or anywhere else), since the changelog
information for unstable is public information.

<p>There are two reasons for releasing information even though secrecy
is requested/required: the problem has been known for too long, or
the information becomes public.

<sect2>Building a package

<p>The most important guideline when making a new package that fixes a
security problem is to make as few changes as possible. People are
relying on the exact behavior of a release once it is made, so any
change made to it can possibly break someone's system. This is
especially true of libraries: the developer must make sure he never
changes the API or ABI, no matter how small the change.

<p>This means that moving to a new upstream version is not a good solution,
instead the relevant changes should be backported. Generally upstream
maintainers are willing to help if needed, if not the Debian Security
Team might be able to help.

<p>In some cases it is not possible to backport a security fix, for
example when large amounts of source code need to be modified or
rewritten. If that happens it might be necessary to move to a new
upstream version, but it should always be coordinated with the security team
beforehand.

<p>Related to this is another important aspect: developers must always
test your change. If there is an exploit the developer should try if
it indeed succeeds on the unpatched package and fails on the fixed
package. The developer should try normal usage as well, sometimes a
security fix can break normal use subtly.

<p>Finally a few technical things for developers to keep in mind:

<list>
<item>Make sure you target the right distribution in your debian/changelog.
  For stable this is stable-security and for testing this is
  testing-security. Do not target &lt;codename&gt;-proposed-updates.

<item>Make sure the version number is proper. It has to be higher than the
  current package, but lower than package versions in later
  distributions. For testing this means there has to be a higher version
  in unstable. If there is none yet (testing and unstable have the same
  version for example) upload a new version to unstable first.

<item>Do not make source-only uploads if your package has any binary-all
  packages. The buildd infrastructure will not build those.

<item>Make sure when compiling a package you compile on a clean system
  which only has packages installed from the distribution you are
  building for. If you do not have such a system yourself you
  can try a debian.org machine (see http://db.debian.org/machines.cgi)
  or set up a chroot (the <package>pbuilder</package> and
  <package>debootstrap</package> packages can be helpful in that
  case).

</list>

<sect2>Uploading security fixes

<p>After the developer has created and tested the new package it needs to be
uploaded so it can be installed in the archives. For security uploads
the place to upload to is
ftp://security-master.debian.org/pub/SecurityUploadQueue/ .

<p>Once an upload to the security queue has been accepted the package will
automatically be rebuilt for all architectures and stored for
verification by the security team.

<p>Uploads waiting for acceptance or verification are only accessible by
the security team. This is necessary since there might be fixes for
security problems that cannot be disclosed yet.

<p>If a member of the security team accepts a package it will be installed
on security.debian.org as well as the proper &lt;codename&gt;-proposed-updates
in ftp-master or non-US archive.

<sect2>The security advisory

<p>Security advisories are written and posted by the security team. However
they certainly do not mind if a maintainer can supply (part of) the text
for them. Information that should be in an advisory is described in
<ref id="dsa">.


<sect id="deb-pack-sign">Package signing in Debian

<p>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<footnote>
<p>Some operating systems have already been plagued with
automatic-updates problems such as the
<url name="Mac OS X Software Update vulnerabity"
id="http://www.cunap.com/~hardingr/projects/osx/exploit.html">.
<p>FIXME: probably the Internet Explorer vulnerability handling
certificate chains has an impact on security updates on Microsoft Windows.
</footnote>.

<p>Debian does not provide signed packages but provides a mechanism
available since Debian 4.0 (codename <em>etch</em>) to check for
downloaded package's integrity<footnote><p>Older releases, such
as Debian 3.1 <em>sarge</em> can use this feature by using backported
versions of this package management tool</p></footnote>. For more information,
see <ref id="apt-0.6">.

<p>This issue is better described in the
<url id="http://www.cryptnet.net/fdp/crypto/strong_distro.html" name="Strong
Distribution HOWTO"> by V. Alex Brennen.

<sect1>The current scheme for package signature checks

<p>The current scheme for package signature checking
using <prgn>apt</prgn> is:

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

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

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

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

<item>If the MD5 sum from the downloaded package is the same as the one in the
<file>Packages.gz</file> 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 <file>Packages.gz</file> and the administrator has 
configured the system to only install checked packages it will not be 
installed either.
</list>

<p>By following the chain of MD5 sums <prgn>apt</prgn> 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).

<p>This scheme is <url
id="http://lists.debian.org/debian-devel/2003/debian-devel-200312/msg01986.html
" name="fully implemented"> in apt 0.6 and is available since
the Debian 4.0 release. For more information see <ref
id="apt-0.6">. Packages that provide a front-end to apt need to be
modified to adapt to this new feature; this is the case of
<prgn>aptitude</prgn> which was <url
id="http://lists.debian.org/debian-devel/2005/03/msg02641.html"
name="modified"> to adapt to this scheme. Front-ends currently known
to work properly with this feature include <prgn>aptitude</prgn> and
<prgn>synaptic</prgn>.

<p>Package signing has been discussed in Debian for quite some time, for
more information you can read:
<url id="http://www.debian.org/News/weekly/2001/8/"> and
<url id="http://www.debian.org/News/weekly/2000/11/">.

<sect1 id="apt-0.6">Secure apt

<p>The apt 0.6 release, available since Debian 4.0 <em>etch</em>
and later releases, includes <em>apt-secure</em>
(also known as <em>secure apt</em>) 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 <prgn>apt-key</prgn> for adding 
new keys to apt's keyring, which by default includes only the current 
Debian archive signing key.

<p>These changes are based on the
patch for <prgn>apt</prgn> (available in <url
id="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=203741" name="Bug
#203741">) which provides this implementation.  

<p>Secure apt works by checking the distribution through the <file>Release</file> file,
as discussed in <ref id="check-releases">. Typically, this process will
be transparent to the administrator although you will need to intervene
every year<footnote>Until an automatic mechanism is developed.</footnote>
to add the new archive key when it is rotated, for more information on the
steps an administrator needs to take a look at <ref id="secure-apt-add-key">.

<p>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 <package>apt</package> package.

<p>You can find more information at
<url id="http://wiki.debian.org/SecureApt" name="the wiki pages"> and the
official documentation: <url id="http://www.enyo.de/fw/software/apt-secure/"
name="Migration to APT 0.6"> and <url
id="http://www.syntaxpolice.org/apt-secure/" name="APT Signature Checking">.

<sect1 id="check-releases">Per distribution release check

<p>This section describes how the distribution release check mechanism
works, it was written by Joey Hess and is also available at the
<url id="http://wiki.debian.org/SecureApt" name="Debian Wiki">.

<sect2>Basic concepts

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

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

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

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

<p><prgn>gpg</prgn> is the tool used in secure apt to sign files and check their
signatures.

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

<sect2><file>Release</file> checksums

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

<example>
MD5Sum:
 6b05b392f792ba5a436d590c129de21f            3453 Packages
 1356479a23edda7a69f24eb8d6f4a14b            1131 Packages.gz
 2a5167881adc9ad1a8864f281b1eb959            1715 Sources
 88de3533bf6e054d1799f8e49b6aed8b             658 Sources.gz
</example>

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

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

<example>
    Package: uqm
    Priority: optional
    ...
    Filename: unstable/uqm_0.4.0-1_i386.deb
    Size: 580558
    MD5sum: 864ec6157c1eea88acfef44d0f34d219
</example>

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

<p>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 <file>Release</file> 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. 

<sect2>Verification of the <file>Release</file> file

<p>To verify the <file>Release</file> file, a gpg signature is added for
the <file>Release</file> file. This is put in a file named <file>Release.gpg</file> that is
shipped alongside the <file>Release</file> file. It looks something like this
<footnote>Technically speaking, this is an ASCII-armored detached gpg signature.</footnote>
, although only gpg actually looks at its contents normally:

<example>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCqKO1nukh8wJbxY8RAsfHAJ9hu8oGNRAl2MSmP5+z2RZb6FJ8kACfWvEx
UBGPVc7jbHHsg78EhMBlV/U=
=x6og
-----END PGP SIGNATURE-----
</example>

<sect2>Check of <file>Release.gpg</file> by <prgn>apt</prgn>

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

<example>
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
</example>

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

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

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

<p>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<footnote>Or has
poisoned your DNS, or is spoofing the server, or has replaced the file in the
mirror you are using, etc.</footnote> has arranged for you, containing a nasty
suprise.

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

<p>It's also worth noting that newer versions of the Debian installer use the same
signed <file>Release</file> 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 <file>Release</file> files on its CDs; apt can be configured to
always trust packages from CDs so this is not a large problem. 

<sect2>How to tell apt what to trust

<p>So the security of the whole system depends on there being a <file>Release.gpg</file>
file, which signs a <file>Release</file> file, and of <prgn>apt</prgn> 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
(<file>/etc/apt/trusted.gpg</file>), and managing the keys is where secure apt
comes in.

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

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

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

<p>That will make <prgn>apt</prgn> trust the official Debian archive, but if you add some
other apt repository to <file>/etc/apt/sources.list</file>, you'll also have to
give <prgn>apt</prgn> 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 <prgn>apt-key add file</prgn> to
add it. Getting the key and verifying it are the trickier parts. 

<sect2>Finding the key for a repository

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

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

<p>The Debian archive signing key is available at <url
id="http://ftp-master.debian.org/ziyi_key_2006.asc"> (replace 2006 with current
year).<footnote>"ziyi" is the name of the tool used for signing on the Debian servers,
the name is based on the name of a <url
id="http://en.wikipedia.org/wiki/Zhang_Ziyi" name="Chinese actress">.
</footnote>

<p><prgn>gpg</prgn> 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:

<example>
$ gpg --keyserver pgpkeys.mit.edu --recv-key 2D230C5F
gpg: requesting key 2D230C5F from hkp server pgpkeys.mit.edu
gpg: key 2D230C5F: public key "Debian Archive Automatic Signing Key (2006) &lt;ftpm
aster@debian.org&gt;" imported
gpg: Total number processed: 1
gpg:               imported: 1
</example>

<p>You can then export that key from your own keyring and feed it to <prgn>apt-key</prgn>:

<example>
$ gpg -a --export 2D230C5F | sudo apt-key add -
gpg: no ultimately trusted keys found
OK
</example>

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

<sect2 id="secure-apt-add-key">Safely adding a key

<p>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 <file>Release</file> file is valid, you can worry about
whether you've actually gotten the right key. Is the 
<url id="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).

<p>It's good to be paranoid in security, but verifying things from here is
harder. <prgn>gpg</prgn> 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
<footnote>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 <ref id="check-non-debian-releases">.
</footnote>.

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

<sect2>Verifying key integrity

<p>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 <url
id="http://debiansystem.info/readers/changes/547-ziyi-key-2006" name="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:

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

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

<example>
$ gpg --export -a 2D230C5F | sudo apt-key add -
Ok
</example>

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

<sect2>Debian archive key yearly rotation

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

<p>In January 2006, a new key for 2006 was made and the <file>Release</file> file began to
be signed by it, but to try to avoid breaking systems that had the old 2005
key, the <file>Release</file> 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.

<p>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 <file>Release</file> 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.

<!-- This is too vague to include here:

<p>Here is how things are expected to work in 2007:

<list>
<item>Early in January a new key for 2007 will be created. Perhaps with an
announcement and a well-defined chain of trust this time.

<item>The <file>Release</file> file will be signed by this key, while also being signed still by the 2006 key. apt and other tools will accept either signature.

<item>A new package, <package>debian-archive-keyring</package>, will have been
installed on everyone's system beforehand. It will be updated to include the
2007 key. When users upgrade to the new version, it will use <prgn>apt-key</prgn> to update
their keyring, removing the 2006 key and adding the 2007 key.

<item>The 2006 key expires on January 31st, 2007.  

</list>

<p>Still uncertain is what will happen to anyone who doesn't upgrade at all in
January, and how this upgrade will be handled for people running stable, once
secure apt is available there.

-->

<sect2>Known release checking problems

<p>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:

<example>
W: GPG error: http://archive.progeny.com sid Release: Unknown error executing gpg
</example>

<p>Although <prgn>apt-key</prgn> list will make the problem plain:

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

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

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

<sect2 id="manual-check-releases">Manual per distribution release check

<p>In case you want to add now the additional security checks and
don't want or cannot run the latest apt version<footnote>Either because
you are using the stable, <em>sarge</em>, 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.</footnote> 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.

<p>This sample code, renamed as <prgn>apt-check-sigs</prgn>, should be 
used in the following way:
<example>
# apt-get update
# apt-check-sigs
(...results...)
# apt-get dist-upgrade
</example>

<p>First you need to:

<list>

<item>get the keys the archive software uses to sign <file>Release</file> files,
<url id="http://ftp-master.debian.org/ziyi_key_2006.asc"> and add them
to <file>~/.gnupg/trustedkeys.gpg</file> (which is what
<prgn>gpgv</prgn> uses by default).
<example>
  gpg --no-default-keyring --keyring trustedkeys.gpg --import ziyi_key_2006.asc
</example>

<item>remove any <file>/etc/apt/sources.list</file> lines that don't
use the normal "dists" structure, or change the script so that it
works with them.

<item>be prepared to ignore the fact that Debian security updates don't
have signed <file>Release</file> files, and that <file>Sources</file> files don't have
appropriate checksums in the <file>Release</file> file (yet).

<item>be prepared to check that the appropriate sources are signed by
the appropriate keys.

</list>

<p>This is the example code for <prgn>apt-check-sigs</prgn>, the
latest version can be retrieved from <url
id="http://people.debian.org/~ajt/apt-check-sigs">.
This code is currently in beta, for more information read
<url id="http://lists.debian.org/debian-devel/2002/debian-devel-200207/msg00421.html">.

<example>
#!/bin/bash

# Copyright (c) 2001 Anthony Towns &lt;ajt@debian.org&gt;
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

rm -rf /tmp/apt-release-check
mkdir /tmp/apt-release-check || exit 1
cd /tmp/apt-release-check

>OK
>MISSING
>NOCHECK
>BAD

arch=`dpkg --print-installation-architecture`

am_root () {
        [ `id -u` -eq 0 ]
}

get_md5sumsize () {
        cat "$1" | awk '/^MD5Sum:/,/^SHA1:/' | 
          MYARG="$2" perl -ne '@f = split /\s+/; if ($f[3] eq $ENV{"MYARG"}) {
print "$f[1] $f[2]\n"; exit(0); }'
}

checkit () {
        local FILE="$1"
        local LOOKUP="$2"

        Y="`get_md5sumsize Release "$LOOKUP"`"
        Y="`echo "$Y" | sed 's/^ *//;s/  */ /g'`"

        if [ ! -e "/var/lib/apt/lists/$FILE" ]; then
                if [ "$Y" = "" ]; then
                        # No file, but not needed anyway
                        echo "OK"
                        return
                fi
                echo "$FILE" >>MISSING
                echo "MISSING $Y"
                return
        fi
        if [ "$Y" = "" ]; then
                echo "$FILE" >>NOCHECK
                echo "NOCHECK"
                return
        fi
        X="`md5sum < /var/lib/apt/lists/$FILE | cut -d\  -f1` `wc -c < /var/lib
/apt/lists/$FILE`"
        X="`echo "$X" | sed 's/^ *//;s/  */ /g'`"
        if [ "$X" != "$Y" ]; then
                echo "$FILE" >>BAD
                echo "BAD"
                return
        fi
        echo "$FILE" >>OK
        echo "OK"
}

echo
echo "Checking sources in /etc/apt/sources.list:"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
(echo "You should take care to ensure that the distributions you're downloading
"
echo "are the ones you think you are downloading, and that they are as up to"
echo "date as you would expect (testing and unstable should be no more than"
echo "two or three days out of date, stable-updates no more than a few weeks"
echo "or a month)."
) | fmt
echo

cat /etc/apt/sources.list | 
  sed 's/^ *//' | grep '^[^#]' |
  while read ty url dist comps; do
        if [ "${url%%:*}" = "http" -o "${url%%:*}" = "ftp" ]; then
                baseurl="${url#*://}"
        else
                continue
        fi

        echo "Source: ${ty} ${url} ${dist} ${comps}"

        rm -f Release Release.gpg
        lynx -reload -dump "${url}/dists/${dist}/Release" >/dev/null 2>&1
        wget -q -O Release "${url}/dists/${dist}/Release"

        if ! grep -q '^' Release; then
                echo "  * NO TOP-LEVEL Release FILE"
                >Release
        else
                origline=`sed -n 's/^Origin: *//p' Release | head -1`
                lablline=`sed -n 's/^Label: *//p' Release | head -1`
                suitline=`sed -n 's/^Suite: *//p' Release | head -1`
                codeline=`sed -n 's/^Codename: *//p' Release | head -1`
                dateline=`grep "^Date:" Release | head -1`
                dscrline=`grep "^Description:" Release | head -1`
                echo "  o Origin: $origline/$lablline"
                echo "  o Suite: $suitline/$codeline"
                echo "  o $dateline"
                echo "  o $dscrline"

                if [ "${dist%%/*}" != "$suitline" -a "${dist%%/*}" != "$codeline" ]; then
                        echo "  * WARNING: asked for $dist, got $suitline/$codeline"
                fi

                lynx -reload -dump "${url}/dists/${dist}/Release.gpg" >/dev/null 2>&1
                wget -q -O Release.gpg "${url}/dists/${dist}/Release.gpg"

                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
                        if [ "$gpgcode" = "GOODSIG" ]; then
                            if [ "$err" != "" ]; then
                                echo "  * Signed by ${err# } key: ${rest#* }"
                            else
                                echo "  o Signed by: ${rest#* }"
                                okay=1
                            fi
                            err=""
                        elif [ "$gpgcode" = "BADSIG" ]; then
                            echo "  * BAD SIGNATURE BY: ${rest#* }"
                            err=""
                        elif [ "$gpgcode" = "ERRSIG" ]; then
                            echo "  * COULDN'T CHECK SIGNATURE BY KEYID: ${rest %% *}"
                            err=""
                        elif [ "$gpgcode" = "SIGREVOKED" ]; then
                            err="$err REVOKED"
                        elif [ "$gpgcode" = "SIGEXPIRED" ]; then
                            err="$err EXPIRED"
                        fi
                    done
                    if [ "$okay" != 1 ]; then
                        echo "  * NO VALID SIGNATURE"
                        >Release
                    fi)
        fi
        okaycomps=""
        for comp in $comps; do
                if [ "$ty" = "deb" ]; then
                        X=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/binary-${arch}/Release" | sed 's,//*,_,g'`" "${comp}/binary-${arch}/Release")
                        Y=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/binary-${arch}/Packages" | sed 's,//*,_,g'`" "${comp}/binary-${arch}/Packages")
                        if [ "$X $Y" = "OK OK" ]; then
                                okaycomps="$okaycomps $comp"
                        else
                                echo "  * PROBLEMS WITH $comp ($X, $Y)"
                        fi
                elif [ "$ty" = "deb-src" ]; then
                        X=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/source/Release" | sed 's,//*,_,g'`" "${comp}/source/Release")
                        Y=$(checkit "`echo "${baseurl}/dists/${dist}/${comp}/source/Sources" | sed 's,//*,_,g'`" "${comp}/source/Sources")
                        if [ "$X $Y" = "OK OK" ]; then
                                okaycomps="$okaycomps $comp"
                        else
                                echo "  * PROBLEMS WITH component $comp ($X, $Y)"
                        fi
                fi
        done
        [ "$okaycomps" = "" ] || echo "  o Okay:$okaycomps"
        echo
  done

echo "Results"
echo "~~~~~~~"
echo

allokay=true

cd /tmp/apt-release-check
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

cd /tmp/apt-release-check
if grep -q ^ UNVALIDATED; then
    allokay=false
    (echo "The following files in /var/lib/apt/lists have not been validated."
    echo "This could turn out to be a harmless indication that this script"
    echo "is buggy or out of date, or it could let trojaned packages get onto"
    echo "your system."
    ) | fmt
    echo
    sed 's/^/    /' < UNVALIDATED
    echo
fi

if grep -q ^ BAD; then
    allokay=false
    (echo "The contents of the following files in /var/lib/apt/lists does not"
    echo "match what was expected. This may mean these sources are out of date,"
    echo "that the archive is having problems, or that someone is actively"
    echo "using your mirror to distribute trojans."
    if am_root; then 
        echo "The files have been renamed to have the extension .FAILED and"
        echo "will be ignored by apt."
        cat BAD | while read a; do
            mv /var/lib/apt/lists/$a /var/lib/apt/lists/${a}.FAILED
        done
    fi) | fmt
    echo
    sed 's/^/    /' < BAD
    echo
fi

if grep -q ^ MISSING; then
    allokay=false
    (echo "The following files from /var/lib/apt/lists were missing. This"
    echo "may cause you to miss out on updates to some vulnerable packages."
    ) | fmt
    echo
    sed 's/^/    /' < MISSING
    echo
fi

if grep -q ^ NOCHECK; then
    allokay=false
    (echo "The contents of the following files in /var/lib/apt/lists could not"
    echo "be validated due to the lack of a signed Release file, or the lack"
    echo "of an appropriate entry in a signed Release file. This probably"
    echo "means that the maintainers of these sources are slack, but may mean"
    echo "these sources are being actively used to distribute trojans."
    if am_root; then 
        echo "The files have been renamed to have the extension .FAILED and"
        echo "will be ignored by apt."
        cat NOCHECK | while read a; do
            mv /var/lib/apt/lists/$a /var/lib/apt/lists/${a}.FAILED
        done
    fi) | fmt
    echo
    sed 's/^/    /' < NOCHECK
    echo
fi

if $allokay; then
    echo 'Everything seems okay!'
    echo
fi

rm -rf /tmp/apt-release-check
</example>

<p>You might need to apply the following patch for <em>sid</em> since
<prgn>md5sum</prgn> adds an '-' after the sum when the input is stdin:

<example>
@@ -37,7 +37,7 @@
        local LOOKUP="$2"

        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 < /var/lib/apt/lists/$FILE` `wc -c < /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" >>BAD
                echo "BAD"
</example>

<sect1 id="check-non-debian-releases">Release check of non Debian sources

<P>Notice that, when using the latest apt version (with <em>secure apt</em>) 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 <file>Release</file> and <file>Release.gpg</file> files in
the non-Debian sources. The <file>Release</file> file can be generated with
<prgn>apt-ftparchive</prgn> (available in <package>apt-utils</package> 0.5.0 and later), 
the <file>Release.gpg</file> is just a detached signature. 
To generate both follow this simple procedure:

<example>
$ rm -f dists/unstable/Release
$ apt-ftparchive release dists/unstable > dists/unstable/Release
$ gpg --sign -ba -o dists/unstable/Release.gpg dists/unstable/Release
</example>

<sect1 id="check-pkg-sign">Alternative per-package signing scheme

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

<p>This package signing scheme can be implemented using
<package>debsig-verify</package> and <package>debsigs</package>.
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.

<p>Latest <prgn>dpkg</prgn> versions (since 1.9.21) incorporate a 
<url
id="http://lists.debian.org/debian-dpkg/2001/debian-dpkg-200103/msg00024.html"
name="patch"> that provides this functionality as soon as 
<package>debsig-verify</package> is installed.

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

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