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
e2327cce
Commit
e2327cce
authored
6 months ago
by
Dominik Fuhrmann
Browse files
Options
Downloads
Patches
Plain Diff
debugging scripts
parent
284c4ddd
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
+21
-16
21 additions, 16 deletions
communicationScripts/client.py
communicationScripts/server.py
+24
-17
24 additions, 17 deletions
communicationScripts/server.py
with
45 additions
and
33 deletions
communicationScripts/client.py
+
21
−
16
View file @
e2327cce
# CLIENT-SKRIPT
import
os
import
os
import
socket
import
socket
import
wolfssl
import
wolfssl
...
@@ -12,27 +11,33 @@ def run_client(file_path):
...
@@ -12,27 +11,33 @@ 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
"
Cipher Suite
'
{
cipher_suite
}
'
erfolgreich gesetzt!
"
)
# Sichere Verbindung mit dem Server herstellen
# Sichere Verbindung mit dem Server herstellen
with
socket
.
create_connection
((
"
192.168.201.132
"
,
5000
))
as
sock
:
try
:
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
192.168.201.132
"
)
as
ssl_sock
:
with
socket
.
create_connection
((
"
192.168.201.132
"
,
5000
),
timeout
=
10
)
as
sock
:
print
(
"
Mit dem Server verbunden!
"
)
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
192.168.201.132
"
)
as
ssl_sock
:
print
(
"
Mit dem Server verbunden und TLS-Handshake abgeschlossen.
"
)
# 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
:
print
(
f
"
Allgemeiner Fehler:
{
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
"
# Stelle sicher, dass die Datei existiert
if
os
.
path
.
exists
(
file_to_send
):
if
not
os
.
path
.
exists
(
file_to_send
):
run_client
(
file_to_send
)
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
else
:
else
:
run_client
(
file_to_send
)
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
communicationScripts/server.py
+
24
−
17
View file @
e2327cce
...
@@ -12,34 +12,41 @@ def run_server():
...
@@ -12,34 +12,41 @@ def run_server():
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
.
set_ciphers
(
cipher_suite
)
context
.
set_ciphers
(
cipher_suite
)
print
(
f
"
TLS-Kontext mit Cipher Suite
'
{
cipher_suite
}
'
erfolgreich initialisiert.
"
)
# 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
mit Cipher Suite:
{
cipher_suite
}
...
"
)
print
(
f
"
Server läuft auf Port 5000
und wartet auf Verbindungen
...
"
)
while
True
:
while
True
:
client_sock
,
addr
=
sock
.
accept
()
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
try
:
try
:
ssl_sock
=
context
.
wrap_socket
(
client_sock
,
server_side
=
True
)
client_sock
,
addr
=
sock
.
accept
()
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
with
context
.
wrap_socket
(
client_sock
,
server_side
=
True
)
as
ssl_sock
:
print
(
f
"
TLS-Handshake erfolgreich mit
{
addr
}
.
"
)
# Datei empfangen
# Datei empfangen
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
while
True
:
while
True
:
data
=
ssl_sock
.
recv
(
1024
)
data
=
ssl_sock
.
recv
(
1024
)
if
not
data
:
if
not
data
:
break
break
f
.
write
(
data
)
f
.
write
(
data
)
print
(
"
Datei erfolgreich empfangen und gespeichert als
'
received_file.txt
'"
)
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
:
ssl_sock
.
close
()
try
:
client_sock
.
close
()
client_sock
.
close
()
except
Exception
:
pass
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
run_server
()
try
:
\ No newline at end of file
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