Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iperf authentication. #58

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/authorized_users.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test,0a40291ff1b65f6ddd11f8979ee64981f43b6dec2d804bdb4bdc26d5889b4454
38 changes: 38 additions & 0 deletions examples/client_with_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import iperf3
import base64

# Return the contents of a PEM file B64 encoded
def get_key_as_base64(key_file):
with open(key_file, 'rb') as file:
raw_key = file.read()
return base64.b64encode(raw_key).decode("ascii")

client = iperf3.Client()
client.duration = 1
client.server_hostname = '127.0.0.1'
client.port = 5200
client.rsa_pubkey = get_key_as_base64("public.pem")
client.username = "test"
client.password = "test7"

print('Connecting to {0}:{1}'.format(client.server_hostname, client.port))
result = client.run()

if result.error:
print(result.error)
else:
print('')
print('Test completed:')
print(' started at {0}'.format(result.time))
print(' bytes transmitted {0}'.format(result.sent_bytes))
print(' retransmits {0}'.format(result.retransmits))
print(' avg cpu load {0}%\n'.format(result.local_cpu_total))

print('Average transmitted data in all sorts of networky formats:')
print(' bits per second (bps) {0}'.format(result.sent_bps))
print(' Kilobits per second (kbps) {0}'.format(result.sent_kbps))
print(' Megabits per second (Mbps) {0}'.format(result.sent_Mbps))
print(' KiloBytes per second (kB/s) {0}'.format(result.sent_kB_s))
print(' MegaBytes per second (MB/s) {0}'.format(result.sent_MB_s))
30 changes: 30 additions & 0 deletions examples/private.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN R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qs5sijA4Ns1+vSgYewttRPAtbJT0VbHhkFAfd
37TPtXRacbI4mre1CEFjccBaIZEA9goZZOFkzvC4YihqLeKhjDwwt5hFKFtjgR4k
NyLOs4m8lxiku3d0rPpC4EOtHHM7Ny7WskDK+6//Bra/h/EQVp0fM+PgIaXvMwx+
QT7eX9ZURTO3Pjg5z5WC6P6Ek5o0jej8FlmrDOEKadWOz/2euPueDTN3m/MQMa+M
HtFeQj/pLcF2loOi6vOAjdDPtok9dID9PfFquT6o9DyIpsLCZIectz940yk9tKnk
asq3ym0cAgLKCfb93MN4hYS5Z3KOeZCTECAAWCrXn9ldXz+/Qgw2ARIZxPc8i3i1
YtRlCo1TGErKVAvmIDIIx1prjkD6i7X3G2gm6C8zSdWoIoZQrySeaaSTj1ie8oDt
E4BaN2cgYvKRYPeJM/VyS4mYwh3Fod0LKfY6w8cat2DEnE4TZql5YByaeT0JHAZt
mTIsU3cTuQX9lPSoCKm5J5NG0Y7t3ZDqj2FqVuy705e+LDmYRrq+WtA4X19VCC2d
Y3YZKYIZyv4za/2M4DaNVz5zd2Y+hYXLR1IyKKGFjhD0lwouiTU4Pm94mqKm4Zoy
-----END RSA PRIVATE KEY-----
27 changes: 27 additions & 0 deletions examples/private_not_protected.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAsSsC4nLqgVEaWTu2t8mvR36InaRAlJymV5S1HlSq6WHGJnWw
rVEIsGbkbWcVwr6KWZybpskmkhg2nLCrSAG8TaObebyCtRslS0ZxGzn+zRFG5WQg
s6c6yHm+gSS2ZQSri1IerNym8RdgoV3Gv8LoAFIM1R1a0T3agUEwQmIjwqnay0lk
pAabAcsRoxhvddvvZhHUFzyKLZonblHA+NNB+I9ySQTSh6sbgBwLBpA3rVl1Qght
jlKAHiQ/r9bJbHjqWNRL6Bx47/g33Rp5mQcJryyXVgDudGaIxWeo7J5Fz95u9YbJ
IKlGywddWWmEC3qWatQ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xkK61DC
aWL3CI0CgYEA4/pRb37I0MwijBRZl4SY6hDQDidAoL3Owkp1ZuXOn3rSnNz/+WGw
ukoktnNmb/RA88Ywcz25fazg1r3RoQj/5BayJv7eUFgSk65QYKT/kgiJf47GK1Q7
It2SH9o6bHQhnc2Xvmx95GYZ7sDAviv7xArSGjA+y7n0NanyeMqQ5WI=
-----END RSA PRIVATE KEY-----
9 changes: 9 additions & 0 deletions examples/public.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsSsC4nLqgVEaWTu2t8mv
R36InaRAlJymV5S1HlSq6WHGJnWwrVEIsGbkbWcVwr6KWZybpskmkhg2nLCrSAG8
TaObebyCtRslS0ZxGzn+zRFG5WQgs6c6yHm+gSS2ZQSri1IerNym8RdgoV3Gv8Lo
AFIM1R1a0T3agUEwQmIjwqnay0lkpAabAcsRoxhvddvvZhHUFzyKLZonblHA+NNB
+I9ySQTSh6sbgBwLBpA3rVl1QghtjlKAHiQ/r9bJbHjqWNRL6Bx47/g33Rp5mQcJ
ryyXVgDudGaIxWeo7J5Fz95u9YbJIKlGywddWWmEC3qWatQ8MCkGzKorXdu+AtPh
kQIDAQAB
-----END PUBLIC KEY-----
3 changes: 1 addition & 2 deletions examples/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import iperf3

import iperf3.iperf3

server = iperf3.Server()
print('Running server: {0}:{1}'.format(server.bind_address, server.port))
Expand Down
54 changes: 54 additions & 0 deletions examples/server_with_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import iperf3.iperf3
import re

server = iperf3.Server()
rsa_privkey = '''MIIEpAIBAAKCAQEA0AKoqwFjngchlz/If0DLBP+5/dmgWpJKgVlHokkQk3ZRj0PR
bSt8zLnmbytsZL8QdknhRuNZXT3S0kY/E5V6+jbTaM59MjI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aFGAJm11XXhDEEdxxbkyQtxCo0cOhfmNjck8O9KY8
7HScMwvIjuqkRrEk/ghZaUUCgYAdSfitUzEyFjgE8pqAyiEt7VSJE2omBHuf1mZQ
wYEc21D+bsnTB+htBqDvOT8TJabztrXOgcZhOGlTDVwQblKJmIQQopBM/nt914Lr
8qWTP3+lEjobjQRPs09dAo7YU14JbPfHeWg7A3fLPFOAtl8c0r26utMM2MKYTSz1
Q1VIQwKBgQC2bHZ/97JyeFCdprerX5khUv7tgZimaTlApVbx+GiF4ifpUcy1+aNe
ECtT7nEtplN1P1AinWUEXCtjETzR5eEKv0Rxof/YUXVMBr5XwpQZujNtmPHEgnNM
QnYrdXI6zUXOntc0SfDNkVJI9wLIM2flZ1/oV3mboTk/a3hefbY6zQ=='''
server.rsa_privkey = re.sub(r"[\n\t\s]*", "", rsa_privkey)
server.authorized_users = "authorized_users.txt"
print('Running server: {0}:{1}'.format(server.bind_address, server.port))

while True:
result = server.run()

if result.error:
print(result.error)
else:
print('')
print('Test results from {0}:{1}'.format(result.remote_host,
result.remote_port))
print(' started at {0}'.format(result.time))
print(' bytes received {0}'.format(result.received_bytes))

print('Average transmitted received in all sorts of networky formats:')
print(' bits per second (bps) {0}'.format(result.received_bps))
print(' Kilobits per second (kbps) {0}'.format(result.received_kbps))
print(' Megabits per second (Mbps) {0}'.format(result.received_Mbps))
print(' KiloBytes per second (kB/s) {0}'.format(result.received_kB_s))
print(' MegaBytes per second (MB/s) {0}'.format(result.received_MB_s))
print('')
Loading