Guest User

Untitled

a guest
Aug 23rd, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | Software | 0 0
  1. # Install a static ssh host key, for use in development
  2. IMAGE_FEATURES[validitems] += "dev-ssh-hostkey"
  3. ROOTFS_POSTPROCESS_COMMAND += "${@feature_enabled('debug-tweaks dev-ssh-hostkey', 'dev_ssh_hostkey; ', d)}"
  4. DEVELOPER_SSH_HOSTKEY ?= "${OE_USER_DIR}/ssh-keys/developer_host_rsa"
  5. DEVELOPER_SSH_HOSTKEY_CREATE ?= "1"
  6. dev_ssh_hostkey() {
  7. local key_src="${DEVELOPER_SSH_HOSTKEY}"
  8. [ "$key_src" ] || {
  9. bbnote "DEVELOPER_SSH_HOSTKEY not set; set to a filename "\
  10. "to have it installed as the SSH host key"
  11. return 0
  12. }
  13. [ -d "${sshconfdir}" ] || {
  14. bbnote "SSH does not seem to be installed in the image, will "\
  15. "not install host key"
  16. return 0
  17. }
  18.  
  19. dev_ssh_verify_hostkey "$key_src" || {
  20. bbwarn "Developer SSH hostkey '$key_src' does not exist; ignoring"
  21. return 0
  22. }
  23.  
  24. bbnote "Installing '$key_src' as the SSH host key for the image (debug-tweaks)"
  25. install -m 0600 "$key_src" "${sshconfdir}/ssh_host_rsa_key"
  26. install -m 0644 "$key_src.pub" "${sshconfdir}/ssh_host_rsa_key.pub"
  27. }
  28.  
  29. # dev_ssh_verify_hostkey returns success if the ssh key, given as parameter,
  30. # exists. If the key does not exist, the function will generate it unless
  31. # requested not to by setting DEVELOPER_SSH_HOSTKEY_CREATE to anything
  32. # other than Y, y, 1 or yes.
  33. dev_ssh_verify_hostkey() {
  34. [ ! -e "$1" ] || return 0
  35.  
  36. case "${DEVELOPER_SSH_HOSTKEY_CREATE}" in
  37. [Yy1]|yes) ;;
  38. *) return 1 ;;
  39. esac
  40.  
  41. # If the specified directory doesn't exist, create it first
  42. [ -d "${1%/*}" ] || mkdir -p "${1%/*}"
  43.  
  44. ssh-keygen -t rsa -N '' -b 2048 \
  45. -C "developer hostkey for $LOGNAME" \
  46. -f "$1" ||
  47. bbwarn "ssh-keygen failed to generate a developer hostkey"
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment