This commit is contained in:
Tobias Oberstein 2017-03-19 20:42:49 +01:00
parent 73ad4cf300
commit ff481ce649
13 changed files with 112 additions and 75 deletions

View File

@ -44,7 +44,8 @@ import six
import txaio
__all__ = ("xor",
__all__ = ("public",
"xor",
"utcnow",
"utcstr",
"id",
@ -72,6 +73,7 @@ def public(obj):
return obj
@public
def encode_truncate(text, limit, encoding='utf8', return_encoded=True):
"""
Given a string, return a truncated version of the string such that
@ -117,6 +119,7 @@ def encode_truncate(text, limit, encoding='utf8', return_encoded=True):
return text
@public
def xor(d1, d2):
"""
XOR two binary strings of arbitrary (equal) length.
@ -148,6 +151,7 @@ def xor(d1, d2):
return d1.tostring()
@public
def utcstr(ts=None):
"""
Format UTC timestamp in ISO 8601 format.
@ -167,6 +171,7 @@ def utcstr(ts=None):
return u"{0}Z".format(ts.strftime(u"%Y-%m-%dT%H:%M:%S.%f")[:-3])
@public
def utcnow():
"""
Get current time in UTC as ISO 8601 string.
@ -334,6 +339,7 @@ Delta" and telephone operators' "Is that 'd' as in 'dog'?".
"""
@public
def generate_token(char_groups, chars_per_group, chars=None, sep=None, lower_case=False):
"""
Generate cryptographically strong tokens, which are strings like `M6X5-YO5W-T5IK`.
@ -389,14 +395,17 @@ def generate_token(char_groups, chars_per_group, chars=None, sep=None, lower_cas
return token_value
@public
def generate_activation_code():
return generate_token(char_groups=3, chars_per_group=4, chars=DEFAULT_TOKEN_CHARS, sep=u'-', lower_case=False)
@public
def generate_user_password():
return generate_token(char_groups=16, chars_per_group=1, chars=DEFAULT_ZBASE32_CHARS, sep=u'-', lower_case=True)
@public
def generate_serial_number():
return generate_token(char_groups=6, chars_per_group=4, chars=DEFAULT_TOKEN_CHARS, sep=u'-', lower_case=False)

View File

@ -38,6 +38,7 @@ import random
from struct import Struct
from operator import xor
from itertools import starmap
from autobahn.util import public
__all__ = (
'pbkdf2',
@ -48,6 +49,7 @@ __all__ = (
'compute_wcs')
@public
def generate_totp_secret(length=10):
"""
Generates a new Base32 encoded, random secret.
@ -65,6 +67,7 @@ def generate_totp_secret(length=10):
return base64.b32encode(os.urandom(length)).decode('ascii')
@public
def compute_totp(secret, offset=0):
"""
Computes the current TOTP code.
@ -92,6 +95,7 @@ def compute_totp(secret, offset=0):
return u'{0:06d}'.format(token)
@public
def check_totp(secret, ticket):
"""
Check a TOTP value received from a principal trying to authenticate against
@ -117,6 +121,7 @@ def check_totp(secret, ticket):
return False
@public
def qrcode_from_totp(secret, label, issuer):
if type(secret) != six.text_type:
raise Exception('secret must be of type unicode, not {}'.format(type(secret)))
@ -184,6 +189,7 @@ else:
return ''.join(map(chr, buf))[:keylen]
@public
def pbkdf2(data, salt, iterations=1000, keylen=32, hashfunc=None):
"""
Returns a binary digest for the PBKDF2 hash algorithm of ``data``
@ -212,6 +218,7 @@ def pbkdf2(data, salt, iterations=1000, keylen=32, hashfunc=None):
return _pbkdf2(data, salt, iterations, keylen, hashfunc or hashlib.sha256)
@public
def derive_key(secret, salt, iterations=1000, keylen=32):
"""
Computes a derived cryptographic key from a password according to PBKDF2.
@ -248,6 +255,7 @@ The characters from which :func:`autobahn.wamp.auth.generate_wcs` generates secr
"""
@public
def generate_wcs(length=14):
"""
Generates a new random secret for use with WAMP-CRA.
@ -268,6 +276,7 @@ def generate_wcs(length=14):
return u"".join([random.choice(WCS_SECRET_CHARSET) for _ in range(length)]).encode('ascii')
@public
def compute_wcs(key, challenge):
"""
Compute an WAMP-CRA authentication signature from an authentication

View File

@ -30,6 +30,8 @@ import json
import six
from autobahn.util import public
__all__ = [
'HAS_CRYPTOBOX',
'EncryptedPayload'
@ -62,6 +64,7 @@ class EncryptedPayload(object):
if HAS_CRYPTOBOX:
@public
class Key(object):
"""
Holds originator and responder keys for an URI.
@ -117,6 +120,7 @@ if HAS_CRYPTOBOX:
if not (self.originator_box or self.responder_box):
raise Exception("insufficient keys provided for at least originator or responder role")
@public
class KeyRing(object):
"""
A keyring holds (cryptobox) public-private key pairs for use with WAMP-cryptobox payload
@ -135,6 +139,7 @@ if HAS_CRYPTOBOX:
default_key = Key(originator_priv=default_key, responder_priv=default_key)
self._default_key = default_key
@public
def generate_key(self):
"""
Generate a new private key and return a pair with the base64 encodings
@ -145,6 +150,7 @@ if HAS_CRYPTOBOX:
pub_key = key.public_key.encode(encoder=Base64Encoder)
return (u'{}'.format(priv_key), u''.format(pub_key))
@public
def set_key(self, uri, key):
"""
Add a key set for a given URI.

View File

@ -352,6 +352,7 @@ def _verify_signify_ed25519_signature(pubkey_file, signature_file, message):
if HAS_CRYPTOSIGN:
@util.public
class SigningKey(object):
"""
A cryptosign private key for signing, and hence usable for authentication or a
@ -378,6 +379,7 @@ if HAS_CRYPTOSIGN:
comment = u'"{}"'.format(self.comment()) if self.comment() else None
return u'Key(can_sign={}, comment={}, public_key={})'.format(self.can_sign(), comment, self.public_key())
@util.public
def can_sign(self):
"""
Check if the key can be used to sign.
@ -387,6 +389,7 @@ if HAS_CRYPTOSIGN:
"""
return self._can_sign
@util.public
def comment(self):
"""
Get the key comment (if any).
@ -396,6 +399,7 @@ if HAS_CRYPTOSIGN:
"""
return self._comment
@util.public
def public_key(self, binary=False):
"""
Returns the public key part of a signing key or the (public) verification key.
@ -413,6 +417,7 @@ if HAS_CRYPTOSIGN:
else:
return key.encode(encoder=encoding.HexEncoder).decode('ascii')
@util.public
def sign(self, data):
"""
Sign some data.
@ -438,6 +443,7 @@ if HAS_CRYPTOSIGN:
# the signature
return txaio.create_future_success(sig.signature)
@util.public
def sign_challenge(self, session, challenge):
"""
Sign WAMP-cryptosign challenge.
@ -489,6 +495,7 @@ if HAS_CRYPTOSIGN:
return d2
@util.public
@classmethod
def from_raw_key(cls, filename, comment=None):
"""
@ -521,6 +528,7 @@ if HAS_CRYPTOSIGN:
key = signing.SigningKey(keydata)
return cls(key, comment)
@util.public
@classmethod
def from_ssh_key(cls, filename):
"""

View File

@ -28,6 +28,7 @@ from __future__ import absolute_import
import six
from autobahn.util import public
from autobahn.wamp.uri import error
__all__ = (
@ -42,12 +43,14 @@ __all__ = (
)
@public
class Error(RuntimeError):
"""
Base class for all exceptions related to WAMP.
"""
@public
class SessionNotReady(Error):
"""
The application tried to perform a WAMP interaction, but the
@ -55,6 +58,7 @@ class SessionNotReady(Error):
"""
@public
class SerializationError(Error):
"""
Exception raised when the WAMP serializer could not serialize the
@ -62,6 +66,7 @@ class SerializationError(Error):
"""
@public
class ProtocolError(Error):
"""
Exception raised when WAMP protocol was violated. Protocol errors
@ -70,6 +75,7 @@ class ProtocolError(Error):
"""
@public
class TransportLost(Error):
"""
Exception raised when the transport underlying the WAMP session
@ -77,6 +83,7 @@ class TransportLost(Error):
"""
@public
class ApplicationError(Error):
"""
Base class for all exceptions that can/may be handled
@ -225,6 +232,7 @@ class ApplicationError(Error):
self.error = error
self.enc_algo = kwargs.pop('enc_algo', None)
@public
def error_message(self):
"""
Get the error message of this exception.
@ -252,6 +260,7 @@ class ApplicationError(Error):
return self.__unicode__().encode('utf8')
@public
@error(ApplicationError.NOT_AUTHORIZED)
class NotAuthorized(Exception):
"""
@ -259,6 +268,7 @@ class NotAuthorized(Exception):
"""
@public
@error(ApplicationError.INVALID_URI)
class InvalidUri(Exception):
"""
@ -266,6 +276,7 @@ class InvalidUri(Exception):
"""
@public
@error(ApplicationError.INVALID_PAYLOAD)
class InvalidPayload(Exception):
"""

View File

@ -30,6 +30,7 @@ from __future__ import absolute_import
import re
import six
from autobahn.util import public
from autobahn.wamp.types import SubscribeOptions
__all__ = (
@ -88,6 +89,7 @@ def convert_starred_uri(uri):
return uri, match
@public
class Pattern(object):
"""
A WAMP URI Pattern.
@ -205,6 +207,7 @@ class Pattern(object):
self._uri = uri
self._target = target
@public
def uri(self):
"""
Returns the original URI (pattern) for this pattern.
@ -246,6 +249,7 @@ class Pattern(object):
else:
raise Exception("no match")
@public
def is_endpoint(self):
"""
Check if this pattern is for a procedure endpoint.
@ -255,6 +259,7 @@ class Pattern(object):
"""
return self._target == Pattern.URI_TARGET_ENDPOINT
@public
def is_handler(self):
"""
Check if this pattern is for an event handler.
@ -264,6 +269,7 @@ class Pattern(object):
"""
return self._target == Pattern.URI_TARGET_HANDLER
@public
def is_exception(self):
"""
Check if this pattern is for an exception.
@ -274,6 +280,7 @@ class Pattern(object):
return self._target == Pattern.URI_TARGET_EXCEPTION
@public
def register(uri):
"""
Decorator for WAMP procedure endpoints.
@ -287,6 +294,7 @@ def register(uri):
return decorate
@public
def subscribe(uri):
"""
Decorator for WAMP event handlers.
@ -300,6 +308,7 @@ def subscribe(uri):
return decorate
@public
def error(uri):
"""
Decorator for WAMP error classes.

View File

@ -8,7 +8,7 @@ Changelog
0.17.3
------
`Published 2017-03-18 <https://pypi.python.org/pypi/autobahn/0.17.3`__
`Published 2017-03-18 <https://pypi.python.org/pypi/autobahn/0.17.3>`__
* fix: docs for publisher black-/whitelisting based on authid/authrole
* fix: serialization for publisher black-/whitelisting based on authid/authrole
@ -19,7 +19,7 @@ Changelog
0.17.2
------
`Published 2017-02-25 <https://pypi.python.org/pypi/autobahn/0.17.2`__
`Published 2017-02-25 <https://pypi.python.org/pypi/autobahn/0.17.2>`__
* new: WAMP-cryptosign elliptic curve based authentication support for asyncio
* new: CI testing on Twisted 17.1
@ -28,7 +28,7 @@ Changelog
0.17.1
------
`Published 2016-12-29 <https://pypi.python.org/pypi/autobahn/0.17.1`__
`Published 2016-12-29 <https://pypi.python.org/pypi/autobahn/0.17.1>`__
* new: demo MQTT and WAMP clients interoperating via Crossbar.io
* new: WAMP message attributes for message resumption
@ -38,7 +38,7 @@ Changelog
0.17.0
------
`Published 2016-11-30 <https://pypi.python.org/pypi/autobahn/0.17.0`__
`Published 2016-11-30 <https://pypi.python.org/pypi/autobahn/0.17.0>`__
* new: WAMP PubSub event retention
* new: WAMP PubSub last will / testament
@ -48,7 +48,7 @@ Changelog
0.16.1
------
`Published 2016-11-07 <https://pypi.python.org/pypi/autobahn/0.16.1`__
`Published 2016-11-07 <https://pypi.python.org/pypi/autobahn/0.16.1>`__
* fix: inconsistency between `PublishOptions` and `Publish` message
* new: improve logging with dropped connections (eg due to timeouts)
@ -59,7 +59,7 @@ Changelog
0.16.0
------
`Published 2016-08-14 <https://pypi.python.org/pypi/autobahn/0.16.0`__
`Published 2016-08-14 <https://pypi.python.org/pypi/autobahn/0.16.0>`__
* new: new `autobahn.wamp.component` API in experimental stage
* new: Ed25519 OpenSSH and OpenBSD signify key support
@ -68,7 +68,7 @@ Changelog
0.15.0
------
`Published 2016-07-19 <https://pypi.python.org/pypi/autobahn/0.15.0`__
`Published 2016-07-19 <https://pypi.python.org/pypi/autobahn/0.15.0>`__
* new: WAMP AP option: register with maximum concurrency
* new: automatic reconnect for WAMP clients ApplicationRunner on Twisted

View File

@ -67,6 +67,10 @@ def _warn_node(self, msg, node, **kwargs):
sphinx.environment.BuildEnvironment.warn_node = _warn_node
try:
from qualname import qualname
except ImportError:
qualname = None
# http://stackoverflow.com/a/21449475/884770
# http://www.sphinx-doc.org/en/stable/ext/autodoc.html#event-autodoc-skip-member
@ -77,11 +81,13 @@ sphinx.environment.BuildEnvironment.warn_node = _warn_node
def autodoc_skip_member(app, what, name, obj, skip, options):
# skip everything that isn't decorated with @autobahn.public or ..
if hasattr(obj, '_is_public') and obj._is_public:
if qualname:
print('public API: {}.{}'.format(obj.__module__, qualname(obj)))
return False
else:
return True
def setup2(app):
def setup(app):
# wire up our custom checker to skip member
app.connect('autodoc-skip-member', autodoc_skip_member)

View File

@ -12,10 +12,9 @@ Site Contents
index
installation
asynchronous-programming
websocket/programming
websocket/programming
wamp/programming
websocket/examples
wamp/examples
reference/autobahn
contribute
changelog

View File

@ -1,29 +0,0 @@
Contribute
==========
|ab| is an open source project, and hosted on GitHub. The `GitHub repository <https://github.com/crossbario/autobahn-python>`_ includes the documentation.
We're looking for all kinds of contributions - from simple fixes of typos in the code or documentation to implementation of new features and additions of tutorials.
If you want to contribute to the code or the documentation:
Fork us on GitHub
-----------------
We use the Fork & Pull Model.
This means that you fork the repo, make changes to your fork, and then make a pull request here on the main repo.
This `article on GitHub <https://help.github.com/articles/using-pull-requests>`_ gives more detailed information on how the process works.
Running the Tests
-----------------
In order to run the unit-tests, we use `Tox <http://tox.readthedocs.org/en/latest/>`_ to build the various test-environments. To run them all, simply run ``tox`` from the top-level directory of the clone.
For test-coverage, see the Makefile target ``test_coverage``, which deletes the coverage data and then runs the test suite with various tox test-environments before outputting HTML annotated coverage to ``./htmlcov/index.html`` and a coverage report to the terminal.
There are two environment variables the tests use: ``USE_TWISTED=1`` or ``USE_ASYNCIO=1`` control whether to run unit-tests that are specific to one framework or the other.
See ``tox.ini`` for details on how to run in the different environments

View File

@ -1,7 +1,7 @@
|AbL|
=====
| |Version| |Downloads| |Build Status| |Coverage| |Docs|
| |Version| |Build Status| |Coverage| |Docs|
--------------
@ -14,24 +14,6 @@
in Python 2 and 3, running on `Twisted`_ **or** `asyncio`_.
Documentation Overview
----------------------
See :ref:`site_contents` for a full site-map. Top-level pages available:
.. toctree::
:maxdepth: 1
installation
asynchronous-programming
wamp/programming
wamp/examples
websocket/programming
websocket/examples
reference/autobahn
contribute
changelog
-----
Autobahn Features
@ -193,8 +175,8 @@ For **WAMP developers**, :doc:`wamp/programming` gives an introduction for progr
:doc:`wamp/examples` lists WAMP code examples covering all features of WAMP.
Community
---------
Get in touch
------------
Development of |ab| takes place on the GitHub `source repository <https://github.com/crossbario/autobahn-python>`_.
@ -217,26 +199,38 @@ You can also reach users and developers on **IRC** channel ``#autobahn`` at `fre
Finally, we are on `Twitter <https://twitter.com/autobahnws>`_.
.. toctree::
:hidden:
Contributing
------------
|ab| is an open source project, and hosted on GitHub. The `GitHub repository <https://github.com/crossbario/autobahn-python>`_ includes the documentation.
We're looking for all kinds of contributions - from simple fixes of typos in the code or documentation to implementation of new features and additions of tutorials.
If you want to contribute to the code or the documentation: we use the Fork & Pull Model.
This means that you fork the repo, make changes to your fork, and then make a pull request here on the main repo.
This `article on GitHub <https://help.github.com/articles/using-pull-requests>`_ gives more detailed information on how the process works.
In order to run the unit-tests, we use `Tox <http://tox.readthedocs.org/en/latest/>`_ to build the various test-environments. To run them all, simply run ``tox`` from the top-level directory of the clone.
For test-coverage, see the Makefile target ``test_coverage``, which deletes the coverage data and then runs the test suite with various tox test-environments before outputting HTML annotated coverage to ``./htmlcov/index.html`` and a coverage report to the terminal.
There are two environment variables the tests use: ``USE_TWISTED=1`` or ``USE_ASYNCIO=1`` control whether to run unit-tests that are specific to one framework or the other.
See ``tox.ini`` for details on how to run in the different environments.
Sitemap
-------
Please see :ref:`site_contents` for a full site-map.
installation
asynchronous-programming
websocket/programming
wamp/programming
websocket/examples
wamp/examples
reference/autobahn
contribute
changelog
.. |Version| image:: https://img.shields.io/pypi/v/autobahn.svg
:target: https://pypi.python.org/pypi/autobahn
.. |Downloads| image:: https://img.shields.io/pypi/dm/autobahn.svg
:target: https://pypi.python.org/pypi/autobahn
.. |GitHub Stars| image:: https://img.shields.io/github/stars/crossbario/autobahn-python.svg?style=social&label=Star
:target: https://github.com/crossbario/autobahn-python

View File

@ -69,6 +69,20 @@ These are plain value-holding classes used in the public WAMP API of Autobahn.
:members:
:undoc-members:
autobahn.wamp.cryptobox
-----------------------
.. automodule:: autobahn.wamp.cryptobox
:members:
:undoc-members:
autobahn.wamp.cryptosign
------------------------
.. automodule:: autobahn.wamp.cryptosign
:members:
:undoc-members:
autobahn.wamp.uri
-----------------

View File

@ -132,6 +132,7 @@ extras_require_dev = [
'sphinx_rtd_theme>=0.1.9', # BSD
'pytest_asyncio', # Apache 2.0
'awscli', # Apache 2.0
'qualname', # BSD
]
# for testing by users with "python setup.py test" (not Tox, which we use)