Skip to content

Commit 4e087a0

Browse files
Merge pull request #831 from gojimmypi/pr-rename-wolfssh-certs
Rename wolfssh test certs
2 parents 7fdcf24 + 341a093 commit 4e087a0

File tree

7 files changed

+110
-65
lines changed

7 files changed

+110
-65
lines changed

examples/echoserver/echoserver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,18 +1704,18 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
17041704
#else
17051705
/* using buffers instead */
17061706
if (isEcc) {
1707-
if ((word32)sizeof_ecc_key_der_256 > bufSz) {
1707+
if ((word32)sizeof_ecc_key_der_256_ssh > bufSz) {
17081708
return 0;
17091709
}
1710-
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
1711-
sz = sizeof_ecc_key_der_256;
1710+
WMEMCPY(buf, ecc_key_der_256_ssh, sizeof_ecc_key_der_256_ssh);
1711+
sz = sizeof_ecc_key_der_256_ssh;
17121712
}
17131713
else {
1714-
if ((word32)sizeof_rsa_key_der_2048 > bufSz) {
1714+
if ((word32)sizeof_rsa_key_der_2048_ssh > bufSz) {
17151715
return 0;
17161716
}
1717-
WMEMCPY(buf, (byte*)rsa_key_der_2048, sizeof_rsa_key_der_2048);
1718-
sz = sizeof_rsa_key_der_2048;
1717+
WMEMCPY(buf, (byte*)rsa_key_der_2048_ssh, sizeof_rsa_key_der_2048_ssh);
1718+
sz = sizeof_rsa_key_der_2048_ssh;
17191719
}
17201720
#endif
17211721

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";

ide/Espressif/ESP-IDF/examples/wolfssh_echoserver/main/echoserver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,18 +1677,18 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
16771677
#else
16781678
/* using buffers instead */
16791679
if (isEcc) {
1680-
if ((word32)sizeof_ecc_key_der_256 > bufSz) {
1680+
if ((word32)sizeof_ecc_key_der_256_ssh > bufSz) {
16811681
return 0;
16821682
}
1683-
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
1684-
sz = sizeof_ecc_key_der_256;
1683+
WMEMCPY(buf, ecc_key_der_256_ssh, sizeof_ecc_key_der_256_ssh);
1684+
sz = sizeof_ecc_key_der_256_ssh;
16851685
}
16861686
else {
1687-
if ((word32)sizeof_rsa_key_der_2048 > bufSz) {
1687+
if ((word32)sizeof_rsa_key_der_2048_ssh > bufSz) {
16881688
return 0;
16891689
}
1690-
WMEMCPY(buf, (byte*)rsa_key_der_2048, sizeof_rsa_key_der_2048);
1691-
sz = sizeof_rsa_key_der_2048;
1690+
WMEMCPY(buf, (byte*)rsa_key_der_2048_ssh, sizeof_rsa_key_der_2048_ssh);
1691+
sz = sizeof_rsa_key_der_2048_ssh;
16921692
}
16931693
#endif
16941694

ide/Renesas/cs+/demo_server/wolfssh_demo.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,18 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
239239
#else
240240
/* using buffers instead */
241241
if (isEcc) {
242-
if (sizeof_ecc_key_der_256 > bufSz) {
242+
if (sizeof_ecc_key_der_256_ssh > bufSz) {
243243
return 0;
244244
}
245-
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
246-
sz = sizeof_ecc_key_der_256;
245+
WMEMCPY(buf, ecc_key_der_256_ssh, sizeof_ecc_key_der_256_ssh);
246+
sz = sizeof_ecc_key_der_256_ssh;
247247
}
248248
else {
249-
if (sizeof_rsa_key_der_2048 > bufSz) {
249+
if (sizeof_rsa_key_der_2048_ssh > bufSz) {
250250
return 0;
251251
}
252-
WMEMCPY(buf, rsa_key_der_2048, sizeof_rsa_key_der_2048);
253-
sz = sizeof_rsa_key_der_2048;
252+
WMEMCPY(buf, rsa_key_der_2048_ssh, sizeof_rsa_key_der_2048_ssh);
253+
sz = sizeof_rsa_key_der_2048_ssh;
254254
}
255255
#endif
256256

ide/mplabx/wolfssh.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,18 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
354354
word32 sz = 0;
355355

356356
if (isEcc) {
357-
if (sizeof_ecc_key_der_256 > bufSz) {
357+
if (sizeof_ecc_key_der_256_ssh > bufSz) {
358358
return 0;
359359
}
360-
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
361-
sz = sizeof_ecc_key_der_256;
360+
WMEMCPY(buf, ecc_key_der_256_ssh, sizeof_ecc_key_der_256_ssh);
361+
sz = sizeof_ecc_key_der_256_ssh;
362362
}
363363
else {
364-
if (sizeof_rsa_key_der_2048 > bufSz) {
364+
if (sizeof_rsa_key_der_2048_ssh > bufSz) {
365365
return 0;
366366
}
367-
WMEMCPY(buf, (byte*)rsa_key_der_2048, sizeof_rsa_key_der_2048);
368-
sz = sizeof_rsa_key_der_2048;
367+
WMEMCPY(buf, (byte*)rsa_key_der_2048_ssh, sizeof_rsa_key_der_2048_ssh);
368+
sz = sizeof_rsa_key_der_2048_ssh;
369369
}
370370

371371
return sz;

tests/auth.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,18 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
201201
#else
202202
/* using buffers instead */
203203
if (isEcc) {
204-
if ((word32)sizeof_ecc_key_der_256 > bufSz) {
204+
if ((word32)sizeof_ecc_key_der_256_ssh > bufSz) {
205205
return 0;
206206
}
207-
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
208-
sz = sizeof_ecc_key_der_256;
207+
WMEMCPY(buf, ecc_key_der_256_ssh, sizeof_ecc_key_der_256_ssh);
208+
sz = sizeof_ecc_key_der_256_ssh;
209209
}
210210
else {
211-
if ((word32)sizeof_rsa_key_der_2048 > bufSz) {
211+
if ((word32)sizeof_rsa_key_der_2048_ssh > bufSz) {
212212
return 0;
213213
}
214-
WMEMCPY(buf, (byte*)rsa_key_der_2048, sizeof_rsa_key_der_2048);
215-
sz = sizeof_rsa_key_der_2048;
214+
WMEMCPY(buf, (byte*)rsa_key_der_2048_ssh, sizeof_rsa_key_der_2048_ssh);
215+
sz = sizeof_rsa_key_der_2048_ssh;
216216
}
217217
#endif
218218

wolfssh/certs_test.h

Lines changed: 18 additions & 9 deletions
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
*
@@ -21,10 +21,19 @@
2121
#ifndef _WOLFSSH_CERTS_TEST_H_
2222
#define _WOLFSSH_CERTS_TEST_H_
2323

24+
/* To distinguish these certs from those in wolfssl add suffix: _ssh
25+
* See: https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h
26+
* Generate: https://github.com/wolfSSL/wolfssl/blob/master/gencertbuf.pl
27+
*
28+
* In C89/C90 (which Watcom generally defaults to), sizeof must be a
29+
* compile-time constant expression when used in a static initializer.
30+
* So don't use `static const int sizeof_`
31+
*/
32+
2433
#if defined(NO_FILESYSTEM)
2534

2635
/* ./keys/server-key-rsa.der, 2048-bit */
27-
static const unsigned char rsa_key_der_2048[] =
36+
static const unsigned char rsa_key_der_2048_ssh[] =
2837
{
2938
0x30, 0x82, 0x04, 0xA3, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
3039
0x01, 0x00, 0xDA, 0x5D, 0xAD, 0x25, 0x14, 0x76, 0x15, 0x59,
@@ -147,10 +156,10 @@ static const unsigned char rsa_key_der_2048[] =
147156
0x56, 0xC3, 0xCE, 0x77, 0x5F, 0x5B, 0xBA, 0x6C, 0x42, 0xF1,
148157
0x21
149158
};
150-
static const int sizeof_rsa_key_der_2048 = sizeof(rsa_key_der_2048);
159+
#define sizeof_rsa_key_der_2048_ssh (sizeof(rsa_key_der_2048_ssh))
151160

152161
/* ./keys/server-key-ecc.der, ECC */
153-
static const unsigned char ecc_key_der_256[] =
162+
static const unsigned char ecc_key_der_256_ssh[] =
154163
{
155164
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x61, 0x09, 0x99,
156165
0x0B, 0x79, 0xD2, 0x5F, 0x28, 0x5A, 0x0F, 0x5D, 0x15, 0xCC,
@@ -166,10 +175,10 @@ static const unsigned char ecc_key_der_256[] =
166175
0x05, 0x58, 0x6B, 0x5F, 0x63, 0xC8, 0xDA, 0x1B, 0xC4, 0xF5,
167176
0x69
168177
};
169-
static const int sizeof_ecc_key_der_256 = sizeof(ecc_key_der_256);
178+
#define sizeof_ecc_key_der_256_ssh (sizeof(ecc_key_der_256_ssh))
170179

171180
/* ./keys/server-key-ecc-384.der, ECC */
172-
static const unsigned char ecc_key_der_384[] =
181+
static const unsigned char ecc_key_der_384_ssh[] =
173182
{
174183
0x30, 0x81, 0xA4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x3E, 0xAD,
175184
0xD2, 0xBB, 0xBF, 0x05, 0xA7, 0xBE, 0x3A, 0x3F, 0x7C, 0x28,
@@ -189,10 +198,10 @@ static const unsigned char ecc_key_der_384[] =
189198
0x3D, 0x3E, 0xB8, 0x8D, 0x46, 0x7B, 0x5F, 0x27, 0xEB, 0xAB,
190199
0x21, 0x61, 0xC0, 0x00, 0x66, 0xFE, 0xBD
191200
};
192-
static const int sizeof_ecc_key_der_384 = sizeof(ecc_key_der_384);
201+
#define sizeof_ecc_key_der_384_ssh (sizeof(ecc_key_der_384_ssh))
193202

194203
/* ./keys/server-key-ecc-521.der, ECC */
195-
static const unsigned char ecc_key_der_521[] =
204+
static const unsigned char ecc_key_der_521_ssh[] =
196205
{
197206
0x30, 0x81, 0xDC, 0x02, 0x01, 0x01, 0x04, 0x42, 0x00, 0x4C,
198207
0xA4, 0xD8, 0x64, 0x28, 0xD9, 0x40, 0x0E, 0x7B, 0x2D, 0xF3,
@@ -218,7 +227,7 @@ static const unsigned char ecc_key_der_521[] =
218227
0x23, 0x7C, 0xA5, 0xA3, 0x45, 0xB1, 0x9E, 0x3F, 0x1A, 0x22,
219228
0x90, 0xB1, 0x54
220229
};
221-
static const int sizeof_ecc_key_der_521 = sizeof(ecc_key_der_521);
230+
#define sizeof_ecc_key_der_521_ssh (sizeof(ecc_key_der_521_ssh))
222231

223232
#endif /* NO_FILESYSTEM */
224233

0 commit comments

Comments
 (0)