blob: 2f278351771ff7af0e0def71306b59857793f5af [file] [log] [blame]
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -07001diff --git Makefile Makefile
2index 2748ac8..cf3292a 100644
3--- Makefile
4+++ Makefile
5@@ -13,37 +13,48 @@
6 #
7
8 # Subdirectories we build in
9-TOPSUBDIRS = doc/manpages doc/technical csrc schema javasrc apps `cat local.subdirs 2>/dev/null || :`
10+TOPSUBDIRS = doc/manpages doc/technical csrc schema `cat local.subdirs 2>/dev/null || :`
11 # Packing list for packaging
12 PACKLIST = Makefile README LICENSE NEWS NOTICES configure doc/index.txt $(TOPSUBDIRS) android experiments
13 BLDMSG = printf '=== %s ' 'Building $@ in' && pwd
14
15+# Include build parameters
16+include csrc/conf.mk
17+
18 default all: _always
19 for i in $(TOPSUBDIRS); do \
20 (cd "$$i" && pwd && $(MAKE) $@) || exit 1; \
21 done
22- (cd csrc/lib && { test -f "$$HOME/.ccnx/.ccnx_keystore" || $(MAKE) test; }; )
23+ if [ "x$(BUILD_JAVA)" = "xtrue" ]; then \
24+ (cd javasrc && $(MAKE) $@); \
25+ if [ "x$(BUILD_APPS)" = "xtrue" ]; then \
26+ (cd apps && $(MAKE) $@); \
27+ fi; \
28+ fi
29 mkdir -p ./lib ./bin
30 test -d ./include || ln -s ./csrc/include
31 (cd csrc && $(MAKE) install INSTALL_BASE=`pwd`/..)
32- (cd javasrc && $(MAKE) install INSTALL_BASE=`pwd`/..)
33- (cd apps && $(MAKE) install INSTALL_BASE=`pwd`/..)
34+ if [ "x$(BUILD_JAVA)" = "xtrue" ]; then \
35+ (cd javasrc && $(MAKE) install INSTALL_BASE=`pwd`/..); \
36+ if [ "x$(BUILD_APPS)" = "xtrue" ]; then \
37+ (cd apps && $(MAKE) install INSTALL_BASE=`pwd`/..); \
38+ fi ;\
39+ fi
40
41 clean depend test check shared: _always
42- for i in $(TOPSUBDIRS); do \
43+ for i in $(TOPSUBDIRS) javasrc apps; do \
44 (cd "$$i" && pwd && $(MAKE) $@) || exit 1; \
45 done
46 @rm -f _always
47
48 testinstall install uninstall: _always
49- IB=`[ -z '$(INSTALL_BASE)' ] && grep ^INSTALL_BASE csrc/conf.mk 2>/dev/null | sed -e 's/ //g' || echo INSTALL_BASE=$(INSTALL_BASE)`; \
50- for i in $(TOPSUBDIRS); do \
51- (cd "$$i" && pwd && $(MAKE) $$IB $@) || exit 1; \
52+ for i in $(TOPSUBDIRS) javasrc apps; do \
53+ (cd "$$i" && pwd && $(MAKE) $@) || exit 1; \
54 done
55 @rm -f _always
56
57 documentation dist-docs: _always
58- for i in $(TOPSUBDIRS) android; do \
59+ for i in $(TOPSUBDIRS) javasrc apps android; do \
60 (cd "$$i" && pwd && $(MAKE) $@) || exit 1; \
61 done
62 @rm -f _always
63diff --git apps/Makefile apps/Makefile
64index acc347c..f0d8638 100644
65--- apps/Makefile
66+++ apps/Makefile
67@@ -19,7 +19,7 @@
68
69 SUBDIRS = HttpProxy ccnChat ccnFileProxy `cat local.subdirs 2>/dev/null || :`
70 MAKEF = -f ../conf.mk -f dir.mk -f ../subr.mk $(PASSTHRU)
71-PASSTHRU = `[ -z '$(INSTALL_BASE)' ] || echo INSTALL_BASE=$(INSTALL_BASE)`
72+PASSTHRU = `[ -z '$(INSTALL_BASE)' ] || echo INSTALL_BASE=$(DESTDIR)$(INSTALL_BASE)`
73 CFLAGS = -g
74 CSRCDIR = ../csrc
75
76diff --git apps/java.mk apps/java.mk
77index df9358e..d1cf718 100644
78--- apps/java.mk
79+++ apps/java.mk
80@@ -12,28 +12,22 @@
81 # FOR A PARTICULAR PURPOSE.
82 #
83
84+include ../conf.mk
85+
86 ANT = `command -v ant || echo echo SKIPPING ant`
87 LIBS = $(JAR)
88 WHINE = sh -c "type $(ANT) 2>/dev/null || \
89 echo Skipping java build in $$(pwd -L) - \
90 $(ANT) is not installed; "
91-# Default, the top-level Makefile default target will
92-# call the install target here but override INSTALL_BASE
93-# with dir in the source tree
94-INSTALL_LIB = $(INSTALL_BASE)/lib
95-INSTALL_BIN = $(INSTALL_BASE)/bin
96-INSTALL = cp
97-CP = cp
98-LS = /bin/ls
99
100 default all: jar
101 check: test
102
103 install:
104 @test -f $(JAR) && $(MAKE) real_install \
105- INSTALL_BASE=$(INSTALL_BASE) \
106- INSTALL_LIB=$(INSTALL_LIB) \
107- INSTALL_BIN=$(INSTALL_BIN) || $(WARN_NO_INSTALL)
108+ INSTALL_BASE=$(DESTDIR)$(INSTALL_BASE) \
109+ INSTALL_LIB=$(DESTDIR)$(INSTALL_LIB) \
110+ INSTALL_BIN=$(DESTDIR)$(INSTALL_BIN) || $(WARN_NO_INSTALL)
111
112 real_install: _always
113 test -d $(INSTALL_LIB)
114@@ -43,8 +37,8 @@ real_install: _always
115 $(CP) -R tools/. $(INSTALL_BIN)
116
117 uninstall:
118- for i in $(LIBS) ""; do test -z "$$i" || rm -f $(INSTALL_LIB)/`basename $$i`; done
119- for i in `$(LS) tools` "" ; do test -z "$$i" || rm -f $(INSTALL_BIN)/`basename $$i`; done
120+ for i in $(LIBS) ""; do test -z "$$i" || rm -f $(DESTDIR)$(INSTALL_LIB)/`basename $$i`; done
121+ for i in `$(LS) tools` "" ; do test -z "$$i" || rm -f $(DESTDIR)$(INSTALL_BIN)/`basename $$i`; done
122
123 # Use ant to actually do the work for these targets
124 jar test: _always
125diff --git csrc/ccnd/ccnd-init-keystore-helper.sh csrc/ccnd/ccnd-init-keystore-helper.sh
126deleted file mode 100755
127index ede0153..0000000
128--- csrc/ccnd/ccnd-init-keystore-helper.sh
129+++ /dev/null
130@@ -1,47 +0,0 @@
131-#!/bin/sh
132-# ccnd/ccnd-init-keystore-helper.sh
133-#
134-# Part of the CCNx distribution.
135-#
136-# Copyright (C) 2009 Palo Alto Research Center, Inc.
137-#
138-# This work is free software; you can redistribute it and/or modify it under
139-# the terms of the GNU General Public License version 2 as published by the
140-# Free Software Foundation.
141-# This work is distributed in the hope that it will be useful, but WITHOUT ANY
142-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
143-# FOR A PARTICULAR PURPOSE.
144-#
145-: ${RSA_KEYSIZE:=1024}
146-exec >&2
147-Fail () {
148- echo '*** Failed' "$*"
149- exit 1
150-}
151-cd `dirname "$1"` || Fail bad setup
152-umask 077
153-trap 'rm -f *.pem openssl.cnf p' 0
154-cat <<EOF >openssl.cnf
155-# This is not really relevant because we're not sending cert requests anywhere,
156-# but openssl req can refuse to go on if it has no config file.
157-[ req ]
158-distinguished_name = req_distinguished_name
159-[ req_distinguished_name ]
160-countryName = Country Name (2 letter code)
161-countryName_default = AU
162-countryName_min = 2
163-countryName_max = 2
164-EOF
165-openssl req -config openssl.cnf \
166- -newkey rsa:$RSA_KEYSIZE \
167- -x509 \
168- -keyout private_key.pem \
169- -out certout.pem \
170- -subj /CN="CCND-internal" \
171- -nodes || Fail openssl req
172-openssl pkcs12 -export \
173- -name "CCND" \
174- -out "$1" \
175- -in certout.pem \
176- -inkey private_key.pem \
177- -password file:p || Fail openssl pkcs12
178diff --git csrc/ccnd/dir.mk csrc/ccnd/dir.mk
179index 72c8438..2ec0946 100644
180--- csrc/ccnd/dir.mk
181+++ csrc/ccnd/dir.mk
182@@ -15,7 +15,7 @@
183 LDLIBS = -L$(CCNLIBDIR) $(MORE_LDLIBS) -lccn
184 CCNLIBDIR = ../lib
185
186-INSTALLED_PROGRAMS = ccnd ccndsmoketest ccnd-init-keystore-helper
187+INSTALLED_PROGRAMS = ccnd ccndsmoketest
188 PROGRAMS = $(INSTALLED_PROGRAMS)
189 DEBRIS = anything.ccnb contentobjecthash.ccnb contentmishash.ccnb \
190 contenthash.ccnb
191@@ -24,7 +24,7 @@ BROKEN_PROGRAMS =
192 CSRC = ccnd_main.c ccnd.c ccnd_msg.c ccnd_stats.c ccnd_internal_client.c ccndsmoketest.c
193 HSRC = ccnd_private.h
194 SCRIPTSRC = testbasics fortunes.ccnb contentobjecthash.ref anything.ref \
195- ccnd-init-keystore-helper.sh minsuffix.ref
196+ minsuffix.ref
197
198 default: $(PROGRAMS)
199
200@@ -40,10 +40,6 @@ ccnd: $(CCND_OBJ) ccnd_built.sh
201 ccnd_built.sh:
202 touch ccnd_built.sh
203
204-ccnd-init-keystore-helper: ccnd-init-keystore-helper.sh
205- sed -e 's@/bin/sh@'`which sh`'@g' ccnd-init-keystore-helper.sh > $@
206- chmod +x $@
207-
208 ccndsmoketest: ccndsmoketest.o
209 $(CC) $(CFLAGS) -o $@ ccndsmoketest.o $(LDLIBS)
210
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700211diff --git csrc/configure csrc/configure
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700212index 962d76a..e838792 100755
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700213--- csrc/configure
214+++ csrc/configure
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700215@@ -39,16 +39,22 @@ TryAppend "`uname -sr | sed -e 's/ /-/g'`"
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700216 TryAppend "local"
217 TryScript "`uname`" "$@"
218 TryScript "local" "$@"
219-ProvideDefault CPREFLAGS = -I../include
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700220-ProvideDefault PCAP_PROGRAMS = ccndumppcap
221-ProvideDefault RESOLV_LIBS = -lresolv
222+ProvideDefault CC = ${CC:=cc}
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700223+ProvideDefault CPREFLAGS = -I../include ${CFLAGS:-}
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700224+ProvideDefault PCAP_PROGRAMS = ${PCAP_PROGRAMS:-ccndumppcap}
225+ProvideDefault RESOLV_LIBS = ${RESOLV_LIBS:--lresolv}
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700226 ProvideDefault INSTALL_BASE = ${INSTALL_BASE:-/usr/local}
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700227-ProvideDefault INSTALL_INCLUDE = '$(INSTALL_BASE)/include'
228-ProvideDefault INSTALL_LIB = '$(INSTALL_BASE)/lib'
229-ProvideDefault INSTALL_BIN = '$(INSTALL_BASE)/bin'
230-ProvideDefault INSTALL = install
231-ProvideDefault RM = rm -f
232-ProvideDefault SH = /bin/sh
233+ProvideDefault INSTALL_INCLUDE = ${INSTALL_INCLUDE:-\$(INSTALL_BASE)/include}
234+ProvideDefault INSTALL_LIB = ${INSTALL_LIB:-\$(INSTALL_BASE)/lib}
235+ProvideDefault INSTALL_BIN = ${INSTALL_BIN:-\$(INSTALL_BASE)/bin}
236+ProvideDefault INSTALL = ${INSTALL:-install}
237+ProvideDefault CP = ${CP:-cp}
238+ProvideDefault RM = ${RM:-rm -f}
239+ProvideDefault SH = ${SH:-/bin/sh}
240+ProvideDefault LS = ${LS:-/bin/ls}
241+
242+ProvideDefault BUILD_JAVA = ${BUILD_JAVA:-true}
243+ProvideDefault BUILD_APPS = ${BUILD_APPS:-true}
244
245 echo ============= conf.mk =============>&2
246 cat conf.mk >&2
247diff --git csrc/include/ccn/ccn.h csrc/include/ccn/ccn.h
248index 548d5d4..22990fb 100644
249--- csrc/include/ccn/ccn.h
250+++ csrc/include/ccn/ccn.h
251@@ -911,7 +911,7 @@ int ccn_encode_StatusResponse(struct ccn_charbuf *buf,
252 * error encountered during a call using the given handle.
253 * ccn_seterror records error info, ccn_geterror gets it.
254 */
255-void ccn_perror(struct ccn *h, const char *s);
256+void ccn_perror(struct ccn *h, const char *s, ...);
257 int ccn_seterror(struct ccn *h, int error_code);
258 int ccn_geterror(struct ccn *h);
259
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700260diff --git csrc/lib/ccn_client.c csrc/lib/ccn_client.c
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700261index 606fd36..35f2b43 100644
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700262--- csrc/lib/ccn_client.c
263+++ csrc/lib/ccn_client.c
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700264@@ -163,9 +163,12 @@ tv_earlier(const struct timeval *a, const struct timeval *b)
265 * where available.
266 */
267 void
268-ccn_perror(struct ccn *h, const char *s)
269+ccn_perror(struct ccn *h, const char *s, ...)
270 {
271 const char *dlm = ": ";
272+ va_list ap;
273+ va_start(ap, s);
274+
275 if (s == NULL) {
276 if (h->err > 0)
277 s = strerror(h->err);
278@@ -173,8 +176,10 @@ ccn_perror(struct ccn *h, const char *s)
279 dlm = s = "";
280 }
281 // XXX - time stamp
282- fprintf(stderr, "ccn_client.c:%d[%d] - error %d%s%s\n",
283- h->errline, (int)getpid(), h->err, dlm, s);
284+ fprintf(stderr, "ccn_client.c:%d[%d] - error %d%s",
285+ h->errline, (int)getpid(), h->err, dlm);
286+ vfprintf(stderr, s, ap);
287+ fprintf(stderr, "\n");
288 }
289
290 static int
291@@ -2562,6 +2567,62 @@ ccn_get_public_key(struct ccn *h,
292 return(res);
293 }
294
295+int
296+ccn_load_key_or_create(struct ccn *h,
297+ const char *keystore,
298+ struct ccn_charbuf *default_pubid,
299+ size_t key_size)
300+{
301+ const char *password = NULL;
302+ int res = 0;
303+
304+ password = getenv ("CCNX_KEYSTORE_PASSWORD");
305+ if (password == 0) {
306+ password = "Th1s1sn0t8g00dp8ssw0rd.";
307+ }
308+
309+ res = ccn_load_private_key(h,
310+ keystore,
311+ password,
312+ default_pubid);
313+
314+ if (res != 0 || default_pubid->length != key_size) {
315+ // two cases, either file exists and we password is wrong or file does not exist
316+
317+ if (access (keystore, R_OK) == 0) {
318+ ccn_perror (h, "Keystore file [%s] exists, but private key cannot be loaded. "
319+ "Check if CCNX_KEYSTORE_PASSWORD is set to a correct password, "
320+ "otherwise remove [%s] and it will be automatically created.",
321+ keystore, keystore);
322+ res = NOTE_ERR (h, -1);
323+ return res;
324+ }
325+
326+ ccn_perror (h, "Keystore [%s] does not exist and will be automatically created", keystore);
327+
328+ res = ccn_keystore_file_init ((char*)keystore, (char*)password,
329+ "ccnxuser", 0, 3650); // create a key valid for 10 years
330+ if (res != 0) {
331+ ccn_perror (h, "Cannot create keystore [%s]", keystore);
332+ res = NOTE_ERRNO (h);
333+ return res;
334+ }
335+
336+ res = ccn_load_private_key(h,
337+ keystore,
338+ password,
339+ default_pubid);
340+ if (res != 0 || default_pubid->length != key_size) {
341+ // this definitely should not happen
342+ ccn_perror (h, "Cannot load keystore [%s] just after it has been created", keystore);
343+ res = NOTE_ERRNO (h);
344+ return res;
345+ }
346+ }
347+
348+ return res;
349+}
350+
351 /**
352 * This is mostly for use within the library,
353 * but may be useful for some clients.
354@@ -2582,6 +2643,7 @@ ccn_chk_signing_params(struct ccn *h,
355 int i;
356 int conflicting;
357 int needed;
358+ struct stat sb;
359
360 if (params != NULL)
361 *result = *params;
362@@ -2607,23 +2669,57 @@ ccn_chk_signing_params(struct ccn *h,
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700363 temp = ccn_charbuf_create();
364 if (default_pubid == NULL || temp == NULL)
365 return(NOTE_ERRNO(h));
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700366+
367+ res = -1;
368+
369+ // check CCNX_DIR
370 ccnx_dir = getenv("CCNX_DIR");
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700371- if (ccnx_dir == NULL || ccnx_dir[0] == 0) {
372- home = getenv("HOME");
373- if (home == NULL)
374- home = "";
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700375+ if (ccnx_dir != NULL && ccnx_dir[0] != 0) {
376+ ccn_charbuf_reset(temp);
377+ ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700378+
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700379+ res = ccn_load_key_or_create (h,
380+ ccn_charbuf_as_string (temp),
381+ default_pubid,
382+ sizeof(result->pubid));
383+ }
384+
385+ if (res < 0) {
386+ // check HOME
387+ home = getenv("HOME");
388+ if (home != NULL) {
389+ // step 1. Check if home directory exists
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700390+ ccn_charbuf_reset(temp);
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700391+ ccn_charbuf_putf(temp, "%s/.ccnx", home);
392+
393+ res = stat (ccn_charbuf_as_string (temp), &sb);
394+ if (res != 0 || !(sb.st_mode & S_IFDIR))
395+ {
396+ res = mkdir (ccn_charbuf_as_string (temp), S_IRWXU);
397+ if (res != 0)
398+ {
399+ ccn_perror (h, "Failed to create directory [%s]", ccn_charbuf_as_string (temp));
400+ }
401+ }
402+
403+ ccn_charbuf_reset(temp);
404 ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", home);
405+
406+ res = ccn_load_key_or_create (h,
407+ ccn_charbuf_as_string (temp),
408+ default_pubid,
409+ sizeof(result->pubid));
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700410+ }
411 }
412- else
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700413- ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700414- res = ccn_load_private_key(h,
415- ccn_charbuf_as_string(temp),
416- "Th1s1sn0t8g00dp8ssw0rd.",
417- default_pubid);
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700418- if (res == 0 && default_pubid->length == sizeof(result->pubid)) {
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700419+
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700420+ if (res == 0) {
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700421 h->default_pubid = default_pubid;
422 default_pubid = NULL;
423 }
424+ else {
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700425+ ccn_perror(h, "Fail to load private key from keystore");
426+ res = NOTE_ERRNO (h);
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700427+ }
428 }
429 if (h->default_pubid == NULL)
430 res = NOTE_ERRNO(h);
431diff --git csrc/lib/ccn_initkeystore.sh csrc/lib/ccn_initkeystore.sh
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700432deleted file mode 100755
433index 12bc9e3..0000000
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700434--- csrc/lib/ccn_initkeystore.sh
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700435+++ /dev/null
436@@ -1,51 +0,0 @@
437-#!/bin/sh
438-# lib/ccn_initkeystore.sh
439-#
440-# Part of the CCNx distribution.
441-#
442-# Copyright (C) 2009-2010 Palo Alto Research Center, Inc.
443-#
444-# This work is free software; you can redistribute it and/or modify it under
445-# the terms of the GNU General Public License version 2 as published by the
446-# Free Software Foundation.
447-# This work is distributed in the hope that it will be useful, but WITHOUT ANY
448-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
449-# FOR A PARTICULAR PURPOSE.
450-#
451-# Create a ccn keystore without relying on java
452-: ${RSA_KEYSIZE:=1024}
453-: ${CCN_USER:=`id -n -u`}
454-Fail () {
455- echo '*** Failed' "$*"
456- exit 1
457-}
458-test -d .ccnx && rm -rf .ccnx
459-test $RSA_KEYSIZE -ge 512 || Fail \$RSA_KEYSIZE too small to sign CCN content
460-(umask 077 && mkdir .ccnx) || Fail $0 Unable to create .ccnx directory
461-cd .ccnx
462-umask 077
463-# Set a trap to cleanup on the way out
464-trap 'rm -f *.pem openssl.cnf' 0
465-cat <<EOF >openssl.cnf
466-# This is not really relevant because we're not sending cert requests anywhere,
467-# but openssl req can refuse to go on if it has no config file.
468-[ req ]
469-distinguished_name = req_distinguished_name
470-[ req_distinguished_name ]
471-countryName = Country Name (2 letter code)
472-countryName_default = AU
473-countryName_min = 2
474-countryName_max = 2
475-EOF
476-openssl req -config openssl.cnf \
477- -newkey rsa:$RSA_KEYSIZE \
478- -x509 \
479- -keyout private_key.pem \
480- -out certout.pem \
481- -subj /CN="$CCN_USER" \
482- -nodes || Fail openssl req
483-openssl pkcs12 -export -name "ccnxuser" \
484- -out .ccnx_keystore \
485- -in certout.pem \
486- -inkey private_key.pem \
487- -password pass:'Th1s1sn0t8g00dp8ssw0rd.' || Fail openssl pkcs12
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700488diff --git csrc/lib/dir.mk csrc/lib/dir.mk
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700489index 6489299..c03316d 100644
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700490--- csrc/lib/dir.mk
491+++ csrc/lib/dir.mk
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700492@@ -21,7 +21,6 @@ PROGRAMS = hashtbtest skel_decode_test \
493
494 BROKEN_PROGRAMS =
495 DEBRIS = ccn_verifysig _bt_*
496-SCRIPTSRC = ccn_initkeystore.sh
497 CSRC = ccn_bloom.c \
498 ccn_btree.c ccn_btree_content.c ccn_btree_store.c \
499 ccn_buf_decoder.c ccn_buf_encoder.c ccn_bulkdata.c \
500@@ -56,28 +55,28 @@ default all: dtag_check lib $(PROGRAMS)
501 # Don't try to build shared libs right now.
502 # all: shlib
503
504-all: basicparsetest ccn_verifysig
505+# all: basicparsetest ccn_verifysig
506
507 install: install_headers
508 install_headers:
509- @test -d $(INSTALL_INCLUDE) || (echo $(INSTALL_INCLUDE) does not exist. Please mkdir -p $(INSTALL_INCLUDE) if this is what you intended. && exit 2)
510- mkdir -p $(INSTALL_INCLUDE)/ccn
511+ @test -d $(DESTDIR)$(INSTALL_INCLUDE) || (echo $(DESTDIR)$(INSTALL_INCLUDE) does not exist. Please mkdir -p $(DESTDIR)$(INSTALL_INCLUDE) if this is what you intended. && exit 2)
512+ mkdir -p $(DESTDIR)$(INSTALL_INCLUDE)/ccn
513 for i in `cd ../include/ccn && echo *.h`; do \
514- cmp -s ../include/ccn/$$i $(INSTALL_INCLUDE)/ccn/$$i || \
515- cp ../include/ccn/$$i $(INSTALL_INCLUDE)/ccn/$$i || \
516+ cmp -s ../include/ccn/$$i $(DESTDIR)$(INSTALL_INCLUDE)/ccn/$$i || \
517+ cp ../include/ccn/$$i $(DESTDIR)$(INSTALL_INCLUDE)/ccn/$$i || \
518 exit 1; \
519 done
520
521 uninstall: uninstall_headers
522 uninstall_headers:
523- test -L $(INSTALL_INCLUDE)/ccn && $(RM) $(INSTALL_INCLUDE)/ccn ||:
524- test -L $(INSTALL_INCLUDE) || $(RM) -r $(INSTALL_INCLUDE)/ccn
525+ test -L $(DESTDIR)$(INSTALL_INCLUDE)/ccn && $(RM) $(DESTDIR)$(INSTALL_INCLUDE)/ccn ||:
526+ test -L $(DESTDIR)$(INSTALL_INCLUDE) || $(RM) -r $(DESTDIR)$(INSTALL_INCLUDE)/ccn
527
528 shlib: $(SHLIBNAME)
529
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700530 lib: libccn.a
531
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700532-test: default keystore_check encodedecodetest ccnbtreetest
533+test: default encodedecodetest ccnbtreetest
534 ./encodedecodetest -o /dev/null
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700535 ./ccnbtreetest
536 ./ccnbtreetest - < q.dat
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700537@@ -86,14 +85,6 @@ test: default keystore_check encodedecodetest ccnbtreetest
538 dtag_check: _always
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700539 @./gen_dtag_table 2>/dev/null | diff - ccn_dtag_table.c | grep '^[<]' >/dev/null && echo '*** Warning: ccn_dtag_table.c may be out of sync with tagnames.cvsdict' || :
540
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700541-keystore_check: ccn_initkeystore.sh
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700542- test -f "$$HOME/.ccnx/.ccnx_keystore" || $(MAKE) -f dir.mk new_keystore
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700543-
544-new_keystore:
545- @echo === CCNx Keystore not found in your home directory
546- @echo === I will create one for you now '(^C to abort)'
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700547- sleep 1 && sh ccn_initkeystore.sh && sleep 3 && mv .ccnx "$$HOME"
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700548-
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700549 libccn.a: $(LIB_OBJS)
550 ar crus $@ $(LIB_OBJS)
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700551
552@@ -113,7 +104,7 @@ skel_decode_test: skel_decode_test.o
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700553 basicparsetest: basicparsetest.o libccn.a
554 $(CC) $(CFLAGS) -o $@ basicparsetest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
555
556-encodedecodetest: encodedecodetest.o
557+encodedecodetest: encodedecodetest.o libccn.a
558 $(CC) $(CFLAGS) -o $@ encodedecodetest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
559
560 ccn_digest.o:
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700561@@ -149,16 +140,16 @@ ccn_fetch.o:
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -0700562 ccn_verifysig.o:
563 $(CC) $(CFLAGS) $(OPENSSL_CFLAGS) -c ccn_verifysig.c
564
565-ccn_verifysig: ccn_verifysig.o
566+ccn_verifysig: ccn_verifysig.o libccn.a
567 $(CC) $(CFLAGS) -o $@ ccn_verifysig.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
568
569 signbenchtest.o:
570 $(CC) $(CFLAGS) $(OPENSSL_CFLAGS) -c signbenchtest.c
571
572-signbenchtest: signbenchtest.o
573+signbenchtest: signbenchtest.o libccn.a
574 $(CC) $(CFLAGS) -o $@ signbenchtest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
575
576-ccndumppcap: ccndumppcap.o
577+ccndumppcap: ccndumppcap.o libccn.a
578 $(CC) $(CFLAGS) -o $@ ccndumppcap.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto -lpcap
579
580 ccnbtreetest.o:
Alexander Afanasyevc1ec69f2012-08-24 18:10:09 -0700581diff --git csrc/lib/encodedecodetest.c csrc/lib/encodedecodetest.c
582index be6a853..09e02ea 100644
583--- csrc/lib/encodedecodetest.c
584+++ csrc/lib/encodedecodetest.c
585@@ -210,17 +210,19 @@ main (int argc, char *argv[]) {
586 NULL};
587 struct path * cur_path = NULL;
588 struct ccn_keystore *keystore = ccn_keystore_create();
589- char *home = getenv("HOME");
590- char *keystore_suffix = "/.ccnx/.ccnx_keystore";
591 char *keystore_name = NULL;
592+ char *keystore_password = NULL;
593
594 int i;
595
596- while ((i = getopt(argc, argv, "k:o:")) != -1) {
597+ while ((i = getopt(argc, argv, "k:p:o:")) != -1) {
598 switch (i) {
599 case 'k':
600 keystore_name = optarg;
601 break;
602+ case 'p':
603+ keystore_password = optarg;
604+ break;
605 case 'o':
606 outname = optarg;
607 break;
608@@ -231,21 +233,38 @@ main (int argc, char *argv[]) {
609 }
610
611
612- if (keystore_name == NULL && home == NULL) {
613- printf("Unable to determine home directory for keystore\n");
614- exit(1);
615- }
616 if (keystore_name == NULL) {
617- keystore_name = calloc(1, strlen(home) + strlen(keystore_suffix) + 1);
618- strcat(keystore_name, home);
619- strcat(keystore_name, keystore_suffix);
620+ keystore_name = tmpnam (NULL); // should be ok, there is just single thread
621 }
622
623- if (0 != ccn_keystore_init(keystore, keystore_name, "Th1s1sn0t8g00dp8ssw0rd.")) {
624- printf("Failed to initialize keystore\n");
625- exit(1);
626+ if (keystore_password == NULL) {
627+ keystore_password = "Th1s1sn0t8g00dp8ssw0rd.";
628 }
629
630+ res = ccn_keystore_init (keystore, keystore_name, keystore_password);
631+ if (res != 0)
632+ {
633+ printf ("Initializing keystore in %s\n", keystore_name);
634+
635+ res = ccn_keystore_file_init (keystore_name, keystore_password,
636+ "ccnxuser", 0, 3650); // create a key valid for 10 years
637+ if (res != 0) {
638+ fprintf (stderr, "Cannot create keystore [%s]", keystore_name);
639+ return res;
640+ }
641+
642+ // init again
643+ res = ccn_keystore_init(keystore, keystore_name, keystore_password);
644+ if (res != 0) {
645+ printf("Failed to initialize keystore\n");
646+ exit(1);
647+ }
648+ }
649+
650+
651+
652+
653+
654 printf("Creating signed_info\n");
655 res = ccn_signed_info_create(signed_info,
656 /*pubkeyid*/ccn_keystore_public_key_digest(keystore),
657diff --git csrc/subr.mk csrc/subr.mk
658index e24c230..3361a49 100644
659--- csrc/subr.mk
660+++ csrc/subr.mk
661@@ -31,20 +31,20 @@ $(OBJDIR)/dir.mk: dir.mk
662 cp -p dir.mk $(OBJDIR)/dir.mk
663
664 install_libs: $(LIBS)
665- @test -d $(INSTALL_LIB) || (echo $(INSTALL_LIB) does not exist. Please mkdir -p $(INSTALL_LIB) if this is what you intended. && exit 2)
666- for i in $(LIBS) ""; do test -z "$$i" || $(INSTALL) $$i $(INSTALL_LIB); done
667+ @test -d $(DESTDIR)$(INSTALL_LIB) || (echo $(DESTDIR)$(INSTALL_LIB) does not exist. Please mkdir -p $(DESTDIR)$(INSTALL_LIB) if this is what you intended. && exit 2)
668+ for i in $(LIBS) ""; do test -z "$$i" || $(INSTALL) $$i $(DESTDIR)$(INSTALL_LIB); done
669
670 install_programs: $(INSTALLED_PROGRAMS)
671- @test -d $(INSTALL_BIN) || (echo $(INSTALL_BIN) does not exist. Please mkdir -p $(INSTALL_BIN) if this is what you intended. && exit 2)
672- for i in $(INSTALLED_PROGRAMS) ""; do test -z "$$i" || $(INSTALL) $$i $(INSTALL_BIN); done
673+ @test -d $(DESTDIR)$(INSTALL_BIN) || (echo $(DESTDIR)$(INSTALL_BIN) does not exist. Please mkdir -p $(DESTDIR)$(INSTALL_BIN) if this is what you intended. && exit 2)
674+ for i in $(INSTALLED_PROGRAMS) ""; do test -z "$$i" || $(INSTALL) $$i $(DESTDIR)$(INSTALL_BIN); done
675
676 install: install_libs install_programs
677
678 uninstall_libs:
679- for i in $(LIBS) ""; do test -z "$$i" || $(RM) $(INSTALL_LIB)/$$i; done
680+ for i in $(LIBS) ""; do test -z "$$i" || $(RM) $(DESTDIR)$(INSTALL_LIB)/$$i; done
681
682 uninstall_programs:
683- for i in $(PROGRAMS) ""; do test -z "$$i" || $(RM) $(INSTALL_BIN)/$$i; done
684+ for i in $(PROGRAMS) ""; do test -z "$$i" || $(RM) $(DESTDIR)$(INSTALL_BIN)/$$i; done
685
686 uninstall: uninstall_libs uninstall_programs
687
688diff --git javasrc/Makefile javasrc/Makefile
689index c5b8444..d2237b6 100644
690--- javasrc/Makefile
691+++ javasrc/Makefile
692@@ -12,6 +12,8 @@
693 # FOR A PARTICULAR PURPOSE.
694 #
695
696+include ../csrc/conf.mk
697+
698 ANT = `command -v ant || echo echo SKIPPING ant`
699 JAR = ccn.jar
700 LIBS = $(JAR) lib/bcprov-jdk16-143.jar lib/kxml2-2.3.0.jar $(EXTRA_LIBS)
701@@ -23,20 +25,15 @@ WARN_NO_INSTALL = echo Nothing installed from javasrc/
702 # Default, the top-level Makefile default target will
703 # call the install target here but override INSTALL_BASE
704 # with dir in the source tree
705-INSTALL_LIB = $(INSTALL_BASE)/lib
706-INSTALL_BIN = $(INSTALL_BASE)/bin
707-INSTALL = cp
708-CP = cp
709-LS = /bin/ls
710
711 default all: jar
712 check: test
713
714 install:
715 @test -f $(JAR) && $(MAKE) real_install \
716- INSTALL_BASE=$(INSTALL_BASE) \
717- INSTALL_LIB=$(INSTALL_LIB) \
718- INSTALL_BIN=$(INSTALL_BIN) || $(WARN_NO_INSTALL)
719+ INSTALL_BASE=$(DESTDIR)$(INSTALL_BASE) \
720+ INSTALL_LIB=$(DESTDIR)$(INSTALL_LIB) \
721+ INSTALL_BIN=$(DESTDIR)$(INSTALL_BIN) || $(WARN_NO_INSTALL)
722
723 real_install: _always
724 test -d $(INSTALL_LIB)
725@@ -46,8 +43,8 @@ real_install: _always
726 $(CP) -R tools/. $(INSTALL_BIN)
727
728 uninstall:
729- for i in $(LIBS) ""; do test -z "$$i" || rm -f $(INSTALL_LIB)/`basename $$i`; done
730- for i in `$(LS) tools` "" ; do test -z "$$i" || rm -f $(INSTALL_BIN)/`basename $$i`; done
731+ for i in $(LIBS) ""; do test -z "$$i" || rm -f $(DESTDIR)$(INSTALL_LIB)/`basename $$i`; done
732+ for i in `$(LS) tools` "" ; do test -z "$$i" || rm -f $(DESTDIR)$(INSTALL_BIN)/`basename $$i`; done
733
734 # Use ant to actually do the work for these targets
735 jar test: _always