1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* Copyright (C) 2016, 2017 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* GnuTLS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuTLS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GnuTLS. If not, see <https://www.gnu.org/licenses/>.
*/
/* Parts copied from GnuTLS example programs. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
#include "utils.h"
/* This checks random art encoding */
static void encode(const char *test_name, const char *type, unsigned key_size,
unsigned char *input, unsigned input_size,
const char *expected)
{
int ret;
gnutls_datum_t out;
ret = gnutls_random_art(GNUTLS_RANDOM_ART_OPENSSH, type, key_size,
input, input_size, &out);
if (ret < 0) {
fail("%s: gnutls_random_art: %s\n", test_name,
gnutls_strerror(ret));
exit(1);
}
if (strlen(expected) != out.size) {
fail("%s: gnutls_random_art: output has incorrect size (%d, expected %d)\n%s\n",
test_name, (int)out.size, (int)strlen(expected), out.data);
exit(1);
}
if (strncasecmp(expected, (char *)out.data, out.size) != 0) {
fail("%s: gnutls_random_art: output does not match the expected:\n%s\n",
test_name, out.data);
exit(1);
}
gnutls_free(out.data);
return;
}
struct encode_tests_st {
const char *name;
unsigned char *raw;
unsigned raw_size;
const char *key_type;
unsigned key_size;
const char *art;
};
struct encode_tests_st encode_tests[] = {
{ .name = "key1",
.raw = (void *)"\x38\x17\x0c\x08\xcb\x45\x8f\xd4\x87\x9c\x34\xb6\xf6\x08\x29\x4c\x50\x31\x2b\xbb",
.raw_size = 20,
.key_type = "RSA",
.key_size = 2048,
.art = "+--[ RSA 2048]----+\n"
"|.o*++==o |\n"
"| + *.===. |\n"
"|. * + +.o |\n"
"| o . o + . |\n"
"|. + S |\n"
"| . o |\n"
"|E |\n"
"| |\n"
"| |\n"
"+-----------------+" },
{ .name = "key2",
.raw = (void *)"\xf8\xa7\x1c\x08\x76\x47\x2c\x08\x38\x17\x0c\x08\x38\x17\x0c\x08\xcb\x45\x8f\xd4\x87\x9c\xa4\xb6\xf6\xf8\x29\xfc\x50\x3f\x2b\xbb",
.raw_size = 32,
.key_type = "RSA",
.key_size = 3072,
.art = "+--[ RSA 3072]----+\n"
"|@*=*+.o |\n"
"|O.B.+* o |\n"
"|.* +..o o |\n"
"| . . + |\n"
"| oo.o S |\n"
"| ..+o.+ |\n"
"| .o ..oo . |\n"
"| oo...o+ |\n"
"| oE+.o |\n"
"+-----------------+" },
{ .name = "key3",
.raw = (void *)"\x38\xf7\x0c\x08\xcb\x34\x8a\xd4\xb7\x9c\x34\xb4\xf6\x08\x29\x4c\x50\x3f\x2b\xbb",
.raw_size = 20,
.key_type = "ECDSA",
.key_size = 256,
.art = "+--[ECDSA 256]---+\n"
"|oo. . |\n"
"|o ..o . |\n"
"| + +** |\n"
"|...+***o |\n"
"|. o +=+.S |\n"
"| o o + |\n"
"| . o |\n"
"| . |\n"
"| E |\n"
"+-----------------+" }
};
void doit(void)
{
unsigned i;
for (i = 0; i < sizeof(encode_tests) / sizeof(encode_tests[0]); i++) {
encode(encode_tests[i].name, encode_tests[i].key_type,
encode_tests[i].key_size, encode_tests[i].raw,
encode_tests[i].raw_size, encode_tests[i].art);
}
}
|