|
@@ -986,6 +986,7 @@ void HTTP_UPSshutdown(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *le
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @brief Проверка пароля для перехода в режим bootloader
|
|
|
* @retval None
|
|
@@ -1284,6 +1285,39 @@ uint8_t GetCookieValue(char *inStr, char *paramName, char *paramValue, uint8_t *
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+char* Parce_Boundary(const char* data, uint32_t len, char* dst, uint8_t dstlen) {
|
|
|
+ char *ptr = NULL;
|
|
|
+ char *boundary = NULL;
|
|
|
+ uint8_t i = 0;
|
|
|
+
|
|
|
+ for (uint32_t j = 0; j < len; j++) {
|
|
|
+ if (strncmp ((char*)(data + j), "boundary=", 9) == 0) {
|
|
|
+ boundary = (char*)data + j + 9;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!boundary) return NULL;
|
|
|
+
|
|
|
+ *dst++ = '-';
|
|
|
+ *dst++ = '-';
|
|
|
+
|
|
|
+ ptr = boundary;
|
|
|
+ while ((*ptr != 0x0d) && (i < dstlen - 4))
|
|
|
+ {
|
|
|
+ *dst++ = *ptr++;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ //*dst++ = '-';
|
|
|
+ //*dst++ = '-';
|
|
|
+ *dst = '\0';
|
|
|
+
|
|
|
+ if (i > 0)
|
|
|
+ return boundary;
|
|
|
+ else
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief
|
|
|
* @retval None
|
|
@@ -1739,20 +1773,20 @@ void ssl_server(void *pvParameters)
|
|
|
// Instead, you may want to use x509parse_crtfile() to read the
|
|
|
// server and CA certificates, as well as x509parse_keyfile().
|
|
|
|
|
|
- ret = x509parse_crt(&srvcert, (unsigned char *) test_srv_crt, strlen(test_srv_crt));
|
|
|
+ ret = x509parse_crt(&srvcert, sSettings.our_srv_crt, strlen(sSettings.our_srv_crt));//(unsigned char *) test_srv_crt
|
|
|
if(ret != 0)
|
|
|
{
|
|
|
//printf(" failed\n ! x509parse_crt returned %d\n\r", ret);
|
|
|
goto exit;
|
|
|
}
|
|
|
- ret = x509parse_crt(&srvcert, (unsigned char *) test_ca_crt, strlen(test_ca_crt));
|
|
|
+ /* ret = x509parse_crt(&srvcert, (unsigned char *) test_ca_crt, strlen(test_ca_crt));
|
|
|
if(ret != 0)
|
|
|
{
|
|
|
//printf(" failed\n ! x509parse_crt returned %d\n\r", ret);
|
|
|
goto exit;
|
|
|
- }
|
|
|
+ }*/
|
|
|
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
|
|
- ret = x509parse_key(&rsa, (unsigned char *) test_srv_key, strlen(test_srv_key), NULL, 0);
|
|
|
+ ret = x509parse_key(&rsa, (unsigned char *) test_srv_key, strlen(test_srv_key), NULL, 0);//
|
|
|
if( ret != 0 )
|
|
|
{
|
|
|
//printf(" failed\n ! x509parse_key returned %d\n\r", ret);
|
|
@@ -2159,6 +2193,90 @@ void ssl_server(void *pvParameters)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else if (strncmp(receiveBuf, "POST /srv_crt_upload.cgi", 24) == 0)
|
|
|
+ {
|
|
|
+ static char boundary[70];
|
|
|
+ static char boundary_buf[70];
|
|
|
+ static char *pbound = NULL;
|
|
|
+ char* ContentOffset = 0;
|
|
|
+ DataOffset = 0;
|
|
|
+ TotalData = 0;
|
|
|
+ memset(sendBuf, 0, sizeof(sendBuf));
|
|
|
+ //printf("receive %s \r\n", receiveBuf);
|
|
|
+ /* parse packet for Content-length field */
|
|
|
+ size = Parse_Content_Length(receiveBuf, receivedBufLen);
|
|
|
+ pbound = Parce_Boundary(receiveBuf, receivedBufLen, boundary, sizeof(boundary));
|
|
|
+ if (pbound != NULL) {
|
|
|
+ ContentOffset = strstr(receiveBuf, boundary);
|
|
|
+ //ContentOffset += 4;
|
|
|
+ DataOffset = strstr(ContentOffset, "\r\n\r\n");
|
|
|
+ if( DataOffset != NULL )
|
|
|
+ DataOffset += 4;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* case of MSIE8 : we do not receive data in the POST packet*/
|
|
|
+ if (DataOffset == NULL)
|
|
|
+ {
|
|
|
+ ssl_server_read();
|
|
|
+ receiveBuf[receivedBufLen] = '\0';
|
|
|
+ // printf("receive2 %s \r\n", receiveBuf);
|
|
|
+ if (pbound != NULL) {
|
|
|
+ ContentOffset = strstr(receiveBuf, boundary);
|
|
|
+ // ContentOffset += 4;
|
|
|
+ DataOffset = strstr(ContentOffset, "\r\n\r\n");
|
|
|
+ if( DataOffset != NULL )
|
|
|
+ DataOffset += 4;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ TotalReceived = receivedBufLen - (uint32_t)(ContentOffset - receiveBuf);
|
|
|
+
|
|
|
+ TotalData += TotalReceived;
|
|
|
+
|
|
|
+ strncat(sendBuf, DataOffset, TotalReceived);
|
|
|
+
|
|
|
+ //for(i = TotalData; i < size; i ++)
|
|
|
+ while(TotalData < size)
|
|
|
+ {
|
|
|
+ ssl_server_read();
|
|
|
+ receiveBuf[receivedBufLen] = '\0';
|
|
|
+ //printf("receive3 %s \r\n", receiveBuf);
|
|
|
+
|
|
|
+ strncat(sendBuf, receiveBuf, receivedBufLen);
|
|
|
+ TotalData += receivedBufLen;
|
|
|
+ //printf("TotalData %d \r\n", TotalData);
|
|
|
+ /*printf("receivedBufLen %d \r\n", 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);
|
|
|
+ // check if last data packet
|
|
|
+ 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,"Некорректный сертефикат");
|
|
|
+ }
|
|
|
+ ssl_sendframes(&ssl, sendBuf, strlen(sendBuf));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
else if (strncmp(receiveBuf, "GET /info.cgi", 13) == 0) // +
|
|
|
{
|
|
|
if (HTTP_InfoPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen) == SEND_REQUIRED_YES)
|