Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a secure TLS socket in Python.
IOT Protocols
import ssl import socket context = ssl.create_default_context() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) secure_sock = context.wrap_socket(sock, server_hostname=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an IP address instead of a domain name for server_hostname.
Leaving server_hostname empty or None.
✗ Incorrect
The server_hostname parameter should be the domain name of the server you want to securely connect to, such as 'example.com'.
2fill in blank
mediumComplete the command to generate a private key using OpenSSL.
IOT Protocols
openssl genpkey -algorithm RSA -out [1] -pkeyopt rsa_keygen_bits:2048
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a certificate file name instead of a key file name.
Using a CSR file name instead of a key file name.
✗ Incorrect
The private key file is usually saved with a .pem extension, such as 'mykey.pem'.
3fill in blank
hardFix the error in the OpenSSL command to create a certificate signing request (CSR).
IOT Protocols
openssl req -new -key private.key -out [1] -subj "/CN=example.com"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Overwriting the private key file as output.
Saving the CSR as a certificate file.
✗ Incorrect
The output file for a CSR should be a new file like 'csr.pem', not a key or certificate file.
4fill in blank
hardFill both blanks to configure a TLS server socket in Python.
IOT Protocols
import ssl import socket context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.load_cert_chain(certfile=[1], keyfile=[2]) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('0.0.0.0', 443)) sock.listen(5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using client certificate or key files for the server.
Mixing up certificate and key file names.
✗ Incorrect
The server certificate file is 'server.crt' and the private key file is 'server.key' for the TLS server.
5fill in blank
hardFill the blanks to create a Python dictionary comprehension that filters TLS versions.
IOT Protocols
tls_versions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'] supported = {version: True for version in tls_versions if version [1] 'TLSv1.3' and version [2] 'TLSv1.3'}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' to exclude versions.
Using wrong comparison operators causing syntax errors.
✗ Incorrect
The comprehension keeps versions not equal to 'TLSv1.3' and less than 'TLSv1.3', filtering supported versions.