Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/cl…
Browse files Browse the repository at this point in the history
…ient_apis_move
  • Loading branch information
erikjohnston committed Jul 23, 2018
2 parents 4fc52b1 + 354a99c commit 0b0b24c
Show file tree
Hide file tree
Showing 81 changed files with 3,718 additions and 3,298 deletions.
2,470 changes: 2,470 additions & 0 deletions CHANGES.md

Large diffs are not rendered by default.

2,839 changes: 0 additions & 2,839 deletions CHANGES.rst

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include synctl
include LICENSE
include VERSION
include *.rst
include *.md
include demo/README
include demo/demo.tls.dh
include demo/*.py
Expand Down
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ We'd like to invite you to join #matrix:matrix.org (via
https://matrix.org/docs/projects/try-matrix-now.html), run a homeserver, take a look
at the `Matrix spec <https://matrix.org/docs/spec>`_, and experiment with the
`APIs <https://matrix.org/docs/api>`_ and `Client SDKs
<http://matrix.org/docs/projects/try-matrix-now.html#client-sdks>`_.
<https://matrix.org/docs/projects/try-matrix-now.html#client-sdks>`_.

Thanks for using Matrix!

Expand Down Expand Up @@ -283,7 +283,7 @@ Connecting to Synapse from a client

The easiest way to try out your new Synapse installation is by connecting to it
from a web client. The easiest option is probably the one at
http://riot.im/app. You will need to specify a "Custom server" when you log on
https://riot.im/app. You will need to specify a "Custom server" when you log on
or register: set this to ``https://domain.tld`` if you setup a reverse proxy
following the recommended setup, or ``https://localhost:8448`` - remember to specify the
port (``:8448``) if not ``:443`` unless you changed the configuration. (Leave the identity
Expand Down Expand Up @@ -329,7 +329,7 @@ Security Note
=============

Matrix serves raw user generated data in some APIs - specifically the `content
repository endpoints <http://matrix.org/docs/spec/client_server/latest.html#get-matrix-media-r0-download-servername-mediaid>`_.
repository endpoints <https://matrix.org/docs/spec/client_server/latest.html#get-matrix-media-r0-download-servername-mediaid>`_.

Whilst we have tried to mitigate against possible XSS attacks (e.g.
https://github.com/matrix-org/synapse/pull/1021) we recommend running
Expand All @@ -348,7 +348,7 @@ Platform-Specific Instructions
Debian
------

Matrix provides official Debian packages via apt from http://matrix.org/packages/debian/.
Matrix provides official Debian packages via apt from https://matrix.org/packages/debian/.
Note that these packages do not include a client - choose one from
https://matrix.org/docs/projects/try-matrix-now.html (or build your own with one of our SDKs :)

Expand Down Expand Up @@ -524,7 +524,7 @@ Troubleshooting Running
-----------------------

If synapse fails with ``missing "sodium.h"`` crypto errors, you may need
to manually upgrade PyNaCL, as synapse uses NaCl (http://nacl.cr.yp.to/) for
to manually upgrade PyNaCL, as synapse uses NaCl (https://nacl.cr.yp.to/) for
encryption and digital signatures.
Unfortunately PyNACL currently has a few issues
(https://github.com/pyca/pynacl/issues/53) and
Expand Down Expand Up @@ -672,8 +672,8 @@ useful just for development purposes. See `<demo/README>`_.
Using PostgreSQL
================

As of Synapse 0.9, `PostgreSQL <http://www.postgresql.org>`_ is supported as an
alternative to the `SQLite <http://sqlite.org/>`_ database that Synapse has
As of Synapse 0.9, `PostgreSQL <https://www.postgresql.org>`_ is supported as an
alternative to the `SQLite <https://sqlite.org/>`_ database that Synapse has
traditionally used for convenience and simplicity.

The advantages of Postgres include:
Expand All @@ -697,7 +697,7 @@ Using a reverse proxy with Synapse
It is recommended to put a reverse proxy such as
`nginx <https://nginx.org/en/docs/http/ngx_http_proxy_module.html>`_,
`Apache <https://httpd.apache.org/docs/current/mod/mod_proxy_http.html>`_ or
`HAProxy <http://www.haproxy.org/>`_ in front of Synapse. One advantage of
`HAProxy <https://www.haproxy.org/>`_ in front of Synapse. One advantage of
doing so is that it means that you can expose the default https port (443) to
Matrix clients without needing to run Synapse with root privileges.

Expand Down
1 change: 0 additions & 1 deletion changelog.d/3316.feature

This file was deleted.

File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion changelog.d/3496.feature

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3497.feature

This file was deleted.

Empty file removed changelog.d/3498.misc
Empty file.
Empty file removed changelog.d/3499.misc
Empty file.
Empty file removed changelog.d/3501.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3505.feature

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/3520.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly announce deleted devices over federation
1 change: 0 additions & 1 deletion changelog.d/3521.feature

This file was deleted.

Empty file removed changelog.d/3530.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3533.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3534.misc

This file was deleted.

Empty file removed changelog.d/3535.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3540.misc

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3541.feature

This file was deleted.

Empty file removed changelog.d/3544.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3546.bugfix

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/3548.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch failures saving metrics captured by Measure, and instead log the faulty metrics information for further analysis.
1 change: 1 addition & 0 deletions changelog.d/3552.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Release notes are now in the Markdown format.
1 change: 1 addition & 0 deletions changelog.d/3553.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics to track resource usage by background processes
1 change: 1 addition & 0 deletions changelog.d/3554.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `code` label to `synapse_http_server_response_time_seconds` prometheus metric
1 change: 1 addition & 0 deletions changelog.d/3556.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics to track resource usage by background processes
1 change: 1 addition & 0 deletions changelog.d/3559.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add config for pep8
File renamed without changes.
1 change: 1 addition & 0 deletions changelog.d/3570.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix potential stack overflow and deadlock under heavy load
1 change: 1 addition & 0 deletions changelog.d/3571.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge Linearizer and Limiter
1 change: 1 addition & 0 deletions changelog.d/3572.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge Linearizer and Limiter
63 changes: 63 additions & 0 deletions docs/admin_api/register_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Shared-Secret Registration
==========================

This API allows for the creation of users in an administrative and
non-interactive way. This is generally used for bootstrapping a Synapse
instance with administrator accounts.

To authenticate yourself to the server, you will need both the shared secret
(``registration_shared_secret`` in the homeserver configuration), and a
one-time nonce. If the registration shared secret is not configured, this API
is not enabled.

To fetch the nonce, you need to request one from the API::

> GET /_matrix/client/r0/admin/register

< {"nonce": "thisisanonce"}

Once you have the nonce, you can make a ``POST`` to the same URL with a JSON
body containing the nonce, username, password, whether they are an admin
(optional, False by default), and a HMAC digest of the content.

As an example::

> POST /_matrix/client/r0/admin/register
> {
"nonce": "thisisanonce",
"username": "pepper_roni",
"password": "pizza",
"admin": true,
"mac": "mac_digest_here"
}

< {
"access_token": "token_here",
"user_id": "@pepper_roni@test",
"home_server": "test",
"device_id": "device_id_here"
}

The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
the shared secret and the content being the nonce, user, password, and either
the string "admin" or "notadmin", each separated by NULs. For an example of
generation in Python::

import hmac, hashlib

def generate_mac(nonce, user, password, admin=False):

mac = hmac.new(
key=shared_secret,
digestmod=hashlib.sha1,
)

mac.update(nonce.encode('utf8'))
mac.update(b"\x00")
mac.update(user.encode('utf8'))
mac.update(b"\x00")
mac.update(password.encode('utf8'))
mac.update(b"\x00")
mac.update(b"admin" if admin else b"notadmin")

return mac.hexdigest()
29 changes: 27 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
[tool.towncrier]
package = "synapse"
filename = "CHANGES.rst"
filename = "CHANGES.md"
directory = "changelog.d"
issue_format = "`#{issue} <https://github.com/matrix-org/synapse/issues/{issue}>`_"
issue_format = "[\\#{issue}](https://github.com/matrix-org/synapse/issues/{issue}>)"

[[tool.towncrier.type]]
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bugfixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "removal"
name = "Deprecations and Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "misc"
name = "Internal Changes"
showcontent = true
32 changes: 29 additions & 3 deletions scripts/register_new_matrix_user
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,37 @@ import yaml


def request_registration(user, password, server_location, shared_secret, admin=False):
req = urllib2.Request(
"%s/_matrix/client/r0/admin/register" % (server_location,),
headers={'Content-Type': 'application/json'}
)

try:
if sys.version_info[:3] >= (2, 7, 9):
# As of version 2.7.9, urllib2 now checks SSL certs
import ssl
f = urllib2.urlopen(req, context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))
else:
f = urllib2.urlopen(req)
body = f.read()
f.close()
nonce = json.loads(body)["nonce"]
except urllib2.HTTPError as e:
print "ERROR! Received %d %s" % (e.code, e.reason,)
if 400 <= e.code < 500:
if e.info().type == "application/json":
resp = json.load(e)
if "error" in resp:
print resp["error"]
sys.exit(1)

mac = hmac.new(
key=shared_secret,
digestmod=hashlib.sha1,
)

mac.update(nonce)
mac.update("\x00")
mac.update(user)
mac.update("\x00")
mac.update(password)
Expand All @@ -40,10 +66,10 @@ def request_registration(user, password, server_location, shared_secret, admin=F
mac = mac.hexdigest()

data = {
"user": user,
"nonce": nonce,
"username": user,
"password": password,
"mac": mac,
"type": "org.matrix.login.shared_secret",
"admin": admin,
}

Expand All @@ -52,7 +78,7 @@ def request_registration(user, password, server_location, shared_secret, admin=F
print "Sending registration request..."

req = urllib2.Request(
"%s/_matrix/client/api/v1/register" % (server_location,),
"%s/_matrix/client/r0/admin/register" % (server_location,),
data=json.dumps(data),
headers={'Content-Type': 'application/json'}
)
Expand Down
12 changes: 9 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ ignore =
pylint.cfg
tox.ini

[flake8]
[pep8]
max-line-length = 90
# W503 requires that binary operators be at the end, not start, of lines. Erik doesn't like it.
# E203 is contrary to PEP8.
# W503 requires that binary operators be at the end, not start, of lines. Erik
# doesn't like it. E203 is contrary to PEP8.
ignore = W503,E203

[flake8]
# note that flake8 inherits the "ignore" settings from "pep8" (because it uses
# pep8 to do those checks), but not the "max-line-length" setting
max-line-length = 90

[isort]
line_length = 89
not_skip = __init__.py
Expand All @@ -31,3 +36,4 @@ known_compat = mock,six
known_twisted=twisted,OpenSSL
multi_line_output=3
include_trailing_comma=true
combine_as_imports=true
2 changes: 1 addition & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
""" This is a reference implementation of a Matrix home server.
"""

__version__ = "0.32.2"
__version__ = "0.33.0"
6 changes: 4 additions & 2 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import os
import sys

from six import iteritems

from twisted.application import service
from twisted.internet import defer, reactor
from twisted.web.resource import EncodingResourceWrapper, NoResource
Expand Down Expand Up @@ -442,7 +444,7 @@ def phone_stats_home():
stats["total_nonbridged_users"] = total_nonbridged_users

daily_user_type_results = yield hs.get_datastore().count_daily_user_type()
for name, count in daily_user_type_results.iteritems():
for name, count in iteritems(daily_user_type_results):
stats["daily_user_type_" + name] = count

room_count = yield hs.get_datastore().get_room_count()
Expand All @@ -453,7 +455,7 @@ def phone_stats_home():
stats["daily_messages"] = yield hs.get_datastore().count_daily_messages()

r30_results = yield hs.get_datastore().count_r30_users()
for name, count in r30_results.iteritems():
for name, count in iteritems(r30_results):
stats["r30_users_" + name] = count

daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages()
Expand Down
4 changes: 3 additions & 1 deletion synapse/app/synctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import sys
import time

from six import iteritems

import yaml

SYNAPSE = [sys.executable, "-B", "-m", "synapse.app.homeserver"]
Expand Down Expand Up @@ -173,7 +175,7 @@ def main():
os.environ["SYNAPSE_CACHE_FACTOR"] = str(cache_factor)

cache_factors = config.get("synctl_cache_factors", {})
for cache_name, factor in cache_factors.iteritems():
for cache_name, factor in iteritems(cache_factors):
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)

worker_configfiles = []
Expand Down
4 changes: 3 additions & 1 deletion synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from six import iteritems

from frozendict import frozendict

from twisted.internet import defer
Expand Down Expand Up @@ -159,7 +161,7 @@ def _encode_state_dict(state_dict):

return [
(etype, state_key, v)
for (etype, state_key), v in state_dict.iteritems()
for (etype, state_key), v in iteritems(state_dict)
]


Expand Down
Loading

0 comments on commit 0b0b24c

Please sign in to comment.