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