blob: 7ca9b074a481e579f1dab01cb2bfa5730bd595a2 [file] [log] [blame]
Alexander Afanasyev9944ebc2012-08-20 18:40:12 -07001diff --git csrc/lib/ccn_client.c csrc/lib/ccn_client.c
2index 606fd36..2642e0c 100644
3--- csrc/lib/ccn_client.c
4+++ csrc/lib/ccn_client.c
5@@ -2435,6 +2435,7 @@ ccn_load_private_key(struct ccn *h,
6 res = NOTE_ERRNO(h);
7 goto Cleanup;
8 }
9+ printf (">>> load_private_key: [%s]\n", keystore_path);
10 res = ccn_keystore_init(keystore,
11 (char *)keystore_path,
12 (char *)keystore_passphrase);
13@@ -2487,6 +2488,7 @@ ccn_load_default_key(struct ccn *h,
14 if (h->default_pubid != NULL)
15 return(NOTE_ERR(h, EINVAL));
16 default_pubid = ccn_charbuf_create();
17+ printf ("Tring to open keystore [%s]\n", keystore_path);
18 res = ccn_load_private_key(h,
19 keystore_path,
20 keystore_passphrase,
21@@ -2607,23 +2609,55 @@ ccn_chk_signing_params(struct ccn *h,
22 temp = ccn_charbuf_create();
23 if (default_pubid == NULL || temp == NULL)
24 return(NOTE_ERRNO(h));
25- ccnx_dir = getenv("CCNX_DIR");
26- if (ccnx_dir == NULL || ccnx_dir[0] == 0) {
27- home = getenv("HOME");
28- if (home == NULL)
29- home = "";
30- ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", home);
31+
32+ res = -1;
33+#ifdef CCNX_DIR
34+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
35+ // check preconfigured directory
36+ ccnx_dir = CCNX_DIR;
37+ if (ccnx_dir != NULL && ccnx_dir[0] != 0) {
38+ ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
39+
40+ res = ccn_load_private_key(h,
41+ ccn_charbuf_as_string(temp),
42+ "Th1s1sn0t8g00dp8ssw0rd.",
43+ default_pubid);
44+ }
45 }
46- else
47+#endif
48+
49+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
50+ // check CCNX_DIR
51+ ccnx_dir = getenv("CCNX_DIR");
52+ if (ccnx_dir != NULL && ccnx_dir[0] != 0) {
53 ccn_charbuf_putf(temp, "%s/.ccnx_keystore", ccnx_dir);
54- res = ccn_load_private_key(h,
55- ccn_charbuf_as_string(temp),
56- "Th1s1sn0t8g00dp8ssw0rd.",
57- default_pubid);
58+
59+ res = ccn_load_private_key(h,
60+ ccn_charbuf_as_string(temp),
61+ "Th1s1sn0t8g00dp8ssw0rd.",
62+ default_pubid);
63+ }
64+ }
65+
66+ if (res < 0 || default_pubid->length != sizeof(result->pubid)) {
67+ // check HOME
68+ home = getenv("HOME");
69+ if (home != NULL) {
70+ ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", home);
71+ res = ccn_load_private_key(h,
72+ ccn_charbuf_as_string(temp),
73+ "Th1s1sn0t8g00dp8ssw0rd.",
74+ default_pubid);
75+ }
76+ }
77+
78 if (res == 0 && default_pubid->length == sizeof(result->pubid)) {
79 h->default_pubid = default_pubid;
80 default_pubid = NULL;
81 }
82+ else {
83+ ccn_perror(h, ccn_charbuf_as_string(temp));
84+ }
85 }
86 if (h->default_pubid == NULL)
87 res = NOTE_ERRNO(h);