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
76fad81d
Commit
76fad81d
authored
6 months ago
by
Dominik Fuhrmann
Browse files
Options
Downloads
Patches
Plain Diff
debugging scripts
parent
6a8f5760
No related branches found
Branches containing commit
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
+8
-34
8 additions, 34 deletions
communicationScripts/client.py
communicationScripts/server.py
+8
-31
8 additions, 31 deletions
communicationScripts/server.py
with
16 additions
and
65 deletions
communicationScripts/client.py
+
8
−
34
View file @
76fad81d
# CLIENT-SKRIPT
import
os
import
socket
import
wolfssl
...
...
@@ -6,44 +7,17 @@ def run_client(file_path):
# CA-Zertifikat laden
ca_cert
=
"
../certificates/ca-cert.pem
"
# Optionen für Verschlüsselungsalgorithmen
print
(
"
Wählen Sie einen Verschlüsselungsalgorithmus:
"
)
print
(
"
1: AES 128 GCM (sicher)
"
)
print
(
"
3: ChaCha20-Poly1305 (sicher)
"
)
print
(
"
4: RC4 (unsicher)
"
)
print
(
"
5: 3DES (unsicher)
"
)
choice_cipher
=
input
(
"
Geben Sie die Nummer des gewünschten Verschlüsselungsalgorithmus ein:
"
)
# Cipher Suite entsprechend der Wahl des Benutzers auswählen
if
choice_cipher
==
"
1
"
:
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# AES 128 GCM (sicher)
elif
choice_cipher
==
"
2
"
:
cipher_suite
=
"
TLS_CHACHA20_POLY1305_SHA256
"
# ChaCha20-Poly1305 (sicher)
elif
choice_cipher
==
"
3
"
:
cipher_suite
=
"
TLS_RSA_WITH_RC4_128_SHA
"
# RC4 (unsicher)
elif
choice_cipher
==
"
4
"
:
cipher_suite
=
"
TLS_RSA_WITH_3DES_EDE_CBC_SHA
"
# 3DES (unsicher)
else
:
print
(
"
Ungültige Auswahl, Standard-AES 128 GCM wird verwendet.
"
)
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# SSL-Kontext erstellen
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_2
)
# Festlegen der Cipher Suite und TLS-Version
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# Sichere Cipher Suite
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
.
load_verify_locations
(
ca_cert
)
context
.
set_ciphers
(
cipher_suite
)
try
:
# Verschlüsselung (Cipher Suite) setzen
context
.
set_ciphers
(
cipher_suite
)
print
(
f
"
Cipher Suite
'
{
cipher_suite
}
'
erfolgreich gesetzt!
"
)
except
Exception
as
e
:
print
(
f
"
Fehler beim Setzen der Cipher Suite:
{
e
}
"
)
print
(
"
Möglicherweise wird die angegebene Cipher Suite von wolfSSL nicht unterstützt.
"
)
return
print
(
f
"
Cipher Suite
'
{
cipher_suite
}
'
erfolgreich gesetzt!
"
)
# Sichere Verbindung mit dem Server herstellen
with
socket
.
create_connection
((
"
192.168.201.20
"
,
5000
))
as
sock
:
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
server
"
)
as
ssl_sock
:
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
192.168.201.20
"
)
as
ssl_sock
:
print
(
"
Mit dem Server verbunden!
"
)
# Datei senden
...
...
@@ -60,4 +34,4 @@ if __name__ == "__main__":
if
not
os
.
path
.
exists
(
file_to_send
):
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
else
:
run_client
(
file_to_send
)
run_client
(
file_to_send
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
communicationScripts/server.py
+
8
−
31
View file @
76fad81d
import
socket
import
wolfssl
# SERVER-SKRIPT
def
run_server
():
# Server-Zertifikat und Schlüssel
cert_file
=
"
../certificates/server-cert.pem
"
key_file
=
"
../certificates/server-key.pem
"
# Optionen für Verschlüsselungsalgorithmen
print
(
"
Wählen Sie einen Verschlüsselungsalgorithmus:
"
)
print
(
"
1: AES 128 GCM (sicher)
"
)
print
(
"
2: ChaCha20 Poly1305 (sicher)
"
)
print
(
"
3: RC4 (unsicher)
"
)
print
(
"
4: 3DES (unsicher)
"
)
choice_cipher
=
input
(
"
Geben Sie die Nummer des gewünschten Verschlüsselungsalgorithmus ein:
"
)
# Cipher Suite entsprechend der Wahl des Benutzers auswählen
if
choice_cipher
==
"
1
"
:
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# AES 128 GCM (sicher)
elif
choice_cipher
==
"
2
"
:
cipher_suite
=
"
TLS_CHACHA20_POLY1305_SHA256
"
# ChaCha20 Poly1305 (sicher)
elif
choice_cipher
==
"
3
"
:
cipher_suite
=
"
TLS_RSA_WITH_RC4_128_SHA
"
# RC4 (unsicher)
elif
choice_cipher
==
"
4
"
:
cipher_suite
=
"
TLS_RSA_WITH_3DES_EDE_CBC_SHA
"
# 3DES (unsicher)
else
:
print
(
"
Ungültige Auswahl, Standard-AES 128 GCM wird verwendet.
"
)
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# SSL-Kontext erstellen (Standard: TLSv1.2, da keine Auswahl mehr)
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_2
)
# Festlegen der Cipher Suite und TLS-Version
cipher_suite
=
"
TLS_AES_128_GCM_SHA256
"
# Sichere Cipher Suite
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_3
)
# TLS 1.3 verwenden
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
# Verschlüsselung (Cipher Suite) setzen
context
.
set_ciphers
(
cipher_suite
)
# Server-Socket erstellen
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
sock
:
sock
.
bind
((
"
0.0.0.0
"
,
5000
))
#
A
uf allen Schnittstellen
lauschen
sock
.
bind
((
"
0.0.0.0
"
,
5000
))
#
Lauschen a
uf allen Schnittstellen
sock
.
listen
(
5
)
print
(
f
"
Server läuft auf Port 5000 mit Cipher Suite:
{
cipher_suite
}
...
"
)
while
True
:
# Verbindung akzeptieren
client_sock
,
addr
=
sock
.
accept
()
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
try
:
# SSL/TLS-Schicht hinzufügen
ssl_sock
=
context
.
wrap_socket
(
client_sock
,
server_side
=
True
)
# Datei empfangen
...
...
@@ -60,8 +37,8 @@ def run_server():
except
Exception
as
e
:
print
(
f
"
Fehler bei der Verarbeitung der Verbindung:
{
e
}
"
)
finally
:
ssl_sock
.
close
()
# SSL-Socket explizit schließen
client_sock
.
close
()
# Basis-Socket explizit schließen
ssl_sock
.
close
()
client_sock
.
close
()
if
__name__
==
"
__main__
"
:
run_server
()
run_server
()
\ No newline at end of file
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