From e93743a09413c8b33507ac460e0a31a62f89aadf Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 29 Aug 2024 13:38:57 +0530 Subject: [PATCH] rust/base64: upgrade crate to latest base64 crate is updated to the latest version 0.22.1. This came with several API changes which are applied to the code. The old calls have been replaced with the newer calls. This was done following the availability of better fns to directly decode into slices/vectors as needed and also that previous version was too old. Along with this change, update the Cargo.lock.in to reflect all changes in the package versions. Task 7219 --- rust/Cargo.lock.in | 4 ++-- rust/Cargo.toml.in | 2 +- rust/src/ffi/base64.rs | 5 +++-- rust/src/http2/detect.rs | 5 +++-- rust/src/http2/parser.rs | 3 ++- rust/src/jsonbuilder.rs | 3 ++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/rust/Cargo.lock.in b/rust/Cargo.lock.in index 747e8e01d9..0c412e1d5c 100644 --- a/rust/Cargo.lock.in +++ b/rust/Cargo.lock.in @@ -114,9 +114,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base64" -version = "0.13.1" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bendy" diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 48e1d1f510..7ec8791ea8 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -58,7 +58,7 @@ sha1 = "~0.10.5" md-5 = "~0.10.1" regex = "~1.5.5" lazy_static = "~1.4.0" -base64 = "~0.13.0" +base64 = "~0.22.1" bendy = { version = "~0.3.3", default-features = false } asn1-rs = { version = "~0.6.1" } ldap-parser = { version = "~0.4.0" } diff --git a/rust/src/ffi/base64.rs b/rust/src/ffi/base64.rs index ea72a344c3..e80dd5b528 100644 --- a/rust/src/ffi/base64.rs +++ b/rust/src/ffi/base64.rs @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -17,6 +17,7 @@ use std::os::raw::c_uchar; use libc::c_ulong; +use base64::{Engine, engine::general_purpose::STANDARD}; #[repr(C)] #[allow(non_camel_case_types)] @@ -42,7 +43,7 @@ pub unsafe extern "C" fn Base64Encode( return Base64ReturnCode::SC_BASE64_INVALID_ARG; } let input = std::slice::from_raw_parts(input, input_len as usize); - let encoded = base64::encode(input); + let encoded = STANDARD.encode(input); if encoded.len() + 1 > *output_len as usize { return Base64ReturnCode::SC_BASE64_OVERFLOW; } diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index b7a43ec522..74bb59223d 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Open Information Security Foundation +/* Copyright (C) 2020-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -24,6 +24,7 @@ use crate::detect::uint::{detect_match_uint, DetectUintData}; use std::ffi::CStr; use std::str::FromStr; use std::rc::Rc; +use base64::{Engine, engine::general_purpose::STANDARD}; fn http2_tx_has_frametype( tx: &mut HTTP2Transaction, direction: Direction, value: u8, @@ -957,7 +958,7 @@ pub unsafe extern "C" fn rs_http2_tx_set_uri( } fn http2_tx_set_settings(state: &mut HTTP2State, input: &[u8]) { - match base64::decode(input) { + match STANDARD.decode(input) { Ok(dec) => { if dec.len() % 6 != 0 { state.set_event(HTTP2Event::InvalidHTTP1Settings); diff --git a/rust/src/http2/parser.rs b/rust/src/http2/parser.rs index 519d1b7bfb..239d4e942a 100644 --- a/rust/src/http2/parser.rs +++ b/rust/src/http2/parser.rs @@ -32,6 +32,7 @@ use nom7::{Err, IResult}; use std::fmt; use std::str::FromStr; use std::rc::Rc; +use base64::{Engine, engine::general_purpose::STANDARD_NO_PAD}; #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq, FromPrimitive, Debug)] @@ -762,7 +763,7 @@ pub fn http2_parse_frame_settings(i: &[u8]) -> IResult<&[u8], Vec IResult<&[u8], Vec> { let (i, _) = tag("/dns-query?dns=")(i)?; - match base64::decode(i) { + match STANDARD_NO_PAD.decode(i) { Ok(dec) => { // i is unused return Ok((i, dec)); diff --git a/rust/src/jsonbuilder.rs b/rust/src/jsonbuilder.rs index bc09fb43cc..56fe91fcbd 100644 --- a/rust/src/jsonbuilder.rs +++ b/rust/src/jsonbuilder.rs @@ -24,6 +24,7 @@ use std::collections::TryReserveError; use std::ffi::CStr; use std::os::raw::c_char; use std::str::Utf8Error; +use base64::{Engine, engine::general_purpose::STANDARD}; const INIT_SIZE: usize = 4096; @@ -807,7 +808,7 @@ impl JsonBuilder { if self.buf.capacity() < self.buf.len() + encoded_len { self.buf.try_reserve(encoded_len)?; } - base64::encode_config_buf(val, base64::STANDARD, &mut self.buf); + STANDARD.encode_string(val, &mut self.buf); Ok(self) } }