Skip to content

Commit 6d293c1

Browse files
committed
- opmsg: allow to selfsign generated personas, so peer can also --decrypt it and check sig
1 parent feb5317 commit 6d293c1

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

src/opmsg.cc

+39-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum {
7777
};
7878

7979

80-
const string banner = "\nopmsg: version=1.76 -- (C) 2017 opmsg-team: https://github.com/stealth/opmsg\n\n";
80+
const string banner = "\nopmsg: version=1.77 -- (C) 2017 opmsg-team: https://github.com/stealth/opmsg\n\n";
8181

8282
/* The iostream lib works not very well wrt customized buffering and flushing
8383
* (unlike C's setbuffer), so we use string streams and flush ourself when we need to.
@@ -582,7 +582,7 @@ int do_verify(const string &verify_file)
582582
}
583583

584584

585-
int do_newpersona(const string &name, const string &type)
585+
int do_newpersona(const string &name, const string &type, bool sign)
586586
{
587587
keystore ks(config::phash, config::cfgbase);
588588

@@ -621,11 +621,35 @@ int do_newpersona(const string &name, const string &type)
621621
estr<<" --deniable";
622622
estr<<"\n\n";
623623
eflush();
624+
624625
ostr<<pub;
625626
if (config::deniable)
626627
ostr<<priv;
628+
629+
// (self-)sign output data shown to user with the freshly generated persona;
630+
// output can be --imported and verified via --decrypt
631+
if (sign) {
632+
string s = ostr.str();
633+
message msg(config::version, config::cfgbase, config::phash, config::khash, config::shash, "null");
634+
msg.src_id(p->get_id());
635+
msg.dst_id(p->get_id());
636+
637+
if (p->get_type() == marker::ec)
638+
msg.kex_id(marker::ec_kex_id);
639+
else
640+
msg.kex_id(marker::rsa_kex_id);
641+
642+
if (msg.encrypt(s, p, p) < 0) {
643+
estr<<prefix<<"ERROR: Signing freshly generated persona key: "<<msg.why()<<endl; eflush();
644+
return -1;
645+
}
646+
ostr.str("");
647+
ostr<<s;
648+
}
649+
627650
ostr<<endl;
628651
oflush();
652+
629653
estr<<prefix<<"Check (by phone, otr, twitter, id-selfie etc.) that above id matches\n";
630654
estr<<prefix<<"the import message from your peer.\n";
631655
estr<<prefix<<"AFTER THAT, you can go ahead, safely exchanging op-messages.\n\n";
@@ -634,15 +658,15 @@ int do_newpersona(const string &name, const string &type)
634658
}
635659

636660

637-
int do_new_rsa_persona(const string &name)
661+
int do_new_rsa_persona(const string &name, bool sign)
638662
{
639-
return do_newpersona(name, marker::rsa);
663+
return do_newpersona(name, marker::rsa, sign);
640664
}
641665

642666

643-
int do_new_ec_persona(const string &name)
667+
int do_new_ec_persona(const string &name, bool sign)
644668
{
645-
return do_newpersona(name, marker::ec);
669+
return do_newpersona(name, marker::ec, sign);
646670
}
647671

648672

@@ -995,7 +1019,7 @@ int main(int argc, char **argv)
9951019
cmode = CMODE_DECRYPT;
9961020
break;
9971021
case 'S':
998-
cmode = CMODE_SIGN;
1022+
cmode |= CMODE_SIGN;
9991023
break;
10001024
case 'P':
10011025
config::my_id = optarg;
@@ -1005,7 +1029,7 @@ int main(int argc, char **argv)
10051029
verify_file = optarg;
10061030
break;
10071031
case 'N':
1008-
cmode = CMODE_NEWP;
1032+
cmode |= CMODE_NEWP;
10091033
break;
10101034
case 'I':
10111035
cmode = CMODE_IMPORT;
@@ -1029,7 +1053,7 @@ int main(int argc, char **argv)
10291053
cmode = CMODE_NEWDHP;
10301054
break;
10311055
case NEWECP:
1032-
cmode = CMODE_NEWECP;
1056+
cmode |= CMODE_NEWECP;
10331057
break;
10341058
case ID_FORMAT_LONG:
10351059
config::idformat = "long";
@@ -1130,16 +1154,18 @@ int main(int argc, char **argv)
11301154
r = do_verify(verify_file);
11311155
break;
11321156
case CMODE_NEWP:
1157+
case CMODE_NEWP|CMODE_SIGN:
11331158
estr<<prefix<<"creating new persona (RSA "<<config::rsa_len<<", DH "<<config::dh_plen<<")\n\n"; eflush();
1134-
r = do_new_rsa_persona(name);
1159+
r = do_new_rsa_persona(name, (cmode & CMODE_SIGN) == CMODE_SIGN);
11351160
break;
11361161
case CMODE_NEWDHP:
11371162
estr<<prefix<<"creating new DHparams for persona "<<idformat(config::my_id)<<"\n\n"; eflush();
11381163
r = do_newdhparams();
11391164
break;
11401165
case CMODE_NEWECP:
1166+
case CMODE_NEWECP|CMODE_SIGN:
11411167
estr<<prefix<<"creating new EC persona (curve "<<config::curves[0]<<")\n\n"; eflush();
1142-
r = do_new_ec_persona(name);
1168+
r = do_new_ec_persona(name, (cmode & CMODE_SIGN) == CMODE_SIGN);
11431169
break;
11441170
case CMODE_IMPORT:
11451171
estr<<prefix<<"importing persona\n"; eflush();
@@ -1156,6 +1182,8 @@ int main(int argc, char **argv)
11561182
case CMODE_PGPLIST:
11571183
r = do_pgplist(name);
11581184
break;
1185+
default:
1186+
estr<<prefix<<"Invalid combination of options?\n";
11591187
}
11601188

11611189
if (cmode != CMODE_PGPLIST) {

0 commit comments

Comments
 (0)