1 /* Copyright (C) 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 use super::ssh::SSHTransaction;
19 use crate::core::STREAM_TOCLIENT;
20 use std::ptr;
21
22 #[no_mangle]
rs_ssh_tx_get_protocol( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u823 pub extern "C" fn rs_ssh_tx_get_protocol(
24 tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8,
25 ) -> u8 {
26 let tx = cast_pointer!(tx, SSHTransaction);
27 if direction & STREAM_TOCLIENT != 0 {
28 let m = &tx.srv_hdr.protover;
29 if m.len() > 0 {
30 unsafe {
31 *buffer = m.as_ptr();
32 *buffer_len = m.len() as u32;
33 }
34 return 1;
35 }
36 } else {
37 let m = &tx.cli_hdr.protover;
38 if m.len() > 0 {
39 unsafe {
40 *buffer = m.as_ptr();
41 *buffer_len = m.len() as u32;
42 }
43 return 1;
44 }
45 }
46 unsafe {
47 *buffer = ptr::null();
48 *buffer_len = 0;
49 }
50
51 return 0;
52 }
53
54 #[no_mangle]
rs_ssh_tx_get_software( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u855 pub extern "C" fn rs_ssh_tx_get_software(
56 tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8,
57 ) -> u8 {
58 let tx = cast_pointer!(tx, SSHTransaction);
59 if direction & STREAM_TOCLIENT != 0 {
60 let m = &tx.srv_hdr.swver;
61 if m.len() > 0 {
62 unsafe {
63 *buffer = m.as_ptr();
64 *buffer_len = m.len() as u32;
65 }
66 return 1;
67 }
68 } else {
69 let m = &tx.cli_hdr.swver;
70 if m.len() > 0 {
71 unsafe {
72 *buffer = m.as_ptr();
73 *buffer_len = m.len() as u32;
74 }
75 return 1;
76 }
77 }
78 unsafe {
79 *buffer = ptr::null();
80 *buffer_len = 0;
81 }
82
83 return 0;
84 }
85
86 #[no_mangle]
rs_ssh_tx_get_hassh( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u887 pub extern "C" fn rs_ssh_tx_get_hassh(
88 tx: *mut std::os::raw::c_void,
89 buffer: *mut *const u8,
90 buffer_len: *mut u32,
91 direction: u8,
92 ) -> u8 {
93 let tx = cast_pointer!(tx, SSHTransaction);
94 if direction & STREAM_TOCLIENT != 0 {
95 let m = &tx.srv_hdr.hassh;
96 if m.len() > 0 {
97 unsafe {
98 *buffer = m.as_ptr();
99 *buffer_len = m.len() as u32;
100 }
101 return 1;
102 }
103 } else {
104 let m = &tx.cli_hdr.hassh;
105 if m.len() > 0 {
106 unsafe {
107 *buffer = m.as_ptr();
108 *buffer_len = m.len() as u32;
109 }
110 return 1;
111 }
112 }
113 unsafe {
114 *buffer = ptr::null();
115 *buffer_len = 0;
116 }
117
118 return 0;
119 }
120
121 #[no_mangle]
rs_ssh_tx_get_hassh_string( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u8122 pub extern "C" fn rs_ssh_tx_get_hassh_string(
123 tx: *mut std::os::raw::c_void,
124 buffer: *mut *const u8,
125 buffer_len: *mut u32,
126 direction: u8,
127 ) -> u8 {
128 let tx = cast_pointer!(tx, SSHTransaction);
129 if direction & STREAM_TOCLIENT != 0 {
130 let m = &tx.srv_hdr.hassh_string;
131 if m.len() > 0 {
132 unsafe {
133 *buffer = m.as_ptr();
134 *buffer_len = m.len() as u32;
135 }
136 return 1;
137 }
138 } else {
139 let m = &tx.cli_hdr.hassh_string;
140 if m.len() > 0 {
141 unsafe {
142 *buffer = m.as_ptr();
143 *buffer_len = m.len() as u32;
144 }
145 return 1;
146 }
147 }
148 unsafe {
149 *buffer = ptr::null();
150 *buffer_len = 0;
151 }
152
153 return 0;
154 }
155