Skip to content

Commit 341a093

Browse files
committed
Update cert file generator: gencertbuf.pl
1 parent dccc62b commit 341a093

File tree

2 files changed

+63
-27
lines changed

2 files changed

+63
-27
lines changed

gencertbuf.pl

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# output C header file to write key buffers to
1616
my $outputFile = "./wolfssh/certs_test.h";
1717

18+
# Add a suffix to distinguish between wolfssl/certs_test.h
19+
my $SSH_SUFFIX = "_ssh";
20+
1821
# ecc keys to be converted
1922

2023
my @fileList_ecc = (
@@ -39,40 +42,57 @@
3942
open OUT_FILE, "+>", $outputFile or die $!;
4043

4144
print OUT_FILE "/* certs_test.h\n";
42-
print OUT_FILE "*\n";
43-
print OUT_FILE "* Copyright (C) 2014-2020 wolfSSL Inc.\n";
44-
print OUT_FILE "*\n";
45-
print OUT_FILE "* This file is part of wolfSSH.\n";
46-
print OUT_FILE "*\n";
47-
print OUT_FILE "* wolfSSH is free software; you can redistribute it and/or modify\n";
48-
print OUT_FILE "* it under the terms of the GNU General Public License as published by\n";
49-
print OUT_FILE "* the Free Software Foundation; either version 3 of the License, or\n";
50-
print OUT_FILE "* (at your option) any later version.\n";
51-
print OUT_FILE "*\n";
52-
print OUT_FILE "* wolfSSH is distributed in the hope that it will be useful,\n";
53-
print OUT_FILE "* but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
54-
print OUT_FILE "* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
55-
print OUT_FILE "* GNU General Public License for more details.\n";
56-
print OUT_FILE "*\n";
57-
print OUT_FILE "* You should have received a copy of the GNU General Public License\n";
58-
print OUT_FILE "* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.\n";
59-
print OUT_FILE "*/\n\n";
60-
print OUT_FILE "#ifndef WOLFSSL_CERTS_TEST_H\n";
61-
print OUT_FILE "#define WOLFSSL_CERTS_TEST_H\n\n";
45+
print OUT_FILE " *\n";
46+
print OUT_FILE " * Copyright (C) 2014-2025 wolfSSL Inc.\n";
47+
print OUT_FILE " *\n";
48+
print OUT_FILE " * This file is part of wolfSSH.\n";
49+
print OUT_FILE " *\n";
50+
print OUT_FILE " * wolfSSH is free software; you can redistribute it and/or modify\n";
51+
print OUT_FILE " * it under the terms of the GNU General Public License as published by\n";
52+
print OUT_FILE " * the Free Software Foundation; either version 3 of the License, or\n";
53+
print OUT_FILE " * (at your option) any later version.\n";
54+
print OUT_FILE " *\n";
55+
print OUT_FILE " * wolfSSH is distributed in the hope that it will be useful,\n";
56+
print OUT_FILE " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
57+
print OUT_FILE " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
58+
print OUT_FILE " * GNU General Public License for more details.\n";
59+
print OUT_FILE " *\n";
60+
print OUT_FILE " * You should have received a copy of the GNU General Public License\n";
61+
print OUT_FILE " * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.\n";
62+
print OUT_FILE " */\n\n";
63+
print OUT_FILE "#ifndef _WOLFSSH_CERTS_TEST_H_\n";
64+
print OUT_FILE "#define _WOLFSSH_CERTS_TEST_H_\n";
65+
print OUT_FILE "\n";
66+
print OUT_FILE "/* To distinguish these certs from those in wolfssl add suffix: _ssh\n";
67+
print OUT_FILE " * See: https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h\n";
68+
print OUT_FILE " * Generate: https://github.com/wolfSSL/wolfssl/blob/master/gencertbuf.pl\n";
69+
print OUT_FILE " *\n";
70+
print OUT_FILE " * In C89/C90 (which Watcom generally defaults to), sizeof must be a\n";
71+
print OUT_FILE " * compile-time constant expression when used in a static initializer.\n";
72+
print OUT_FILE " * So don't use `static const int sizeof_`\n";
73+
print OUT_FILE " */\n";
74+
print OUT_FILE "\n";
6275

6376
# convert and print 2048-bit certs/keys
64-
print OUT_FILE "#ifdef NO_FILESYSTEM\n\n";
77+
print OUT_FILE "#if defined(NO_FILESYSTEM)\n\n";
6578
for (my $i = 0; $i < $num_2048; $i++) {
6679

6780
my $fname = $fileList_2048[$i][0];
6881
my $sname = $fileList_2048[$i][1];
6982

83+
# Add a suffix to distinguish between wolfssl/certs_test.h
84+
$sname .= $SSH_SUFFIX;
85+
7086
print OUT_FILE "/* $fname, 2048-bit */\n";
7187
print OUT_FILE "static const unsigned char $sname\[] =\n";
7288
print OUT_FILE "{\n";
7389
file_to_hex($fname);
7490
print OUT_FILE "};\n";
75-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
91+
92+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
93+
# compile-time constant expression when used in a static initializer.
94+
# So don't use `static const int sizeof_` here:
95+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
7696
}
7797

7898
# convert and print ECC cert/keys
@@ -81,16 +101,23 @@
81101
my $fname = $fileList_ecc[$i][0];
82102
my $sname = $fileList_ecc[$i][1];
83103

104+
# Add a suffix to distinguish between wolfssl/certs_test.h
105+
$sname .= $SSH_SUFFIX;
106+
84107
print OUT_FILE "/* $fname, ECC */\n";
85108
print OUT_FILE "static const unsigned char $sname\[] =\n";
86109
print OUT_FILE "{\n";
87110
file_to_hex($fname);
88111
print OUT_FILE "};\n";
89-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
112+
113+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
114+
# compile-time constant expression when used in a static initializer.
115+
# So don't use `static const int sizeof_` here:
116+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
90117
}
91118

92119
print OUT_FILE "#endif /* NO_FILESYSTEM */\n\n";
93-
print OUT_FILE "#endif /* WOLFSSL_CERTS_TEST_H */\n\n";
120+
print OUT_FILE "#endif /* _WOLFSSL_CERTS_TEST_H_ */\n\n";
94121

95122
# close certs_test.h file
96123
close OUT_FILE or die $!;
@@ -107,21 +134,30 @@ sub file_to_hex {
107134

108135
for (my $i = 0, my $j = 1; $i < $fileLen; $i++, $j++)
109136
{
137+
# Indent 4 spaces
110138
if ($j == 1) {
111-
print OUT_FILE "\t";
139+
print OUT_FILE " ";
112140
}
141+
113142
read($fp, $byte, 1) or die "Error reading $fileName";
114143
my $output = sprintf("0x%02X", ord($byte));
115144
print OUT_FILE $output;
116145

146+
# comma at the end of the array declaration
117147
if ($i != ($fileLen - 1)) {
118-
print OUT_FILE ", ";
148+
print OUT_FILE ",";
119149
}
120150

121151
if ($j == 10) {
122152
$j = 0;
123153
print OUT_FILE "\n";
124154
}
155+
else {
156+
# Space between each byte, except last one
157+
if ($i < $fileLen - 1) {
158+
print OUT_FILE " ";
159+
}
160+
}
125161
}
126162

127163
print OUT_FILE "\n";

wolfssh/certs_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* certs_test.h
22
*
3-
* Copyright (C) 2014-2024 wolfSSL Inc.
3+
* Copyright (C) 2014-2025 wolfSSL Inc.
44
*
55
* This file is part of wolfSSH.
66
*

0 commit comments

Comments
 (0)