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