Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua: provide base64 lib to lua - v2 #12498

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jasonish
Copy link
Member

Adds a Lua library exposing basic base64 functions to Lua. For details on the
function checkout the base64.rst page added in the userguide.

Commits:

  • base64: prefix base64 C API with "SC"
  • base64: expose nopad variant to C API
  • rust/ffi/base64: rustfmt
  • lua: add base64 lib
  • doc/userguide: document Lua base64 library
  • base64: add a lenient decoder

SV_BRANCH=OISF/suricata-verify#2260

Expose base64 standard, and standard_no_pad encoding to Lua scripts.

Ticket: OISF#7074
Create a lenient base64 decode for Lua that is indifferent to spacing
and allows trailing data.

Expose to Lua as "decode_lenient".

Ticket: OISF#7074
@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 629 657 104.45%

Pipeline 24405

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24422

uint8_t *decoded = SCCalloc(decoded_len, sizeof(uint8_t));

for (uint8_t mode = Base64ModeRFC2045; mode <= Base64ModeStrict; mode++) {
(void)Base64Decode(src, len, mode, decoded);
for (uint8_t mode = SCBase64ModeRFC2045; mode <= SCBase64ModeStrict; mode++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, you changed the order in the enum, so this loop quits too early

@@ -40,7 +40,7 @@
static int DetectTransformFromSCBase64DecodeSetup(DetectEngineCtx *, Signature *, const char *);
static void DetectTransformFromSCBase64DecodeFree(DetectEngineCtx *, void *);
#ifdef UNITTESTS
#define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t)SCBase64ModeRFC4648
#define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t) SCBase64ModeRFC4648
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in right commit :-p

FAIL_IF_NOT(buffer.inspect_len == 15);
// PrintRawDataFp(stdout, buffer.inspect, buffer.inspect_len);
InspectionBufferFree(&buffer);
PASS;
}
static void DetectTransformFromBase64DecodeRegisterTests(void)
static void DetectTransformFromSCBase64DecodeRegisterTests(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your grep|sed is gone too far :-p

size_t input_len;
const char *input = luaL_checklstring(L, 1, &input_len);
size_t out_len = SCBase64EncodeBufferSize(input_len);
char output[out_len + 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like stack alloc... How big can it get ?

let mut num_decoded: u32 = 0;
let config = base64::engine::GeneralPurposeConfig::new()
.with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent);
let decoder = base64::engine::GeneralPurpose::new(&base64::alphabet::STANDARD, config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How lenient is this ? Like tolerating spaces inside the base64 ?

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall but some details to improve on like not renaming DetectTransformFromBase64DecodeRegister to DetectTransformFromSCBase64DecodeRegister

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants