test-apt-key-net-update 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. # mock
  8. requires_root() {
  9. return 0
  10. }
  11. # extract net_update() and import it
  12. func=$( sed -n -e '/^add_keys_with_verify_against_master_keyring/,/^}/p' ${BUILDDIRECTORY}/apt-key )
  13. eval "$func"
  14. mkdir -p ./etc/apt
  15. TRUSTEDFILE=./etc/apt/trusted.gpg
  16. mkdir -p ./var/lib/apt/keyrings
  17. TMP_KEYRING=./var/lib/apt/keyrings/maybe-import-keyring.gpg
  18. GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring"
  19. GPG="$GPG_CMD --keyring $TRUSTEDFILE"
  20. MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg
  21. # COPYIED from apt-key.in --------------
  22. # gpg needs a trustdb to function, but it can't be invalid (not even empty)
  23. # so we create a temporary directory to store our fresh readable trustdb in
  24. TRUSTDBDIR="$(mktemp -d)"
  25. CURRENTTRAP="${CURRENTTRAP} rm -rf '${TRUSTDBDIR}';"
  26. trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  27. chmod 700 "$TRUSTDBDIR"
  28. # We also don't use a secret keyring, of course, but gpg panics and
  29. # implodes if there isn't one available - and writeable for imports
  30. SECRETKEYRING="${TRUSTDBDIR}/secring.gpg"
  31. touch $SECRETKEYRING
  32. GPG_CMD="$GPG_CMD --secret-keyring $SECRETKEYRING"
  33. GPG_CMD="$GPG_CMD --trustdb-name ${TRUSTDBDIR}/trustdb.gpg"
  34. #----------------------------------------- END COPY
  35. msgtest "add_keys_with_verify_against_master_keyring"
  36. if [ ! -e $MASTER_KEYRING ]; then
  37. echo -n "No $MASTER_KEYRING found"
  38. msgskip
  39. exit 0
  40. fi
  41. # test bad keyring and ensure its not added (LP: #857472)
  42. ADD_KEYRING=./keys/exploid-keyring-with-dupe-keys.pub
  43. if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
  44. msgfail
  45. else
  46. msgpass
  47. fi
  48. # ensure the keyring is still empty
  49. gpg_out=$($GPG --list-keys)
  50. msgtest "Test if keyring is empty"
  51. if [ -n "" ]; then
  52. msgfail
  53. else
  54. msgpass
  55. fi
  56. # test another possible attack vector using subkeys (LP: #1013128)
  57. msgtest "add_keys_with_verify_against_master_keyring with subkey attack"
  58. ADD_KEYRING=./keys/exploid-keyring-with-dupe-subkeys.pub
  59. if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
  60. msgfail
  61. else
  62. msgpass
  63. fi
  64. # ensure the keyring is still empty
  65. gpg_out=$($GPG --list-keys)
  66. msgtest "Test if keyring is empty"
  67. if [ -n "" ]; then
  68. msgfail
  69. else
  70. msgpass
  71. fi
  72. # test good keyring and ensure we get no errors
  73. ADD_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg
  74. if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
  75. msgpass
  76. else
  77. msgfail
  78. fi
  79. testequal './etc/apt/trusted.gpg
  80. ---------------------
  81. pub 1024D/437D05B5 2004-09-12
  82. uid Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
  83. sub 2048g/79164387 2004-09-12
  84. pub 1024D/FBB75451 2004-12-30
  85. uid Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
  86. pub 4096R/C0B21F32 2012-05-11
  87. uid Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>
  88. pub 4096R/EFE21092 2012-05-11
  89. uid Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>
  90. ' $GPG --list-keys