summaryrefslogtreecommitdiff
path: root/src/share/ma/add_certifier
blob: bd41f23966e2c46958ed150e9cc4e3450b0d28a7 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere authentication add-certifier subcommand
  4. #
  5. # This function adds a certifier whose signatures will be used to
  6. # calculate validity of keys used to connect to user accounts on the
  7. # server. The specified certifier key is first retrieved from the Web
  8. # of Trust with the monkeysphere-user-controlled gpg_sphere keyring.
  9. # Once then new key is retrieved, it is imported into the core
  10. # keyring. The gpg_core then ltsigns the key with the desired trust
  11. # level, and then the key is exported back to the gpg_sphere keyring.
  12. # The gpg_sphere has ultimate owner trust of the core key, so the core
  13. # ltsigs on the new certifier key can then be used by gpg_sphere
  14. # calculate validity for keys inserted in the authorized_keys file.
  15. #
  16. # This is all to keep the monkeysphere user that connects to the
  17. # keyservers from accessing the core secret key.
  18. #
  19. # The monkeysphere scripts are written by:
  20. # Jameson Rollins <jrollins@finestructure.net>
  21. # Jamie McClelland <jm@mayfirst.org>
  22. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  23. #
  24. # They are Copyright 2008-2009, and are all released under the GPL,
  25. # version 3 or later.
  26. add_certifier() {
  27. local domain=
  28. local trust=full
  29. local depth=1
  30. local keyID
  31. local importinfo
  32. local fingerprint
  33. local ltsignCommand
  34. local trustval
  35. # get options
  36. while true ; do
  37. case "$1" in
  38. -n|--domain)
  39. domain="$2"
  40. shift 2
  41. ;;
  42. -t|--trust)
  43. trust="$2"
  44. shift 2
  45. ;;
  46. -d|--depth)
  47. depth="$2"
  48. shift 2
  49. ;;
  50. *)
  51. if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
  52. failure "Unknown option '$1'.
  53. Type '$PGRM help' for usage."
  54. fi
  55. break
  56. ;;
  57. esac
  58. done
  59. keyID="$1"
  60. if [ -z "$keyID" ] ; then
  61. failure "You must specify the key ID of a key to add, or specify a file to read the key from."
  62. fi
  63. if [ -f "$keyID" ] ; then
  64. log info "Reading key from file '$keyID':"
  65. fingerprints=$(su_monkeysphere_user \
  66. ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
  67. if [ $(printf "%s" "$fingerprints" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
  68. failure "There was not exactly one gpg key in the file."
  69. fi
  70. gpg_sphere "--import" < "$keyID" || failure "could not read key from '$keyID'"
  71. keyID="$fingerprints"
  72. else
  73. # get the key from the key server
  74. log debug "retrieving key from keyserver..."
  75. gpg_sphere "--keyserver $KEYSERVER --recv-key '0x${keyID}!'" || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
  76. fi
  77. export keyID
  78. # get the full fingerprint of new certifier key
  79. log debug "getting fingerprint of certifier key..."
  80. fingerprint=$(gpg_sphere "--list-key --with-colons --with-fingerprint 0x${keyID}!" \
  81. | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
  82. if [ -z "$fingerprint" ] ; then
  83. failure "Key '$keyID' not found."
  84. fi
  85. log info "key found:"
  86. gpg_sphere "--fingerprint 0x${fingerprint}!"
  87. if [ "$PROMPT" = "true" ] ; then
  88. echo "Are you sure you want to add the above key as a"
  89. read -p "certifier of users on this system? (Y/n) " OK; OK=${OK:-Y}
  90. if [ "${OK/y/Y}" != 'Y' ] ; then
  91. failure "Identity certifier not added."
  92. fi
  93. else
  94. log debug "adding key without prompting."
  95. fi
  96. # export the key to the core keyring so that the core can sign the
  97. # new certifier key
  98. log debug "exporting retrieved certifier key to core keyring..."
  99. gpg_sphere "--export 0x${fingerprint}!" | gpg_core --import
  100. case "$trust" in
  101. 'marginal')
  102. trustval=1
  103. ;;
  104. 'full')
  105. trustval=2
  106. ;;
  107. *)
  108. failure "Trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)."
  109. ;;
  110. esac
  111. # edit-key script to ltsign key
  112. # NOTE: *all* user IDs will be ltsigned
  113. ltsignCommand=$(cat <<EOF
  114. ltsign
  115. y
  116. $trustval
  117. $depth
  118. $domain
  119. y
  120. save
  121. EOF
  122. )
  123. # core ltsigns the newly imported certifier key
  124. log debug "executing core ltsign script..."
  125. if echo "$ltsignCommand" | \
  126. gpg_core --command-fd 0 --edit-key "0x${fingerprint}!" ; then
  127. # transfer the new sigs back to the sphere keyring
  128. gpg_core_sphere_sig_transfer
  129. # update the sphere trustdb
  130. log debug "updating sphere trustdb..."
  131. gpg_sphere "--check-trustdb" 2>&1 | log debug
  132. log info "Identity certifier added."
  133. else
  134. failure "Problem adding identify certifier."
  135. fi
  136. }