Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_pac.c
34879 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/fuzzing/fuzz_pac.c */2/*3* Copyright (C) 2024 by Arjun. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,22* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR24* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,26* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED28* OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031/*32* Fuzzing harness implementation for krb5_pac_parse.33*/3435#include "autoconf.h"36#include <k5-int.h>3738#define U(x) (uint8_t *)x39#define kMinInputLength 240#define kMaxInputLength 10244142static const krb5_keyblock kdc_keyblock = {430, ENCTYPE_ARCFOUR_HMAC,4416, U("\xB2\x86\x75\x71\x48\xAF\x7F\xD2\x52\xC5\x36\x03\xA1\x50\xB7\xE7")45};4647static const krb5_keyblock member_keyblock = {480, ENCTYPE_ARCFOUR_HMAC,4916, U("\xD2\x17\xFA\xEA\xE5\xE6\xB5\xF9\x5C\xCC\x94\x07\x7A\xB8\xA5\xFC")50};5152static time_t authtime = 1120440609;53static const char *user = "[email protected]";5455extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);5657int58LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)59{60krb5_error_code ret;61krb5_context context = NULL;62krb5_pac pac;63krb5_principal princ = NULL;6465if (size < kMinInputLength || size > kMaxInputLength)66return 0;6768ret = krb5_init_context(&context);69if (ret)70return 0;7172ret = krb5_parse_name(context, user, &princ);73if (ret)74goto cleanup;7576ret = krb5_pac_parse(context, data, size, &pac);77if (ret)78goto cleanup;7980krb5_pac_verify(context, pac, authtime, princ, NULL, NULL);81krb5_pac_verify_ext(context, pac, authtime, princ, NULL, NULL, TRUE);82krb5_pac_verify(context, pac, authtime, princ, &member_keyblock,83&kdc_keyblock);8485krb5_pac_free(context, pac);8687cleanup:88krb5_free_principal(context, princ);89krb5_free_context(context);9091return 0;92}939495