SSL/TLS File Post with Multipart Form
Overview
This NetBurner application demonstrates secure file uploading capabilities using SSL/TLS encryption. It provides a web interface that allows users to select and upload files to the NetBurner device through an HTTPS connection. The uploaded files are then processed and displayed back to the user on a web page.
- Note
- Browsers require a valid device certificate signed by a Certificate Authority known to the browser. Unless you install your self-signed Certificate Authority certificate in the web browser, you will see a warning message in the browser and should select the option to "continue anyway".
Features
- SSL/TLS Security: Secure file transfers using HTTPS protocol
- Multipart Form Support: Handles file uploads through HTML multipart forms
- File Display: Shows uploaded file content in both text and binary formats
- Web Interface: Simple HTML form for file selection and upload
- Real-time Processing: Immediate processing and display of uploaded files
Application Components
Core Files
- main.cpp: Main application entry point that initializes the network stack, enables HTTPS server, and manages the main application loop
- formcode.cpp: Contains the file processing logic and HTTP POST callback handlers
- index.html: Web interface with file upload form
- ServerCert.cpp: SSL certificate data for HTTPS connections
- ServerKey.cpp: SSL private key data for HTTPS connections
Key Functions
File Processing (formcode.cpp
)
ProcessPostFile()
: Reads uploaded file data into a buffer
ShowFileData()
: Displays file content with optional binary format
PostCallBack()
: Handles HTTP POST events during file upload process
Main Application (main.cpp
)
UserMain()
: Initializes network, starts HTTPS server, and waits for network connectivity
How It Works
- Initialization: The application starts by initializing the network stack and enabling system diagnostics
- HTTPS Server: Starts the HTTPS web server with SSL/TLS encryption
- Network Wait: Waits up to 5 seconds for an active network connection (DHCP)
- File Upload Process:
- User accesses the web interface through HTTPS
- Selects a file using the HTML form
- Clicks "Send File" to initiate upload
- Server processes the multipart form data
- File content is read and stored in a buffer
- Processed file is displayed back to the user
Security Features
SSL/TLS Implementation
- Uses embedded SSL certificate and private key
- Provides encrypted communication between browser and device
- Protects file uploads from interception
Browser Requirements
Modern browsers require valid certificates for file uploads. This application includes:
- Self-signed certificate embedded in the firmware
- Certificate Authority (CA) certificate may need installation in browser
- Warning messages in browsers must be handled properly for file uploads to work
Technical Specifications
Buffer Management
- File Buffer Size: 10,000 bytes maximum
- Read Buffer: 16-byte chunks for binary display
- Memory Safety: Prevents buffer overflows during file processing
File Display Formats
- Text Mode: Shows readable characters with HTML entity encoding
- Binary Mode: Displays hexadecimal values alongside ASCII representation
- HTML Safe: Converts special characters (&, <, >, ") to HTML entities
Usage Instructions
- Deploy the Application: Flash the firmware to your NetBurner device
- Network Connection: Ensure the device has network connectivity
- Access Web Interface: Navigate to the device's IP address using HTTPS
- Upload Files: Use the file selection form to choose and upload files
- View Results: The uploaded file content will be displayed on the result page
Testing
A quick test can be performed by uploading the included ReadMe.txt
file to verify the application is working correctly.
Important Notes
Certificate Warnings
- Browsers may display security warnings for self-signed certificates
- For form variables, users can typically choose to continue despite warnings
- For file uploads, proper certificate handling is more critical
- Consider installing a valid CA certificate in browsers for production use
File Size Limitations
- Maximum file size is limited to 10,000 bytes
- Larger files will be truncated to fit within the buffer
- Consider increasing
FILE_BUFFER_SIZE
for larger file support
Production Considerations
- Remove
EnableSystemDiagnostics()
for production deployments
- Consider implementing additional file type validation
- Add error handling for network connectivity issues
- Implement proper certificate management for production environments
Development Environment
This application is built for the NetBurner platform using the NetBurner Network Development Kit (NNDK). The code utilizes NetBurner-specific libraries for HTTP handling, SSL/TLS support, and network operations.
Related Examples
This example builds upon the standard examples\web\HtmlFilePost
example by adding SSL/TLS encryption capabilities for secure file transfers.