Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document tls.cert.auth #3010

Merged
merged 5 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/modules/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ static int tls_cert_verify(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
const char *types[2] = { "CERTIFICATE", NULL };
const char *names[1] = { "certificate" };

nwf marked this conversation as resolved.
Show resolved Hide resolved
const char *error = fill_page_with_pem(L, &tls_server_cert_area[0], flash_offset, types, names);
if (error) {
return luaL_error(L, error);
Expand Down
55 changes: 52 additions & 3 deletions docs/modules/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ none

## tls.cert.verify()

Controls the vertificate verification process when the Nodemcu makes a secure connection.
Controls the certificate verification process when the Nodemcu makes a secure connection.

#### Syntax
`tls.cert.verify(enable)`

`tls.cert.verify(pemdata)`
`tls.cert.verify(pemdata[, pemdata])`
marcelstoer marked this conversation as resolved.
Show resolved Hide resolved
marcelstoer marked this conversation as resolved.
Show resolved Hide resolved

#### Parameters
- `enable` A boolean which indicates whether verification should be enabled or not. The default at boot is `false`.
- `pemdata` A string containing the CA certificate to use for verification.
- `pemdata` A string containing the CA certificate to use for verification. There can be several of these.

#### Returns
`true` if it worked.
Expand Down Expand Up @@ -321,6 +321,55 @@ The alternative approach is easier for development, and that is to supply the PE
will store the certificate into the flash chip and turn on verification for that certificate. Subsequent boots of the nodemcu can then
use `tls.cert.verify(true)` and use the stored certificate.

## tls.cert.auth()

Controls the certificate verification process when the Nodemcu authenticates against the client like when receiving a secure connection.
marcelstoer marked this conversation as resolved.
Show resolved Hide resolved

marcelstoer marked this conversation as resolved.
Show resolved Hide resolved
#### Syntax
`tls.cert.auth(enable)`

`tls.cert.auth(pemdata[, pemdata])`

#### Parameters
- `enable` A boolean which indicates whether verification should be enabled or not. The default at boot is `false`.
- `pemdata` A string containing the CA certificate to use for verification. There can be several of these.
marcelstoer marked this conversation as resolved.
Show resolved Hide resolved

#### Returns
`true` if it worked.

Can throw a number of errors if invalid data is supplied.

#### Example
Open an mqtt client.
marcelstoer marked this conversation as resolved.
Show resolved Hide resolved
```
tls.cert.auth(true)
tls.cert.verify(true)

m = mqtt.Client('basicPubSub', 1500, "admin", "admin", 1)
```
For further discussion see https://github.com/nodemcu/nodemcu-firmware/issues/2576

Load a certificate into the flash chip and make a request.

nwf marked this conversation as resolved.
Show resolved Hide resolved
```
tls.cert.auth([[
-----BEGIN CERTIFICATE-----
CLIENT CERTIFICATE String (PEM file)
-----END CERTIFICATE-----
]])
```
nwf marked this conversation as resolved.
Show resolved Hide resolved

#### Notes
The certificate needed for verification is stored in the flash chip. The `tls.cert.auth` call with `true`
enables verification against the value stored in the flash.

marcelstoer marked this conversation as resolved.
Show resolved Hide resolved
The certificate can not be loaded into the flash chip at initial boot of the firmware.
It only can be supplied by passing the PEM data as a string value to `tls.cert.auth`. This
will store the certificate into the flash chip and turn on verification for that certificate.
Subsequent boots of the nodemcu can then use `tls.cert.auth(true)` and use the stored certificate.



# tls.setDebug function

mbedTLS can be compiled with debug support. If so, the tls.setDebug
Expand Down