- changed interface of ike_sa
[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)
75 {
76 return SUCCESS;
77 }
78
79 /**
80 * Implements state_t.get_state
81 */
82 static ike_sa_state_t get_state(private_ike_sa_init_responded_t *this)
83 {
84 return IKE_SA_INIT_RESPONDED;
85 }
86
87 /**
88 * Implements state_t.get_state
89 */
90 static status_t destroy(private_ike_sa_init_responded_t *this)
91 {
92 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy ike_sa_init_responded_t state object");
93
94 this->logger->log(this->logger, CONTROL | MOST, "Destroy shared_secret");
95 allocator_free(this->shared_secret.ptr);
96
97 this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
98 allocator_free(this->sent_nonce.ptr);
99
100 this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
101 allocator_free(this->received_nonce.ptr);
102
103 allocator_free(this);
104 return SUCCESS;
105 }
106
107 /*
108 * Described in header.
109 */
110
111 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)
112 {
113 private_ike_sa_init_responded_t *this = allocator_alloc_thing(private_ike_sa_init_responded_t);
114
115 if (this == NULL)
116 {
117 return NULL;
118 }
119
120 /* interface functions */
121 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
122 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
123 this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
124
125 /* private data */
126 this->ike_sa = ike_sa;
127 this->logger = this->ike_sa->get_logger(this->ike_sa);
128 this->shared_secret = shared_secret;
129 this->received_nonce = received_nonce;
130 this->sent_nonce = sent_nonce;
131
132 return &(this->public);
133 }