factor error classes into a common file
This commit is contained in:
		
							parent
							
								
									8f1ce1f835
								
							
						
					
					
						commit
						46f1fd2cd0
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
from __future__ import print_function
 | 
					from __future__ import print_function
 | 
				
			||||||
import os, sys, time, re, requests, json, textwrap
 | 
					import os, sys, time, re, requests, json
 | 
				
			||||||
from binascii import hexlify, unhexlify
 | 
					from binascii import hexlify, unhexlify
 | 
				
			||||||
from spake2 import SPAKE2_Symmetric
 | 
					from spake2 import SPAKE2_Symmetric
 | 
				
			||||||
from nacl.secret import SecretBox
 | 
					from nacl.secret import SecretBox
 | 
				
			||||||
| 
						 | 
					@ -8,32 +8,13 @@ from nacl import utils
 | 
				
			||||||
from .eventsource import EventSourceFollower
 | 
					from .eventsource import EventSourceFollower
 | 
				
			||||||
from .. import __version__
 | 
					from .. import __version__
 | 
				
			||||||
from .. import codes
 | 
					from .. import codes
 | 
				
			||||||
from ..errors import ServerError
 | 
					from ..errors import (ServerError, Timeout, WrongPasswordError,
 | 
				
			||||||
 | 
					                      ReflectionAttack, UsageError)
 | 
				
			||||||
from ..util.hkdf import HKDF
 | 
					from ..util.hkdf import HKDF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SECOND = 1
 | 
					SECOND = 1
 | 
				
			||||||
MINUTE = 60*SECOND
 | 
					MINUTE = 60*SECOND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Timeout(Exception):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class WrongPasswordError(Exception):
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    Key confirmation failed. Either you or your correspondent typed the code
 | 
					 | 
				
			||||||
    wrong, or a would-be man-in-the-middle attacker guessed incorrectly. You
 | 
					 | 
				
			||||||
    could try again, giving both your correspondent and the attacker another
 | 
					 | 
				
			||||||
    chance.
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    # or the data blob was corrupted, and that's why decrypt failed
 | 
					 | 
				
			||||||
    def explain(self):
 | 
					 | 
				
			||||||
        return textwrap.dedent(self.__doc__)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ReflectionAttack(Exception):
 | 
					 | 
				
			||||||
    """An attacker (or bug) reflected our outgoing message back to us."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class UsageError(Exception):
 | 
					 | 
				
			||||||
    """The programmer did something wrong."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# relay URLs are:
 | 
					# relay URLs are:
 | 
				
			||||||
# GET /list                                         -> {channel-ids: [INT..]}
 | 
					# GET /list                                         -> {channel-ids: [INT..]}
 | 
				
			||||||
# POST /allocate/SIDE                               -> {channel-id: INT}
 | 
					# POST /allocate/SIDE                               -> {channel-id: INT}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
import functools
 | 
					import functools, textwrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ServerError(Exception):
 | 
					class ServerError(Exception):
 | 
				
			||||||
    def __init__(self, message, relay):
 | 
					    def __init__(self, message, relay):
 | 
				
			||||||
| 
						 | 
					@ -16,3 +16,23 @@ def handle_server_error(func):
 | 
				
			||||||
            print("Server error (from %s):\n%s" % (e.relay, e.message))
 | 
					            print("Server error (from %s):\n%s" % (e.relay, e.message))
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
    return _wrap
 | 
					    return _wrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Timeout(Exception):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class WrongPasswordError(Exception):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Key confirmation failed. Either you or your correspondent typed the code
 | 
				
			||||||
 | 
					    wrong, or a would-be man-in-the-middle attacker guessed incorrectly. You
 | 
				
			||||||
 | 
					    could try again, giving both your correspondent and the attacker another
 | 
				
			||||||
 | 
					    chance.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    # or the data blob was corrupted, and that's why decrypt failed
 | 
				
			||||||
 | 
					    def explain(self):
 | 
				
			||||||
 | 
					        return textwrap.dedent(self.__doc__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ReflectionAttack(Exception):
 | 
				
			||||||
 | 
					    """An attacker (or bug) reflected our outgoing message back to us."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UsageError(Exception):
 | 
				
			||||||
 | 
					    """The programmer did something wrong."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,20 +13,10 @@ from spake2 import SPAKE2_Symmetric
 | 
				
			||||||
from .eventsource_twisted import ReconnectingEventSource
 | 
					from .eventsource_twisted import ReconnectingEventSource
 | 
				
			||||||
from .. import __version__
 | 
					from .. import __version__
 | 
				
			||||||
from .. import codes
 | 
					from .. import codes
 | 
				
			||||||
from ..errors import ServerError
 | 
					from ..errors import (ServerError, WrongPasswordError,
 | 
				
			||||||
 | 
					                      ReflectionAttack, UsageError)
 | 
				
			||||||
from ..util.hkdf import HKDF
 | 
					from ..util.hkdf import HKDF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WrongPasswordError(Exception):
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    Key confirmation failed.
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ReflectionAttack(Exception):
 | 
					 | 
				
			||||||
    """An attacker (or bug) reflected our outgoing message back to us."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class UsageError(Exception):
 | 
					 | 
				
			||||||
    """The programmer did something wrong."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@implementer(IBodyProducer)
 | 
					@implementer(IBodyProducer)
 | 
				
			||||||
class DataProducer:
 | 
					class DataProducer:
 | 
				
			||||||
    def __init__(self, data):
 | 
					    def __init__(self, data):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user