1.1 --- a/db/safewords.py Wed May 06 12:59:35 2015 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,42 +0,0 @@
1.4 -#!/usr/bin/env python3
1.5 -
1.6 -from sqlite3 import connect
1.7 -from os import environ
1.8 -from argparse import ArgumentParser
1.9 -from re import sub
1.10 -
1.11 -try:
1.12 - environ["ALLUSERSPROFILE"]
1.13 -except KeyError:
1.14 - db_file = "/usr/local/share/pEp/system.db"
1.15 -else:
1.16 - db_file = environ["ALLUSERSPROFILE"] + r"\pEp\system.db"
1.17 -
1.18 -p = ArgumentParser(description="show safewords instead of hex fingerprint")
1.19 -p.add_argument('--db-path', '-d', type=str, default=db_file,
1.20 - help='path to pEp system db (default: ' + db_file + ')')
1.21 -p.add_argument('--lang', '-l', type=str, default="en",
1.22 - help='use dictionary for language LANG (default: en)')
1.23 -p.add_argument('--short', '-s', action='store_true',
1.24 - help='display the first 5 of the safewords')
1.25 -p.add_argument('hex', metavar="hex", type=str, nargs='+',
1.26 - help='hex values of fingerprint')
1.27 -
1.28 -args = p.parse_args()
1.29 -
1.30 -c = connect(args.db_path).cursor()
1.31 -hex_string = sub(r"\W", "", "".join(args.hex))
1.32 -
1.33 -def hex_word(s):
1.34 - n = min(20, len(s)) if args.short else len(s)
1.35 - for i in range(0, n, 4):
1.36 - yield s[i:i+4]
1.37 -
1.38 -r = []
1.39 -
1.40 -for arg in hex_word(hex_string):
1.41 - c.execute("select word from wordlist where id = {} and lang = lower('{}')".format(
1.42 - str(int(arg, 16)), args.lang))
1.43 - r.append(c.fetchall()[0][0])
1.44 -
1.45 -print(" ".join(r))
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/db/trustwords.py Wed May 06 13:00:38 2015 +0200
2.3 @@ -0,0 +1,42 @@
2.4 +#!/usr/bin/env python3
2.5 +
2.6 +from sqlite3 import connect
2.7 +from os import environ
2.8 +from argparse import ArgumentParser
2.9 +from re import sub
2.10 +
2.11 +try:
2.12 + environ["ALLUSERSPROFILE"]
2.13 +except KeyError:
2.14 + db_file = "/usr/local/share/pEp/system.db"
2.15 +else:
2.16 + db_file = environ["ALLUSERSPROFILE"] + r"\pEp\system.db"
2.17 +
2.18 +p = ArgumentParser(description="show trustwords instead of hex fingerprint")
2.19 +p.add_argument('--db-path', '-d', type=str, default=db_file,
2.20 + help='path to pEp system db (default: ' + db_file + ')')
2.21 +p.add_argument('--lang', '-l', type=str, default="en",
2.22 + help='use dictionary for language LANG (default: en)')
2.23 +p.add_argument('--short', '-s', action='store_true',
2.24 + help='display the first 5 of the trustwords')
2.25 +p.add_argument('hex', metavar="hex", type=str, nargs='+',
2.26 + help='hex values of fingerprint')
2.27 +
2.28 +args = p.parse_args()
2.29 +
2.30 +c = connect(args.db_path).cursor()
2.31 +hex_string = sub(r"\W", "", "".join(args.hex))
2.32 +
2.33 +def hex_word(s):
2.34 + n = min(20, len(s)) if args.short else len(s)
2.35 + for i in range(0, n, 4):
2.36 + yield s[i:i+4]
2.37 +
2.38 +r = []
2.39 +
2.40 +for arg in hex_word(hex_string):
2.41 + c.execute("select word from wordlist where id = {} and lang = lower('{}')".format(
2.42 + str(int(arg, 16)), args.lang))
2.43 + r.append(c.fetchall()[0][0])
2.44 +
2.45 +print(" ".join(r))
3.1 --- a/src/pgp_netpgp.c Wed May 06 12:59:35 2015 +0200
3.2 +++ b/src/pgp_netpgp.c Wed May 06 13:00:38 2015 +0200
3.3 @@ -523,10 +523,10 @@
3.4 if(*str == NULL)
3.5 return 0;
3.6
3.7 - for (n = 0, i = 0 ; i < length - 1; i += 2) {
3.8 - n += snprintf(&((*str)[n]), 6, "%02x%02x ", *fpr++, *fpr++);
3.9 + for (n = 0, i = 0 ; i < length - 2; i += 2) {
3.10 + n += snprintf(&((*str)[n]), 6, "%02x%02x ", fpr[i], fpr[i+1]);
3.11 }
3.12 - snprintf(&((*str)[n]), 5, "%02x%02x", *fpr++, *fpr++);
3.13 + snprintf(&((*str)[n]), 5, "%02x%02x", fpr[i], fpr[i+1]);
3.14
3.15 return 1;
3.16 }
3.17 @@ -542,9 +542,10 @@
3.18 while (*str == ' ') str++;
3.19 for (j = 0; j < 2; j++) {
3.20 uint8_t *byte = &fpr[*length];
3.21 + *byte = 0;
3.22 for (i = 0; i < 2; i++) {
3.23 if (i > 0)
3.24 - *byte *= 16;
3.25 + *byte = *byte << 4;
3.26 if (*str >= 'a' && *str <= 'f')
3.27 *byte += 10 + *str - 'a';
3.28 else if (*str >= 'A' && *str <= 'F')
3.29 @@ -555,7 +556,7 @@
3.30 return 0;
3.31 str++;
3.32 }
3.33 - *length++;
3.34 + (*length)++;
3.35 }
3.36 }
3.37 return 1;
3.38 @@ -565,11 +566,13 @@
3.39 pgp_key_t pubkey;
3.40 unsigned public;
3.41 PEP_STATUS result;
3.42 +
3.43
3.44 if ((public = (newkey->type == PGP_PTAG_CT_PUBLIC_KEY))){
3.45 pubkey = *newkey;
3.46 } else {
3.47 // Duplicate key as public only
3.48 + bzero(&pubkey, sizeof(pubkey));
3.49 if (!pgp_keydata_dup(&pubkey, newkey, 1 /* make_public */)){
3.50 return PEP_OUT_OF_MEMORY;
3.51 }
3.52 @@ -613,7 +616,6 @@
3.53 {
3.54 netpgp_t *netpgp;
3.55 pgp_key_t newkey;
3.56 - pgp_key_t pubkey;
3.57
3.58 PEP_STATUS result;
3.59 char newid[1024];
3.60 @@ -642,7 +644,6 @@
3.61 cipher = netpgp_getvar(netpgp, "cipher");
3.62
3.63 bzero(&newkey, sizeof(newkey));
3.64 - bzero(&pubkey, sizeof(pubkey));
3.65
3.66 // Generate the key
3.67 if (!pgp_rsa_generate_keypair(&newkey, 4096, 65537UL, hashalg, cipher,
3.68 @@ -696,23 +697,21 @@
3.69 netpgp = &session->ctx;
3.70
3.71 if (str_to_fpr(fprstr, fpr, &length)) {
3.72 - if (!pgp_deletekeybyfpr(netpgp->io,
3.73 + unsigned insec = pgp_deletekeybyfpr(netpgp->io,
3.74 (pgp_keyring_t *)netpgp->secring,
3.75 - (const uint8_t *)fpr, length)) {
3.76 - return PEP_KEY_NOT_FOUND;
3.77 + (const uint8_t *)fpr, length);
3.78 + unsigned inpub = pgp_deletekeybyfpr(netpgp->io,
3.79 + (pgp_keyring_t *)netpgp->pubring,
3.80 + (const uint8_t *)fpr, length);
3.81 + if(!insec && !inpub){
3.82 + result = PEP_KEY_NOT_FOUND;
3.83 + } else {
3.84 + result = PEP_STATUS_OK;
3.85 }
3.86 }else{
3.87 return PEP_OUT_OF_MEMORY;
3.88 }
3.89
3.90 - /* pair was found in secring delete also corresponding pubkey
3.91 - * in pubring if it exists */
3.92 - if(res) {
3.93 - pgp_deletekeybyfpr(netpgp->io,
3.94 - (pgp_keyring_t *)netpgp->pubring,
3.95 - (const uint8_t *)fpr, length);
3.96 - }
3.97 -
3.98 // save rings (key ownership transfered)
3.99 if (netpgp_save_pubring(netpgp) &&
3.100 netpgp_save_secring(netpgp))
3.101 @@ -749,6 +748,8 @@
3.102 }
3.103 pgp_memory_add(mem, (const uint8_t*)key_data, size);
3.104
3.105 + bzero(&tmpring, sizeof(tmpring));
3.106 +
3.107 if (pgp_keyring_read_from_mem(netpgp->io, &tmpring,
3.108 _armoured(key_data, size, ARMOR_KEY_HEAD),
3.109 mem) == 0){
3.110 @@ -764,7 +765,9 @@
3.111
3.112 pgp_memory_free(mem);
3.113
3.114 - if (result != PEP_STATUS_OK){
3.115 + if (result == PEP_STATUS_OK){
3.116 + pgp_keyring_free(&tmpring);
3.117 + }else{
3.118 pgp_keyring_purge(&tmpring);
3.119 }
3.120
3.121 @@ -787,13 +790,13 @@
3.122 size_t buflen;
3.123
3.124 assert(session);
3.125 - assert(fpr);
3.126 + assert(fprstr);
3.127 assert(key_data);
3.128 assert(size);
3.129
3.130 netpgp = &session->ctx;
3.131
3.132 - if (!session || !fpr || !key_data || !size)
3.133 + if (!session || !fprstr || !key_data || !size)
3.134 return PEP_UNKNOWN_ERROR;
3.135
3.136 if (str_to_fpr(fprstr, fpr, &fprlen)) {
4.1 --- a/test/pEpEngineTest.cc Wed May 06 12:59:35 2015 +0200
4.2 +++ b/test/pEpEngineTest.cc Wed May 06 13:00:38 2015 +0200
4.3 @@ -202,6 +202,7 @@
4.4
4.5 cout << "export_key()\n\n";
4.6 PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
4.7 + cout << "export_key() exits with " << export_status << "\n";
4.8 assert(export_status == PEP_STATUS_OK);
4.9 cout << key_data << "\n\n";
4.10