Implemented a common Phase 1 helper class to use by main and aggressive modes
[strongswan.git] / src / libcharon / sa / ikev1 / phase1.h
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 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 /**
17 * @defgroup phase1 phase1
18 * @{ @ingroup ikev1
19 */
20
21 #ifndef PHASE1_H_
22 #define PHASE1_H_
23
24 typedef struct phase1_t phase1_t;
25
26 #include <sa/ike_sa.h>
27 #include <crypto/diffie_hellman.h>
28
29 /**
30 * Common phase 1 helper for main and aggressive mode.
31 */
32 struct phase1_t {
33
34 /**
35 * Create keymat hasher.
36 *
37 * @param proposal negotiated proposal
38 * @return TRUE if hasher created
39 */
40 bool (*create_hasher)(phase1_t *this, proposal_t *proposal);
41
42 /**
43 * Create DH object using SA keymat.
44 *
45 * @param group negotiated DH group
46 * @return TRUE if group supported
47 */
48 bool (*create_dh)(phase1_t *this, diffie_hellman_group_t group);
49
50 /**
51 * Derive key material.
52 *
53 * @param peer_cfg peer config to look up shared key for, or NULL
54 * @param method negotiated authenticated method
55 * @param proposal selected IKE proposal
56 * @return TRUE if successful
57 */
58 bool (*derive_keys)(phase1_t *this, peer_cfg_t *peer_cfg,
59 auth_method_t method, proposal_t *proposal);
60 /**
61 * Verify a HASH or SIG payload in message.
62 *
63 * @param method negotiated auth method
64 * @param message message containing HASH or SIG payload
65 * @param id_data encoded identity, including protocol/port fields
66 * @return TRUE if verified successfully
67 */
68 bool (*verify_auth)(phase1_t *this, auth_method_t method,
69 message_t *message, chunk_t id_data);
70
71 /**
72 * Build a HASH or SIG payload and add it to message.
73 *
74 * @param method negotiated auth method
75 * @param message message to add payload to
76 * @param id_data encoded identity, including protocol/port fields
77 * @return TRUE if built successfully
78 */
79 bool (*build_auth)(phase1_t *this, auth_method_t method,
80 message_t *message, chunk_t id_data);
81
82 /**
83 * Get the IKEv1 authentication method defined by peer config.
84 *
85 * @param peer_cfg peer config to get auth method from
86 * @return auth method, or AUTH_NONE
87 */
88 auth_method_t (*get_auth_method)(phase1_t *this, peer_cfg_t *peer_cfg);
89
90 /**
91 * Select a peer config as responder.
92 *
93 * @param method used authentication method
94 * @param id initiator identity
95 * @return selected peer config, NULL if none found
96 */
97 peer_cfg_t* (*select_config)(phase1_t *this, auth_method_t method,
98 identification_t *id);
99
100 /**
101 * Get configured identity from peer config.
102 *
103 * @param peer_cfg peer config to get identity from
104 * @param local TRUE to get own identity, FALSE for remote
105 * @return identity, pointing to internal config data
106 */
107 identification_t* (*get_id)(phase1_t *this, peer_cfg_t *peer_cfg, bool local);
108
109 /**
110 * Extract and store SA payload bytes from encoded message.
111 *
112 * @param message message to extract SA payload bytes from
113 * @return TRUE if SA payload found
114 */
115 bool (*save_sa_payload)(phase1_t *this, message_t *message);
116
117 /**
118 * Add Nonce and KE payload to message.
119 *
120 * @param message message to add payloads
121 * @return TRUE if payloads added successfully
122 */
123 bool (*add_nonce_ke)(phase1_t *this, message_t *message);
124
125 /**
126 * Extract Nonce and KE payload from message.
127 *
128 * @param message message to get payloads from
129 * @return TRUE if payloads extracted successfully
130 */
131 bool (*get_nonce_ke)(phase1_t *this, message_t *message);
132
133 /**
134 * Destroy a phase1_t.
135 */
136 void (*destroy)(phase1_t *this);
137 };
138
139 /**
140 * Create a phase1 instance.
141 *
142 * @param ike_sa IKE_SA to set up
143 * @param initiator TRUE if initiating actively
144 * @return Phase 1 helper
145 */
146 phase1_t *phase1_create(ike_sa_t *ike_sa, bool initiator);
147
148 #endif /** PHASE1_H_ @}*/