annotate src/auth/mech-rpa.c @ 2915:25bc79e67271 HEAD

Initial response support for NTLM and RPA. Patch by Andrey Panin.
author Timo Sirainen <tss@iki.fi>
date Mon, 29 Nov 2004 04:30:14 +0200
parents e44a84dc947c
children 052f3a5743af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /*
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 * Compuserve RPA authentication mechanism.
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 *
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 *
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 * it under the terms of the GNU Lesser General Public License as published
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 * by the Free Software Foundation; either version 2 of the License, or
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 * (at your option) any later version.
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "common.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "mech.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "passdb.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "str.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include "strfuncs.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "safe-memset.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include "randgen.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #include "buffer.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include "hostpid.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #include "hex-binary.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 #include "md5.h"
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 struct rpa_auth_request {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct auth_request auth_request;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 pool_t pool;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 int phase;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 /* cached: */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 unsigned char *pwd_md5;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 size_t service_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 const unsigned char *service_ucs2be;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 size_t username_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 const unsigned char *username_ucs2be;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 size_t realm_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 const unsigned char *realm_ucs2be;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 /* requested: */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 unsigned char *service_challenge;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 unsigned char *service_timestamp;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 /* received: */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 unsigned int user_challenge_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 unsigned char *user_challenge;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 unsigned char *user_response;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 unsigned char *session_key;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 };
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 #define RPA_SCHALLENGE_LEN 32
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 #define RPA_UCHALLENGE_LEN 16
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 #define RPA_TIMESTAMP_LEN 14
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 #define ASN1_APPLICATION 0x60
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 /* Object id encoded using ASN.1 DER */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 static const unsigned char rpa_oid[] = {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x73, 0x01, 0x01
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 };
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 void *ucs2be_str(pool_t pool, const char *str, size_t *size);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 /*
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 * Compute client -> server authentication response.
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
67 static void rpa_user_response(struct rpa_auth_request *request,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 unsigned char *digest)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 struct md5_context ctx;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 unsigned char z[48];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 memset(z, 0, sizeof(z));
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 md5_init(&ctx);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
76 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 md5_update(&ctx, z, sizeof(z));
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
78 md5_update(&ctx, request->username_ucs2be, request->username_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
79 md5_update(&ctx, request->service_ucs2be, request->service_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
80 md5_update(&ctx, request->realm_ucs2be, request->realm_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
81 md5_update(&ctx, request->user_challenge, request->user_challenge_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
82 md5_update(&ctx, request->service_challenge, RPA_SCHALLENGE_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
83 md5_update(&ctx, request->service_timestamp, RPA_TIMESTAMP_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
84 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 md5_final(&ctx, digest);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 /*
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 * Compute server -> client authentication response.
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
91 static void rpa_server_response(struct rpa_auth_request *request,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 unsigned char *digest)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 struct md5_context ctx;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 unsigned char tmp[16];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 unsigned char z[48];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 int i;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 memset(z, 0, sizeof(z));
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 md5_init(&ctx);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
102 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 md5_update(&ctx, z, sizeof(z));
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
104 md5_update(&ctx, request->service_ucs2be, request->service_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
105 md5_update(&ctx, request->username_ucs2be, request->username_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
106 md5_update(&ctx, request->realm_ucs2be, request->realm_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
107 md5_update(&ctx, request->service_challenge, RPA_SCHALLENGE_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
108 md5_update(&ctx, request->user_challenge, request->user_challenge_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
109 md5_update(&ctx, request->service_timestamp, RPA_TIMESTAMP_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
110 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 md5_final(&ctx, tmp);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 for (i = 0; i < 16; i++)
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
114 tmp[i] = request->session_key[i] ^ tmp[i];
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 md5_init(&ctx);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
117 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 md5_update(&ctx, z, sizeof(z));
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
119 md5_update(&ctx, request->service_ucs2be, request->service_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
120 md5_update(&ctx, request->username_ucs2be, request->username_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
121 md5_update(&ctx, request->realm_ucs2be, request->realm_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
122 md5_update(&ctx, request->session_key, 16);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
123 md5_update(&ctx, request->service_challenge, RPA_SCHALLENGE_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
124 md5_update(&ctx, request->user_challenge, request->user_challenge_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
125 md5_update(&ctx, request->service_timestamp, RPA_TIMESTAMP_LEN);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 md5_update(&ctx, tmp, 16);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
127 md5_update(&ctx, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 md5_final(&ctx, digest);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 static const unsigned char *
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 rpa_check_message(const unsigned char *data, const unsigned char *end,
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
133 const char **error)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 const unsigned char *p = data;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 unsigned int len = 0;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 if (p + 2 > end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 *error = "message too short";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 if (*p++ != ASN1_APPLICATION) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 *error = "invalid data type";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 if ((*p & 0x80) != 0) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 unsigned int nbytes = *p++ & 0x7f;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 while (nbytes-- > 0) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 if (p >= end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 *error = "invalid structure length";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 len = (len << 8) | *p++;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 } else
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 len = *p++;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 if ((size_t)(end - p) != len) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 *error = "structure length disagrees with data size";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 if (p + sizeof(rpa_oid) > end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 *error = "not enough space for object id";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 if (memcmp(p, rpa_oid, sizeof(rpa_oid)) != 0) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 *error = "invalid object id";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 return NULL;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 return p + sizeof(rpa_oid);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 static int
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
181 rpa_parse_token1(const void *data, size_t data_size, const char **error)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 const unsigned char *end = ((unsigned char *) data) + data_size;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 const unsigned char *p;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 unsigned int version_lo, version_hi;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 p = rpa_check_message(data, end, error);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 if (p == NULL)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 if (p + 6 > end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 *error = "message too short";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 version_lo = p[0] + (p[1] << 8);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 version_hi = p[2] + (p[3] << 8);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 if ((version_lo > 3) || (version_hi < 3)) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 *error = "protocol version mismatch";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 p += 4;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 if ((p[0] != 0) || (p[1] != 1)) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 *error = "invalid message flags";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 p += 2;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 if (p != end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 *error = "unneeded data found";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 return TRUE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 static unsigned int
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 rpa_read_buffer(pool_t pool, const unsigned char **data,
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 const unsigned char *end, unsigned char **buffer)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 const unsigned char *p = *data;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 unsigned int len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 if (p > end)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 return 0;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 len = *p++;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 if (p + len > end)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 return 0;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 *buffer = p_malloc(pool, len);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 memcpy(*buffer, p, len);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 *data += 1 + len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 return len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 static char *
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 rpa_parse_username(pool_t pool, const char *username)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 const char *p = strrchr(username, '@');
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 return p == NULL ? p_strdup(pool, username) :
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 p_strdup_until(pool, username, p);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 static int
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
251 rpa_parse_token3(struct rpa_auth_request *request, const void *data,
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
252 size_t data_size, const char **error)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
254 struct auth_request *auth_request = &request->auth_request;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 const unsigned char *end = ((unsigned char *)data) + data_size;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 const unsigned char *p;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 unsigned int len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 const char *user;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 p = rpa_check_message(data, end, error);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 if (p == NULL)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 /* Read username@realm */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 if (p + 2 > end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 *error = "message too short";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 len = (p[0] >> 8) + p[1];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 if (p + 2 + len > end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 *error = "message too short";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 p += 2;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 user = t_strndup(p, len);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 p += len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
280 auth_request->user = rpa_parse_username(request->pool, user);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
282 request->username_ucs2be = ucs2be_str(request->pool, auth_request->user,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
283 &request->username_len);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 /* Read user challenge */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
286 request->user_challenge_len = rpa_read_buffer(request->pool, &p, end,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
287 &request->user_challenge);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
288 if (request->user_challenge_len == 0) {
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 *error = "invalid user challenge";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 /* Read user response */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
294 len = rpa_read_buffer(request->pool, &p, end, &request->user_response);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 if (len != RPA_UCHALLENGE_LEN) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 *error = "invalid user response";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 if (p != end) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 *error = "unneeded data found";
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 return FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 return TRUE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 static void
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 buffer_append_asn1_length(buffer_t *buf, unsigned int length)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 if (length < 0x80) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 buffer_append_c(buf, length);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 } else if (length < 0x100) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 buffer_append_c(buf, 0x81);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 buffer_append_c(buf, length);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 } else {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 buffer_append_c(buf, 0x82);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 buffer_append_c(buf, length >> 8);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 buffer_append_c(buf, length & 0xff);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322
2629
6ba9dcff11b9 Compiler warning fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
323 static const unsigned char *
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
324 mech_rpa_build_token2(struct rpa_auth_request *request,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 const char *realms, size_t *size)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 unsigned int realms_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 unsigned int length;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 buffer_t *buf;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 unsigned char timestamp[RPA_TIMESTAMP_LEN / 2];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
331
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 realms_len = strlen(realms);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 length = sizeof(rpa_oid) + 3 + RPA_SCHALLENGE_LEN +
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 RPA_TIMESTAMP_LEN + 2 + realms_len;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
336 buf = buffer_create_dynamic(request->pool, length + 4);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 buffer_append_c(buf, ASN1_APPLICATION);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 buffer_append_asn1_length(buf, length);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 buffer_append(buf, rpa_oid, sizeof(rpa_oid));
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 /* Protocol version */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 buffer_append_c(buf, 3);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 buffer_append_c(buf, 0);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 /* Service challenge */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
347 request->service_challenge =
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
348 p_malloc(request->pool, RPA_SCHALLENGE_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
349 random_fill(request->service_challenge, RPA_SCHALLENGE_LEN);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 buffer_append_c(buf, RPA_SCHALLENGE_LEN);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
351 buffer_append(buf, request->service_challenge, RPA_SCHALLENGE_LEN);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 /* Timestamp, looks like clients accept anything we send */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 random_fill(timestamp, sizeof(timestamp));
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
355 request->service_timestamp = p_malloc(request->pool, RPA_TIMESTAMP_LEN);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
356 memcpy(request->service_timestamp,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
357 binary_to_hex(timestamp, sizeof(timestamp)),
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 RPA_TIMESTAMP_LEN);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
359 buffer_append(buf, request->service_timestamp, RPA_TIMESTAMP_LEN);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361 /* Realm list */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 buffer_append_c(buf, realms_len >> 8);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 buffer_append_c(buf, realms_len & 0xff);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 buffer_append(buf, realms, realms_len);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 *size = buffer_get_used_size(buf);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 return buffer_free_without_data(buf);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369
2629
6ba9dcff11b9 Compiler warning fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2522
diff changeset
370 static const unsigned char *
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
371 mech_rpa_build_token4(struct rpa_auth_request *request, size_t *size)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 unsigned int length = sizeof(rpa_oid) + 17 + 17 + 1;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 buffer_t *buf;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 unsigned char server_response[16];
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
377 buf = buffer_create_dynamic(request->pool, length + 4);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 buffer_append_c(buf, ASN1_APPLICATION);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 buffer_append_asn1_length(buf, length);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 buffer_append(buf, rpa_oid, sizeof(rpa_oid));
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 /* Generate random session key */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
384 request->session_key = p_malloc(request->pool, 16);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
385 random_fill(request->session_key, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 /* Server authentication response */
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
388 rpa_server_response(request, server_response);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 buffer_append_c(buf, 16);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 buffer_append(buf, server_response, 16);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 buffer_append_c(buf, 16);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
393 buffer_append(buf, request->session_key, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 /* Status, 0 - success */
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 buffer_append_c(buf, 0);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 *size = buffer_get_used_size(buf);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 return buffer_free_without_data(buf);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 static void
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 rpa_credentials_callback(const char *credentials,
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 struct auth_request *auth_request)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
406 struct rpa_auth_request *request =
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407 (struct rpa_auth_request *)auth_request;
2764
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
408 unsigned char response[16];
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 buffer_t *hash_buffer;
2764
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
410 const unsigned char *token4;
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
411 size_t token4_size;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412
2764
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
413 if (credentials == NULL) {
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
414 mech_auth_finish(auth_request, NULL, 0, FALSE);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 return;
2764
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
416 }
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
418 request->pwd_md5 = p_malloc(request->pool, 16);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
419 hash_buffer = buffer_create_data(request->pool, request->pwd_md5, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 hex_to_binary(credentials, hash_buffer);
2764
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
421
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
422 rpa_user_response(request, response);
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
423 if (memcmp(response, request->user_response, 16) != 0) {
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
424 mech_auth_finish(auth_request, NULL, 0, FALSE);
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
425 return;
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
426 }
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
427
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
428 token4 = mech_rpa_build_token4(request, &token4_size);
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
429 auth_request->callback(auth_request, AUTH_CLIENT_RESULT_CONTINUE,
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
430 token4, token4_size);
3cc4ebb5f42d Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents: 2736
diff changeset
431 request->phase = 2;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
434 static void
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 mech_rpa_auth_phase1(struct auth_request *auth_request,
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
436 const unsigned char *data, size_t data_size)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
438 struct rpa_auth_request *request =
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 (struct rpa_auth_request *)auth_request;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 const unsigned char *token2;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 size_t token2_size;
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
442 const char *service, *error;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 if (!rpa_parse_token1(data, data_size, &error)) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 if (verbose) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 i_info("rpa(%s): invalid token 1, %s",
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 get_log_prefix(auth_request), error);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 mech_auth_finish(auth_request, NULL, 0, FALSE);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
450 return;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452
2781
e44a84dc947c s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents: 2764
diff changeset
453 service = t_str_lcase(auth_request->service);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
455 token2 = mech_rpa_build_token2(request, t_strconcat(service, "@",
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 my_hostname, NULL), &token2_size);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
458 request->service_ucs2be = ucs2be_str(request->pool, service,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
459 &request->service_len);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
460 request->realm_ucs2be = ucs2be_str(request->pool, my_hostname,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
461 &request->realm_len);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
463 auth_request->callback(auth_request, AUTH_CLIENT_RESULT_CONTINUE,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
464 token2, token2_size);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
465 request->phase = 1;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
468 static void
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 mech_rpa_auth_phase2(struct auth_request *auth_request,
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
470 const unsigned char *data, size_t data_size)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
472 struct rpa_auth_request *request =
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 (struct rpa_auth_request *)auth_request;
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
474 const char *error;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
476 if (!rpa_parse_token3(request, data, data_size, &error)) {
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 if (verbose) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 i_info("rpa(%s): invalid token 3, %s",
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 get_log_prefix(auth_request), error);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 mech_auth_finish(auth_request, NULL, 0, FALSE);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
482 return;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
485 if (!mech_fix_username(auth_request->user, &error)) {
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 if (verbose) {
2522
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
487 i_info("rpa(%s): %s",
a07fb16b9a24 Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents: 2510
diff changeset
488 get_log_prefix(auth_request), error);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
489 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490 mech_auth_finish(auth_request, NULL, 0, FALSE);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
491 return;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494 passdb->lookup_credentials(auth_request, PASSDB_CREDENTIALS_RPA,
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 rpa_credentials_callback);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
498 static void
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499 mech_rpa_auth_phase3(struct auth_request *auth_request,
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
500 const unsigned char *data, size_t data_size)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 static const unsigned char client_ack[3] = { 0x60, 0x01, 0x00 };
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 int ret = TRUE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 if ((data_size != sizeof(client_ack)) ||
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506 (memcmp(data, client_ack, sizeof(client_ack)) != 0)) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
507 if (verbose) {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
508 i_info("rpa(%s): invalid token 5 or client rejects us",
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
509 get_log_prefix(auth_request));
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511 ret = FALSE;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
512 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
513
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
514 mech_auth_finish(auth_request, NULL, 0, ret);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
516
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
517 static void
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518 mech_rpa_auth_continue(struct auth_request *auth_request,
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
519 const unsigned char *data, size_t data_size,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
520 mech_callback_t *callback)
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
521 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
522 struct rpa_auth_request *request =
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
523 (struct rpa_auth_request *)auth_request;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
524
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525 auth_request->callback = callback;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
526
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
527 switch (request->phase) {
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
528 case 0:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
529 mech_rpa_auth_phase1(auth_request, data, data_size);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
530 break;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
531 case 1:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
532 mech_rpa_auth_phase2(auth_request, data, data_size);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
533 break;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
534 case 2:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
535 mech_rpa_auth_phase3(auth_request, data, data_size);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
536 break;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
537 default:
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
538 mech_auth_finish(auth_request, NULL, 0, FALSE);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
539 break;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
540 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
543 static void
2915
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
544 mech_rpa_auth_initial(struct auth_request *request,
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
545 const unsigned char *data, size_t data_size,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546 mech_callback_t *callback)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547 {
2915
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
548 if (data_size == 0)
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
549 callback(request, AUTH_CLIENT_RESULT_CONTINUE, NULL, 0);
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
550 else
25bc79e67271 Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2781
diff changeset
551 mech_rpa_auth_continue(request, data, data_size, callback);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
552 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
553
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 static void
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
555 mech_rpa_auth_free(struct auth_request *auth_request)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
557 struct rpa_auth_request *request =
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
558 (struct rpa_auth_request *)auth_request;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
559
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
560 if (request->pwd_md5 != NULL)
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
561 safe_memset(request->pwd_md5, 0, 16);
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
562
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563 pool_unref(auth_request->pool);
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
565
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566 static struct auth_request *mech_rpa_auth_new(void)
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
567 {
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
568 struct rpa_auth_request *request;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
569 pool_t pool;
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
570
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
571 pool = pool_alloconly_create("rpa_auth_request", 256);
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
572 request = p_new(pool, struct rpa_auth_request, 1);
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
573 request->pool = pool;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
574 request->phase = 0;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
575
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
576 request->auth_request.refcount = 1;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
577 request->auth_request.pool = pool;
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
578 return &request->auth_request;
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579 }
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 const struct mech_module mech_rpa = {
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582 "RPA",
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
584 MEMBER(flags) MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE,
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586 MEMBER(passdb_need_plain) FALSE,
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587 MEMBER(passdb_need_credentials) TRUE,
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
588
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
589 mech_rpa_auth_new,
2736
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
590 mech_rpa_auth_initial,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
591 mech_rpa_auth_continue,
0f31778d3c34 Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
592 mech_rpa_auth_free
2428
abef2ac8843a Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593 };