Makefile.in 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. # This Makefile is for Dropbear SSH Server and Client
  2. # @configure_input@
  3. # invocation:
  4. # make PROGRAMS="dropbear dbclient scp" MULTI=1 SCPPROGRESS=1
  5. #
  6. # to make a multiple-program binary "dropbearmulti".
  7. # This example will include dropbear, scp, dropbearkey, dropbearconvert, and
  8. # dbclient functionality, and includes the progress-bar functionality in scp.
  9. ifndef PROGRAMS
  10. PROGRAMS=dropbear dbclient dropbearkey dropbearconvert
  11. endif
  12. STATIC_LTC=libtomcrypt/libtomcrypt.a
  13. STATIC_LTM=libtommath/libtommath.a
  14. LIBTOM_LIBS=@LIBTOM_LIBS@
  15. ifeq (@BUNDLED_LIBTOM@, 1)
  16. LIBTOM_DEPS=$(STATIC_LTC) $(STATIC_LTM)
  17. LIBTOM_CLEAN=ltc-clean ltm-clean
  18. CPPFLAGS+=-I$(srcdir)/libtomcrypt/src/headers/
  19. LIBTOM_LIBS=$(STATIC_LTC) $(STATIC_LTM)
  20. endif
  21. OPTION_HEADERS = default_options_guard.h sysoptions.h
  22. ifneq ($(wildcard localoptions.h),)
  23. CPPFLAGS+=-DLOCALOPTIONS_H_EXISTS
  24. OPTION_HEADERS += localoptions.h
  25. endif
  26. COMMONOBJS=dbutil.o buffer.o dbhelpers.o \
  27. dss.o bignum.o \
  28. signkey.o rsa.o dbrandom.o \
  29. queue.o \
  30. atomicio.o compat.o fake-rfc2553.o \
  31. ltc_prng.o ecc.o ecdsa.o sk-ecdsa.o crypto_desc.o \
  32. curve25519.o ed25519.o sk-ed25519.o \
  33. dbmalloc.o \
  34. gensignkey.o gendss.o genrsa.o gened25519.o
  35. SVROBJS=svr-kex.o svr-auth.o sshpty.o \
  36. svr-authpasswd.o svr-authpubkey.o svr-authpubkeyoptions.o svr-session.o svr-service.o \
  37. svr-chansession.o svr-runopts.o svr-agentfwd.o svr-main.o svr-x11fwd.o\
  38. svr-tcpfwd.o svr-authpam.o
  39. CLIOBJS=cli-main.o cli-auth.o cli-authpasswd.o cli-kex.o \
  40. cli-session.o cli-runopts.o cli-chansession.o \
  41. cli-authpubkey.o cli-tcpfwd.o cli-channel.o cli-authinteract.o \
  42. cli-agentfwd.o
  43. CLISVROBJS=common-session.o packet.o common-algo.o common-kex.o \
  44. common-channel.o common-chansession.o termcodes.o loginrec.o \
  45. tcp-accept.o listener.o process-packet.o dh_groups.o \
  46. common-runopts.o circbuffer.o list.o netio.o chachapoly.o gcm.o
  47. KEYOBJS=dropbearkey.o
  48. CONVERTOBJS=dropbearconvert.o keyimport.o signkey_ossh.o
  49. SCPOBJS=scp.o progressmeter.o atomicio.o scpmisc.o compat.o
  50. ifeq (@DROPBEAR_FUZZ@, 1)
  51. allobjs = $(COMMONOBJS) fuzz/fuzz-common.o fuzz/fuzz-wrapfd.o $(CLISVROBJS) $(CLIOBJS) $(SVROBJS) @CRYPTLIB@
  52. allobjs:=$(subst svr-main.o, ,$(allobjs))
  53. allobjs:=$(subst cli-main.o, ,$(allobjs))
  54. dropbearobjs=$(allobjs) svr-main.o
  55. dbclientobjs=$(allobjs) cli-main.o
  56. dropbearkeyobjs=$(allobjs) $(KEYOBJS)
  57. dropbearconvertobjs=$(allobjs) $(CONVERTOBJS)
  58. # CXX only set when fuzzing
  59. CXX=@CXX@
  60. FUZZ_CLEAN=fuzz-clean
  61. else
  62. dropbearobjs=$(COMMONOBJS) $(CLISVROBJS) $(SVROBJS)
  63. dbclientobjs=$(COMMONOBJS) $(CLISVROBJS) $(CLIOBJS)
  64. dropbearkeyobjs=$(COMMONOBJS) $(KEYOBJS)
  65. dropbearconvertobjs=$(COMMONOBJS) $(CONVERTOBJS)
  66. scpobjs=$(SCPOBJS)
  67. endif
  68. ifeq (@DROPBEAR_PLUGIN@, 1)
  69. # rdynamic makes all the global symbols of dropbear available to all the loaded shared libraries
  70. # this allow a plugin to reuse existing crypto/utilities like base64_decode/base64_encode without
  71. # the need to rewrite them.
  72. PLUGIN_LIBS=-ldl -rdynamic
  73. else
  74. PLUGIN_LIBS=
  75. endif
  76. VPATH=@srcdir@
  77. srcdir=@srcdir@
  78. prefix=@prefix@
  79. exec_prefix=@exec_prefix@
  80. datarootdir = @datarootdir@
  81. bindir=@bindir@
  82. sbindir=@sbindir@
  83. mandir=@mandir@
  84. .DELETE_ON_ERROR:
  85. CC=@CC@
  86. AR=@AR@
  87. RANLIB=@RANLIB@
  88. STRIP=@STRIP@
  89. INSTALL=@INSTALL@
  90. CPPFLAGS+=@CPPFLAGS@ -I. -I$(srcdir)
  91. CFLAGS+=@CFLAGS@
  92. LIBS+=@LIBS@
  93. LDFLAGS=@LDFLAGS@
  94. EXEEXT=@EXEEXT@
  95. STATIC=@STATIC@
  96. # whether we're building client, server, or both for the common objects.
  97. # evilness so we detect 'dropbear' by itself as a word
  98. ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdropbearZ, Z$(prog)Z))))
  99. CPPFLAGS+= -DDROPBEAR_SERVER
  100. endif
  101. ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdbclientZ, Z$(prog)Z))))
  102. CPPFLAGS+= -DDROPBEAR_CLIENT
  103. endif
  104. # these are exported so that libtomcrypt's makefile will use them
  105. export CC
  106. export CFLAGS
  107. export CPPFLAGS
  108. export RANLIB AR STRIP
  109. ifeq ($(STATIC), 1)
  110. LDFLAGS+=-static
  111. endif
  112. ifeq ($(MULTI), 1)
  113. TARGETS=dropbearmulti$(EXEEXT)
  114. else
  115. TARGETS=$(PROGRAMS)
  116. endif
  117. # for the scp progress meter. The -D doesn't affect anything else.
  118. ifeq ($(SCPPROGRESS), 1)
  119. CPPFLAGS+=-DPROGRESS_METER
  120. endif
  121. all: $(TARGETS)
  122. # for simplicity assume all source depends on all headers
  123. HEADERS=$(wildcard $(srcdir)/*.h *.h) $(OPTION_HEADERS)
  124. %.o : %.c $(HEADERS)
  125. $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
  126. default_options_guard.h: default_options.h
  127. @echo Creating $@
  128. @printf "/*\n > > > Do not edit this file (default_options_guard.h) < < <\nGenerated from "$^"\nLocal customisation goes in localoptions.h\n*/\n\n" > $@.tmp
  129. @$(srcdir)/ifndef_wrapper.sh < $^ >> $@.tmp
  130. @mv $@.tmp $@
  131. strip: $(TARGETS)
  132. $(STRIP) $(addsuffix $(EXEEXT), $(TARGETS))
  133. install: $(addprefix inst_, $(TARGETS))
  134. insmultidropbear: dropbearmulti$(EXEEXT)
  135. $(INSTALL) -d $(DESTDIR)$(sbindir)
  136. -rm -f $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
  137. -ln -s $(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
  138. $(INSTALL) -d $(DESTDIR)$(mandir)/man8
  139. $(INSTALL) -m 644 $(srcdir)/dropbear.8 $(DESTDIR)$(mandir)/man8/dropbear.8
  140. insmulti%: dropbearmulti$(EXEEXT)
  141. $(INSTALL) -d $(DESTDIR)$(bindir)
  142. -rm -f $(DESTDIR)$(bindir)/$*$(EXEEXT)
  143. -ln -s $(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(bindir)/$*$(EXEEXT)
  144. $(INSTALL) -d $(DESTDIR)$(mandir)/man1
  145. if test -e $(srcdir)/$*.1; then $(INSTALL) -m 644 $(srcdir)/$*.1 $(DESTDIR)$(mandir)/man1/$*.1; fi
  146. # dropbear should go in sbin, so it needs a separate rule
  147. inst_dropbear: dropbear
  148. $(INSTALL) -d $(DESTDIR)$(sbindir)
  149. $(INSTALL) dropbear$(EXEEXT) $(DESTDIR)$(sbindir)
  150. $(INSTALL) -d $(DESTDIR)$(mandir)/man8
  151. $(INSTALL) -m 644 $(srcdir)/dropbear.8 $(DESTDIR)$(mandir)/man8/dropbear.8
  152. inst_%: %
  153. $(INSTALL) -d $(DESTDIR)$(bindir)
  154. $(INSTALL) $*$(EXEEXT) $(DESTDIR)$(bindir)
  155. $(INSTALL) -d $(DESTDIR)$(mandir)/man1
  156. if test -e $(srcdir)/$*.1; then $(INSTALL) -m 644 $(srcdir)/$*.1 $(DESTDIR)$(mandir)/man1/$*.1; fi
  157. inst_dropbearmulti: $(addprefix insmulti, $(PROGRAMS))
  158. # for some reason the rule further down doesn't like $($@objs) as a prereq.
  159. dropbear: $(dropbearobjs)
  160. dbclient: $(dbclientobjs)
  161. dropbearkey: $(dropbearkeyobjs)
  162. dropbearconvert: $(dropbearconvertobjs)
  163. dropbear: $(HEADERS) $(LIBTOM_DEPS) Makefile
  164. $(CC) $(LDFLAGS) -o $@$(EXEEXT) $($@objs) $(LIBTOM_LIBS) $(LIBS) @CRYPTLIB@ $(PLUGIN_LIBS)
  165. dbclient: $(HEADERS) $(LIBTOM_DEPS) Makefile
  166. $(CC) $(LDFLAGS) -o $@$(EXEEXT) $($@objs) $(LIBTOM_LIBS) $(LIBS)
  167. dropbearkey dropbearconvert: $(HEADERS) $(LIBTOM_DEPS) Makefile
  168. $(CC) $(LDFLAGS) -o $@$(EXEEXT) $($@objs) $(LIBTOM_LIBS) $(LIBS)
  169. # scp doesn't use the libs so is special.
  170. scp: $(SCPOBJS) $(HEADERS) Makefile
  171. $(CC) $(LDFLAGS) -o $@$(EXEEXT) $(SCPOBJS)
  172. # multi-binary compilation.
  173. MULTIOBJS=
  174. ifeq ($(MULTI),1)
  175. MULTIOBJS=dbmulti.o $(sort $(foreach prog, $(PROGRAMS), $($(prog)objs)))
  176. CPPFLAGS+=$(addprefix -DDBMULTI_, $(PROGRAMS)) -DDROPBEAR_MULTI
  177. endif
  178. dropbearmulti$(EXEEXT): $(HEADERS) $(MULTIOBJS) $(LIBTOM_DEPS) Makefile
  179. $(CC) $(LDFLAGS) -o $@ $(MULTIOBJS) $(LIBTOM_LIBS) $(LIBS) @CRYPTLIB@
  180. multibinary: dropbearmulti$(EXEEXT)
  181. multilink: multibinary $(addprefix link, $(PROGRAMS))
  182. link%:
  183. -rm -f $*$(EXEEXT)
  184. -ln -s dropbearmulti$(EXEEXT) $*$(EXEEXT)
  185. $(STATIC_LTC): $(OPTION_HEADERS)
  186. $(MAKE) -C libtomcrypt
  187. $(STATIC_LTM): $(OPTION_HEADERS)
  188. $(MAKE) -C libtommath
  189. .PHONY : clean sizes thisclean distclean tidy ltc-clean ltm-clean lint check
  190. ltc-clean:
  191. $(MAKE) -C libtomcrypt clean
  192. ltm-clean:
  193. $(MAKE) -C libtommath clean
  194. sizes: dropbear
  195. objdump -t dropbear|grep ".text"|cut -d "." -f 2|sort -rn
  196. clean: $(LIBTOM_CLEAN) $(FUZZ_CLEAN) thisclean
  197. thisclean:
  198. -rm -f dropbear$(EXEEXT) dbclient$(EXEEXT) dropbearkey$(EXEEXT) \
  199. dropbearconvert$(EXEEXT) scp$(EXEEXT) scp-progress$(EXEEXT) \
  200. dropbearmulti$(EXEEXT) *.o *.da *.bb *.bbg *.prof
  201. distclean: clean tidy
  202. -rm -f config.h
  203. -rm -f Makefile
  204. -rm -f default_options_guard.h
  205. tidy:
  206. -rm -f *~ *.gcov */*~
  207. lint:
  208. cd $(srcdir); ./dropbear_lint.sh
  209. check: lint
  210. make -C test
  211. ## Fuzzing targets
  212. # list of fuzz targets
  213. FUZZ_TARGETS=fuzzer-preauth fuzzer-pubkey fuzzer-verify fuzzer-preauth_nomaths \
  214. fuzzer-kexdh fuzzer-kexecdh fuzzer-kexcurve25519 fuzzer-client fuzzer-client_nomaths \
  215. fuzzer-postauth_nomaths
  216. FUZZER_OPTIONS = $(addsuffix .options, $(FUZZ_TARGETS))
  217. FUZZ_OBJS = $(addprefix fuzz/,$(addsuffix .o,$(FUZZ_TARGETS))) \
  218. fuzz/fuzz-sshpacketmutator.o
  219. list-fuzz-targets:
  220. @echo $(FUZZ_TARGETS)
  221. # fuzzers that don't use libfuzzer, just a standalone harness that feeds inputs
  222. fuzzstandalone: FUZZLIB=fuzz/fuzz-harness.o
  223. fuzzstandalone: fuzz/fuzz-harness.o fuzz-targets
  224. # Build all the fuzzers. Usually like
  225. # make fuzz-targets FUZZLIB=-lFuzzer.a
  226. # the library provides main(). Otherwise
  227. # make fuzzstandalone
  228. # provides a main in fuzz-harness.c
  229. fuzz-targets: $(FUZZ_TARGETS) $(FUZZER_OPTIONS)
  230. $(FUZZ_TARGETS): $(FUZZ_OBJS) $(allobjs) $(LIBTOM_DEPS)
  231. $(CXX) $(CXXFLAGS) fuzz/$@.o $(LDFLAGS) $(allobjs) -o $@$(EXEEXT) $(LIBTOM_LIBS) $(LIBS) $(FUZZLIB) @CRYPTLIB@
  232. # fuzzers that use the custom mutator - these expect a SSH network stream
  233. MUTATOR_FUZZERS=fuzzer-client fuzzer-client_nomaths \
  234. fuzzer-preauth fuzzer-preauth_nomaths fuzzer-postauth_nomaths
  235. # Skip custom mutators for -fsanitize-memory since libfuzzer doesn't initialise memory
  236. # Pending fix for it https://github.com/google/oss-fuzz/issues/4605
  237. ifeq (,$(findstring fsanitize=memory, $(CFLAGS)))
  238. $(MUTATOR_FUZZERS): allobjs += fuzz/fuzz-sshpacketmutator.o
  239. endif
  240. fuzzer-%.options: Makefile
  241. echo "[libfuzzer]" > $@
  242. echo "max_len = 50000" >> $@
  243. # run this to update hardcoded hostkeys for for fuzzing.
  244. # hostkeys.c is checked in to hg.
  245. fuzz-hostkeys:
  246. dropbearkey -t rsa -f keyr
  247. dropbearkey -t dss -f keyd
  248. dropbearkey -t ecdsa -size 256 -f keye
  249. dropbearkey -t ed25519 -f keyed25519
  250. echo > hostkeys.c
  251. /usr/bin/xxd -i -a keyr >> hostkeys.c
  252. /usr/bin/xxd -i -a keye >> hostkeys.c
  253. /usr/bin/xxd -i -a keyd >> hostkeys.c
  254. /usr/bin/xxd -i -a keyed25519 >> hostkeys.c
  255. fuzz-clean:
  256. -rm -f fuzz/*.o $(FUZZ_TARGETS) $(FUZZER_OPTIONS)