implemented xauth as a pluto plugin
[strongswan.git] / src / pluto / plugins / xauth / xauth_default_verifier.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <keys.h>
17
18 #include "xauth_default_verifier.h"
19
20 typedef struct private_xauth_default_verifier_t private_xauth_default_verifier_t;
21
22 /**
23 * private data of xauth_default_verifier
24 */
25 struct private_xauth_default_verifier_t {
26
27 /**
28 * public functions
29 */
30 xauth_verifier_t public;
31 };
32
33 METHOD(xauth_verifier_t, verify_secret, bool,
34 private_xauth_default_verifier_t *this, connection_t *c, chunk_t secret)
35 {
36 identification_t *user, *server;
37 chunk_t xauth_secret;
38 bool success = FALSE;
39
40 server = c->spd.this.id;
41 user = (c->xauth_identity) ? c->xauth_identity : c->spd.that.id;
42
43 if (get_xauth_secret(user, server, &xauth_secret))
44 {
45 success = chunk_equals(secret, xauth_secret);
46 chunk_clear(&xauth_secret);
47 }
48 return success;
49 }
50
51 METHOD(xauth_verifier_t, destroy, void,
52 private_xauth_default_verifier_t *this)
53 {
54 free(this);
55 }
56
57
58 /*
59 * Described in header.
60 */
61 xauth_verifier_t *xauth_default_verifier_create()
62 {
63 private_xauth_default_verifier_t *this;
64
65 INIT(this,
66 .public = {
67 .verify_secret = _verify_secret,
68 .destroy = _destroy,
69 }
70 );
71
72 return &this->public;
73 }
74