Makefile 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #
  2. # Copyright (C) 2006-2020 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. PKG_NAME:=dropbear
  9. PKG_VERSION:=2024.86
  10. PKG_RELEASE:=1
  11. PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
  12. PKG_SOURCE_URL:= \
  13. https://matt.ucc.asn.au/dropbear/releases/ \
  14. https://dropbear.nl/mirror/releases/
  15. PKG_HASH:=e78936dffc395f2e0db099321d6be659190966b99712b55c530dd0a1822e0a5e
  16. PKG_LICENSE:=MIT
  17. PKG_LICENSE_FILES:=LICENSE libtomcrypt/LICENSE libtommath/LICENSE
  18. PKG_CPE_ID:=cpe:/a:dropbear_ssh_project:dropbear_ssh
  19. PKG_BUILD_PARALLEL:=1
  20. PKG_ASLR_PIE_REGULAR:=1
  21. PKG_BUILD_FLAGS:=no-mips16 gc-sections lto
  22. PKG_FIXUP:=autoreconf
  23. PKG_FLAGS:=nonshared
  24. PKG_CONFIG_DEPENDS:= \
  25. CONFIG_TARGET_INIT_PATH CONFIG_DROPBEAR_ECC CONFIG_DROPBEAR_ECC_FULL \
  26. CONFIG_DROPBEAR_CURVE25519 CONFIG_DROPBEAR_ZLIB \
  27. CONFIG_DROPBEAR_ED25519 CONFIG_DROPBEAR_CHACHA20POLY1305 \
  28. CONFIG_DROPBEAR_U2F CONFIG_DROPBEAR_ECDSA_SK CONFIG_DROPBEAR_ED25519_SK \
  29. CONFIG_DROPBEAR_UTMP CONFIG_DROPBEAR_PUTUTLINE \
  30. CONFIG_DROPBEAR_DBCLIENT CONFIG_DROPBEAR_SCP CONFIG_DROPBEAR_ASKPASS \
  31. CONFIG_DROPBEAR_DBCLIENT_AGENTFORWARD CONFIG_DROPBEAR_AGENTFORWARD \
  32. CONFIG_DROPBEAR_MODERN_ONLY
  33. include $(INCLUDE_DIR)/package.mk
  34. ifneq ($(DUMP),1)
  35. STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell echo $(CONFIG_TARGET_INIT_PATH) | $(MKHASH) md5)
  36. endif
  37. define Package/dropbear/Default
  38. URL:=https://matt.ucc.asn.au/dropbear/
  39. endef
  40. define Package/dropbear/config
  41. source "$(SOURCE)/Config.in"
  42. endef
  43. define Package/dropbear
  44. $(call Package/dropbear/Default)
  45. SECTION:=net
  46. CATEGORY:=Base system
  47. TITLE:=Small SSH2 client/server
  48. DEPENDS:= +DROPBEAR_ZLIB:zlib
  49. ALTERNATIVES:=100:/usr/bin/ssh-keygen:/usr/sbin/dropbear
  50. $(if $(CONFIG_DROPBEAR_SCP),ALTERNATIVES+= \
  51. 100:/usr/bin/scp:/usr/sbin/dropbear,)
  52. $(if $(CONFIG_DROPBEAR_DBCLIENT),ALTERNATIVES+= \
  53. 100:/usr/bin/ssh:/usr/sbin/dropbear,)
  54. endef
  55. define Package/dropbear/description
  56. A small SSH2 server/client designed for small memory environments.
  57. endef
  58. define Package/dropbear/conffiles
  59. /etc/config/dropbear
  60. /etc/dropbear/authorized_keys
  61. /etc/dropbear/dropbear_ecdsa_host_key
  62. /etc/dropbear/dropbear_ed25519_host_key
  63. /etc/dropbear/dropbear_rsa_host_key
  64. endef
  65. define Package/dropbearconvert
  66. $(call Package/dropbear/Default)
  67. SECTION:=utils
  68. CATEGORY:=Utilities
  69. TITLE:=Utility for converting SSH keys
  70. DEPENDS:= +DROPBEAR_ZLIB:zlib
  71. endef
  72. CONFIGURE_ARGS += \
  73. --disable-pam \
  74. --enable-openpty \
  75. --enable-syslog \
  76. --disable-lastlog \
  77. --disable-utmpx \
  78. $(if $(CONFIG_DROPBEAR_UTMP),,--disable-utmp) \
  79. --disable-wtmp \
  80. --disable-wtmpx \
  81. --disable-loginfunc \
  82. $(if $(CONFIG_DROPBEAR_PUTUTLINE),,--disable-pututline) \
  83. --disable-pututxline \
  84. $(if $(CONFIG_DROPBEAR_ZLIB),,--disable-zlib) \
  85. --enable-bundled-libtom
  86. ##############################################################################
  87. #
  88. # option,value - add option to localoptions.h
  89. # !!option,value - replace option in src/sysoptions.h
  90. #
  91. ##############################################################################
  92. # adjust allowed shell list (if getusershell(3) is missing):
  93. # - COMPAT_USER_SHELLS
  94. # remove protocol idented software version number:
  95. # - LOCAL_IDENT
  96. # disable legacy/unsafe methods and unused functionality:
  97. # - DROPBEAR_CLI_NETCAT
  98. # - DROPBEAR_DSS
  99. # - DO_MOTD
  100. # - DROPBEAR_DH_GROUP14_SHA1
  101. # - DROPBEAR_SHA1_HMAC
  102. DB_OPT_COMMON = \
  103. !!LOCAL_IDENT,"SSH-2.0-dropbear" \
  104. COMPAT_USER_SHELLS,"/bin/ash","/bin/sh" \
  105. DEFAULT_PATH,"$(TARGET_INIT_PATH)" \
  106. DEFAULT_ROOT_PATH,"$(TARGET_INIT_PATH)" \
  107. DROPBEAR_DSS,0 \
  108. DROPBEAR_CLI_NETCAT,0 \
  109. DO_MOTD,0 \
  110. DROPBEAR_DH_GROUP14_SHA1,0 \
  111. DROPBEAR_SHA1_HMAC,0 \
  112. ##############################################################################
  113. #
  114. # option,config,enabled,disabled = add option to localoptions.h
  115. # !!option,config,enabled,disabled = replace option in src/sysoptions.h
  116. #
  117. # option := (config) ? enabled : disabled
  118. #
  119. ##############################################################################
  120. DB_OPT_CONFIG = \
  121. !!DROPBEAR_ECC_384,CONFIG_DROPBEAR_ECC_FULL,1,0 \
  122. !!DROPBEAR_ECC_521,CONFIG_DROPBEAR_ECC_FULL,1,0 \
  123. DROPBEAR_CURVE25519,CONFIG_DROPBEAR_CURVE25519,1,0 \
  124. DROPBEAR_CHACHA20POLY1305,CONFIG_DROPBEAR_CHACHA20POLY1305,1,0 \
  125. DROPBEAR_ED25519,CONFIG_DROPBEAR_ED25519,1,0 \
  126. DROPBEAR_ECDSA,CONFIG_DROPBEAR_ECC,1,0 \
  127. DROPBEAR_ECDH,CONFIG_DROPBEAR_ECC,1,0 \
  128. DROPBEAR_SK_KEYS,CONFIG_DROPBEAR_U2F,1,0 \
  129. DROPBEAR_SK_ECDSA,CONFIG_DROPBEAR_ECDSA_SK,1,0 \
  130. DROPBEAR_SK_ED25519,CONFIG_DROPBEAR_ED25519_SK,1,0 \
  131. DROPBEAR_CLI_ASKPASS_HELPER,CONFIG_DROPBEAR_ASKPASS,1,0 \
  132. DROPBEAR_CLI_AGENTFWD,CONFIG_DROPBEAR_DBCLIENT_AGENTFORWARD,1,0 \
  133. DROPBEAR_SVR_AGENTFWD,CONFIG_DROPBEAR_AGENTFORWARD,1,0 \
  134. DROPBEAR_AES128,CONFIG_DROPBEAR_MODERN_ONLY,0,1 \
  135. DROPBEAR_AES256,CONFIG_DROPBEAR_MODERN_ONLY,0,1 \
  136. DROPBEAR_ENABLE_CTR_MODE,CONFIG_DROPBEAR_MODERN_ONLY,0,1 \
  137. DROPBEAR_RSA,CONFIG_DROPBEAR_MODERN_ONLY,0,1 \
  138. DROPBEAR_RSA_SHA1,CONFIG_DROPBEAR_MODERN_ONLY,0,1 \
  139. TARGET_CFLAGS += -DARGTYPE=3
  140. xsedx:=$(shell printf '\027')
  141. db_opt_add =echo '\#define $(1) $(2)' >> $(PKG_BUILD_DIR)/localoptions.h
  142. db_opt_replace =$(ESED) '/^\#define $(1) .*$$$$/{h;:a;$$$$!n;/^\#.+$$$$/bb;/^$$$$/bb;H;ba;:b;x;s$(xsedx)^.+$$$$$(xsedx)\#define $(1) $(2)$(xsedx)p;x};p' -n $(PKG_BUILD_DIR)/src/sysoptions.h
  143. define Build/Configure/dropbear_headers
  144. $(strip $(foreach s,$(DB_OPT_COMMON), \
  145. $(if $(filter !!%,$(word 1,$(subst $(comma),$(space),$(s)))), \
  146. $(call db_opt_replace,$(patsubst !!%,%,$(word 1,$(subst $(comma),$(space),$(s)))),$(subst $(space),$(comma),$(wordlist 2,$(words $(subst $(comma),$(space),$(s))),$(subst $(comma),$(space),$(s))))), \
  147. $(call db_opt_add,$(word 1,$(subst $(comma),$(space),$(s))),$(subst $(space),$(comma),$(wordlist 2,$(words $(subst $(comma),$(space),$(s))),$(subst $(comma),$(space),$(s))))) \
  148. ) ; \
  149. ))
  150. $(strip $(foreach s,$(DB_OPT_CONFIG), \
  151. $(if $(filter !!%,$(word 1,$(subst $(comma),$(space),$(s)))), \
  152. $(call db_opt_replace,$(patsubst !!%,%,$(word 1,$(subst $(comma),$(space),$(s)))),$(if $($(word 2,$(subst $(comma),$(space),$(s)))),$(word 3,$(subst $(comma),$(space),$(s))),$(word 4,$(subst $(comma),$(space),$(s))))), \
  153. $(call db_opt_add,$(word 1,$(subst $(comma),$(space),$(s))),$(if $($(word 2,$(subst $(comma),$(space),$(s)))),$(word 3,$(subst $(comma),$(space),$(s))),$(word 4,$(subst $(comma),$(space),$(s))))) \
  154. ) ; \
  155. ))
  156. endef
  157. define Build/Configure/dropbear_objects
  158. grep -ERZl -e '($(subst $(space),|,$(strip $(sort $(patsubst !!%,%,$(foreach s,$(DB_OPT_COMMON) $(DB_OPT_CONFIG),$(word 1,$(subst $(comma),$(space),$(s)))))))))' \
  159. $(PKG_BUILD_DIR)/ | sed -zE 's/^(.+)\.[^.]+$$$$/\1.o/' | sort -uV | xargs -0 -r rm -fv || :
  160. endef
  161. define Build/Configure
  162. rm -f $(PKG_BUILD_DIR)/localoptions.h
  163. $(Build/Configure/Default)
  164. : > $(PKG_BUILD_DIR)/localoptions.h
  165. $(Build/Configure/dropbear_headers)
  166. # Enforce rebuild of files depending on configured options
  167. $(Build/Configure/dropbear_objects)
  168. # Rebuild them on config change
  169. +$(MAKE) -C $(PKG_BUILD_DIR)/libtomcrypt clean
  170. +$(MAKE) -C $(PKG_BUILD_DIR)/libtommath clean
  171. endef
  172. define Build/Compile
  173. +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
  174. $(TARGET_CONFIGURE_OPTS) \
  175. IGNORE_SPEED=1 \
  176. PROGRAMS="dropbear $(if $(CONFIG_DROPBEAR_DBCLIENT),dbclient,) dropbearkey $(if $(CONFIG_DROPBEAR_SCP),scp,)" \
  177. MULTI=1 SCPPROGRESS=1
  178. +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
  179. $(TARGET_CONFIGURE_OPTS) \
  180. IGNORE_SPEED=1 \
  181. PROGRAMS="dropbearconvert"
  182. endef
  183. define Package/dropbear/install
  184. $(INSTALL_DIR) $(1)/usr/sbin
  185. $(INSTALL_BIN) $(PKG_BUILD_DIR)/dropbearmulti $(1)/usr/sbin/dropbear
  186. $(INSTALL_DIR) $(1)/usr/bin
  187. $(if $(CONFIG_DROPBEAR_DBCLIENT),$(LN) ../sbin/dropbear $(1)/usr/bin/dbclient,)
  188. $(LN) ../sbin/dropbear $(1)/usr/bin/dropbearkey
  189. $(INSTALL_DIR) $(1)/etc/config
  190. $(INSTALL_CONF) ./files/dropbear.config $(1)/etc/config/dropbear
  191. $(INSTALL_DIR) $(1)/etc/init.d
  192. $(INSTALL_BIN) ./files/dropbear.init $(1)/etc/init.d/dropbear
  193. $(INSTALL_DIR) $(1)/etc/dropbear
  194. $(INSTALL_DIR) $(1)/lib/preinit
  195. $(INSTALL_DATA) ./files/dropbear.failsafe $(1)/lib/preinit/99_10_failsafe_dropbear
  196. $(INSTALL_DIR) $(1)/etc/uci-defaults
  197. $(INSTALL_DATA) ./files/dropbear.defaults $(1)/etc/uci-defaults/50-dropbear
  198. $(foreach f,$(filter /etc/dropbear/%,$(Package/dropbear/conffiles)),$(if $(wildcard $(TOPDIR)/files/$(f)),chmod 0600 $(TOPDIR)/files/$(f) || :; ))
  199. endef
  200. define Package/dropbearconvert/install
  201. $(INSTALL_DIR) $(1)/usr/bin
  202. $(INSTALL_BIN) $(PKG_BUILD_DIR)/dropbearconvert $(1)/usr/bin/dropbearconvert
  203. endef
  204. $(eval $(call BuildPackage,dropbear))
  205. $(eval $(call BuildPackage,dropbearconvert))