5c7ba092729dc2ba1402aa43ed1ae0a2ebecace8
[strongswan.git] / Source / charon / sa / states / ike_sa_init_responded.c
1 /**
2 * @file ike_sa_init_responded.c
3 *
4 * @brief State of a IKE_SA after responding to an IKE_SA_INIT request
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "ike_sa_init_responded.h"
24
25 #include <utils/allocator.h>
26
27
28 typedef struct private_ike_sa_init_responded_t private_ike_sa_init_responded_t;
29
30 /**
31 * Private data of a ike_sa_init_responded_t object.
32 *
33 */
34 struct private_ike_sa_init_responded_t {
35 /**
36 * methods of the state_t interface
37 */
38 ike_sa_init_responded_t public;
39
40 /**
41 * Shared secret from DH-Exchange
42 *
43 * All needed secrets are derived from this shared secret and then passed to the next
44 * state of type ike_sa_established_t
45 */
46 chunk_t shared_secret;
47
48 /**
49 * Sent nonce used to calculate secrets
50 */
51 chunk_t received_nonce;
52
53 /**
54 * Sent nonce used to calculate secrets
55 */
56 chunk_t sent_nonce;
57
58 /**
59 * Assigned IKE_SA
60 */
61 protected_ike_sa_t *ike_sa;
62
63 /**
64 * Logger used to log data
65 *
66 * Is logger of ike_sa!
67 */
68 logger_t *logger;
69 };
70
71 /**
72 * Implements state_t.get_state
73 */
74 static status_t process_message(private_ike_sa_init_responded_t *this, message_t *message, state_t **new_state)
75 {
76 *new_state = (state_t *) this;
77 return SUCCESS;
78 }
79
80 /**
81 * Implements state_t.get_state
82 */
83 static ike_sa_state_t get_state(private_ike_sa_init_responded_t *this)
84 {
85 return IKE_SA_INIT_RESPONDED;
86 }
87
88 /**
89 * Implements state_t.get_state
90 */
91 static status_t destroy(private_ike_sa_init_responded_t *this)
92 {
93 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy ike_sa_init_responded_t state object");
94
95 this->logger->log(this->logger, CONTROL | MOST, "Destroy shared_secret");
96 allocator_free(this->shared_secret.ptr);
97
98 this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
99 allocator_free(this->sent_nonce.ptr);
100
101 this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
102 allocator_free(this->received_nonce.ptr);
103
104 allocator_free(this);
105 return SUCCESS;
106 }
107
108 /*
109 * Described in header.
110 */
111
112 ike_sa_init_responded_t *ike_sa_init_responded_create(protected_ike_sa_t *ike_sa, chunk_t shared_secret, chunk_t received_nonce, chunk_t sent_nonce)
113 {
114 private_ike_sa_init_responded_t *this = allocator_alloc_thing(private_ike_sa_init_responded_t);
115
116 if (this == NULL)
117 {
118 return NULL;
119 }
120
121 /* interface functions */
122 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *,state_t **)) process_message;
123 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
124 this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
125
126 /* private data */
127 this->ike_sa = ike_sa;
128 this->logger = this->ike_sa->logger;
129 this->shared_secret = shared_secret;
130 this->received_nonce = received_nonce;
131 this->sent_nonce = sent_nonce;
132
133 return &(this->public);
134 }