Skip to content

Commit a612d6c

Browse files
authored
Merge pull request #22 from ejohnstown/rekeying
Rekeying
2 parents 1524047 + 4ff6a52 commit a612d6c

11 files changed

Lines changed: 1198 additions & 516 deletions

File tree

README.md

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ wolfssh
33

44
wolfSSL's Embeddable SSH Server
55

6+
dependencies
7+
------------
8+
9+
wolfSSH is dependent on wolfCrypt. The simplest configuration of wolfSSL
10+
required for wolfSSH is the default build.
11+
12+
$ cd wolfssl
13+
$ ./configure [OPTIONS]
14+
$ make check
15+
$ sudo make install
16+
17+
To use the key generation function in wolfSSH, wolfSSL will need to be
18+
configured with keygen: `--enable-keygen`.
19+
20+
If the bulk of wolfSSL code isn't desired, wolfSSL can be configured with
21+
the crypto only option: `--enable-cryptonly`.
22+
23+
624
building
725
--------
826

@@ -17,6 +35,7 @@ The `autogen.sh` script only has to be run the first time after cloning the
1735
repository. If you have already run it or are using code from a source
1836
archive, you should skip it.
1937

38+
2039
examples
2140
--------
2241

@@ -38,13 +57,14 @@ The server will send a canned banner to the client:
3857
Characters typed into the client will be echoed to the screen by the server.
3958
If the characters are echoed twice, the client has local echo enabled.
4059

60+
4161
testing notes
4262
-------------
4363

4464
After cloning the repository, be sure to make the testing private keys read-
4565
only for the user, otherwise ssh_client will tell you to do it.
4666

47-
$ chmod 0600 ./certs/key-gretel.pem ./certs/key-hansel.pem
67+
$ chmod 0600 ./keys/key-gretel.pem ./keys/key-hansel.pem
4868

4969
Authentication against the example echoserver can be done with a password or
5070
public key. To use a password the command line:
@@ -58,40 +78,14 @@ Where the `USER` and password pairs are:
5878

5979
To use public key authentication use the command line:
6080

61-
$ ssh_client -i ./certs/key-USER.pem -p 22222 USER@localhost
81+
$ ssh_client -i ./keys/key-USER.pem -p 22222 USER@localhost
6282

6383
Where the user can be `gretel` or `hansel`.
6484

6585

66-
coding standard
67-
---------------
68-
69-
1. Exceptions are allowed with good reason.
70-
71-
2. Follow the existing style.
72-
73-
3. Try not to shorthand variables, except for ijk as indicies.
74-
75-
4. Lengths of arrays should have the array name followed by Sz.
76-
77-
5. Single return per function.
78-
79-
6. Check all incoming parameters.
80-
81-
7. No gotos.
82-
83-
8. Check all return codes. It feels a little tedious, but the preferred method
84-
is running checks against success. This way if a function returns an error, the
85-
code will drop to the end.
86-
87-
```
88-
ret = functionCall(parameter);
89-
if (ret == SUCCESS)
90-
ret = secondFunctionCall(otherParameter);
91-
if (ret == SUCCESS)
92-
ret = thirdFunctionCall(aParameter, anotherParameter);
93-
cleanUp();
94-
return ret;
95-
```
86+
release notes
87+
-------------
9688

89+
### wolfSSH v1.0.0 (10/24/2016)
9790

91+
Initial release.

configure.ac

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (C) 2014-2016 wolfSSL Inc.
33
# All right reserved.
44

5-
AC_INIT([wolfssh], [0.2.0], [http://wolfssl.com], [wolfssh])
5+
AC_INIT([wolfssh], [1.0.0], [http://wolfssl.com], [wolfssh])
66
AC_PREREQ([2.63])
77
AC_CONFIG_AUX_DIR([build-aux])
88

@@ -17,18 +17,18 @@ AC_ARG_PROGRAM
1717
AC_CONFIG_MACRO_DIR([m4])
1818
AC_CONFIG_HEADERS([src/config.h])
1919

20-
WOLFSSH_LIBRARY_VERSION=1:2:0
21-
# | | |
22-
# +------+ | +---+
23-
# | | |
24-
# current:revision:age
25-
# | | |
26-
# | | +- increment if interfaces have been added
27-
# | | set to zero if interfaces have been removed
28-
# | | or changed
29-
# | +- increment if source code has changed
30-
# | set to zero if current is incremented
31-
# +- increment if interfaces have been added, removed or changed
20+
WOLFSSH_LIBRARY_VERSION=2:0:1
21+
# | | |
22+
# +------+ | +---+
23+
# | | |
24+
# current:revision:age
25+
# | | |
26+
# | | +- increment if interfaces have been added
27+
# | | set to zero if interfaces have been removed
28+
# | | or changed
29+
# | +- increment if source code has changed
30+
# | set to zero if current is incremented
31+
# +- increment if interfaces have been added, removed or changed
3232
AC_SUBST([WOLFSSH_LIBRARY_VERSION])
3333

3434
LT_PREREQ([2.2])
@@ -105,6 +105,8 @@ AC_ARG_ENABLE([keygen],
105105
AS_IF([test "x$ENABLED_KEYGEN" = "xyes"],
106106
[AM_CFLAGS="$AM_CFLAGS -DWOLFSSH_KEYGEN"])
107107

108+
AM_CONDITIONAL([BUILD_KEYGEN], [test "x$ENABLED_KEYGEN" = "xyes"])
109+
108110

109111
# Checks for typedefs, structures, and compiler characteristics.
110112
if test "$ac_cv_sizeof_long" = "8"; then

examples/echoserver/echoserver.c

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ typedef struct {
9292
} thread_ctx_t;
9393

9494

95-
#ifndef DEFAULT_HIGHWATER_MARK
96-
#define DEFAULT_HIGHWATER_MARK 0
95+
#ifndef EXAMPLE_HIGHWATER_MARK
96+
#define EXAMPLE_HIGHWATER_MARK 0x3FFF8000 /* 1GB - 32kB */
97+
#endif
98+
#ifndef EXAMPLE_BUFFER_SZ
99+
#define EXAMPLE_BUFFER_SZ 4096
97100
#endif
98101

99102

@@ -284,23 +287,54 @@ static THREAD_RETURN CYASSL_THREAD server_worker(void* vArgs)
284287
WOLFSSH* ssh = (WOLFSSH*)vArgs;
285288
SOCKET_T clientFd = wolfSSH_get_fd(ssh);
286289

287-
uint8_t buf[4096];
288-
int bufSz;
289-
290290
if (wolfSSH_accept(ssh) == WS_SUCCESS) {
291-
292-
while (1) {
293-
bufSz = wolfSSH_stream_read(ssh, buf, sizeof(buf));
294-
if (bufSz > 0) {
295-
wolfSSH_stream_send(ssh, buf, bufSz);
296-
if (find_char(0x03, buf, bufSz))
297-
break;
298-
}
299-
else {
300-
printf("wolfSSH_stream_read returned %d\n", bufSz);
301-
break;
291+
uint8_t* buf = NULL;
292+
uint8_t* tmpBuf;
293+
int bufSz, backlogSz = 0, rxSz, txSz, stop = 0, txSum;
294+
295+
do {
296+
bufSz = EXAMPLE_BUFFER_SZ + backlogSz;
297+
298+
tmpBuf = realloc(buf, bufSz);
299+
if (tmpBuf == NULL)
300+
stop = 1;
301+
else
302+
buf = tmpBuf;
303+
304+
if (!stop) {
305+
rxSz = wolfSSH_stream_read(ssh,
306+
buf + backlogSz,
307+
EXAMPLE_BUFFER_SZ);
308+
if (rxSz > 0) {
309+
backlogSz += rxSz;
310+
txSum = 0;
311+
txSz = 0;
312+
313+
while (backlogSz != txSum && txSz >= 0 && !stop) {
314+
txSz = wolfSSH_stream_send(ssh,
315+
buf + txSum,
316+
backlogSz - txSum);
317+
318+
if (txSz > 0) {
319+
if (find_char(0x03, buf + txSum, txSz))
320+
stop = 1;
321+
else
322+
txSum += txSz;
323+
}
324+
else if (txSz != WS_REKEYING)
325+
stop = 1;
326+
}
327+
328+
if (txSum < backlogSz)
329+
memmove(buf, buf + txSum, backlogSz - txSum);
330+
backlogSz -= txSum;
331+
}
332+
else
333+
stop = 1;
302334
}
303-
}
335+
} while (!stop);
336+
337+
free(buf);
304338
}
305339
close(clientFd);
306340
wolfSSH_free(ssh);
@@ -592,29 +626,12 @@ static int wsUserAuth(uint8_t authType,
592626
}
593627

594628

595-
static int wsHighwater(uint8_t side, void* ctx)
596-
{
597-
if (ctx) {
598-
WOLFSSH* ssh = (WOLFSSH*)ctx;
599-
uint32_t highwaterMark = wolfSSH_GetHighwater(ssh);
600-
601-
printf("HIGHWATER ALERT: (%u) %s\n", highwaterMark,
602-
(side == WOLFSSH_HWSIDE_RECEIVE) ? "receive" : "transmit");
603-
highwaterMark *= 2;
604-
printf(" Doubling the highwater mark to %u.\n", highwaterMark);
605-
wolfSSH_SetHighwater(ssh, highwaterMark);
606-
}
607-
608-
return 0;
609-
}
610-
611-
612629
int main(void)
613630
{
614631
WOLFSSH_CTX* ctx = NULL;
615632
PwMapList pwMapList;
616633
SOCKET_T listenFd = 0;
617-
uint32_t defaultHighwater = DEFAULT_HIGHWATER_MARK;
634+
uint32_t defaultHighwater = EXAMPLE_HIGHWATER_MARK;
618635

619636
#ifdef DEBUG_WOLFSSH
620637
wolfSSH_Debugging_ON();
@@ -633,8 +650,6 @@ int main(void)
633650

634651
memset(&pwMapList, 0, sizeof(pwMapList));
635652
wolfSSH_SetUserAuth(ctx, wsUserAuth);
636-
if (defaultHighwater > 0)
637-
wolfSSH_SetHighwaterCb(ctx, defaultHighwater, wsHighwater);
638653

639654
{
640655
uint8_t buf[SCRATCH_BUFFER_SIZE];
@@ -678,8 +693,10 @@ int main(void)
678693
}
679694
wolfSSH_SetUserAuthCtx(ssh, &pwMapList);
680695
/* Use the session object for its own highwater callback ctx */
681-
if (defaultHighwater > 0)
696+
if (defaultHighwater > 0) {
682697
wolfSSH_SetHighwaterCtx(ssh, (void*)ssh);
698+
wolfSSH_SetHighwater(ssh, defaultHighwater);
699+
}
683700

684701
if (listen(listenFd, 5) != 0)
685702
err_sys("tcp listen failed");

notes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
wolfssh notes
2+
=============
3+
4+
coding standard
5+
---------------
6+
7+
1. Exceptions are allowed with good reason.
8+
9+
2. Follow the existing style.
10+
11+
3. Try not to shorthand variables, except for ijk as indicies.
12+
13+
4. Lengths of arrays should have the array name followed by Sz.
14+
15+
5. Single return per function.
16+
17+
6. Check all incoming parameters.
18+
19+
7. No gotos.
20+
21+
8. Check all return codes. It feels a little tedious, but the preferred method
22+
is running checks against success. This way if a function returns an error, the
23+
code will drop to the end.
24+
25+
```
26+
ret = functionCall(parameter);
27+
if (ret == SUCCESS)
28+
ret = secondFunctionCall(otherParameter);
29+
if (ret == SUCCESS)
30+
ret = thirdFunctionCall(aParameter, anotherParameter);
31+
cleanUp();
32+
return ret;
33+
```
34+
35+

src/include.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
lib_LTLIBRARIES+= src/libwolfssh.la
77
src_libwolfssh_la_SOURCES = src/ssh.c \
88
src/internal.c \
9-
src/keygen.c \
109
src/memory.c \
1110
src/log.c \
1211
src/io.c \
@@ -20,3 +19,7 @@ EXTRA_DIST +=
2019
if !BUILD_INLINE
2120
src_libwolfssh_la_SOURCES += src/misc.c
2221
endif
22+
23+
if BUILD_KEYGEN
24+
src_libwolfssh_la_SOURCES += src/keygen.c
25+
endif

0 commit comments

Comments
 (0)