Annotation of embedaddon/strongswan/src/libcharon/sa/ikev1/authenticators/hybrid_authenticator.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2011 Martin Willi
3: * Copyright (C) 2011 revosec AG
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 "hybrid_authenticator.h"
17:
18: #include <daemon.h>
19: #include <sa/ikev1/authenticators/psk_v1_authenticator.h>
20:
21: typedef struct private_hybrid_authenticator_t private_hybrid_authenticator_t;
22:
23: /**
24: * Private data of an hybrid_authenticator_t object.
25: */
26: struct private_hybrid_authenticator_t {
27:
28: /**
29: * Public authenticator_t interface.
30: */
31: hybrid_authenticator_t public;
32:
33: /**
34: * Public key authenticator
35: */
36: authenticator_t *sig;
37:
38: /**
39: * HASH payload authenticator without credentials
40: */
41: authenticator_t *hash;
42: };
43:
44: METHOD(authenticator_t, build_i, status_t,
45: private_hybrid_authenticator_t *this, message_t *message)
46: {
47: return this->hash->build(this->hash, message);
48: }
49:
50: METHOD(authenticator_t, process_r, status_t,
51: private_hybrid_authenticator_t *this, message_t *message)
52: {
53: return this->hash->process(this->hash, message);
54: }
55:
56: METHOD(authenticator_t, build_r, status_t,
57: private_hybrid_authenticator_t *this, message_t *message)
58: {
59: return this->sig->build(this->sig, message);
60: }
61:
62: METHOD(authenticator_t, process_i, status_t,
63: private_hybrid_authenticator_t *this, message_t *message)
64: {
65: return this->sig->process(this->sig, message);
66: }
67:
68: METHOD(authenticator_t, destroy, void,
69: private_hybrid_authenticator_t *this)
70: {
71: DESTROY_IF(this->hash);
72: DESTROY_IF(this->sig);
73: free(this);
74: }
75:
76: /*
77: * Described in header.
78: */
79: hybrid_authenticator_t *hybrid_authenticator_create(ike_sa_t *ike_sa,
80: bool initiator, diffie_hellman_t *dh,
81: chunk_t dh_value, chunk_t sa_payload,
82: chunk_t id_payload)
83: {
84: private_hybrid_authenticator_t *this;
85:
86: INIT(this,
87: .public = {
88: .authenticator = {
89: .is_mutual = (void*)return_false,
90: .destroy = _destroy,
91: },
92: },
93: .hash = (authenticator_t*)psk_v1_authenticator_create(ike_sa, initiator,
94: dh, dh_value, sa_payload, id_payload, TRUE),
95: .sig = authenticator_create_v1(ike_sa, initiator, AUTH_RSA, dh,
96: dh_value, sa_payload, chunk_clone(id_payload)),
97: );
98: if (!this->sig || !this->hash)
99: {
100: destroy(this);
101: return NULL;
102: }
103: if (initiator)
104: {
105: this->public.authenticator.build = _build_i;
106: this->public.authenticator.process = _process_i;
107: }
108: else
109: {
110: this->public.authenticator.build = _build_r;
111: this->public.authenticator.process = _process_r;
112: }
113: return &this->public;
114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>