Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SSE-IoT-Encryption
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dominik Fuhrmann
SSE-IoT-Encryption
Commits
41c6306b
Commit
41c6306b
authored
6 months ago
by
Dominik Fuhrmann
Browse files
Options
Downloads
Patches
Plain Diff
more debugging
parent
9b815097
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
communicationScripts/client.py
+9
-13
9 additions, 13 deletions
communicationScripts/client.py
communicationScripts/server.py
+22
-25
22 additions, 25 deletions
communicationScripts/server.py
with
31 additions
and
38 deletions
communicationScripts/client.py
+
9
−
13
View file @
41c6306b
...
@@ -11,34 +11,30 @@ def run_client(file_path):
...
@@ -11,34 +11,30 @@ def run_client(file_path):
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
.
load_verify_locations
(
ca_cert
)
context
.
load_verify_locations
(
ca_cert
)
context
.
set_ciphers
(
cipher_suite
)
context
.
set_ciphers
(
cipher_suite
)
print
(
f
"
TLS-Kontext mit Cipher Suite
'
{
cipher_suite
}
'
erfolgreich initialisiert.
"
)
print
(
f
"
TLS-Kontext mit Cipher Suite
'
{
cipher_suite
}
'
erfolgreich initialisiert.
"
)
# Sichere Verbindung mit dem Server herstellen
# Sichere Verbindung mit dem Server herstellen
try
:
try
:
with
socket
.
create_connection
((
"
192.168.201.132
"
,
5000
)
,
timeout
=
10
)
as
sock
:
with
socket
.
create_connection
((
"
192.168.201.132
"
,
5000
))
as
sock
:
sock
.
setblocking
(
False
)
# Setze den Socket in den Nicht-Blockierungsmodus
print
(
"
Verbindung zum Server wird hergestellt...
"
)
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
192.168.201.132
"
)
as
ssl_sock
:
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
192.168.201.132
"
)
as
ssl_sock
:
print
(
"
Mit dem Server verbunden
und TLS-Handshake abgeschlossen.
"
)
print
(
"
Mit dem Server verbunden
!
"
)
# Datei senden
# Datei senden
with
open
(
file_path
,
"
rb
"
)
as
f
:
with
open
(
file_path
,
"
rb
"
)
as
f
:
while
chunk
:
=
f
.
read
(
1024
):
while
chunk
:
=
f
.
read
(
1024
):
ssl_sock
.
sendall
(
chunk
)
ssl_sock
.
sendall
(
chunk
)
print
(
f
"
Datei
'
{
file_path
}
'
erfolgreich an den Server gesendet.
"
)
print
(
f
"
Datei
'
{
file_path
}
'
erfolgreich an den Server gesendet.
"
)
except
FileNotFoundError
:
print
(
f
"
Die Datei
'
{
file_path
}
'
wurde nicht gefunden!
"
)
except
socket
.
timeout
:
print
(
"
Die Verbindung zum Server ist abgelaufen!
"
)
except
wolfssl
.
SSLError
as
e
:
print
(
f
"
TLS-Fehler:
{
e
}
"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"
Allgemeiner Fehl
er:
{
e
}
"
)
print
(
f
"
Fehler bei der Verbindung zum Serv
er:
{
e
}
"
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# Dateipfad der zu übertragenden Datei
# Dateipfad der zu übertragenden Datei
file_to_send
=
"
../testData/test.txt
"
file_to_send
=
"
../testData/test.txt
"
if
os
.
path
.
exists
(
file_to_send
):
# Stelle sicher, dass die Datei existiert
run_client
(
file_to_send
)
if
not
os
.
path
.
exists
(
file_to_send
):
else
:
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
else
:
run_client
(
file_to_send
)
This diff is collapsed.
Click to expand it.
communicationScripts/server.py
+
22
−
25
View file @
41c6306b
...
@@ -6,47 +6,44 @@ def run_server():
...
@@ -6,47 +6,44 @@ def run_server():
# Server-Zertifikat und Schlüssel
# Server-Zertifikat und Schlüssel
cert_file
=
"
../certificates/server-cert.pem
"
cert_file
=
"
../certificates/server-cert.pem
"
key_file
=
"
../certificates/server-key.pem
"
key_file
=
"
../certificates/server-key.pem
"
ca_cert
=
"
../certificates/ca-cert.pem
"
# CA Zertifikat, um Client zu verifizieren
# Festlegen der Cipher Suite und TLS-Version
# Festlegen der Cipher Suite und TLS-Version
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# Sichere Cipher Suite
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# Sichere Cipher Suite
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
load_verify_locations
(
ca_cert
)
context
.
set_ciphers
(
cipher_suite
)
context
.
set_ciphers
(
cipher_suite
)
print
(
f
"
TLS-Kontext mit Cipher Suite
'
{
cipher_suite
}
'
erfolgreich initialisiert.
"
)
context
.
set_verify
(
wolfssl
.
VERIFY_PEER
)
# Überprüfen des Clientzertifikats
# Server-Socket erstellen
# Server-Socket erstellen
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
sock
:
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
sock
:
sock
.
settimeout
(
10
)
# Setze einen Timeout für Verbindungen
sock
.
bind
((
"
0.0.0.0
"
,
5000
))
# Lauschen auf allen Schnittstellen
sock
.
bind
((
"
0.0.0.0
"
,
5000
))
# Lauschen auf allen Schnittstellen
sock
.
listen
(
5
)
sock
.
listen
(
5
)
print
(
f
"
Server läuft auf Port 5000
und wartet auf Verbindungen
...
"
)
print
(
f
"
Server läuft auf Port 5000
mit Cipher Suite:
{
cipher_suite
}
...
"
)
while
True
:
while
True
:
client_sock
,
addr
=
sock
.
accept
()
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
try
:
try
:
client_sock
,
addr
=
sock
.
accept
()
ssl_sock
=
context
.
wrap_socket
(
client_sock
,
server_side
=
True
)
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
# Datei empfangen
with
context
.
wrap_socket
(
client_sock
,
server_side
=
True
)
as
ssl_sock
:
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
print
(
f
"
TLS-Handshake erfolgreich mit
{
addr
}
.
"
)
while
True
:
data
=
ssl_sock
.
recv
(
1024
)
# Datei empfangen
if
not
data
:
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
break
while
True
:
f
.
write
(
data
)
data
=
ssl_sock
.
recv
(
1024
)
print
(
"
Datei erfolgreich empfangen und gespeichert als
'
received_file.txt
'"
)
if
not
data
:
break
f
.
write
(
data
)
print
(
"
Datei erfolgreich empfangen und gespeichert als
'
received_file.txt
'"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"
Fehler bei der Verarbeitung der Verbindung:
{
e
}
"
)
print
(
f
"
Fehler bei der Verarbeitung der Verbindung:
{
e
}
"
)
finally
:
finally
:
try
:
ssl_sock
.
close
()
client_sock
.
close
()
client_sock
.
close
()
except
Exception
:
pass
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
try
:
run_server
()
run_server
()
except
KeyboardInterrupt
:
print
(
"
\n
Server wurde beendet.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment