0
0
Raspberry Piprogramming~20 mins

HTTPS for web server in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
HTTPS Server Mastery on Raspberry Pi
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Python HTTPS server code snippet?

Consider this Python code snippet running on a Raspberry Pi to start a simple HTTPS server using http.server and ssl modules. What will it print when started successfully?

Raspberry Pi
import http.server
import ssl

server_address = ('', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True)
print('Serving on https://localhost:4443')
httpd.serve_forever()
AServing on https://localhost:4443
BServing on https://0.0.0.0:4443
CError: certfile not found
DServing on http://localhost:4443
Attempts:
2 left
💡 Hint

Look at the print statement and the port used.

🧠 Conceptual
intermediate
1:30remaining
Which file is essential to enable HTTPS on a Raspberry Pi web server?

To enable HTTPS on a Raspberry Pi web server, which file must you have to provide the server's identity securely?

Aindex.html (homepage file)
Bconfig.txt (system configuration file)
Cserver.pem (certificate and private key file)
Dhosts (local DNS file)
Attempts:
2 left
💡 Hint

Think about what HTTPS needs to prove the server's identity.

🔧 Debug
advanced
2:30remaining
Why does this HTTPS server code raise an error?

Look at this Python code snippet for an HTTPS server on Raspberry Pi. It raises an error when run. What is the cause?

Raspberry Pi
import http.server
import ssl

server_address = ('', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='server.key', certfile='server.crt', server_side=True)
httpd.serve_forever()
Assl.wrap_socket requires certfile only, not keyfile
BPort 4443 is reserved and cannot be used
Chttp.server.HTTPServer does not support SSL wrapping
DMissing combined PEM file; keyfile and certfile must be combined
Attempts:
2 left
💡 Hint

Check the SSL wrapping parameters and file requirements.

📝 Syntax
advanced
2:00remaining
Which option correctly creates an SSL context for HTTPS on Raspberry Pi?

Choose the correct Python code snippet that creates an SSL context for an HTTPS server on Raspberry Pi.

A
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_SSLv3)
context.load_cert_chain('server.pem')
B
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain('server.pem')
C
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_cert_chain('server.pem')
D
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.load_cert_chain('server.pem')
Attempts:
2 left
💡 Hint

Look for the protocol designed for servers.

🚀 Application
expert
3:00remaining
How many simultaneous HTTPS connections can this Raspberry Pi server handle?

Given this Python HTTPS server code running on Raspberry Pi, how many simultaneous HTTPS client connections can it handle by default?

Raspberry Pi
import http.server
import ssl

server_address = ('', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()
A1
B5
C10
DUnlimited
Attempts:
2 left
💡 Hint

Consider the default behavior of http.server.HTTPServer.