Mercurial > dovecot > core-2.2
annotate src/auth/mech-rpa.c @ 3064:2d33734b16d5 HEAD
Split auth_request* functions from mech.c to auth-request.c
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 07 Jan 2005 20:51:10 +0200 |
parents | 052f3a5743af |
children | 29d83a8bb50d |
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: */ |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
32 unsigned char pwd_md5[16]; |
2428
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 |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
402 static int verify_credentials(struct rpa_auth_request *request, |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
403 const char *credentials) |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
404 { |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
405 unsigned char response[16]; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
406 buffer_t *hash_buffer; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
407 |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
408 hash_buffer = buffer_create_data(request->pool, request->pwd_md5, 16); |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
409 hex_to_binary(credentials, hash_buffer); |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
410 |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
411 rpa_user_response(request, response); |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
412 return memcmp(response, request->user_response, 16) == 0; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
413 } |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
414 |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 static void |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
416 rpa_credentials_callback(enum passdb_result result, |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
417 const char *credentials, |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 struct auth_request *auth_request) |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
420 struct rpa_auth_request *request = |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 (struct rpa_auth_request *)auth_request; |
2764
3cc4ebb5f42d
Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
422 const unsigned char *token4; |
3cc4ebb5f42d
Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
423 size_t token4_size; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
425 switch (result) { |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
426 case PASSDB_RESULT_OK: |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
427 if (!verify_credentials(request, credentials)) |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
428 auth_request_fail(auth_request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
429 else { |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
430 token4 = mech_rpa_build_token4(request, &token4_size); |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
431 auth_request->callback(auth_request, |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
432 AUTH_CLIENT_RESULT_CONTINUE, |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
433 token4, token4_size); |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
434 request->phase = 2; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
435 } |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
436 break; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
437 case PASSDB_RESULT_INTERNAL_FAILURE: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
438 auth_request_internal_failure(auth_request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
439 break; |
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
440 default: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
441 auth_request_fail(auth_request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
442 break; |
2764
3cc4ebb5f42d
Didn't work with asynchronous passdb.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
443 } |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
446 static void |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 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
|
448 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
|
449 { |
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 struct rpa_auth_request *request = |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 (struct rpa_auth_request *)auth_request; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 const unsigned char *token2; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 size_t token2_size; |
2522
a07fb16b9a24
Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents:
2510
diff
changeset
|
454 const char *service, *error; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 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
|
457 if (verbose) { |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 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
|
459 get_log_prefix(auth_request), error); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 } |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
461 auth_request_fail(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
|
462 return; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 |
2781
e44a84dc947c
s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents:
2764
diff
changeset
|
465 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
|
466 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
467 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
|
468 my_hostname, NULL), &token2_size); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 |
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 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
|
471 &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
|
472 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
|
473 &request->realm_len); |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
475 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
|
476 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
|
477 request->phase = 1; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
480 static void |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 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
|
482 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
|
483 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
484 struct rpa_auth_request *request = |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 (struct rpa_auth_request *)auth_request; |
2522
a07fb16b9a24
Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents:
2510
diff
changeset
|
486 const char *error; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
488 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
|
489 if (verbose) { |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 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
|
491 get_log_prefix(auth_request), error); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 } |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
493 auth_request_fail(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
|
494 return; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 |
2522
a07fb16b9a24
Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents:
2510
diff
changeset
|
497 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
|
498 if (verbose) { |
2522
a07fb16b9a24
Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents:
2510
diff
changeset
|
499 i_info("rpa(%s): %s", |
a07fb16b9a24
Changed "invalid username" error message.
Timo Sirainen <tss@iki.fi>
parents:
2510
diff
changeset
|
500 get_log_prefix(auth_request), error); |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 } |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
502 auth_request_fail(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
|
503 return; |
2428
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 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 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
|
507 rpa_credentials_callback); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
510 static void |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 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
|
512 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
|
513 { |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 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
|
515 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 if ((data_size != sizeof(client_ack)) || |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 (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
|
518 if (verbose) { |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 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
|
520 get_log_prefix(auth_request)); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 } |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
522 auth_request_fail(auth_request); |
3058
052f3a5743af
Make FAIL reply contain "temp" parameter if the authentication failed
Timo Sirainen <tss@iki.fi>
parents:
2915
diff
changeset
|
523 } else { |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
524 auth_request_success(auth_request, NULL, 0); |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
528 static void |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 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
|
530 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
|
531 mech_callback_t *callback) |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
533 struct rpa_auth_request *request = |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
534 (struct rpa_auth_request *)auth_request; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
536 auth_request->callback = callback; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 break; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
542 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
|
543 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
|
544 break; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
545 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
|
546 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
|
547 break; |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
548 default: |
3064
2d33734b16d5
Split auth_request* functions from mech.c to auth-request.c
Timo Sirainen <tss@iki.fi>
parents:
3058
diff
changeset
|
549 auth_request_fail(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
|
550 break; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
551 } |
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 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
554 static void |
2915
25bc79e67271
Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2781
diff
changeset
|
555 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
|
556 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
|
557 mech_callback_t *callback) |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
558 { |
2915
25bc79e67271
Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2781
diff
changeset
|
559 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
|
560 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
|
561 else |
25bc79e67271
Initial response support for NTLM and RPA. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2781
diff
changeset
|
562 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
|
563 } |
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 static void |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 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
|
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 (struct rpa_auth_request *)auth_request; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
570 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
571 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
|
572 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
|
573 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
574 pool_unref(auth_request->pool); |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
576 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
577 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
|
578 { |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
579 struct rpa_auth_request *request; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 pool_t pool; |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 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
|
583 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
|
584 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
|
585 request->phase = 0; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
587 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
|
588 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
|
589 return &request->auth_request; |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
590 } |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 const struct mech_module mech_rpa = { |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 "RPA", |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
595 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
|
596 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 MEMBER(passdb_need_plain) FALSE, |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 MEMBER(passdb_need_credentials) TRUE, |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
599 |
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 mech_rpa_auth_free |
2428
abef2ac8843a
Added Compuserve RPA authentication. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
604 }; |