blob: 5b1a91d6e24e25ae53615f5b4451e75fcbe780b5 [file] [log] [blame]
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -07001diff --git Makefile Makefile
2index 2748ac8..34b67af 100644
3--- Makefile
4+++ Makefile
5@@ -13,7 +13,7 @@
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
14diff --git csrc/configure csrc/configure
15index 962d76a..43ec3ea 100755
16--- csrc/configure
17+++ csrc/configure
18@@ -39,7 +39,7 @@ TryAppend "`uname -sr | sed -e 's/ /-/g'`"
19 TryAppend "local"
20 TryScript "`uname`" "$@"
21 TryScript "local" "$@"
22-ProvideDefault CPREFLAGS = -I../include
23+ProvideDefault CPREFLAGS = -I../include ${CFLAGS:-}
24 ProvideDefault PCAP_PROGRAMS = ccndumppcap
25 ProvideDefault RESOLV_LIBS = -lresolv
26 ProvideDefault INSTALL_BASE = ${INSTALL_BASE:-/usr/local}
27diff --git csrc/lib/ccn_client.c csrc/lib/ccn_client.c
28index 606fd36..9b3760c 100644
29--- csrc/lib/ccn_client.c
30+++ csrc/lib/ccn_client.c
31@@ -2435,6 +2435,7 @@ ccn_load_private_key(struct ccn *h,
32 res = NOTE_ERRNO(h);
33 goto Cleanup;
34 }
35+ fprintf (stderr, ">>> load_private_key: [%s]\n", keystore_path);
36 res = ccn_keystore_init(keystore,
37 (char *)keystore_path,
38 (char *)keystore_passphrase);
39@@ -2487,6 +2488,7 @@ ccn_load_default_key(struct ccn *h,
40 if (h->default_pubid != NULL)
41 return(NOTE_ERR(h, EINVAL));
42 default_pubid = ccn_charbuf_create();
43+ printf ("Tring to open keystore [%s]\n", keystore_path);
44 res = ccn_load_private_key(h,
45 keystore_path,
46 keystore_passphrase,
47@@ -2607,23 +2609,58 @@ ccn_chk_signing_params(struct ccn *h,
48 temp = ccn_charbuf_create();
49 if (default_pubid == NULL || temp == NULL)
50 return(NOTE_ERRNO(h));
51- ccnx_dir = getenv("CCNX_DIR");
52- if (ccnx_dir == NULL || ccnx_dir[0] == 0) {
53- home = getenv("HOME");
54- if (home == NULL)
55- home = "";
56- ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", home);
57+
58+ res = -1;
59+#ifdef CCNX_DIR
60+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
61+ // check preconfigured directory
62+ ccnx_dir = CCNX_DIR;
63+ if (ccnx_dir != NULL && ccnx_dir[0] != 0) {
64+ ccn_charbuf_reset(temp);
65+ ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
66+
67+ res = ccn_load_private_key(h,
68+ ccn_charbuf_as_string(temp),
69+ "Th1s1sn0t8g00dp8ssw0rd.",
70+ default_pubid);
71+ }
72 }
73- else
74+#endif
75+
76+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
77+ // check CCNX_DIR
78+ ccnx_dir = getenv("CCNX_DIR");
79+ if (ccnx_dir != NULL && ccnx_dir[0] != 0) {
80+ ccn_charbuf_reset(temp);
81 ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
82- res = ccn_load_private_key(h,
83- ccn_charbuf_as_string(temp),
84- "Th1s1sn0t8g00dp8ssw0rd.",
85- default_pubid);
86+
87+ res = ccn_load_private_key(h,
88+ ccn_charbuf_as_string(temp),
89+ "Th1s1sn0t8g00dp8ssw0rd.",
90+ default_pubid);
91+ }
92+ }
93+
94+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
95+ // check HOME
96+ home = getenv("HOME");
97+ if (home != NULL) {
98+ ccn_charbuf_reset(temp);
99+ ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", home);
100+ res = ccn_load_private_key(h,
101+ ccn_charbuf_as_string(temp),
102+ "Th1s1sn0t8g00dp8ssw0rd.",
103+ default_pubid);
104+ }
105+ }
106+
107 if (res == 0 && default_pubid->length == sizeof(result->pubid)) {
108 h->default_pubid = default_pubid;
109 default_pubid = NULL;
110 }
111+ else {
112+ ccn_perror(h, ccn_charbuf_as_string(temp));
113+ }
114 }
115 if (h->default_pubid == NULL)
116 res = NOTE_ERRNO(h);
117diff --git csrc/lib/ccn_initkeystore.sh csrc/lib/ccn_initkeystore.sh
118index 12bc9e3..a171a0e 100755
119--- csrc/lib/ccn_initkeystore.sh
120+++ csrc/lib/ccn_initkeystore.sh
121@@ -15,6 +15,7 @@
122 # Create a ccn keystore without relying on java
123 : ${RSA_KEYSIZE:=1024}
124 : ${CCN_USER:=`id -n -u`}
125+: ${CCNX_HOME:=.ccnx}
126 Fail () {
127 echo '*** Failed' "$*"
128 exit 1
129@@ -37,6 +38,7 @@ countryName_default = AU
130 countryName_min = 2
131 countryName_max = 2
132 EOF
133+RANDFILE=.rnd
134 openssl req -config openssl.cnf \
135 -newkey rsa:$RSA_KEYSIZE \
136 -x509 \
137diff --git csrc/lib/ccn_keystore.c csrc/lib/ccn_keystore.c
138index ac936c3..c103dd8 100644
139--- csrc/lib/ccn_keystore.c
140+++ csrc/lib/ccn_keystore.c
141@@ -76,6 +76,8 @@ ccn_keystore_init(struct ccn_keystore *p, char *filename, char *password)
142 int digest_size;
143 int res;
144
145+ fprintf (stderr, "Trying to open [%s]\n\n", filename);
146+
147 OpenSSL_add_all_algorithms();
148 fp = fopen(filename, "rb");
149 if (fp == NULL)
150diff --git csrc/lib/dir.mk csrc/lib/dir.mk
151index 6489299..145eec7 100644
152--- csrc/lib/dir.mk
153+++ csrc/lib/dir.mk
154@@ -78,7 +78,7 @@ shlib: $(SHLIBNAME)
155 lib: libccn.a
156
157 test: default keystore_check encodedecodetest ccnbtreetest
158- ./encodedecodetest -o /dev/null
159+ ./encodedecodetest -k $(CCNX_DIR)/.ccnx_keystore -o /dev/null
160 ./ccnbtreetest
161 ./ccnbtreetest - < q.dat
162 rm -R _bt_*
163@@ -87,12 +87,12 @@ dtag_check: _always
164 @./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' || :
165
166 keystore_check: ccn_initkeystore.sh
167- test -f "$$HOME/.ccnx/.ccnx_keystore" || $(MAKE) -f dir.mk new_keystore
168+ test -f "$(CCNX_DIR)/.ccnx_keystore" || $(MAKE) -f dir.mk new_keystore
169
170 new_keystore:
171 @echo === CCNx Keystore not found in your home directory
172 @echo === I will create one for you now '(^C to abort)'
173- sleep 1 && sh ccn_initkeystore.sh && sleep 3 && mv .ccnx "$$HOME"
174+ sleep 1 && sh ccn_initkeystore.sh && sleep 3 && mkdir -p "$(CCNX_DIR)/" && mv .ccnx/.ccnx_keystore "$(CCNX_DIR)/"
175
176 libccn.a: $(LIB_OBJS)
177 ar crus $@ $(LIB_OBJS)
178@@ -113,7 +113,7 @@ skel_decode_test: skel_decode_test.o
179 basicparsetest: basicparsetest.o libccn.a
180 $(CC) $(CFLAGS) -o $@ basicparsetest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
181
182-encodedecodetest: encodedecodetest.o
183+encodedecodetest: encodedecodetest.o libccn.a
184 $(CC) $(CFLAGS) -o $@ encodedecodetest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
185
186 ccn_digest.o:
187@@ -149,16 +149,16 @@ ccn_fetch.o:
188 ccn_verifysig.o:
189 $(CC) $(CFLAGS) $(OPENSSL_CFLAGS) -c ccn_verifysig.c
190
191-ccn_verifysig: ccn_verifysig.o
192+ccn_verifysig: ccn_verifysig.o libccn.a
193 $(CC) $(CFLAGS) -o $@ ccn_verifysig.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
194
195 signbenchtest.o:
196 $(CC) $(CFLAGS) $(OPENSSL_CFLAGS) -c signbenchtest.c
197
198-signbenchtest: signbenchtest.o
199+signbenchtest: signbenchtest.o libccn.a
200 $(CC) $(CFLAGS) -o $@ signbenchtest.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto
201
202-ccndumppcap: ccndumppcap.o
203+ccndumppcap: ccndumppcap.o libccn.a
204 $(CC) $(CFLAGS) -o $@ ccndumppcap.o $(LDLIBS) $(OPENSSL_LIBS) -lcrypto -lpcap
205
206 ccnbtreetest.o:
207diff --git csrc/lib/encodedecodetest.c csrc/lib/encodedecodetest.c
208index be6a853..21b288b 100644
209--- csrc/lib/encodedecodetest.c
210+++ csrc/lib/encodedecodetest.c
211@@ -241,6 +241,7 @@ main (int argc, char *argv[]) {
212 strcat(keystore_name, keystore_suffix);
213 }
214
215+ printf ("\nWTF %s\n\n", keystore_name);
216 if (0 != ccn_keystore_init(keystore, keystore_name, "Th1s1sn0t8g00dp8ssw0rd.")) {
217 printf("Failed to initialize keystore\n");
218 exit(1);