Skip to content

Commit 8270119

Browse files
committed
x/crypto/otr: update libotr test code for version 4.
The test for this package contains a test case (disabled by default) that exercises the code against libotr (the reference implementation). Since that test was written, libotr has updated to version 4 which contains non-backwards-compatible API changes. This change updates the test harness for version 4 of libotr. Change-Id: Ib40c899c609cc827903ae18fd80476d179bf0a33 Reviewed-on: https://go-review.googlesource.com/16936 Reviewed-by: Andrew Gerrand <adg@golang.org>
1 parent fb90bd2 commit 8270119

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

otr/libotr_test_helper.c

+35-28
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <proto.h>
1515
#include <message.h>
16+
#include <privkey.h>
1617

1718
static int g_session_established = 0;
1819

@@ -30,25 +31,9 @@ void inject_message(void *opdata, const char *accountname, const char *protocol,
3031
fprintf(stderr, "libotr helper sent: %s\n", message);
3132
}
3233

33-
void notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary) {
34-
fprintf(stderr, "NOTIFY: %s %s %s %s\n", username, title, primary, secondary);
35-
}
36-
37-
int display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg) {
38-
fprintf(stderr, "MESSAGE: %s %s\n", username, msg);
39-
return 1;
40-
}
41-
4234
void update_context_list(void *opdata) {
4335
}
4436

45-
const char *protocol_name(void *opdata, const char *protocol) {
46-
return "PROTOCOL";
47-
}
48-
49-
void protocol_name_free(void *opdata, const char *protocol_name) {
50-
}
51-
5237
void new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]) {
5338
fprintf(stderr, "NEW FINGERPRINT\n");
5439
g_session_established = 1;
@@ -66,10 +51,6 @@ void gone_insecure(void *opdata, ConnContext *context) {
6651
void still_secure(void *opdata, ConnContext *context, int is_reply) {
6752
}
6853

69-
void log_message(void *opdata, const char *message) {
70-
fprintf(stderr, "MESSAGE: %s\n", message);
71-
}
72-
7354
int max_message_size(void *opdata, ConnContext *context) {
7455
return 99999;
7556
}
@@ -81,25 +62,48 @@ const char *account_name(void *opdata, const char *account, const char *protocol
8162
void account_name_free(void *opdata, const char *account_name) {
8263
}
8364

65+
const char *error_message(void *opdata, ConnContext *context, OtrlErrorCode err_code) {
66+
return "ERR";
67+
}
68+
69+
void error_message_free(void *opdata, const char *msg) {
70+
}
71+
72+
void resent_msg_prefix_free(void *opdata, const char *prefix) {
73+
}
74+
75+
void handle_smp_event(void *opdata, OtrlSMPEvent smp_event, ConnContext *context, unsigned short progress_event, char *question) {
76+
}
77+
78+
void handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) {
79+
fprintf(stderr, "msg event: %d %s\n", msg_event, message);
80+
}
81+
8482
OtrlMessageAppOps uiops = {
8583
policy,
8684
NULL,
8785
is_logged_in,
8886
inject_message,
89-
notify,
90-
display_otr_message,
9187
update_context_list,
92-
protocol_name,
93-
protocol_name_free,
9488
new_fingerprint,
9589
write_fingerprints,
9690
gone_secure,
9791
gone_insecure,
9892
still_secure,
99-
log_message,
10093
max_message_size,
10194
account_name,
10295
account_name_free,
96+
NULL, /* received_symkey */
97+
error_message,
98+
error_message_free,
99+
NULL, /* resent_msg_prefix */
100+
resent_msg_prefix_free,
101+
handle_smp_event,
102+
handle_msg_event,
103+
NULL /* create_instag */,
104+
NULL /* convert_msg */,
105+
NULL /* convert_free */,
106+
NULL /* timer_control */,
103107
};
104108

105109
static const char kPrivateKeyData[] = "(privkeys (account (name \"account\") (protocol proto) (private-key (dsa (p #00FC07ABCF0DC916AFF6E9AE47BEF60C7AB9B4D6B2469E436630E36F8A489BE812486A09F30B71224508654940A835301ACC525A4FF133FC152CC53DCC59D65C30A54F1993FE13FE63E5823D4C746DB21B90F9B9C00B49EC7404AB1D929BA7FBA12F2E45C6E0A651689750E8528AB8C031D3561FECEE72EBB4A090D450A9B7A857#) (q #00997BD266EF7B1F60A5C23F3A741F2AEFD07A2081#) (g #535E360E8A95EBA46A4F7DE50AD6E9B2A6DB785A66B64EB9F20338D2A3E8FB0E94725848F1AA6CC567CB83A1CC517EC806F2E92EAE71457E80B2210A189B91250779434B41FC8A8873F6DB94BEA7D177F5D59E7E114EE10A49CFD9CEF88AE43387023B672927BA74B04EB6BBB5E57597766A2F9CE3857D7ACE3E1E3BC1FC6F26#) (y #0AC8670AD767D7A8D9D14CC1AC6744CD7D76F993B77FFD9E39DF01E5A6536EF65E775FCEF2A983E2A19BD6415500F6979715D9FD1257E1FE2B6F5E1E74B333079E7C880D39868462A93454B41877BE62E5EF0A041C2EE9C9E76BD1E12AE25D9628DECB097025DD625EF49C3258A1A3C0FF501E3DC673B76D7BABF349009B6ECF#) (x #14D0345A3562C480A039E3C72764F72D79043216#)))))\n";
@@ -142,7 +146,7 @@ main() {
142146

143147
char *newmessage = NULL;
144148
OtrlTLV *tlvs;
145-
int ignore_message = otrl_message_receiving(userstate, &uiops, NULL, "account", "proto", "peer", message, &newmessage, &tlvs, NULL, NULL);
149+
int ignore_message = otrl_message_receiving(userstate, &uiops, NULL, "account", "proto", "peer", message, &newmessage, &tlvs, NULL, NULL, NULL);
146150
if (tlvs) {
147151
otrl_tlv_free(tlvs);
148152
}
@@ -154,16 +158,19 @@ main() {
154158
gcry_error_t err;
155159
char *newmessage = NULL;
156160

157-
err = otrl_message_sending(userstate, &uiops, NULL, "account", "proto", "peer", "test message", NULL, &newmessage, NULL, NULL);
161+
err = otrl_message_sending(userstate, &uiops, NULL, "account", "proto", "peer", 0, "test message", NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL);
158162
if (newmessage == NULL) {
159163
fprintf(stderr, "libotr didn't encrypt message\n");
160164
return 1;
161165
}
162166
write(1, newmessage, strlen(newmessage));
163167
write(1, "\n", 1);
164-
g_session_established = 0;
168+
fprintf(stderr, "libotr sent: %s\n", newmessage);
165169
otrl_message_free(newmessage);
170+
171+
g_session_established = 0;
166172
write(1, "?OTRv2?\n", 8);
173+
fprintf(stderr, "libotr sent: ?OTRv2\n");
167174
}
168175
}
169176

0 commit comments

Comments
 (0)