Skip to content

Commit 4a258d2

Browse files
Merge pull request #383 from tim-weller-wolfssl/mynewt-updates
Update wolfSSL Mynewt OS examples
2 parents 4be73cc + c5fc23f commit 4a258d2

3 files changed

Lines changed: 157 additions & 47 deletions

File tree

mynewt/README.md

Lines changed: 152 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,129 @@
1-
Apache Mynewt examples
2-
=============
1+
# Apache Mynewt examples
32

43
## Overview
54

6-
It provides follows mynewt packages.
5+
[Mynewt](https://mynewt.apache.org) is a security-oriented OS for IoT.
76

8-
- apps/wolfsslclienttlsmn
9-
- client-tls simple example ssl/tls client application for mn_socket.
7+
WolfSSL integration with the Mynewt OS may be found in the `/IDE/mynewt`
8+
directory in the `wolfssl` source-tree. Support includes the wolfCrypt test
9+
application which demonstrates the cryptography provided by the wolfCrypt
10+
component of wolfSSL.
1011

11-
## Prepare
12+
`wolfssl` provides the following mynewt packages:
1213

13-
install `newt` command by referencing below document.
14+
- _crypto/wolfsslwolfssl_ - wolfSSL SSL/TLS and wolfCrypt cryptography library
15+
- _apps/wolfcrypttest_ - wolfCrypt unit test application
16+
17+
The examples for wolfSSL and Mynewt found in the `mynewt` directory of
18+
`wolfssl-examples` (this directory) includes demonstration of additional
19+
wolfSSL capabilities such as TLS.
20+
21+
`wolfssl-examples` provides the follows mynewt packages:
22+
23+
- _apps/wolfsslclienttlsmn_ - simple client TLS application for `mn_socket`
24+
25+
The Mynewt OS has a primary command-line tool called `newt` which is used to
26+
configure and build Mynewt for targets. Targets include a simulated environment
27+
for Linux hosts, which will be used by the wolfSSL applications. Mynewt installs
28+
to a project directory from which the `newt` command is run.
29+
30+
## Setup
31+
32+
1. Install Mynewt `newt` command using instructions found at:
1433

1534
http://mynewt.apache.org/latest/get_started/native_install/index.html
1635

17-
## How to setup
36+
2. Create Mynewt project directory (e.g. `mynewt`).
37+
38+
In parent folder of new Mynewt project directory:
39+
40+
```
41+
$ newt new mynewt
42+
```
43+
44+
NOTE: If problems are encountered creating a new Mynewt project an alternative:
1845

19-
### delopy wolfssl source to mynewt project
20-
Specify the path of the mynewt project and execute `mynewt/setup.sh`.
46+
```
47+
$ git clone git@github.com:apache/mynewt-blinky.git mynewt
48+
$ cd mynewt
49+
$ newt upgrade
50+
```
51+
52+
3. Install wolfSSL support into Mynewt project.
2153

22-
```bash
23-
./mynewt/setup.sh /path/to/myproject_path
54+
In the `wolfssl/IDE/mynewt` directory:
55+
56+
```
57+
$ ./setup path-to-mynewt
2458
```
2559

26-
This script will deploy wolfssl's mynewt package described in the Overview to the mynewt project.
60+
4. Install wolfSSL examples support into Mynewt project.
2761

28-
## example setting example applications to targets
62+
In the `wolfssl-examples/mynewt` directory:
2963

30-
This section explains how to set wolfssl example application to target device.
64+
```
65+
$ ./setup path-to-mynewt
66+
```
67+
68+
## Configuration
3169

32-
Please execute follows commands at only once.
70+
1. Create client TLS application for simulator target.
3371

34-
create wolfsslclienttlsmn_sim that is simulator device for unit test of client-tls.
72+
In Mynewt project directory:
3573

3674
```
37-
cd /path/to/myproject_path
38-
newt target delete wolfsslclienttlsmn_sim
39-
newt target create wolfsslclienttlsmn_sim
40-
newt target set wolfsslclienttlsmn_sim app=apps/wolfsslclienttlsmn
41-
newt target set wolfsslclienttlsmn_sim bsp=@apache-mynewt-core/hw/bsp/native
42-
newt target set wolfsslclienttlsmn_sim build_profile=debug
75+
$ newt target create wolfsslclienttlsmn_sim
76+
$ newt target set wolfsslclienttlsmn_sim app=apps/wolfsslclienttlsmn
77+
$ newt target set wolfsslclienttlsmn_sim bsp=@apache-mynewt-core/hw/bsp/native
78+
$ newt target set wolfsslclienttlsmn_sim build_profile=debug
4379
```
4480

81+
## Build and Run
4582

46-
## build & test
83+
1. Build client TLS application.
4784

48-
build and execute wolfsslclienttlsmn_sim
85+
In Mynewt project directory:
4986

5087
```
51-
newt clean wolfsslclienttlsmn_sim
52-
newt build wolfsslclienttlsmn_sim
53-
./bin/targets/wolfsslclienttlsmn_sim/app/apps/wolfsslclienttlsmn/wolfsslclienttlsmn.elf
88+
$ newt clean wolfsslclienttlsmn_sim
89+
$ newt build wolfsslclienttlsmn_sim
5490
```
5591

56-
## Usage
57-
### connect `wolfsslclienttlsmn`
92+
2. Run client TLS application
5893

59-
`wolfssl clienttlsmn.elf` displays tty file path.
60-
be able to connect `wolfsslclienttlsmn.elf` by using terminal softwre such as `screen` or `kermit`.
94+
In Mynewt project directory:
6195

62-
### command list
96+
```
97+
$ ./bin/targets/wolfsslclienttlsmn_sim/app/apps/wolfsslclienttlsmn/wolfsslclienttlsmn.elf
98+
```
6399

64-
`wolfsslclienttlsmn` has below commands.
100+
The Mynewt simulator will display the linux host device where the application's
101+
uart is accessible via a terminal emulator program such as `picocom`, `screen` or
102+
`kermit`. For example: `uart0 at /dev/pts/3`
103+
104+
3. Connect terminal emulator (e.g. picocom) to simulated application UART.
105+
106+
```
107+
$ sudo picocom -b 115200 /dev/pts/3
108+
```
109+
110+
The application will display the Mynewt shell prompt `compat>` (press ENTER if
111+
shell prompt is not visiable). Entering `help` will display commands available,
112+
including the `wolfssl` command with represents the client TLS application.
113+
114+
## Usage
115+
116+
### Command list
117+
118+
The client TLS application `wolfssl` has the following commands:
65119

66120

67121
| command | argument | describe | example |
68122
|---------|----------------------------------|----------------------------|---------------------------------------|
69123
| time | "unix timestamp" | To set the time | "time 1532616682" |
70124
| net | udp | create udp socket | "net udp" |
71125
| net | tcp | create tcp socket | "net tcp" |
72-
| net | connect "ipaddress" port | connect "ipaddress" | "net connect 93.184.216.34" 443 |
126+
| net | connect "ipaddress" port | connect "ipaddress" | "net connect 93.184.216.34 443" |
73127
| net | close | close socket | "net close" |
74128
| net | send "string" "ipaddress" "port" | send string | "net send "GET \r\n" 93.184.216.34 80 |
75129
| net | recv "ipaddress" | recv from ipaddress | "net recv 93.184.216.34 80 |
@@ -79,24 +133,79 @@ be able to connect `wolfsslclienttlsmn.elf` by using terminal softwre such as `s
79133
| wolfssl | read | recv via ssl | "wolfssl recv" |
80134
| wolfssl | clear | finish wolfssl library | "wolfssl clear" |
81135

82-
### command examples
83-
get `index.html` from `www.example.com:443`
136+
### Command examples
137+
Get `index.html` from `www.example.com:443` (i.e. `93.184.216.34:443`) using
138+
Mynewt TCP networking and the wolfSSL TLS and crypto.
139+
140+
At the Mynewt `compat>` shell prompt:
84141

85142
```
86143
net tcp
87-
net connect
144+
net connect 93.184.216.34 443
88145
wolfssl init
89146
wolfssl connect
90-
wolfssl write
147+
wolfssl write "GET /"
91148
wolfssl read
92149
wolfssl clear
93150
net close
94151
```
95152

96-
# jenkins script
97-
## setup for jenkins node
153+
The resulting application output should be similar to the following:
154+
155+
```
156+
compat> net tcp
157+
001143 mn_socket(TCP) = 0 566b7800
158+
compat> net connect 93.184.216.34 443
159+
005078 93.184.216.34/443
160+
005078 mn_connect() = 0
161+
compat> net_test_writable 0 - 0
162+
wolfssl init
163+
005853 wolfssl contexts are initialized
164+
005854 wolfSSL ctx initialize
165+
compat> wolfssl connect
166+
006517 wolfSSL_connect() = 1
167+
compat> wolfssl write "GET /"
168+
009182 wolfSSL_write() = 4L
169+
compat> wolfssl read
170+
010564 HTTP/1.0 501 Not Implemented
171+
Content-Type: text/html
172+
Content-Length: 357
173+
Connection: close
174+
Date: Wed, 12 Apr 2023 14:49:27 <?xml version="1.0" encoding="iso-8859-1"?>
175+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
176+
"http://wwwitle>501 - Not Implemented</title>
177+
</head>
178+
<body>
179+
<h1>501 - Not Implemented</h1>
180+
</body>
181+
</html>
182+
183+
010578
184+
010578 ERROR: wolfSSL_read rc:-1 err:6
185+
compat> wolfssl clear
186+
012551 clear wolfssl contexts
187+
012553 wolfSSL ctx clear
188+
compat> net close
189+
012893 mn_close() = 0
190+
compat>
191+
```
192+
193+
NOTE: The server-side connection close after reception of data results in the
194+
read error.
195+
196+
## Notes
197+
198+
- Client TLS example run on _Ubuntu 22.04LTS_ host with _wolfSSL v5.6.0_.
199+
200+
- See `wolfssl/IDE/mynewt/README.md` for details on wolfSSL integration and use
201+
of the wolfCrypt test application.
202+
203+
204+
# Jenkins script (test automation)
205+
206+
## Setup for jenkins node
98207

99-
install below softwares
208+
Install:
100209

101210
- git
102211
- expect
@@ -106,7 +215,7 @@ install below softwares
106215

107216
## Usage
108217

109-
execute `jenkins.sh` script on jenkins.
218+
Execute `jenkins.sh` script on jenkins.
110219

111220
```
112221
./mynewt/jenkins.sh

mynewt/apps.wolfsslclienttlsmn.pkg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pkg.deps:
2828
- "@apache-mynewt-core/kernel/os"
2929
- "@apache-mynewt-core/sys/console/full"
3030
- "@apache-mynewt-core/net/ip/mn_socket"
31-
- "@apache-mynewt-core/boot/bootutil"
31+
- "@mcuboot/boot/bootutil"
3232
- "@apache-mynewt-core/sys/shell"
3333
- "@apache-mynewt-core/sys/config"
3434
- "@apache-mynewt-core/sys/console/full"

mynewt/client-tls-mn.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
#ifdef ARCH_sim
5151
#include <mcu/mcu_sim.h>
52+
extern time_t time(time_t*);
5253
#endif
5354

5455
/* wolfSSL */
@@ -96,6 +97,8 @@ time_cli(int argc, char **argv)
9697
tz.tz_minuteswest = 0;
9798
tz.tz_dsttime = 0;
9899
os_settimeofday(&utctime, &tz);
100+
101+
return 0;
99102
}
100103

101104
/* net command */
@@ -419,8 +422,6 @@ wolfssl_cli(int argc, char **argv)
419422
{
420423
int rc;
421424
int err = 0;
422-
char errBuffer[80];
423-
struct os_mbuf *m;
424425

425426
if (argc < 2) {
426427
return 0;
@@ -470,7 +471,7 @@ wolfssl_cli(int argc, char **argv)
470471
}
471472
console_printf("%.*s\n", rc, buff);
472473
}
473-
console_printf("\n", buff);
474+
console_printf("\n");
474475

475476
} else {
476477
console_printf("ERROR: unknown command: %s\n", subCommand);

0 commit comments

Comments
 (0)