|
1 | 1 | # wolfSSH MPLABX |
2 | 2 |
|
3 | | -This is example project to create a wolfSSH library and example code for adding |
4 | | -a wolfSSH echoserver to a MPLABX project. |
| 3 | +This is an example project demonstrating how to build the `wolfSSH` library and |
| 4 | + use it to add a SSH server to an MPLABX project. |
5 | 5 |
|
6 | | -Tested on a ATSAMV71Q21B with MPLABX version 6.20. |
| 6 | +Tested on an **ATSAMV71Q21B** using **MPLABX version 6.20**. |
7 | 7 |
|
8 | | -### Building wolfSSH library |
| 8 | +--- |
9 | 9 |
|
10 | | -The library project is located at ide/mplabx/wolfssh.X |
| 10 | +## Building the wolfSSH Library |
11 | 11 |
|
12 | | -- First open wolfssh.X with MPLABX IDE then click on "CM" content manager and |
13 | | -import the ide/mplabx/wolfssh.X/mcc-manifest-generated-success.yml file. |
14 | | -- Click apply. |
15 | | -- Next click "MCC" and "generate". |
16 | | -- To build from the command line, do the following after the XC32 toolchain has |
17 | | -been installed. |
| 12 | +The library project is located at: |
18 | 13 |
|
19 | 14 | ``` |
| 15 | +
|
| 16 | +ide/mplabx/wolfssh.X |
| 17 | +
|
| 18 | +``` |
| 19 | + |
| 20 | +### Using MPLABX IDE |
| 21 | + |
| 22 | +1. Open the `wolfssh.X` project in MPLABX. |
| 23 | +2. Click **CM (Content Manager)** and import the manifest: |
| 24 | + |
| 25 | +``` |
| 26 | +
|
| 27 | +ide/mplabx/wolfssh.X/mcc-manifest-generated-success.yml |
| 28 | +
|
| 29 | +```` |
| 30 | +
|
| 31 | +3. Click **Apply**. |
| 32 | +4. Click **MCC** and then **Generate**. |
| 33 | +5. Build the project via the IDE (hammer icon or `Run → Build Project`). |
| 34 | +
|
| 35 | +### Using the Command Line |
| 36 | +
|
| 37 | +After installing the XC32 toolchain: |
| 38 | +
|
| 39 | +```sh |
20 | 40 | cd ide/mplabx/wolfssh.X |
21 | 41 | make |
| 42 | +```` |
| 43 | +
|
| 44 | +This produces: |
| 45 | +
|
| 46 | +``` |
| 47 | +ide/mplabx/wolfssh.X/dist/default/production/wolfssh.X.a |
22 | 48 | ``` |
23 | 49 |
|
24 | | -- To build using the IDE open the project ide/mplabx/wolfssh.X and click build. |
| 50 | +> **Important:** The application and wolfSSL must be built using the **same** |
| 51 | + `user_settings.h` as used for the wolfSSH library. Mismatched macros can result |
| 52 | + in undefined behavior or crashes. |
25 | 53 |
|
| 54 | +--- |
26 | 55 |
|
27 | | -This will produce a wolfssh.X.a library in the directory |
28 | | -ide/mplabx/wolfssh.X/dist/default/production/wolfssh.X.a |
| 56 | +## Building the Example Application |
| 57 | +
|
| 58 | +### Steps: |
| 59 | +
|
| 60 | +1. **Set Preprocessor Macros**: |
| 61 | +
|
| 62 | + * Define `WOLFSSL_USER_SETTINGS`. |
| 63 | + * Add include path to `ide/mplabx/user_settings.h`. |
| 64 | +
|
| 65 | +2. **Remove** the generated `app.c` from Source Files. |
| 66 | +
|
| 67 | +3. **Link the wolfSSH Library**: |
| 68 | +
|
| 69 | + * Go to **Project Properties → Libraries → Add Library/Object File**. |
| 70 | + * Select `wolfssh.X.a`. |
29 | 71 |
|
30 | | -The application and wolfSSL must be built with the same user_settings.h as the |
31 | | -wolfSSH library was built with! Differences in macro's defined for |
32 | | -configuration will cause undefined behavior and potential crashes. |
| 72 | +4. **Add Source File**: |
33 | 73 |
|
34 | | -### Building an example app |
| 74 | + * Right-click the project → **Add Existing Item**. |
| 75 | + * Select `ide/mplabx/wolfssh.c`. |
35 | 76 |
|
36 | | -1) Adjust the "Preprocessor macros" to include WOLFSSL_USER_SETTINGS and add an |
37 | | - include path to ide/mplabx/user_settings.h. |
38 | | -2) Remove the generated app.c from Source File |
39 | | -3) Link to the wolfssh.X.a library. Properties->Libraries->Add Library/Object |
40 | | - File... |
41 | | -4) Right click on the project and add existing item. Select ide/mplabx/wolfssh.c |
42 | | -5) Increase the heap size to 200,000 by right clicking on the project, selecting |
43 | | - "Properties"->"x32-ld" |
| 77 | +5. **Increase Heap Size**: |
| 78 | +
|
| 79 | + * Right-click the project → **Properties → XC32-ld**. |
| 80 | + * Set heap size to at least **200,000**. |
| 81 | +
|
| 82 | +### Notes |
| 83 | +
|
| 84 | +* Tested with heap and stack sizes of **200,000**. |
| 85 | +* TX buffer size: **1024 bytes**. |
| 86 | +* Tested with `wolfSSH version 1.4.20`. |
| 87 | +
|
| 88 | +After flashing the board, a wolfSSH server will be listening on port **22**. |
| 89 | +You can connect using the provided client: |
| 90 | +
|
| 91 | +```sh |
| 92 | +./examples/client/client -u jill -P upthehill -h 192.168.1.120 -p 22 |
| 93 | +``` |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## Overriding the File System for SFTP |
| 98 | + |
| 99 | +This example shows how to override the SFTP file system interface and apply |
| 100 | + restrictions based on the logged-in user. It uses Microchip's file system but |
| 101 | + the approach is generic. |
| 102 | + |
| 103 | +### Enabling a Custom File System |
| 104 | + |
| 105 | +1. **Define `WOLFSSH_USER_FILESYSTEM`** in `user_settings.h`. |
| 106 | + |
| 107 | +2. **Provide `myFilesystem.h`**: |
| 108 | + |
| 109 | + * Required when `WOLFSSH_USER_FILESYSTEM` is defined. |
| 110 | + * Ensure it's in your include path (e.g., move it to the wolfSSH `include/` directory). |
| 111 | + |
| 112 | +3. **Add `myFilesystem.c`** to the wolfSSH project. |
| 113 | + |
| 114 | +4. **Recompile** the library. |
| 115 | + |
| 116 | +### Example File Operation Categories |
| 117 | + |
| 118 | +* **Safe operations**: Navigation, file downloads. |
| 119 | +* **Restricted operations**: Modifying or deleting files. |
| 120 | + |
| 121 | +Set the custom file system handle as follows: |
| 122 | + |
| 123 | +```c |
| 124 | +wolfSSH_SetFilesystemHandle(ssh, (void*)ssh); |
| 125 | +``` |
| 126 | +
|
| 127 | +### Integration Example (in `wolfssh.c`) |
| 128 | +
|
| 129 | +```c |
| 130 | +case APP_SSH_SFTP_START: |
| 131 | + SYS_CONSOLE_PRINT("Setting starting SFTP directory to [%s]\r\n", "/mnt/myDrive1"); |
| 132 | + if (wolfSSH_SFTP_SetDefaultPath(ssh, "/mnt/myDrive1") != WS_SUCCESS) { |
| 133 | + SYS_CONSOLE_PRINT("Error setting starting directory\r\n"); |
| 134 | + SYS_CONSOLE_PRINT("Error = %d\r\n", wolfSSH_get_error(ssh)); |
| 135 | + appData.state = APP_SSH_CLEANUP; |
| 136 | + } |
| 137 | + wolfSSH_SetFilesystemHandle(ssh, (void*)ssh); |
| 138 | + appData.state = APP_SSH_SFTP; |
| 139 | + break; |
| 140 | +``` |
44 | 141 |
|
45 | | -Notes: |
| 142 | +### Privileged Access |
46 | 143 |
|
47 | | -For the current project this was tested with the heap and stack set to 200,000 |
48 | | - each. This was not trimed to see the minumum possible heap and stack usage yet. |
49 | | - The TX buffer size used was set to 1024. The example was developed with wolfssh |
50 | | - version 1.4.20. |
| 144 | +Logging in as user `admin` with password `fetchapail` enables restricted operations. |
51 | 145 |
|
52 | | -After building and flashing the board a wolfSSH echoserver will be open on port |
53 | | - 22 which can be connected to by using the example client bundled with wolfSSH. |
54 | | - ```./examples/client/client -u jill -P upthehill -h 192.168.1.120 -p 22``` |
|
0 commit comments