|
@@ -3008,7 +3008,10 @@ void ssl_server(void *pvParameters)
|
|
|
case SSL_PROCESSING :
|
|
|
|
|
|
sendPtr = SSL_ProcessingRoutine(&sendBufLoadLen);
|
|
|
- ssl_state = SSL_WRITE;
|
|
|
+ if (sendPtr)
|
|
|
+ ssl_state = SSL_WRITE;
|
|
|
+ else
|
|
|
+ ssl_state = SSL_ACCEPT;
|
|
|
|
|
|
break;
|
|
|
|
|
@@ -3016,6 +3019,10 @@ void ssl_server(void *pvParameters)
|
|
|
ssl_state = SSL_WriteRoutine(&ssl, sendPtr, sendBufLoadLen);
|
|
|
break;
|
|
|
|
|
|
+ case SSL_ERROR :
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
case SSL_CRITICAL_ERROR:
|
|
|
|
|
|
mbedtls_x509_crt_free( &srvcert );
|
|
@@ -3056,15 +3063,18 @@ void HTTPS_Init()
|
|
|
|
|
|
void SSL_ReadRoutine(mbedtls_ssl_context *ssl, unsigned char* recvBuf)
|
|
|
{
|
|
|
- int ret, len;
|
|
|
+ int ret;
|
|
|
|
|
|
mbedtls_printf( " < Read from client:" );
|
|
|
do
|
|
|
{
|
|
|
- len = sizeof( recvBuf ) - 1;
|
|
|
- memset( recvBuf, 0, sizeof( recvBuf ) );
|
|
|
- ret = mbedtls_ssl_read(ssl, recvBuf, len );
|
|
|
+ receivedBufLen = RECIVE_BUF_MAX_LEN - 1;
|
|
|
+ memset(recvBuf, 0, RECIVE_BUF_MAX_LEN);
|
|
|
+ ret = mbedtls_ssl_read(ssl, recvBuf, (size_t)receiveBuf);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
|
|
|
{
|
|
|
continue;
|
|
@@ -3088,10 +3098,13 @@ void SSL_ReadRoutine(mbedtls_ssl_context *ssl, unsigned char* recvBuf)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- len = ret;
|
|
|
+ receivedBufLen = ret;
|
|
|
|
|
|
- mbedtls_printf( " %d bytes read\r\n", len);
|
|
|
+ mbedtls_printf( " %d bytes read\r\n", receivedBufLen);
|
|
|
|
|
|
+ printf(receiveBuf);
|
|
|
+ printf("\r\n");
|
|
|
+
|
|
|
if( ret > 0 )
|
|
|
break;
|
|
|
|
|
@@ -3107,21 +3120,16 @@ SSL_SERVER_STATE SSL_WriteRoutine(mbedtls_ssl_context *ssl, char *data, int data
|
|
|
|
|
|
char* SSL_ProcessingRoutine(uint16_t* sendLen)
|
|
|
{
|
|
|
- char* ptr;
|
|
|
Cockie();
|
|
|
getAuthenticatedState();
|
|
|
+
|
|
|
+ fs_open("/main.css", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+*/
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
- fs_open("/main.css", &file);
|
|
|
- *sendLen = file.len;
|
|
|
- return file.data;
|
|
|
-
|
|
|
-#if 0
|
|
|
+#if 1
|
|
|
if ( Authenticated == false && sSettings.sRADIUS.Auth_enable == false)
|
|
|
{
|
|
|
HTTP_LOGIN(sendBuf, sendLen);
|
|
@@ -3129,184 +3137,529 @@ char* SSL_ProcessingRoutine(uint16_t* sendLen)
|
|
|
}
|
|
|
else if ( Authenticated == false )
|
|
|
{
|
|
|
- if (strncmp(receiveBuf, "GET /main.css", 13) == 0)
|
|
|
- {
|
|
|
- fs_open("/main.css", &file);
|
|
|
- *sendLen = file.len;
|
|
|
- return file.data;
|
|
|
- }
|
|
|
- else if (strncmp(receiveBuf, "GET /rotek.png", 14) == 0)
|
|
|
- {
|
|
|
- fs_open("/rotek.png", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
- }
|
|
|
- else if (strncmp(receiveBuf, "GET /favicon.ico", 16) == 0)
|
|
|
- {
|
|
|
- fs_open("/favicon.ico", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
- }
|
|
|
- else if (strncmp(receiveBuf, "GET /role.js", 12) == 0)
|
|
|
- {
|
|
|
- fs_open("/role.js", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
- }
|
|
|
- else if (strncmp(receiveBuf, "POST /login.cgi", 15) == 0)
|
|
|
- {
|
|
|
- uint32_t req_data_received = 0;
|
|
|
- char *offset;
|
|
|
+ return AuthenticatedFalseRoutine(sendLen);
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
- offset = 0;
|
|
|
-
|
|
|
- post_data_count = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
-
|
|
|
- if (post_data_count < MAX_POST_REQ_LEN)
|
|
|
- {
|
|
|
- memset(post_req_data, 0, MAX_POST_REQ_LEN);
|
|
|
+}
|
|
|
|
|
|
- offset = (strstr(receiveBuf, "\r\n\r\n")) + 4;
|
|
|
- req_data_received = receivedBufLen - (offset - &receiveBuf[0]);
|
|
|
+
|
|
|
+char* AuthenticatedFalseRoutine(uint16_t* sendLen)
|
|
|
+{
|
|
|
+ if (strncmp(receiveBuf, "GET /main.css", 13) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/main.css", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /rotek.png", 14) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/rotek.png", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /favicon.ico", 16) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/favicon.ico", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /role.js", 12) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/role.js", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "POST /login.cgi", 15) == 0)
|
|
|
+ {
|
|
|
+ uint32_t req_data_received = 0;
|
|
|
+ char *offset = 0;
|
|
|
+
|
|
|
+ post_data_count = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
+
|
|
|
+ if (post_data_count < MAX_POST_REQ_LEN)
|
|
|
+ {
|
|
|
+ memset(post_req_data, 0, MAX_POST_REQ_LEN);
|
|
|
+ offset = (strstr(receiveBuf, "\r\n\r\n")) + 4;
|
|
|
+ req_data_received = receivedBufLen - (offset - &receiveBuf[0]);
|
|
|
|
|
|
- if (offset != 0)
|
|
|
+ if (offset != 0)
|
|
|
+ {
|
|
|
+ if (req_data_received < post_data_count)
|
|
|
+ {
|
|
|
+ snprintf(post_req_data, req_data_received, "%s", receiveBuf);
|
|
|
+ post_data_count -= req_data_received;
|
|
|
+
|
|
|
+ SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
+ offset = receiveBuf;
|
|
|
+ }
|
|
|
+ if(strlen(receiveBuf) != 0)
|
|
|
+ {
|
|
|
+ strncat(post_req_data, offset, post_data_count);
|
|
|
+ if (HTTP_ConfirmWebPwd(post_req_data, sendBuf, strlen(post_req_data), sendLen) == SEND_REQUIRED_YES)
|
|
|
{
|
|
|
- if (req_data_received < post_data_count)
|
|
|
- {
|
|
|
- snprintf(post_req_data, req_data_received, "%s", receiveBuf);
|
|
|
- post_data_count -= req_data_received;
|
|
|
-
|
|
|
-
|
|
|
- SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
-
|
|
|
- offset = receiveBuf;
|
|
|
- }
|
|
|
-
|
|
|
- if(strlen(receiveBuf) != 0)
|
|
|
- {
|
|
|
-
|
|
|
- strncat(post_req_data, offset, post_data_count);
|
|
|
- if (HTTP_ConfirmWebPwd(post_req_data, send, strlen(post_req_data), sendLen) == SEND_REQUIRED_YES)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- fs_open("/rslogin.html", &file);
|
|
|
- else
|
|
|
- fs_open("/login.html", &file);
|
|
|
- ssl_sendframes(&ssl, file.data, file.len);*/
|
|
|
-
|
|
|
- }
|
|
|
- post_data_count = 0;
|
|
|
- }
|
|
|
- else{
|
|
|
-
|
|
|
- if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
- fs_open("/rslogin.html", &file);
|
|
|
- else
|
|
|
- fs_open("/login.html", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
-
|
|
|
- post_data_count = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- else
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
-
|
|
|
- if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
- fs_open("/rslogin.html", &file);
|
|
|
- else
|
|
|
- fs_open("/login.html", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
-
|
|
|
- post_data_count = 0;
|
|
|
- }
|
|
|
+
|
|
|
+ fs_open("/rslogin.html", &file);
|
|
|
+ else
|
|
|
+ fs_open("/login.html", &file);
|
|
|
+ ssl_sendframes(&ssl, file.data, file.len);*/
|
|
|
+
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ post_data_count = 0;
|
|
|
}
|
|
|
- else
|
|
|
+ else
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- post_data_count = 0;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
- fs_open("/rslogin.html", &file);
|
|
|
- else
|
|
|
- fs_open("/login.html", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (post_data_count > 0)
|
|
|
- {
|
|
|
- strncat(post_req_data, receiveBuf, post_data_count);
|
|
|
-
|
|
|
- if (HTTP_ConfirmWebPwd(post_req_data, send, strlen(post_req_data), sendLen) == SEND_REQUIRED_YES)
|
|
|
- {
|
|
|
-
|
|
|
+ fs_open("/rslogin.html", &file);
|
|
|
+ else
|
|
|
+ fs_open("/login.html", &file);
|
|
|
+
|
|
|
+ post_data_count = 0;
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
+ fs_open("/rslogin.html", &file);
|
|
|
+ else
|
|
|
+ fs_open("/login.html", &file);
|
|
|
+
|
|
|
post_data_count = 0;
|
|
|
- log_post_reqn = 0;
|
|
|
- }
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ post_data_count = 0;
|
|
|
+
|
|
|
+ if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
+ fs_open("/rslogin.html", &file);
|
|
|
else
|
|
|
- {
|
|
|
- if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
- fs_open("/rslogin.html", &file);
|
|
|
- else
|
|
|
- fs_open("/login.html", &file);
|
|
|
- send = file.data; *sendLen = file.len;
|
|
|
- }
|
|
|
- }
|
|
|
-#endif
|
|
|
+ fs_open("/login.html", &file);
|
|
|
+
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (post_data_count > 0)
|
|
|
+ {
|
|
|
+ strncat(post_req_data, receiveBuf, post_data_count);
|
|
|
+ post_data_count = 0;
|
|
|
+ log_post_reqn = 0;
|
|
|
|
|
|
+ if (HTTP_ConfirmWebPwd(post_req_data, sendBuf, strlen(post_req_data), sendLen) == SEND_REQUIRED_YES)
|
|
|
+ {
|
|
|
+
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if((sSettings.sRADIUS.RDSEnable == true) && (fl_raddius_net_err == false))
|
|
|
+ fs_open("/rslogin.html", &file);
|
|
|
+ else
|
|
|
+ fs_open("/login.html", &file);
|
|
|
+
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
-#if 1
|
|
|
-void SSL_Send( mbedtls_ssl_context *ssl, char *data, int datalen )
|
|
|
+char* AuthenticatedTrueRoutine(uint16_t* sendLen)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- int ret, len;
|
|
|
-
|
|
|
- nbrframes = datalen / FRAME_SIZE;
|
|
|
-
|
|
|
-
|
|
|
- while(nbrframes > 0)
|
|
|
- {
|
|
|
- index = k * FRAME_SIZE;
|
|
|
- ssl_write( ssl, (unsigned char *)(data + index), FRAME_SIZE );
|
|
|
- nbrframes--;
|
|
|
- k++;
|
|
|
- }
|
|
|
-
|
|
|
- index = k * FRAME_SIZE;
|
|
|
- lastframe = datalen % FRAME_SIZE ;
|
|
|
- ssl_write( ssl, (unsigned char *)(data + index), lastframe );
|
|
|
-*/
|
|
|
+ char *DataOffset;
|
|
|
|
|
|
-
|
|
|
- while( ( ret = mbedtls_ssl_write( ssl, (unsigned char*)data, datalen ) ) <= 0 )
|
|
|
- {
|
|
|
- if( ret == MBEDTLS_ERR_NET_CONN_RESET )
|
|
|
+ if (strncmp(receiveBuf, "GET /main.css", 13) == 0)
|
|
|
{
|
|
|
- mbedtls_printf( " failed\r\n ! peer closed the connection\r\n" );
|
|
|
- goto reset;
|
|
|
+ fs_open("/main.css", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /rotek.png", 14) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/rotek.png", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
}
|
|
|
+ else if (strncmp(receiveBuf, "GET /favicon.ico", 16) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/favicon.ico", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /main.js", 12) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/main.js", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /role.js", 12) == 0)
|
|
|
+ {
|
|
|
+ fs_open("/role.js", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /settings.html", 18) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UpdateUserLoginTime(user_id);
|
|
|
+ if (seclevel == 0)
|
|
|
+ fs_open("/settings.html", &file);
|
|
|
+ else
|
|
|
+ fs_open("/index.html", &file);
|
|
|
+
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /info.html", 14) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UpdateUserLoginTime(user_id);
|
|
|
+ fs_open("/info.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /history.html", 17) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UpdateUserLoginTime(user_id);
|
|
|
+ fs_open("/history.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /ups_history.html", 21) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UpdateUserLoginTime(user_id);
|
|
|
+ fs_open("/ups_history.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /getJson.cgi", 16) == 0)
|
|
|
+ {
|
|
|
+ HTTP_GetParamsPage1(sendBuf);
|
|
|
+ *sendLen = strlen(sendBuf);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /settings.cgi", 17) == 0)
|
|
|
+ {
|
|
|
+ if (seclevel == 0) {
|
|
|
+ SET_PAGE = SET_PAGE_PAGE2;
|
|
|
+ if (HTTP_SettingsPage(receiveBuf, sendBuf, receivedBufLen, sendLen) == SEND_REQUIRED_YES)
|
|
|
+ {
|
|
|
+ *sendLen = strlen(sendBuf);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "POST /settings.cgi", 18) == 0)
|
|
|
+ {
|
|
|
+ if (seclevel == 0)
|
|
|
+ {
|
|
|
+ DataOffset = 0;
|
|
|
+
|
|
|
+ TotalReceived = 0;
|
|
|
+ TotalData = 0;
|
|
|
+ memset(sendBuf, 0, strlen(sendBuf));
|
|
|
+
|
|
|
+
|
|
|
+ size = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
+ DataOffset = strstr(receiveBuf, "managerIP");
|
|
|
+
|
|
|
+
|
|
|
+ if (DataOffset == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
+ DataOffset = strstr(receiveBuf, "managerIP");
|
|
|
+ }
|
|
|
|
|
|
- if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
|
|
+ TotalReceived = receivedBufLen - (DataOffset - &receiveBuf[0]);
|
|
|
+ TotalData += TotalReceived;
|
|
|
+ strncat(sendBuf, DataOffset, TotalReceived);
|
|
|
+
|
|
|
+ for (int i = TotalData; i < size; i ++)
|
|
|
+ {
|
|
|
+
|
|
|
+ SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
+ strncat(sendBuf, receiveBuf, receivedBufLen);
|
|
|
+ TotalData += receivedBufLen;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TotalData == size)
|
|
|
+ {
|
|
|
+ DBG printf("State: Received %d bytes\r\n", (int)TotalData);
|
|
|
+
|
|
|
+ strncat(sendBuf, " ", 1);
|
|
|
+ HTTP_SetSettings(sendBuf, strlen(sendBuf));
|
|
|
+ memset(sendBuf, 0, size);
|
|
|
+ strcpy(sendBuf, "HTTP/1.1 200 OK\r\n");
|
|
|
+ strcat(sendBuf, "\r\n\r\n");
|
|
|
+ strcat(sendBuf,"<!DOCTYPE html><html lang=""><head><meta http-equiv=\"refresh\" content=\"0;url=/settings.html\"/></head></html>\r\n\r\n");
|
|
|
+ sendBufLoadLen = strlen(sendBuf);
|
|
|
+ *sendLen = sendBufLoadLen;
|
|
|
+ return sendBuf;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "POST /srv_crt_upload.cgi", 24) == 0)
|
|
|
{
|
|
|
- mbedtls_printf( " failed\r\n ! mbedtls_ssl_write returned %d\r\n", ret );
|
|
|
- goto exit;
|
|
|
+ static char boundary[70];
|
|
|
+ static char *pbound = NULL;
|
|
|
+ char* ContentOffset = 0;
|
|
|
+ DataOffset = 0;
|
|
|
+ TotalData = 0;
|
|
|
+
|
|
|
+ memset(sendBuf, 0, sizeof(sendBuf));
|
|
|
+
|
|
|
+
|
|
|
+ size = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
+ pbound = Parce_Boundary(receiveBuf, receivedBufLen, boundary, sizeof(boundary));
|
|
|
+ if (pbound != NULL)
|
|
|
+ {
|
|
|
+ ContentOffset = strstr(receiveBuf, boundary);
|
|
|
+
|
|
|
+ DataOffset = strstr(ContentOffset, "\r\n\r\n");
|
|
|
+ if( DataOffset != NULL )
|
|
|
+ DataOffset += 4;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (DataOffset == NULL)
|
|
|
+ {
|
|
|
+ SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
+ receiveBuf[receivedBufLen] = '\0';
|
|
|
+ printf("receive2 %s \r\n", receiveBuf);
|
|
|
+ if (pbound != NULL)
|
|
|
+ {
|
|
|
+ ContentOffset = strstr(receiveBuf, boundary);
|
|
|
+
|
|
|
+ DataOffset = strstr(ContentOffset, "\r\n\r\n");
|
|
|
+ if( DataOffset != NULL )
|
|
|
+ DataOffset += 4;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ TotalReceived = receivedBufLen - (uint32_t)(ContentOffset - receiveBuf);
|
|
|
+ TotalData += TotalReceived;
|
|
|
+ strncat(sendBuf, DataOffset, TotalReceived);
|
|
|
+
|
|
|
+ while(TotalData < size)
|
|
|
+ {
|
|
|
+ ssl_server_read();
|
|
|
+ receiveBuf[receivedBufLen] = '\0';
|
|
|
+
|
|
|
+ strncat(sendBuf, receiveBuf, receivedBufLen);
|
|
|
+ TotalData += receivedBufLen;
|
|
|
+
|
|
|
+
|
|
|
+ printf("TotalData %d \r\n", TotalData);
|
|
|
+ printf("size %d \r\n", size);
|
|
|
+ printf("receive3 %s \r\n", (receiveBuf+receivedBufLen - 30));*/
|
|
|
+ }
|
|
|
+ printf("TotalData %d \r\n", TotalData);
|
|
|
+
|
|
|
+ if (TotalData == size)
|
|
|
+ {
|
|
|
+ printf("receive %s \r\n", sendBuf);
|
|
|
+ if(strstr(sendBuf, "BEGIN CERTIFICATE") != NULL)
|
|
|
+ {
|
|
|
+ DataOffset = strstr(sendBuf, "-----END CERTIFICATE");
|
|
|
+ uint32_t len_crt = (uint32_t)(DataOffset - sendBuf) + 25;
|
|
|
+ memset(sSettings.our_srv_crt, 0, sizeof(sSettings.our_srv_crt));
|
|
|
+ memcpy(sSettings.our_srv_crt, sendBuf, len_crt);
|
|
|
+ strcat(sendBuf, "\r\n");
|
|
|
+ HTTP_SaveSettings();
|
|
|
+ memset(sendBuf, 0, sizeof(sendBuf));
|
|
|
+ strcpy(sendBuf, "HTTP/1.1 200 OK\r\n\r\n");
|
|
|
+ strcat(sendBuf,"1");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ memset(sendBuf, 0, sizeof(sendBuf));
|
|
|
+ strcpy(sendBuf, "HTTP/1.1 200 OK\r\n\r\n");
|
|
|
+ strcat(sendBuf,"Некорректный сертефикат");
|
|
|
+ }
|
|
|
+ *sendLen = strlen(sendBuf);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /info.cgi", 13) == 0)
|
|
|
+ {
|
|
|
+ if (HTTP_InfoPage(receiveBuf, sendBuf, receivedBufLen, sendLen) == SEND_REQUIRED_YES)
|
|
|
+ {
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "POST /info.cgi", 14) == 0)
|
|
|
+ {
|
|
|
+ if (seclevel == 0)
|
|
|
+ {
|
|
|
+ DataOffset = 0;
|
|
|
+
|
|
|
+ TotalReceived = 0;
|
|
|
+ TotalData = 0;
|
|
|
+ memset(sendBuf, 0, strlen(sendBuf));
|
|
|
+
|
|
|
+ size = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
+ DataOffset = strstr(receiveBuf, "owner");
|
|
|
+
|
|
|
+
|
|
|
+ if (DataOffset == 0)
|
|
|
+ {
|
|
|
+ SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
|
|
|
+ DataOffset = strstr(receiveBuf, "owner");
|
|
|
+ }
|
|
|
+
|
|
|
+ TotalReceived = receivedBufLen - (DataOffset - &receiveBuf[0]);
|
|
|
+ TotalData += TotalReceived;
|
|
|
+ strncat(sendBuf, DataOffset, TotalReceived);
|
|
|
+
|
|
|
+
|
|
|
+ if (TotalReceived == size)
|
|
|
+ {
|
|
|
+ strncat(sendBuf, " ", 1);
|
|
|
+ HTTP_SetInfo(sendBuf, strlen(sendBuf));
|
|
|
+ DataFlag = 0;
|
|
|
+ BrowserFlag = 0;
|
|
|
+ memset(sendBuf, 0, size);
|
|
|
+
|
|
|
+ strcpy(sendBuf, "HTTP/1.1 200 OK\r\n");
|
|
|
+ strcat(sendBuf, "\r\n\r\n");
|
|
|
+ strcat(sendBuf,"<!DOCTYPE html><html lang=""><head><meta http-equiv=\"refresh\" content=\"0;url=/info.html\"/></head></html>\r\n\r\n");
|
|
|
+
|
|
|
+ *sendLen = strlen(sendBuf);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if(receivedBufLen)
|
|
|
+ {
|
|
|
+ strncat(sendBuf, ptr, receivedBufLen);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /history.cgi", 16) == 0)
|
|
|
+ {
|
|
|
+ int res;
|
|
|
+ res = HTTP_HistoryPage(receiveBuf, sendBuf, receivedBufLen, sendLen);
|
|
|
+
|
|
|
+ if (res == SEND_REQUIRED_FILE)
|
|
|
+ {
|
|
|
+ ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
|
|
|
+
|
|
|
+
|
|
|
+ HTTP_SendHistory();
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (res == SEND_REQUIRED_YES)
|
|
|
+ {
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (strncmp(receiveBuf, "GET /ups_history.cgi", 19) == 0)
|
|
|
+ {
|
|
|
+ int res;
|
|
|
+
|
|
|
+ res = HTTP_UpsHistoryPage(receiveBuf, sendBuf, receivedBufLen, sendLen);
|
|
|
+
|
|
|
+ if (res == SEND_REQUIRED_FILE)
|
|
|
+ {
|
|
|
+ ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ HTTP_SendLog();
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (res == SEND_REQUIRED_YES)
|
|
|
+ {
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /bat_test.cgi", 17) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UPSTest(receiveBuf, sendBuf, receivedBufLen, sendLen);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /ups_power.cgi", 18) == 0)
|
|
|
+ {
|
|
|
+ HTTP_UPSshutdown(receiveBuf, sendBuf, receivedBufLen, sendLen);
|
|
|
+ return sendBuf;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /reset.cgi", 14) == 0)
|
|
|
+ {
|
|
|
+ HTTP_ResetSettings();
|
|
|
+ HTTP_SaveSettings();
|
|
|
+
|
|
|
+ fs_open("/settings.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /reboot.cgi", 15) == 0)
|
|
|
+ {
|
|
|
+ HTTP_Reboot();
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /confirm.cgi", 16) == 0)
|
|
|
+ {
|
|
|
+ SetWebReinitFlag(false);
|
|
|
+ SetConfirmWebParamsFlag();
|
|
|
+
|
|
|
+ fs_open("/index.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /fw_update.cgi", 18) == 0)
|
|
|
+ {
|
|
|
+ HTTP_ConfirmBootPwd(receiveBuf, sendBuf, receivedBufLen, sendLen);
|
|
|
+ ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /changepwd.cgi", 18) == 0)
|
|
|
+ {
|
|
|
+ HTTP_ChangeUserPwd(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
+ ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (strncmp(receiveBuf, "GET /setProdate.cgi", 19) == 0)
|
|
|
+ {
|
|
|
+ HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
+ ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HTTP_UpdateUserLoginTime(user_id);
|
|
|
+ fs_open("/index.html", &file);
|
|
|
+ *sendLen = file.len;
|
|
|
+ return file.data;
|
|
|
}
|
|
|
- }
|
|
|
-*/
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
|
|
|
#define FRAME_SIZE (1000)
|
|
|
SSL_SERVER_STATE SSL_SendFrames(mbedtls_ssl_context *ssl, char *data, int datalen)
|
|
@@ -3342,7 +3695,8 @@ SSL_SERVER_STATE SSL_SendFrames(mbedtls_ssl_context *ssl, char *data, int datale
|
|
|
if( retClose != MBEDTLS_ERR_SSL_WANT_READ && retClose != MBEDTLS_ERR_SSL_WANT_WRITE )
|
|
|
{
|
|
|
mbedtls_printf( " failed\r\n ! mbedtls_ssl_close_notify returned %d\r\n", ret );
|
|
|
-
|
|
|
+
|
|
|
+ return SSL_ACCEPT;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3368,7 +3722,9 @@ SSL_SERVER_STATE SSL_Write(mbedtls_ssl_context *ssl, char *data, int datalen)
|
|
|
if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
|
|
{
|
|
|
mbedtls_printf( " failed\r\n ! mbedtls_ssl_write returned %d\r\n", ret );
|
|
|
- return SSL_CRITICAL_ERROR;
|
|
|
+
|
|
|
+
|
|
|
+ return SSL_ACCEPT;
|
|
|
}
|
|
|
}
|
|
|
|