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
3477fc4f
Commit
3477fc4f
authored
6 months ago
by
Dominik Fuhrmann
Browse files
Options
Downloads
Patches
Plain Diff
adapted scripts
parent
9b994bbc
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
scripts/client.py
+15
-14
15 additions, 14 deletions
scripts/client.py
scripts/server.py
+27
-24
27 additions, 24 deletions
scripts/server.py
with
42 additions
and
38 deletions
scripts/client.py
+
15
−
14
View file @
3477fc4f
import
os
import
os
import
socket
import
wolfssl
import
wolfssl
def
run_client
(
file_path
):
def
run_client
(
file_path
):
# CA-Zertifikat laden
# CA-Zertifikat laden
ca_cert
=
"
../certificates/ca-cert.pem
"
ca_cert
=
"
../certificates/ca-cert.pem
"
context
=
WolfSSLContext
(
SSL_METHOD_TLSv1_2
)
# SSL-Kontext erstellen
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_2
)
context
.
load_verify_locations
(
ca_cert
)
context
.
load_verify_locations
(
ca_cert
)
context
.
set_cipher_list
(
"
RC4-SHA
"
)
# Sichere Verbindung mit dem Server herstellen
with
socket
.
create_connection
((
"
192.168.178.51
"
,
5000
))
as
sock
:
# Verbindung mit dem Server herstellen
with
context
.
wrap_socket
(
sock
,
server_hostname
=
"
server
"
)
as
ssl_sock
:
client
=
WolfSSLClient
(
context
,
"
192.168.178.51
"
,
5000
)
print
(
"
Mit dem Server verbunden!
"
)
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
)
client
.
send
(
chunk
)
print
(
f
"
Datei
'
{
file_path
}
'
erfolgreich an den Server gesendet.
"
)
print
(
f
"
Datei
'
{
file_path
}
'
erfolgreich an den Server gesendet.
"
)
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
# Stelle sicher, dass die Datei existiert
if
not
os
.
path
.
exists
(
file_to_send
):
if
not
os
.
path
.
exists
(
file_to_send
):
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
print
(
f
"
Die Datei
'
{
file_to_send
}
'
wurde nicht gefunden!
"
)
...
...
This diff is collapsed.
Click to expand it.
scripts/server.py
+
27
−
24
View file @
3477fc4f
import
o
s
import
s
ocket
import
wolfssl
import
wolfssl
def
run_server
():
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
"
context
=
WolfSSLContext
(
SSL_METHOD_TLSv1_2
)
# SSL-Kontext erstellen
context
.
use_certificate_file
(
cert_file
)
context
=
wolfssl
.
SSLContext
(
wolfssl
.
PROTOCOL_TLSv1_2
)
context
.
use_privatekey_file
(
key_file
)
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
set_cipher_list
(
"
RC4-SHA
"
)
# Server-Socket erstellen
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
sock
:
# Server starten
sock
.
bind
((
"
192.168.178.51
"
,
5000
))
server
=
WolfSSLServer
(
context
,
"
192.168.178.51
"
,
5000
)
sock
.
listen
(
5
)
print
(
"
Server läuft auf Port 5000...
"
)
print
(
"
Server läuft auf Port 5000...
"
)
with
server
.
accept
()
as
conn
:
# Verbindung akzeptieren und SSL/TLS-Schicht hinzufügen
print
(
"
Verbindung akzeptiert!
"
)
with
context
.
wrap_socket
(
sock
,
server_side
=
True
)
as
ssock
:
conn
,
addr
=
ssock
.
accept
()
# Datei empfangen
print
(
f
"
Verbindung akzeptiert von
{
addr
}
!
"
)
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
while
True
:
# Datei empfangen
data
=
conn
.
recv
(
1024
)
with
conn
:
if
not
data
:
with
open
(
"
received_file.txt
"
,
"
wb
"
)
as
f
:
break
while
True
:
f
.
write
(
data
)
data
=
conn
.
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
'"
)
if
__name__
==
"
__main__
"
:
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