pyrad 2.4__py3-none-any.whl → 2.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/Makefile +20 -0
- docs/make.bat +36 -0
- docs/source/_static/logo.png +0 -0
- docs/source/api/client.rst +10 -0
- docs/source/api/dictionary.rst +10 -0
- docs/source/api/host.rst +7 -0
- docs/source/api/packet.rst +48 -0
- docs/source/api/proxy.rst +7 -0
- docs/source/api/server.rst +13 -0
- docs/source/conf.py +158 -0
- docs/source/index.rst +75 -0
- example/acct.py +41 -0
- example/auth.py +37 -0
- example/auth_async.py +164 -0
- example/client-coa.py +61 -0
- example/coa.py +40 -0
- example/dictionary +405 -0
- example/dictionary.freeradius +91 -0
- example/pyrad.log +0 -0
- example/server.py +68 -0
- example/server_async.py +117 -0
- example/status.py +26 -0
- pyrad/__init__.py +3 -3
- pyrad/client.py +14 -6
- pyrad/client_async.py +16 -13
- pyrad/dictfile.py +2 -5
- pyrad/dictionary.py +6 -7
- pyrad/host.py +1 -1
- pyrad/packet.py +145 -114
- pyrad/proxy.py +2 -2
- pyrad/server.py +3 -7
- pyrad/server_async.py +3 -4
- pyrad/tests/__init__.py +5 -0
- pyrad/tests/mock.py +145 -0
- pyrad/tests/test_bidict.py +56 -0
- pyrad/tests/test_client.py +183 -0
- pyrad/tests/test_dictionary.py +357 -0
- pyrad/tests/test_host.py +87 -0
- pyrad/tests/test_packet.py +679 -0
- pyrad/tests/test_proxy.py +96 -0
- pyrad/tests/test_server.py +323 -0
- pyrad/tests/test_tools.py +126 -0
- pyrad/tools.py +254 -158
- {pyrad-2.4.dist-info → pyrad-2.5.0.dist-info}/METADATA +44 -20
- pyrad-2.5.0.dist-info/RECORD +51 -0
- {pyrad-2.4.dist-info → pyrad-2.5.0.dist-info}/WHEEL +1 -1
- {pyrad-2.4.dist-info → pyrad-2.5.0.dist-info/licenses}/LICENSE.txt +1 -1
- pyrad-2.5.0.dist-info/top_level.txt +3 -0
- pyrad-2.4.dist-info/RECORD +0 -19
- pyrad-2.4.dist-info/top_level.txt +0 -1
- {pyrad-2.4.dist-info → pyrad-2.5.0.dist-info}/zip-safe +0 -0
docs/Makefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line.
|
|
5
|
+
SPHINXOPTS =
|
|
6
|
+
SPHINXBUILD = sphinx-build
|
|
7
|
+
SPHINXPROJ = pyrad
|
|
8
|
+
SOURCEDIR = source
|
|
9
|
+
BUILDDIR = build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
docs/make.bat
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
@ECHO OFF
|
|
2
|
+
|
|
3
|
+
pushd %~dp0
|
|
4
|
+
|
|
5
|
+
REM Command file for Sphinx documentation
|
|
6
|
+
|
|
7
|
+
if "%SPHINXBUILD%" == "" (
|
|
8
|
+
set SPHINXBUILD=sphinx-build
|
|
9
|
+
)
|
|
10
|
+
set SOURCEDIR=source
|
|
11
|
+
set BUILDDIR=build
|
|
12
|
+
set SPHINXPROJ=pyrad
|
|
13
|
+
|
|
14
|
+
if "%1" == "" goto help
|
|
15
|
+
|
|
16
|
+
%SPHINXBUILD% >NUL 2>NUL
|
|
17
|
+
if errorlevel 9009 (
|
|
18
|
+
echo.
|
|
19
|
+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
|
20
|
+
echo.installed, then set the SPHINXBUILD environment variable to point
|
|
21
|
+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
|
22
|
+
echo.may add the Sphinx directory to PATH.
|
|
23
|
+
echo.
|
|
24
|
+
echo.If you don't have Sphinx installed, grab it from
|
|
25
|
+
echo.http://sphinx-doc.org/
|
|
26
|
+
exit /b 1
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
30
|
+
goto end
|
|
31
|
+
|
|
32
|
+
:help
|
|
33
|
+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
34
|
+
|
|
35
|
+
:end
|
|
36
|
+
popd
|
|
Binary file
|
docs/source/api/host.rst
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
:mod:`pyrad.packet` -- packet encoding and decoding
|
|
2
|
+
===================================================
|
|
3
|
+
|
|
4
|
+
.. automodule:: pyrad.packet
|
|
5
|
+
|
|
6
|
+
.. autoclass:: Packet
|
|
7
|
+
:members:
|
|
8
|
+
|
|
9
|
+
.. autoclass:: AuthPacket
|
|
10
|
+
:members:
|
|
11
|
+
|
|
12
|
+
.. autoclass:: AcctPacket
|
|
13
|
+
:members:
|
|
14
|
+
|
|
15
|
+
.. autoclass:: CoAPacket
|
|
16
|
+
:members:
|
|
17
|
+
|
|
18
|
+
.. autoclass:: PacketError
|
|
19
|
+
:members:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Constants
|
|
23
|
+
---------
|
|
24
|
+
|
|
25
|
+
The :mod:`pyrad.packet` module defines several common constants
|
|
26
|
+
that are useful when dealing with RADIUS packets.
|
|
27
|
+
|
|
28
|
+
The following packet codes are defined:
|
|
29
|
+
|
|
30
|
+
================== ======
|
|
31
|
+
Constant name Value
|
|
32
|
+
================== ======
|
|
33
|
+
AccessRequest 1
|
|
34
|
+
------------------ ------
|
|
35
|
+
AccessAccept 2
|
|
36
|
+
AccessReject 3
|
|
37
|
+
AccountingRequest 4
|
|
38
|
+
AccountingResponse 5
|
|
39
|
+
AccessChallenge 11
|
|
40
|
+
StatusServer 12
|
|
41
|
+
StatusClient 13
|
|
42
|
+
DisconnectRequest 40
|
|
43
|
+
DisconnectACK 41
|
|
44
|
+
DisconnectNAK 42
|
|
45
|
+
CoARequest 43
|
|
46
|
+
CoAACK 44
|
|
47
|
+
CoANAK 45
|
|
48
|
+
================== ======
|
docs/source/conf.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# pyrad documentation build configuration file, created by
|
|
4
|
+
# sphinx-quickstart on Thu Feb 2 15:16:16 2017.
|
|
5
|
+
#
|
|
6
|
+
# This file is execfile()d with the current directory set to its
|
|
7
|
+
# containing dir.
|
|
8
|
+
#
|
|
9
|
+
# Note that not all possible configuration values are present in this
|
|
10
|
+
# autogenerated file.
|
|
11
|
+
#
|
|
12
|
+
# All configuration values have a default; values that are commented out
|
|
13
|
+
# serve to show the default.
|
|
14
|
+
|
|
15
|
+
# If extensions (or modules to document with autodoc) are in another directory,
|
|
16
|
+
# add these directories to sys.path here. If the directory is relative to the
|
|
17
|
+
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import sys
|
|
21
|
+
sys.path.insert(0, os.path.abspath('../../'))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# -- General configuration ------------------------------------------------
|
|
25
|
+
|
|
26
|
+
# If your documentation needs a minimal Sphinx version, state it here.
|
|
27
|
+
#
|
|
28
|
+
# needs_sphinx = '1.0'
|
|
29
|
+
|
|
30
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
|
31
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
32
|
+
# ones.
|
|
33
|
+
extensions = ['sphinx.ext.autodoc',
|
|
34
|
+
'sphinx.ext.intersphinx',
|
|
35
|
+
'sphinx.ext.todo',
|
|
36
|
+
'sphinx.ext.viewcode']
|
|
37
|
+
|
|
38
|
+
# Add any paths that contain templates here, relative to this directory.
|
|
39
|
+
templates_path = ['_templates']
|
|
40
|
+
|
|
41
|
+
# The suffix(es) of source filenames.
|
|
42
|
+
# You can specify multiple suffix as a list of string:
|
|
43
|
+
#
|
|
44
|
+
# source_suffix = ['.rst', '.md']
|
|
45
|
+
source_suffix = '.rst'
|
|
46
|
+
|
|
47
|
+
# The master toctree document.
|
|
48
|
+
master_doc = 'index'
|
|
49
|
+
|
|
50
|
+
# General information about the project.
|
|
51
|
+
project = u'pyrad'
|
|
52
|
+
copyright = u'Copyright 2002-2026 Wichert Akkerman, Christian Giese, Istvan Ruzman and Stefan Lieberth. All rights reserved.'
|
|
53
|
+
author = u'Christian Giese <gic@gicnet.de>, Istvan Ruzman <istvan@ruzman.eu> and Stefan Lieberth <stefan@lieberth.net>'
|
|
54
|
+
|
|
55
|
+
# The version info for the project you're documenting, acts as replacement for
|
|
56
|
+
# |version| and |release|, also used in various other places throughout the
|
|
57
|
+
# built documents.
|
|
58
|
+
#
|
|
59
|
+
# The short X.Y version.
|
|
60
|
+
version = u'2.5'
|
|
61
|
+
# The full version, including alpha/beta/rc tags.
|
|
62
|
+
release = u'2.5'
|
|
63
|
+
|
|
64
|
+
# The language for content autogenerated by Sphinx. Refer to documentation
|
|
65
|
+
# for a list of supported languages.
|
|
66
|
+
#
|
|
67
|
+
# This is also used if you do content translation via gettext catalogs.
|
|
68
|
+
# Usually you set "language" from the command line for these cases.
|
|
69
|
+
language = None
|
|
70
|
+
|
|
71
|
+
# List of patterns, relative to source directory, that match files and
|
|
72
|
+
# directories to ignore when looking for source files.
|
|
73
|
+
# This patterns also effect to html_static_path and html_extra_path
|
|
74
|
+
exclude_patterns = []
|
|
75
|
+
|
|
76
|
+
# The name of the Pygments (syntax highlighting) style to use.
|
|
77
|
+
pygments_style = 'sphinx'
|
|
78
|
+
|
|
79
|
+
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
|
80
|
+
todo_include_todos = True
|
|
81
|
+
|
|
82
|
+
# -- Options for HTML output ----------------------------------------------
|
|
83
|
+
|
|
84
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
85
|
+
# a list of builtin themes.
|
|
86
|
+
#
|
|
87
|
+
# html_theme = 'alabaster'
|
|
88
|
+
|
|
89
|
+
# Theme options are theme-specific and customize the look and feel of a theme
|
|
90
|
+
# further. For a list of options available for each theme, see the
|
|
91
|
+
# documentation.
|
|
92
|
+
#
|
|
93
|
+
# html_theme_options = {}
|
|
94
|
+
|
|
95
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
|
96
|
+
# relative to this directory. They are copied after the builtin static files,
|
|
97
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
98
|
+
html_static_path = ['_static']
|
|
99
|
+
|
|
100
|
+
html_logo = '_static/logo.png'
|
|
101
|
+
|
|
102
|
+
# -- Options for HTMLHelp output ------------------------------------------
|
|
103
|
+
|
|
104
|
+
# Output file base name for HTML help builder.
|
|
105
|
+
htmlhelp_basename = 'pyraddoc'
|
|
106
|
+
|
|
107
|
+
# -- Options for LaTeX output ---------------------------------------------
|
|
108
|
+
|
|
109
|
+
latex_elements = {
|
|
110
|
+
# The paper size ('letterpaper' or 'a4paper').
|
|
111
|
+
#
|
|
112
|
+
# 'papersize': 'letterpaper',
|
|
113
|
+
|
|
114
|
+
# The font size ('10pt', '11pt' or '12pt').
|
|
115
|
+
#
|
|
116
|
+
# 'pointsize': '10pt',
|
|
117
|
+
|
|
118
|
+
# Additional stuff for the LaTeX preamble.
|
|
119
|
+
#
|
|
120
|
+
# 'preamble': '',
|
|
121
|
+
|
|
122
|
+
# Latex figure (float) alignment
|
|
123
|
+
#
|
|
124
|
+
# 'figure_align': 'htbp',
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
# Grouping the document tree into LaTeX files. List of tuples
|
|
128
|
+
# (source start file, target name, title,
|
|
129
|
+
# author, documentclass [howto, manual, or own class]).
|
|
130
|
+
latex_documents = [
|
|
131
|
+
(master_doc, 'pyrad.tex', u'pyrad Documentation',
|
|
132
|
+
u'Christian Giese and Istvan Ruzman', 'manual'),
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# -- Options for manual page output ---------------------------------------
|
|
137
|
+
|
|
138
|
+
# One entry per manual page. List of tuples
|
|
139
|
+
# (source start file, name, description, authors, manual section).
|
|
140
|
+
man_pages = [
|
|
141
|
+
(master_doc, 'pyrad', u'pyrad Documentation',
|
|
142
|
+
[author], 1)
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# -- Options for Texinfo output -------------------------------------------
|
|
147
|
+
|
|
148
|
+
# Grouping the document tree into Texinfo files. List of tuples
|
|
149
|
+
# (source start file, target name, title, author,
|
|
150
|
+
# dir menu entry, description, category)
|
|
151
|
+
texinfo_documents = [
|
|
152
|
+
(master_doc, 'pyrad', u'pyrad Documentation',
|
|
153
|
+
author, 'pyrad', 'Python implementation of the RADIUS protocol.',
|
|
154
|
+
'RADIUS'),
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
# Example configuration for intersphinx: refer to the Python standard library.
|
|
158
|
+
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
|
docs/source/index.rst
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
*********************************
|
|
3
|
+
:mod:`pyrad` -- RADIUS for Python
|
|
4
|
+
*********************************
|
|
5
|
+
|
|
6
|
+
:Author: Wichert Akkerman
|
|
7
|
+
:Version: |version|
|
|
8
|
+
|
|
9
|
+
Introduction
|
|
10
|
+
============
|
|
11
|
+
|
|
12
|
+
pyrad is an implementation of a RADIUS client/server as described in RFC2865.
|
|
13
|
+
It takes care of all the details like building RADIUS packets, sending
|
|
14
|
+
them and decoding responses.
|
|
15
|
+
|
|
16
|
+
Here is an example of doing a authentication request::
|
|
17
|
+
|
|
18
|
+
from pyrad.client import Client
|
|
19
|
+
from pyrad.dictionary import Dictionary
|
|
20
|
+
import pyrad.packet
|
|
21
|
+
|
|
22
|
+
srv = Client(server="localhost", secret=b"Kah3choteereethiejeimaeziecumi",
|
|
23
|
+
dict=Dictionary("dictionary"))
|
|
24
|
+
|
|
25
|
+
# create request
|
|
26
|
+
req = srv.CreateAuthPacket(code=pyrad.packet.AccessRequest,
|
|
27
|
+
User_Name="wichert", NAS_Identifier="localhost")
|
|
28
|
+
req["User-Password"] = req.PwCrypt("password")
|
|
29
|
+
|
|
30
|
+
# send request
|
|
31
|
+
reply = srv.SendPacket(req)
|
|
32
|
+
|
|
33
|
+
if reply.code == pyrad.packet.AccessAccept:
|
|
34
|
+
print("access accepted")
|
|
35
|
+
else:
|
|
36
|
+
print("access denied")
|
|
37
|
+
|
|
38
|
+
print("Attributes returned by server:")
|
|
39
|
+
for i in reply.keys():
|
|
40
|
+
print("%s: %s" % (i, reply[i]))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Requirements & Installation
|
|
44
|
+
===========================
|
|
45
|
+
|
|
46
|
+
pyrad requires Python 3.6 or later
|
|
47
|
+
|
|
48
|
+
Installing is simple; pyrad uses the standard distutils system for installing
|
|
49
|
+
Python modules::
|
|
50
|
+
|
|
51
|
+
python setup.py install
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
API Documentation
|
|
55
|
+
=================
|
|
56
|
+
|
|
57
|
+
Per-module :mod:`pyrad` API documentation.
|
|
58
|
+
|
|
59
|
+
.. toctree::
|
|
60
|
+
:maxdepth: 2
|
|
61
|
+
|
|
62
|
+
api/client
|
|
63
|
+
api/dictionary
|
|
64
|
+
api/host
|
|
65
|
+
api/packet
|
|
66
|
+
api/proxy
|
|
67
|
+
api/server
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
Indices and tables
|
|
71
|
+
==================
|
|
72
|
+
|
|
73
|
+
* :ref:`genindex`
|
|
74
|
+
* :ref:`modindex`
|
|
75
|
+
* :ref:`search`
|
example/acct.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
from pyrad.client import Client
|
|
3
|
+
from pyrad.dictionary import Dictionary
|
|
4
|
+
import random
|
|
5
|
+
import socket
|
|
6
|
+
import sys
|
|
7
|
+
import pyrad.packet
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def SendPacket(srv, req):
|
|
11
|
+
try:
|
|
12
|
+
srv.SendPacket(req)
|
|
13
|
+
except pyrad.client.Timeout:
|
|
14
|
+
print("RADIUS server does not reply")
|
|
15
|
+
sys.exit(1)
|
|
16
|
+
except socket.error as error:
|
|
17
|
+
print("Network error: " + error[1])
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
|
|
20
|
+
srv = Client(server="localhost", secret=b"Kah3choteereethiejeimaeziecumi", dict=Dictionary("dictionary"))
|
|
21
|
+
|
|
22
|
+
req = srv.CreateAcctPacket(User_Name="wichert")
|
|
23
|
+
|
|
24
|
+
req["NAS-IP-Address"] = "192.168.1.10"
|
|
25
|
+
req["NAS-Port"] = 0
|
|
26
|
+
req["NAS-Identifier"] = "trillian"
|
|
27
|
+
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
|
|
28
|
+
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
|
|
29
|
+
req["Framed-IP-Address"] = "10.0.0.100"
|
|
30
|
+
|
|
31
|
+
print("Sending accounting start packet")
|
|
32
|
+
req["Acct-Status-Type"] = "Start"
|
|
33
|
+
SendPacket(srv, req)
|
|
34
|
+
|
|
35
|
+
print("Sending accounting stop packet")
|
|
36
|
+
req["Acct-Status-Type"] = "Stop"
|
|
37
|
+
req["Acct-Input-Octets"] = random.randrange(2**10, 2**30)
|
|
38
|
+
req["Acct-Output-Octets"] = random.randrange(2**10, 2**30)
|
|
39
|
+
req["Acct-Session-Time"] = random.randrange(120, 3600)
|
|
40
|
+
req["Acct-Terminate-Cause"] = random.choice(["User-Request", "Idle-Timeout"])
|
|
41
|
+
SendPacket(srv, req)
|
example/auth.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
from pyrad.client import Client
|
|
3
|
+
from pyrad.dictionary import Dictionary
|
|
4
|
+
import socket
|
|
5
|
+
import sys
|
|
6
|
+
import pyrad.packet
|
|
7
|
+
|
|
8
|
+
srv = Client(server="127.0.0.1", secret=b"Kah3choteereethiejeimaeziecumi", dict=Dictionary("dictionary"))
|
|
9
|
+
|
|
10
|
+
req = srv.CreateAuthPacket(code=pyrad.packet.AccessRequest, User_Name="wichert")
|
|
11
|
+
|
|
12
|
+
req["NAS-IP-Address"] = "192.168.1.10"
|
|
13
|
+
req["NAS-Port"] = 0
|
|
14
|
+
req["Service-Type"] = "Login-User"
|
|
15
|
+
req["NAS-Identifier"] = "trillian"
|
|
16
|
+
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
|
|
17
|
+
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
|
|
18
|
+
req["Framed-IP-Address"] = "10.0.0.100"
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
print("Sending authentication request")
|
|
22
|
+
reply = srv.SendPacket(req)
|
|
23
|
+
except pyrad.client.Timeout:
|
|
24
|
+
print("RADIUS server does not reply")
|
|
25
|
+
sys.exit(1)
|
|
26
|
+
except socket.error as error:
|
|
27
|
+
print("Network error: " + error[1])
|
|
28
|
+
sys.exit(1)
|
|
29
|
+
|
|
30
|
+
if reply.code == pyrad.packet.AccessAccept:
|
|
31
|
+
print("Access accepted")
|
|
32
|
+
else:
|
|
33
|
+
print("Access denied")
|
|
34
|
+
|
|
35
|
+
print("Attributes returned by server:")
|
|
36
|
+
for i in reply.keys():
|
|
37
|
+
print("%s: %s" % (i, reply[i]))
|
example/auth_async.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import traceback
|
|
7
|
+
from pyrad.dictionary import Dictionary
|
|
8
|
+
from pyrad.client_async import ClientAsync
|
|
9
|
+
from pyrad.packet import AccessAccept
|
|
10
|
+
|
|
11
|
+
logging.basicConfig(level="DEBUG",
|
|
12
|
+
format="%(asctime)s [%(levelname)-8s] %(message)s")
|
|
13
|
+
client = ClientAsync(server="localhost",
|
|
14
|
+
secret=b"Kah3choteereethiejeimaeziecumi",
|
|
15
|
+
timeout=4,
|
|
16
|
+
dict=Dictionary("dictionary"))
|
|
17
|
+
|
|
18
|
+
loop = asyncio.get_event_loop()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def create_request(client, user):
|
|
22
|
+
req = client.CreateAuthPacket(User_Name=user)
|
|
23
|
+
|
|
24
|
+
req["NAS-IP-Address"] = "192.168.1.10"
|
|
25
|
+
req["NAS-Port"] = 0
|
|
26
|
+
req["Service-Type"] = "Login-User"
|
|
27
|
+
req["NAS-Identifier"] = "trillian"
|
|
28
|
+
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
|
|
29
|
+
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
|
|
30
|
+
req["Framed-IP-Address"] = "10.0.0.100"
|
|
31
|
+
|
|
32
|
+
return req
|
|
33
|
+
|
|
34
|
+
def print_reply(reply):
|
|
35
|
+
if reply.code == AccessAccept:
|
|
36
|
+
print("Access accepted")
|
|
37
|
+
else:
|
|
38
|
+
print("Access denied")
|
|
39
|
+
|
|
40
|
+
print("Attributes returned by server:")
|
|
41
|
+
for i in reply.keys():
|
|
42
|
+
print("%s: %s" % (i, reply[i]))
|
|
43
|
+
|
|
44
|
+
def test_auth1():
|
|
45
|
+
|
|
46
|
+
global client
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
# Initialize transports
|
|
50
|
+
loop.run_until_complete(
|
|
51
|
+
asyncio.ensure_future(
|
|
52
|
+
client.initialize_transports(enable_auth=True,
|
|
53
|
+
local_addr='127.0.0.1',
|
|
54
|
+
local_auth_port=8000,
|
|
55
|
+
enable_acct=True,
|
|
56
|
+
enable_coa=True)))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
req = client.CreateAuthPacket(User_Name="wichert")
|
|
61
|
+
|
|
62
|
+
req["NAS-IP-Address"] = "192.168.1.10"
|
|
63
|
+
req["NAS-Port"] = 0
|
|
64
|
+
req["Service-Type"] = "Login-User"
|
|
65
|
+
req["NAS-Identifier"] = "trillian"
|
|
66
|
+
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
|
|
67
|
+
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
|
|
68
|
+
req["Framed-IP-Address"] = "10.0.0.100"
|
|
69
|
+
|
|
70
|
+
future = client.SendPacket(req)
|
|
71
|
+
|
|
72
|
+
# loop.run_until_complete(future)
|
|
73
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
74
|
+
asyncio.gather(
|
|
75
|
+
future,
|
|
76
|
+
return_exceptions=True
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
))
|
|
80
|
+
|
|
81
|
+
if future.exception():
|
|
82
|
+
print('EXCEPTION ', future.exception())
|
|
83
|
+
else:
|
|
84
|
+
reply = future.result()
|
|
85
|
+
|
|
86
|
+
if reply.code == AccessAccept:
|
|
87
|
+
print("Access accepted")
|
|
88
|
+
else:
|
|
89
|
+
print("Access denied")
|
|
90
|
+
|
|
91
|
+
print("Attributes returned by server:")
|
|
92
|
+
for i in reply.keys():
|
|
93
|
+
print("%s: %s" % (i, reply[i]))
|
|
94
|
+
|
|
95
|
+
# Close transports
|
|
96
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
97
|
+
client.deinitialize_transports()))
|
|
98
|
+
print('END')
|
|
99
|
+
|
|
100
|
+
del client
|
|
101
|
+
except Exception as exc:
|
|
102
|
+
print('Error: ', exc)
|
|
103
|
+
print('\n'.join(traceback.format_exc().splitlines()))
|
|
104
|
+
# Close transports
|
|
105
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
106
|
+
client.deinitialize_transports()))
|
|
107
|
+
|
|
108
|
+
loop.close()
|
|
109
|
+
|
|
110
|
+
def test_multi_auth():
|
|
111
|
+
|
|
112
|
+
global client
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
# Initialize transports
|
|
116
|
+
loop.run_until_complete(
|
|
117
|
+
asyncio.ensure_future(
|
|
118
|
+
client.initialize_transports(enable_auth=True,
|
|
119
|
+
local_addr='127.0.0.1',
|
|
120
|
+
local_auth_port=8000,
|
|
121
|
+
enable_acct=True,
|
|
122
|
+
enable_coa=True)))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
reqs = []
|
|
127
|
+
for i in range(255):
|
|
128
|
+
req = create_request(client, "user%s" % i)
|
|
129
|
+
future = client.SendPacket(req)
|
|
130
|
+
reqs.append(future)
|
|
131
|
+
|
|
132
|
+
# loop.run_until_complete(future)
|
|
133
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
134
|
+
asyncio.gather(
|
|
135
|
+
*reqs,
|
|
136
|
+
return_exceptions=True
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
))
|
|
140
|
+
|
|
141
|
+
for future in reqs:
|
|
142
|
+
if future.exception():
|
|
143
|
+
print('EXCEPTION ', future.exception())
|
|
144
|
+
else:
|
|
145
|
+
reply = future.result()
|
|
146
|
+
print_reply(reply)
|
|
147
|
+
|
|
148
|
+
# Close transports
|
|
149
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
150
|
+
client.deinitialize_transports()))
|
|
151
|
+
print('END')
|
|
152
|
+
|
|
153
|
+
del client
|
|
154
|
+
except Exception as exc:
|
|
155
|
+
print('Error: ', exc)
|
|
156
|
+
print('\n'.join(traceback.format_exc().splitlines()))
|
|
157
|
+
# Close transports
|
|
158
|
+
loop.run_until_complete(asyncio.ensure_future(
|
|
159
|
+
client.deinitialize_transports()))
|
|
160
|
+
|
|
161
|
+
loop.close()
|
|
162
|
+
|
|
163
|
+
#test_multi_auth()
|
|
164
|
+
test_auth1()
|