1*38a52bd3SEd Maste #include <stddef.h>
2*38a52bd3SEd Maste #include <stdio.h>
3*38a52bd3SEd Maste #include <stdint.h>
4*38a52bd3SEd Maste #include <string.h>
5*38a52bd3SEd Maste #include <stdlib.h>
6*38a52bd3SEd Maste #include <pwd.h>
7*38a52bd3SEd Maste #include <unistd.h>
8*38a52bd3SEd Maste
9*38a52bd3SEd Maste extern "C" {
10*38a52bd3SEd Maste
11*38a52bd3SEd Maste #include "hostfile.h"
12*38a52bd3SEd Maste #include "auth.h"
13*38a52bd3SEd Maste #include "auth-options.h"
14*38a52bd3SEd Maste #include "sshkey.h"
15*38a52bd3SEd Maste
16*38a52bd3SEd Maste // testdata/id_ed25519.pub and testdata/id_ed25519-cert.pub
17*38a52bd3SEd Maste const char *pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDPQXmEVMVLmeFRyafKMVWgPDkv8/uRBTwmcEDatZzMD";
18*38a52bd3SEd Maste const char *certtext = "ssh-ed25519-cert-v01@openssh.com AAAAIHNzaC1lZDI1NTE5LWNlcnQtdjAxQG9wZW5zc2guY29tAAAAIMDQjYH6XRzH3j3MW1DdjCoAfvrHfgjnVGF+sLK0pBfqAAAAIDPQXmEVMVLmeFRyafKMVWgPDkv8/uRBTwmcEDatZzMDAAAAAAAAA+sAAAABAAAAB3VseXNzZXMAAAAXAAAAB3VseXNzZXMAAAAIb2R5c3NldXMAAAAAAAAAAP//////////AAAAAAAAAIIAAAAVcGVybWl0LVgxMS1mb3J3YXJkaW5nAAAAAAAAABdwZXJtaXQtYWdlbnQtZm9yd2FyZGluZwAAAAAAAAAWcGVybWl0LXBvcnQtZm9yd2FyZGluZwAAAAAAAAAKcGVybWl0LXB0eQAAAAAAAAAOcGVybWl0LXVzZXItcmMAAAAAAAAAAAAAADMAAAALc3NoLWVkMjU1MTkAAAAgM9BeYRUxUuZ4VHJp8oxVaA8OS/z+5EFPCZwQNq1nMwMAAABTAAAAC3NzaC1lZDI1NTE5AAAAQBj0og+s09/HpwdHZbzN0twooKPDWWrxGfnP1Joy6cDnY2BCSQ7zg9vbq11kLF8H/sKOTZWAQrUZ7LlChOu9Ogw= id_ed25519.pub";
19*38a52bd3SEd Maste
20*38a52bd3SEd Maste // stubs
auth_debug_add(const char * fmt,...)21*38a52bd3SEd Maste void auth_debug_add(const char *fmt,...)
22*38a52bd3SEd Maste {
23*38a52bd3SEd Maste }
24*38a52bd3SEd Maste
25*38a52bd3SEd Maste void
auth_log_authopts(const char * loc,const struct sshauthopt * opts,int do_remote)26*38a52bd3SEd Maste auth_log_authopts(const char *loc, const struct sshauthopt *opts, int do_remote)
27*38a52bd3SEd Maste {
28*38a52bd3SEd Maste }
29*38a52bd3SEd Maste
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)30*38a52bd3SEd Maste int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
31*38a52bd3SEd Maste {
32*38a52bd3SEd Maste char *tmp, *o, *cp = (char *)malloc(size + 1 + strlen(pubkey) + 1);
33*38a52bd3SEd Maste struct sshauthopt *opts = NULL;
34*38a52bd3SEd Maste struct passwd *pw = getpwuid(getuid());
35*38a52bd3SEd Maste static struct sshkey *key, *cert;
36*38a52bd3SEd Maste
37*38a52bd3SEd Maste if (key == NULL) {
38*38a52bd3SEd Maste if ((key = sshkey_new(KEY_UNSPEC)) == NULL ||
39*38a52bd3SEd Maste (cert = sshkey_new(KEY_UNSPEC)) == NULL)
40*38a52bd3SEd Maste abort();
41*38a52bd3SEd Maste if ((o = tmp = strdup(pubkey)) == NULL ||
42*38a52bd3SEd Maste sshkey_read(key, &tmp) != 0)
43*38a52bd3SEd Maste abort();
44*38a52bd3SEd Maste free(o);
45*38a52bd3SEd Maste if ((o = tmp = strdup(certtext)) == NULL ||
46*38a52bd3SEd Maste sshkey_read(cert, &tmp) != 0)
47*38a52bd3SEd Maste abort();
48*38a52bd3SEd Maste free(o);
49*38a52bd3SEd Maste }
50*38a52bd3SEd Maste if (cp == NULL || pw == NULL || key == NULL || cert == NULL)
51*38a52bd3SEd Maste abort();
52*38a52bd3SEd Maste
53*38a52bd3SEd Maste // Cleanup whitespace at input EOL.
54*38a52bd3SEd Maste for (; size > 0 && strchr(" \t\r\n", data[size - 1]) != NULL; size--) ;
55*38a52bd3SEd Maste
56*38a52bd3SEd Maste // Append a pubkey that will match.
57*38a52bd3SEd Maste memcpy(cp, data, size);
58*38a52bd3SEd Maste cp[size] = ' ';
59*38a52bd3SEd Maste memcpy(cp + size + 1, pubkey, strlen(pubkey) + 1);
60*38a52bd3SEd Maste
61*38a52bd3SEd Maste // Try key.
62*38a52bd3SEd Maste if ((tmp = strdup(cp)) == NULL)
63*38a52bd3SEd Maste abort();
64*38a52bd3SEd Maste (void) auth_check_authkey_line(pw, key, tmp, "127.0.0.1", "localhost",
65*38a52bd3SEd Maste "fuzz", &opts);
66*38a52bd3SEd Maste free(tmp);
67*38a52bd3SEd Maste sshauthopt_free(opts);
68*38a52bd3SEd Maste
69*38a52bd3SEd Maste // Try cert.
70*38a52bd3SEd Maste if ((tmp = strdup(cp)) == NULL)
71*38a52bd3SEd Maste abort();
72*38a52bd3SEd Maste (void) auth_check_authkey_line(pw, cert, tmp, "127.0.0.1", "localhost",
73*38a52bd3SEd Maste "fuzz", &opts);
74*38a52bd3SEd Maste free(tmp);
75*38a52bd3SEd Maste sshauthopt_free(opts);
76*38a52bd3SEd Maste
77*38a52bd3SEd Maste free(cp);
78*38a52bd3SEd Maste return 0;
79*38a52bd3SEd Maste }
80*38a52bd3SEd Maste
81*38a52bd3SEd Maste } // extern "C"
82