1 /* Copyright (C) 2018-2020 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18 // written by Pierre Chifflier <chifflier@wzdftpd.net>
19
20 use crate::jsonbuilder::{JsonBuilder, JsonError};
21 use crate::ikev2::ikev2::{IKEV2State,IKEV2Transaction};
22
23 use crate::ikev2::ipsec_parser::IKEV2_FLAG_INITIATOR;
24
ikev2_log_response(state: &mut IKEV2State, tx: &mut IKEV2Transaction, jb: &mut JsonBuilder) -> Result<(), JsonError>25 fn ikev2_log_response(state: &mut IKEV2State,
26 tx: &mut IKEV2Transaction,
27 jb: &mut JsonBuilder)
28 -> Result<(), JsonError>
29 {
30 jb.set_uint("version_major", tx.hdr.maj_ver as u64)?;
31 jb.set_uint("version_minor", tx.hdr.min_ver as u64)?;
32 jb.set_uint("exchange_type", tx.hdr.exch_type.0 as u64)?;
33 jb.set_uint("message_id", tx.hdr.msg_id as u64)?;
34 jb.set_string("init_spi", &format!("{:016x}", tx.hdr.init_spi))?;
35 jb.set_string("resp_spi", &format!("{:016x}", tx.hdr.resp_spi))?;
36 if tx.hdr.flags & IKEV2_FLAG_INITIATOR != 0 {
37 jb.set_string("role", &"initiator")?;
38 } else {
39 jb.set_string("role", &"responder")?;
40 jb.set_string("alg_enc", &format!("{:?}", state.alg_enc))?;
41 jb.set_string("alg_auth", &format!("{:?}", state.alg_auth))?;
42 jb.set_string("alg_prf", &format!("{:?}", state.alg_prf))?;
43 jb.set_string("alg_dh", &format!("{:?}", state.alg_dh))?;
44 jb.set_string("alg_esn", &format!("{:?}", state.alg_esn))?;
45 }
46 jb.set_uint("errors", tx.errors as u64)?;
47 jb.open_array("payload")?;
48 for payload in tx.payload_types.iter() {
49 jb.append_string(&format!("{:?}", payload))?;
50 }
51 jb.close()?;
52 jb.open_array("notify")?;
53 for notify in tx.notify_types.iter() {
54 jb.append_string(&format!("{:?}", notify))?;
55 }
56 jb.close()?;
57 Ok(())
58 }
59
60 #[no_mangle]
rs_ikev2_log_json_response(state: &mut IKEV2State, tx: &mut IKEV2Transaction, jb: &mut JsonBuilder) -> bool61 pub extern "C" fn rs_ikev2_log_json_response(state: &mut IKEV2State,
62 tx: &mut IKEV2Transaction,
63 jb: &mut JsonBuilder)
64 -> bool
65 {
66 ikev2_log_response(state, tx, jb).is_ok()
67 }
68