Statistics: Posted by Npt — Fri Sep 25, 2015 11:32 pm
Statistics: Posted by hdrut — Fri Sep 25, 2015 9:18 pm
Statistics: Posted by Npt — Fri Sep 25, 2015 2:03 pm
Statistics: Posted by hdrut — Fri Sep 25, 2015 4:38 am
Statistics: Posted by Npt — Fri Sep 25, 2015 12:58 am
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
cnt
connected with <SSID>, channel 1
ip:192.168.2.200,mask:255.255.255.0,gw:192.168.2.1
WiFi is up, starting HTTPS server...
HTTPS server started.
pm open phy_2,type:2 0 0
server handshake start.
server handshake ok!
Client connected from 192.168.2.105:41708.
Received 292 bytes from client:
--begin data--
GET / HTTP/1.1
Host: myesp
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
--end data--
Sent data to client.
server's data invalid protocol
3ffefff0 already freed
3fff0010 already freed
Fatal exception 29(StoreProhibitedCause):
epc1=0x4000df98, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000000c, depc=0x00000000
Code:
#include"ets_sys.h"
#include"osapi.h"
#include"gpio.h"
#include"os_type.h"
#include"user_interface.h"
#include"mem.h"
#include"espconn.h"
#include"driver/uart.h"
// Make your own user_config.h
#include"user_config.h" // defines WIFI_SSID and WIFI_PSWD
// These files are created by makecert.sh
#include"cert.h" // defines myesp_crt_DER and myesp_crt_DER_len
#include"private_key.h" // defines myesp_key_DER and myesp_key_DER_len
// listener connection data
struct espconn listenConn;
esp_tcp listenConnTcp;
// standard HTTP reply
uint8_t* reply = "HTTP/1.1 200 OK\r\n"
"Connection: close\r\n" // make the client (browser) close the connection after receipt
"Content-type: text/html\r\n"
"Content-length: 30\r\n\r\n"
"<html><body>Test</body></html>\0";
void ICACHE_FLASH_ATTR
onRecv(void* arg, char* data, unsigned short length)
{
os_printf("Received %d bytes from client:\n--begin data--\n", length);
uart0_tx_buffer(data, length);
os_printf("\n--end data--\n");
// send reply
struct espconn* clientConn = (struct espconn*)arg;
espconn_secure_send(clientConn, reply, os_strlen(reply));
/*
* (Under normal circumstances you should check the received data first,
* making sure in particular that the complete HTTP request has been
* received. Most of the time, it will arrive in one piece, but there's
* no guarantee. It could be split up into multiple callbacks. But since
* this is a minimal example, we'll ignore such things and just send the
* reply. Just keep in mind that this might result in multiple responses,
* especially when the client is not a browser but a slowly typing human
* on an SSL console.)
*/
}
void ICACHE_FLASH_ATTR
onSent(void* arg)
{
os_printf("Sent data to client.\n");
}
void ICACHE_FLASH_ATTR
onError(void* arg, int8_t err)
{
os_printf("Connection error: %d\n", err);
}
void ICACHE_FLASH_ATTR
onDisconn(void* arg)
{
os_printf("Client disconnected.\n");
}
void ICACHE_FLASH_ATTR
onClientConnected(void* arg)
{
struct espconn* clientConn = (struct espconn*)arg;
os_printf("Client connected from %d.%d.%d.%d:%d.\n",
clientConn->proto.tcp->remote_ip[0],
clientConn->proto.tcp->remote_ip[1],
clientConn->proto.tcp->remote_ip[2],
clientConn->proto.tcp->remote_ip[3],
clientConn->proto.tcp->remote_port);
// register callback functions
espconn_regist_recvcb(clientConn, onRecv);
espconn_regist_sentcb(clientConn, onSent);
espconn_regist_reconcb(clientConn, onError);
espconn_regist_disconcb(clientConn, onDisconn);
}
void ICACHE_FLASH_ATTR
onWifiEvent(System_Event_t *event)
{
if(event->event != EVENT_STAMODE_CONNECTED)
return;
os_printf("WiFi is up, starting HTTPS server...\n");
// set listener configuration and register callback
listenConn.type = ESPCONN_TCP;
listenConn.state = ESPCONN_NONE;
listenConn.proto.tcp = &listenConnTcp;
listenConnTcp.local_port = 443;
espconn_regist_connectcb(&listenConn, onClientConnected);
// SSL configuration
espconn_secure_set_size(0x02, 8192); // use maximum amount of space possible
espconn_secure_ca_disable(0x02);
/*
* I'm not quite sure what this function does. I'm assuming the previous
* line turns off client authentication (which as far as I know is never
* used in HTTPS).
* See http://bbs.espressif.com/viewtopic.php?f=7&t=1129 for a discussion
* on this.
*/
// set server certificate (defined in user_config.h and cert.h)
espconn_secure_set_default_certificate(myesp_crt_DER, myesp_crt_DER_len);
espconn_secure_set_default_private_key(myesp_key_DER, myesp_key_DER_len);
// start listening
espconn_secure_accept(&listenConn);
os_printf("HTTPS server started.\n");
}
void ICACHE_FLASH_ATTR
onInitDone()
{
// WiFi configuration
wifi_set_opmode(STATION_MODE);
struct station_config config;
strcpy(config.ssid, WIFI_SSID); // defined in user_config.h
strcpy(config.password, WIFI_PSWD); // defined in user_config.h
config.bssid_set = 0;
wifi_station_set_config(&config);
wifi_station_set_hostname("myesp"); // ESP's host name (matches certificate)
// set static IP (seems more appropriate for a server)
wifi_station_dhcpc_stop();
struct ip_info ipInfo;
IP4_ADDR(&ipInfo.ip, 192, 168, 2, 200); // static IP
IP4_ADDR(&ipInfo.netmask, 255, 255, 255, 0); // netmask
IP4_ADDR(&ipInfo.gw, 192, 168, 2, 1); // gateway
wifi_set_ip_info(STATION_IF, &ipInfo);
ip_addr_t dns;
IP4_ADDR(&dns, 192, 168, 2, 1); // DNS server
espconn_dns_setserver(1, &dns);
// connect
wifi_set_event_handler_cb(onWifiEvent);
wifi_station_connect();
}
void ICACHE_FLASH_ATTR
user_init()
{
// initialise UART
uart_init(BIT_RATE_9600, BIT_RATE_9600); // 9600 baud
system_set_os_print(1);
// register post-initialisation callback
system_init_done_cb(onInitDone);
}
Code:
#!/bin/bash
#------------------------------------------------------------------------------
# cleanup any previously created files
rm -f myca.* myesp.* cert.h private_key.h
#------------------------------------------------------------------------------
# create a CA called "myca"
# create a private key
openssl genrsa -out myca.key 1024
# create certificate
cat > myca.conf << EOF
[ req ]
distinguished_name = req_distinguished_name
prompt = no
[ req_distinguished_name ]
C = FR
ST = IDF
L = Paris
O = MyCompany
OU = MyDept
CN = myca
EOF
openssl req -new -x509 -days 3650 -key myca.key -out myca.crt -config myca.conf
# create serial number file
echo "01" > myca.srl
#------------------------------------------------------------------------------
# create a certificate for the ESP (hostname: "myesp")
# create a private key
openssl genrsa -out myesp.key 1024
# create certificate signing request
cat > myesp.conf << EOF
[ req ]
distinguished_name = req_distinguished_name
prompt = no
[ req_distinguished_name ]
C = FR
ST = IDF
L = Paris
O = MyCompany
OU = MyDept
CN = myesp
EOF
openssl req -new -key myesp.key -out myesp.csr -config myesp.conf
# have myca sign the certificate
openssl x509 -days 3650 -CA myca.crt -CAkey myca.key -in myesp.csr -req -out myesp.crt
# verify
openssl verify -CAfile myca.crt myesp.crt
# convert private key and certificate into DER format
openssl rsa -in myesp.key -outform DER -out myesp.key.DER
openssl x509 -in myesp.crt -outform DER -out myesp.crt.DER
# create header files
xxd -i myesp.crt.DER > cert.h
xxd -i myesp.key.DER > private_key.h
Statistics: Posted by Npt — Tue Sep 22, 2015 4:17 pm
Statistics: Posted by hdrut — Thu Sep 17, 2015 7:36 pm
Statistics: Posted by Npt — Thu Sep 17, 2015 5:21 pm
Statistics: Posted by ESP_Faye — Thu Sep 17, 2015 5:12 pm
Statistics: Posted by Npt — Wed Sep 16, 2015 11:51 pm
Statistics: Posted by hdrut — Wed Sep 16, 2015 11:16 pm
Code:
espconn_secure_set_size(0x02, 8192);
espconn_secure_ca_disable(0x02); // Not sure if this is needed, but it shouldn't hurt, right? I'm assuming
// this means "Don't try to authenicate the client".
espconn_secure_accept(&listenConn);
Testing SSL server Node001 on port 443
Supported Server Cipher(s):
Failed SSLv3 256 bits ECDHE-RSA-AES256-GCM-SHA384
Failed SSLv3 256 bits ECDHE-ECDSA-AES256-GCM-SHA384
Statistics: Posted by Npt — Wed Sep 16, 2015 6:40 pm