0
0
Raspberry Piprogramming~10 mins

HTTPS for web server in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a simple HTTPS server using Python's http.server module.

Raspberry Pi
import http.server
import ssl

server_address = ('localhost', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='[1]', certfile='server.pem', server_side=True)
httpd.serve_forever()
Drag options to blanks, or click blank then click option'
Aserver.key
Bserver.pem
Ckey.pem
Dcert.pem
Attempts:
3 left
💡 Hint
Common Mistakes
Using the certificate file instead of the key file for the keyfile parameter.
2fill in blank
medium

Complete the command to generate a self-signed certificate using OpenSSL.

Raspberry Pi
openssl req -x509 -newkey rsa:4096 -keyout [1] -out server.pem -days 365 -nodes
Drag options to blanks, or click blank then click option'
Aserver.pem
Bkey.pem
Cserver.key
Dcert.pem
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing the certificate output file with the key output file.
3fill in blank
hard

Fix the error in the Python code to correctly wrap the socket for HTTPS.

Raspberry Pi
import http.server
import ssl

httpd = http.server.HTTPServer(('0.0.0.0', 4443), http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', keyfile=[1], server_side=True)
httpd.serve_forever()
Drag options to blanks, or click blank then click option'
A'server.key'
Bserver.key
C'server.pem'
D'key.pem'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the filename without quotes causing a NameError.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps domain names to their certificate expiration days.

Raspberry Pi
cert_days = {domain: [1] for domain, cert in certs.items() if cert.[2] > 0}
Drag options to blanks, or click blank then click option'
Acert.expiration_days
Bcert.expiry
Cexpiration_days
Ddays_left
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names that do not exist in the certificate object.
5fill in blank
hard

Fill all three blanks to create a secure HTTPS server setup with certificate and key files.

Raspberry Pi
import http.server
import ssl

server_address = ('', 443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=[1], certfile=[2], server_side=[3])
httpd.serve_forever()
Drag options to blanks, or click blank then click option'
A'server.key'
B'server.pem'
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect file names or forgetting to set server_side to True.