Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/tests/fuzzing/fuzz_pac.c
34879 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* tests/fuzzing/fuzz_pac.c */
3
/*
4
* Copyright (C) 2024 by Arjun. All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
*
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
*
13
* * Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in
15
* the documentation and/or other materials provided with the
16
* distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29
* OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
/*
33
* Fuzzing harness implementation for krb5_pac_parse.
34
*/
35
36
#include "autoconf.h"
37
#include <k5-int.h>
38
39
#define U(x) (uint8_t *)x
40
#define kMinInputLength 2
41
#define kMaxInputLength 1024
42
43
static const krb5_keyblock kdc_keyblock = {
44
0, ENCTYPE_ARCFOUR_HMAC,
45
16, U("\xB2\x86\x75\x71\x48\xAF\x7F\xD2\x52\xC5\x36\x03\xA1\x50\xB7\xE7")
46
};
47
48
static const krb5_keyblock member_keyblock = {
49
0, ENCTYPE_ARCFOUR_HMAC,
50
16, U("\xD2\x17\xFA\xEA\xE5\xE6\xB5\xF9\x5C\xCC\x94\x07\x7A\xB8\xA5\xFC")
51
};
52
53
static time_t authtime = 1120440609;
54
static const char *user = "[email protected]";
55
56
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
57
58
int
59
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
60
{
61
krb5_error_code ret;
62
krb5_context context = NULL;
63
krb5_pac pac;
64
krb5_principal princ = NULL;
65
66
if (size < kMinInputLength || size > kMaxInputLength)
67
return 0;
68
69
ret = krb5_init_context(&context);
70
if (ret)
71
return 0;
72
73
ret = krb5_parse_name(context, user, &princ);
74
if (ret)
75
goto cleanup;
76
77
ret = krb5_pac_parse(context, data, size, &pac);
78
if (ret)
79
goto cleanup;
80
81
krb5_pac_verify(context, pac, authtime, princ, NULL, NULL);
82
krb5_pac_verify_ext(context, pac, authtime, princ, NULL, NULL, TRUE);
83
krb5_pac_verify(context, pac, authtime, princ, &member_keyblock,
84
&kdc_keyblock);
85
86
krb5_pac_free(context, pac);
87
88
cleanup:
89
krb5_free_principal(context, princ);
90
krb5_free_context(context);
91
92
return 0;
93
}
94
95