Recognize HTTPS.

Although we for sure don't support HTTPS we need to recognize it. Nowadays it has become pretty usual to redirect HTTP URLs to HTTPS URLs in order to force privacy (thanks, NSA !). So far our redirection handler didn't recognize an HTTPS URL as abslute URLs and therefore appended it to the curent URL. This led to an endless redirection loop. Now we recognize the HTTPS redirection and generate a minimal document on the fly to inform the user of (for us unrachable) the redirection target.

HTML links with HTTPS URLs are treated just like fragment-only links meaning that they get simply completely ignored.
This commit is contained in:
Oliver Schmidt 2015-06-05 15:44:09 +02:00
parent 2f2295c182
commit e6903e4e7e
5 changed files with 29 additions and 8 deletions

View file

@ -1,4 +1,5 @@
http_http "http://" http_http "http://"
http_https "https://"
http_200 "200 " http_200 "200 "
http_301 "301 " http_301 "301 "
http_302 "302 " http_302 "302 "
@ -10,3 +11,4 @@ http_location "location: "
http_host "Host: " http_host "Host: "
http_crnl "\r\n" http_crnl "\r\n"
http_html ".html" http_html ".html"
http_redirect "<body>Redirect to "

View file

@ -1,6 +1,9 @@
const char http_http[8] = const char http_http[8] =
/* "http://" */ /* "http://" */
{0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, }; {0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, };
const char http_https[9] =
/* "https://" */
{0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, };
const char http_200[5] = const char http_200[5] =
/* "200 " */ /* "200 " */
{0x32, 0x30, 0x30, 0x20, }; {0x32, 0x30, 0x30, 0x20, };
@ -34,3 +37,6 @@ const char http_crnl[3] =
const char http_html[6] = const char http_html[6] =
/* ".html" */ /* ".html" */
{0x2e, 0x68, 0x74, 0x6d, 0x6c, }; {0x2e, 0x68, 0x74, 0x6d, 0x6c, };
const char http_redirect[19] =
/* "<body>Redirect to " */
{0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x74, 0x6f, 0x20, };

View file

@ -1,4 +1,5 @@
extern const char http_http[8]; extern const char http_http[8];
extern const char http_https[9];
extern const char http_200[5]; extern const char http_200[5];
extern const char http_301[5]; extern const char http_301[5];
extern const char http_302[5]; extern const char http_302[5];
@ -10,3 +11,4 @@ extern const char http_location[11];
extern const char http_host[7]; extern const char http_host[7];
extern const char http_crnl[3]; extern const char http_crnl[3];
extern const char http_html[6]; extern const char http_html[6];
extern const char http_redirect[19];

View file

@ -49,7 +49,7 @@
#define HTTPFLAG_NONE 0 #define HTTPFLAG_NONE 0
#define HTTPFLAG_OK 1 #define HTTPFLAG_OK 1
#define HTTPFLAG_MOVED 2 #define HTTPFLAG_MOVED 2
#define HTTPFLAG_ERROR 3 #define HTTPFLAG_HTTPS 3
#define ISO_nl 0x0a #define ISO_nl 0x0a
@ -360,7 +360,9 @@ parse_headers(uint16_t len)
cptr = s.httpheaderline + cptr = s.httpheaderline +
sizeof(http_location) - 1; sizeof(http_location) - 1;
if(strncmp(cptr, http_http, 7) == 0) { if(strncmp(cptr, http_https, sizeof(http_https) - 1) == 0) {
s.httpflag = HTTPFLAG_HTTPS;
} else if(strncmp(cptr, http_http, 7) == 0) {
cptr += 7; cptr += 7;
for(i = 0; i < s.httpheaderlineptr - 7; ++i) { for(i = 0; i < s.httpheaderlineptr - 7; ++i) {
if(*cptr == 0 || if(*cptr == 0 ||
@ -407,7 +409,7 @@ newdata(void)
} }
if(len > 0 && s.state == WEBCLIENT_STATE_DATA && if(len > 0 && s.state == WEBCLIENT_STATE_DATA &&
s.httpflag != HTTPFLAG_MOVED) { s.httpflag == HTTPFLAG_OK) {
webclient_datahandler((char *)uip_appdata, len); webclient_datahandler((char *)uip_appdata, len);
} }
} }
@ -445,7 +447,6 @@ webclient_appcall(void *state)
return; return;
} }
/* The acked() and newdata() functions may alter the uip_appdata /* The acked() and newdata() functions may alter the uip_appdata
ptr, so we need to store it in the "dataptr" variable so that we ptr, so we need to store it in the "dataptr" variable so that we
can restore it before the senddata() function is called. */ can restore it before the senddata() function is called. */
@ -478,10 +479,18 @@ webclient_appcall(void *state)
if(uip_closed()) { if(uip_closed()) {
tcp_markconn(uip_conn, NULL); tcp_markconn(uip_conn, NULL);
if(s.httpflag != HTTPFLAG_MOVED) { switch(s.httpflag) {
case HTTPFLAG_HTTPS:
/* Send some info to the user. */
webclient_datahandler((char *)http_redirect, sizeof(http_redirect) - 1);
webclient_datahandler(s.file, strlen(s.file));
webclient_datahandler((char *)http_crnl, sizeof(http_crnl) - 1);
/* FALLTHROUGH */
case HTTPFLAG_OK:
/* Send NULL data to signal EOF. */ /* Send NULL data to signal EOF. */
webclient_datahandler(NULL, 0); webclient_datahandler(NULL, 0);
} else { break;
case HTTPFLAG_MOVED:
/* conn = uip_connect(uip_conn->ripaddr, s.port); /* conn = uip_connect(uip_conn->ripaddr, s.port);
if(conn != NULL) { if(conn != NULL) {
dispatcher_markconn(conn, NULL); dispatcher_markconn(conn, NULL);
@ -493,6 +502,7 @@ webclient_appcall(void *state)
} }
#endif /* UIP_UDP */ #endif /* UIP_UDP */
webclient_get(s.host, s.port, s.file); webclient_get(s.host, s.port, s.file);
break;
} }
} }
} }

View file

@ -900,7 +900,8 @@ htmlparser_word(char *word, unsigned char wordlen)
void void
htmlparser_link(char *text, unsigned char textlen, char *url) htmlparser_link(char *text, unsigned char textlen, char *url)
{ {
if(url[0] == ISO_hash) { /* No link for https or fragment-only as we would't be able to handle it anyway. */
if(url[0] == ISO_hash || strncmp(url, http_https, sizeof(http_https) - 1) == 0) {
htmlparser_word(text, textlen); htmlparser_word(text, textlen);
} else { } else {
add_pagewidget(text, textlen, url, CTK_WIDGET_HYPERLINK, 0); add_pagewidget(text, textlen, url, CTK_WIDGET_HYPERLINK, 0);