dropbear: Activate PIE by default
[oweals/openwrt.git] / package / network / services / dropbear / Makefile
1 #
2 # Copyright (C) 2006-2016 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:=2019.78
12 PKG_RELEASE:=2
13
14 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
15 PKG_SOURCE_URL:= \
16         http://matt.ucc.asn.au/dropbear/releases/ \
17         https://dropbear.nl/mirror/releases/
18 PKG_HASH:=525965971272270995364a0eb01f35180d793182e63dd0b0c3eb0292291644a4
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_USE_MIPS16:=0
27 PKG_FIXUP:=autoreconf
28
29 PKG_CONFIG_DEPENDS:= \
30         CONFIG_TARGET_INIT_PATH CONFIG_DROPBEAR_ECC CONFIG_DROPBEAR_ECC_FULL \
31         CONFIG_DROPBEAR_CURVE25519 CONFIG_DROPBEAR_ZLIB \
32         CONFIG_DROPBEAR_UTMP CONFIG_DROPBEAR_PUTUTLINE \
33         CONFIG_DROPBEAR_DBCLIENT
34
35 include $(INCLUDE_DIR)/package.mk
36
37 ifneq ($(DUMP),1)
38   STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell echo $(CONFIG_TARGET_INIT_PATH) | mkhash md5)
39 endif
40
41 define Package/dropbear/Default
42   URL:=http://matt.ucc.asn.au/dropbear/
43 endef
44
45 define Package/dropbear/config
46         source "$(SOURCE)/Config.in"
47 endef
48
49 define Package/dropbear
50   $(call Package/dropbear/Default)
51   SECTION:=net
52   CATEGORY:=Base system
53   TITLE:=Small SSH2 client/server
54   DEPENDS:= +DROPBEAR_ZLIB:zlib
55   ALTERNATIVES:=\
56           100:/usr/bin/ssh:/usr/sbin/dropbear \
57           100:/usr/bin/scp:/usr/sbin/dropbear \
58
59 endef
60
61 define Package/dropbear/description
62  A small SSH2 server/client designed for small memory environments.
63 endef
64
65 define Package/dropbear/conffiles
66 $(if $(CONFIG_DROPBEAR_ECC),/etc/dropbear/dropbear_ecdsa_host_key)
67 /etc/dropbear/dropbear_rsa_host_key
68 /etc/config/dropbear
69 endef
70
71 define Package/dropbearconvert
72   $(call Package/dropbear/Default)
73   SECTION:=utils
74   CATEGORY:=Utilities
75   TITLE:=Utility for converting SSH keys
76   DEPENDS:= +DROPBEAR_ZLIB:zlib
77 endef
78
79 CONFIGURE_ARGS += \
80         --disable-pam \
81         --enable-openpty \
82         --enable-syslog \
83         --disable-lastlog \
84         --disable-utmpx \
85         $(if $(CONFIG_DROPBEAR_UTMP),,--disable-utmp) \
86         --disable-wtmp \
87         --disable-wtmpx \
88         --disable-loginfunc \
89         $(if $(CONFIG_DROPBEAR_PUTUTLINE),,--disable-pututline) \
90         --disable-pututxline \
91         $(if $(CONFIG_DROPBEAR_ZLIB),,--disable-zlib) \
92         --enable-bundled-libtom
93
94 TARGET_CFLAGS += -DARGTYPE=3 -ffunction-sections -fdata-sections -flto
95 TARGET_LDFLAGS += -Wl,--gc-sections -flto=jobserver
96
97 define Build/Configure
98         : > $(PKG_BUILD_DIR)/localoptions.h
99
100         $(Build/Configure/Default)
101
102         echo '#define DEFAULT_PATH "$(TARGET_INIT_PATH)"' >> \
103                 $(PKG_BUILD_DIR)/localoptions.h
104
105         echo '#define DROPBEAR_CURVE25519 $(if $(CONFIG_DROPBEAR_CURVE25519),1,0)' >> \
106                 $(PKG_BUILD_DIR)/localoptions.h
107
108         for OPTION in DROPBEAR_ECDSA DROPBEAR_ECDH; do \
109                 echo "#define $$$$OPTION $(if $(CONFIG_DROPBEAR_ECC),1,0)" >> \
110                         $(PKG_BUILD_DIR)/localoptions.h; \
111         done
112
113         # remove protocol idented software version number
114         $(ESED) 's,^(#define LOCAL_IDENT) .*$$$$,\1 "SSH-2.0-dropbear",g' \
115                 $(PKG_BUILD_DIR)/sysoptions.h
116
117         # disable legacy/unsafe methods and unused functionality
118         for OPTION in INETD_MODE DROPBEAR_CLI_NETCAT \
119         DROPBEAR_3DES DROPBEAR_DSS DROPBEAR_ENABLE_CBC_MODE \
120         DROPBEAR_SHA1_96_HMAC DROPBEAR_USE_PASSWORD_ENV; do \
121                 echo "#define $$$$OPTION 0" >> \
122                         $(PKG_BUILD_DIR)/localoptions.h; \
123         done
124
125         # enable nistp384 and nistp521 only if full ECC support was requested
126         for OPTION in DROPBEAR_ECC_384 DROPBEAR_ECC_521; do \
127                 $(ESED) 's,^(#define '$$$$OPTION') .*$$$$,\1 $(if $(CONFIG_DROPBEAR_ECC_FULL),1,0),g' \
128                 $(PKG_BUILD_DIR)/sysoptions.h; \
129         done
130
131         # Enforce rebuild of svr-chansession.c
132         rm -f $(PKG_BUILD_DIR)/svr-chansession.o
133
134         # Rebuild them on config change
135         +$(MAKE) -C $(PKG_BUILD_DIR)/libtomcrypt clean
136         +$(MAKE) -C $(PKG_BUILD_DIR)/libtommath clean
137 endef
138
139 define Build/Compile
140         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
141                 $(TARGET_CONFIGURE_OPTS) \
142                 PROGRAMS="dropbear $(if $(CONFIG_DROPBEAR_DBCLIENT),dbclient,) dropbearkey scp" \
143                 MULTI=1 SCPPROGRESS=1
144         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
145                 $(TARGET_CONFIGURE_OPTS) \
146                 PROGRAMS="dropbearconvert"
147 endef
148
149 define Package/dropbear/install
150         $(INSTALL_DIR) $(1)/usr/sbin
151         $(INSTALL_BIN) $(PKG_BUILD_DIR)/dropbearmulti $(1)/usr/sbin/dropbear
152         $(INSTALL_DIR) $(1)/usr/bin
153         $(if $(CONFIG_DROPBEAR_DBCLIENT),$(LN) ../sbin/dropbear $(1)/usr/bin/dbclient,)
154         $(LN) ../sbin/dropbear $(1)/usr/bin/dropbearkey
155         $(INSTALL_DIR) $(1)/etc/config
156         $(INSTALL_CONF) ./files/dropbear.config $(1)/etc/config/dropbear
157         $(INSTALL_DIR) $(1)/etc/init.d
158         $(INSTALL_BIN) ./files/dropbear.init $(1)/etc/init.d/dropbear
159         $(INSTALL_DIR) $(1)/usr/lib/opkg/info
160         $(INSTALL_DIR) $(1)/etc/dropbear
161         $(if $(CONFIG_DROPBEAR_ECC),touch $(1)/etc/dropbear/dropbear_ecdsa_host_key)
162         touch $(1)/etc/dropbear/dropbear_rsa_host_key
163 endef
164
165 define Package/dropbearconvert/install
166         $(INSTALL_DIR) $(1)/usr/bin
167         $(INSTALL_BIN) $(PKG_BUILD_DIR)/dropbearconvert $(1)/usr/bin/dropbearconvert
168 endef
169
170 $(eval $(call BuildPackage,dropbear))
171 $(eval $(call BuildPackage,dropbearconvert))