void main() { SSL_Cert_t my_cert; // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); memset(&my_cert, 0, sizeof(my_cert)); // When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need // to be parsed and registered with the library. For use with a // server, we need to know our own private key. if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) || SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM)) exit(7); // Register certificate with HTTPS server. https_set_cert(&my_cert); tcp_reserveport(443); /* * http_handler needs to be called to handle the active http servers. */ while (1) { http_handler(); } }
void main() { SSL_Cert_t my_cert; /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); memset(&my_cert, 0, sizeof(my_cert)); // When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need // to be parsed and registered with the library. For use with a // server, we need to know our own private key. if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) || SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM)) exit(7); // Register certificate with HTTPS server. https_set_cert(&my_cert); /* * tcp_reserveport causes the web server to ignore requests when there * isn't an available socket (HTTP_MAXSERVERS are all serving index_html * or rabbit1.gif). This saves some memory, but can cause the client * delays when retrieving pages. */ tcp_reserveport(80); // Also reserve the HTTPS port tcp_reserveport(443); /* * http_handler needs to be called to handle the active http servers. */ while (1) { http_handler(); } }
SSPEC_MIMETABLE_END void main(void) { int user1; int user2; int user3; int user1_enabled; int user2_enabled; int user3_enabled; int page1; int ch; // Can't store this on the stack (auto) since the HTTP server library stores // a reference to it for use later. static far SSL_Cert_t my_cert; /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); _f_memset(&my_cert, 0, sizeof(my_cert)); // When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need // to be parsed and registered with the library. For use with a // server, we need to know our own private key. if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) || SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM)) exit(7); // Register certificate with HTTPS server. https_set_cert(&my_cert); printf("Press '1', '2', or '3' to disable/enable the three users.\n"); printf("Press 'b', 'd', or 'n' to set the authentication to basic, digest, or none.\n\n"); /* * HTTP_DIGEST_AUTH is the default authentication type when * digest authentication has been enabled, so this line is not * strictly necessary. The other possible values are * HTTP_BASIC_AUTH and HTTP_NO_AUTH. */ http_setauthentication(HTTP_DIGEST_AUTH); printf("Using digest authentication\n"); /* * The following lines add three users, a web page, and an image, and * associates the users with the web page. The userx_enabled * variables are used to keep track of which users are current * enabled. */ user1_enabled = 1; user2_enabled = 1; user3_enabled = 1; user1 = sauth_adduser("foo", "bar", SERVER_HTTPS); user2 = sauth_adduser("foo2", "bar2", SERVER_HTTPS); user3 = sauth_adduser("foo3", "bar3", SERVER_HTTPS); page1 = sspec_addxmemfile("/", index_html, SERVER_HTTPS); sspec_adduser(page1, user1); sspec_adduser(page1, user2); sspec_adduser(page1, user3); sspec_setrealm(page1, "Admin"); sspec_addxmemfile("rabbit1.gif", rabbit1_gif, SERVER_HTTPS); /* * tcp_reserveport causes the web server to ignore requests when there * isn't an available socket (HTTP_MAXSERVERS are all serving index_html * or rabbit1.gif). This saves some memory, but can cause the client * delays when retrieving pages (versus increasing HTTP_MAXSERVERS). * We reserve port 443 for HTTPS communication */ tcp_reserveport(HTTPS_PORT); while (1) { /* * Watch for user keypresses */ if (kbhit()) { ch = getchar(); switch (ch) { case '1': /* * Handle the keypress for User 1 */ user1_enabled = !user1_enabled; if (user1_enabled) { /* * sspec_adduser() adds a user to a resource */ sspec_adduser(page1, user1); printf("User 1 enabled\n"); } else { /* * sspec_removeuser() removes a user from a resource */ sspec_removeuser(page1, user1); printf("User 1 disabled\n"); } break; case '2': user2_enabled = !user2_enabled; if (user2_enabled) { sspec_adduser(page1, user2); printf("User 2 enabled\n"); } else { sspec_removeuser(page1, user2); printf("User 2 disabled\n"); } break; case '3': user3_enabled = !user3_enabled; if (user3_enabled) { sspec_adduser(page1, user3); printf("User 3 enabled\n"); } else { sspec_removeuser(page1, user3); printf("User 3 disabled\n"); } break; case 'b': http_setauthentication(HTTP_BASIC_AUTH); printf("Using basic authentication\n"); break; case 'd': http_setauthentication(HTTP_DIGEST_AUTH); printf("Using digest authentication\n"); break; case 'n': http_setauthentication(HTTP_NO_AUTH); printf("Using no authentication\n"); break; } } /* * http_handler needs to be called to handle the active http servers */ http_handler(); } }