mirror of https://github.com/jesopo/ircrobots
Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
jesopo | 7c9a144124 | |
jesopo | e3c91a50e1 | |
jesopo | f2ba48a582 | |
jesopo | cf2e69a9e2 | |
jesopo | a1a459c13e | |
jesopo | 81fa77cf29 | |
jesopo | 422a9a93c1 | |
jesopo | b04a0e0136 | |
jesopo | 7bb4c3d069 | |
jesopo | 9a2f2156fe | |
alicetries | 0435404ec3 | |
jesopo | 63025af311 | |
jesopo | 20c4f8f98c |
|
@ -3,3 +3,4 @@ from .server import Server
|
|||
from .params import (ConnectionParams, SASLUserPass, SASLExternal, SASLSCRAM,
|
||||
STSPolicy, ResumePolicy)
|
||||
from .ircv3 import Capability
|
||||
from .security import TLS
|
||||
|
|
|
@ -8,7 +8,7 @@ from .contexts import ServerContext
|
|||
from .matching import Response, ANY
|
||||
from .interface import ICapability
|
||||
from .params import ConnectionParams, STSPolicy, ResumePolicy
|
||||
from .security import TLS_VERIFYCHAIN
|
||||
from .security import TLSVerifyChain
|
||||
|
||||
class Capability(ICapability):
|
||||
def __init__(self,
|
||||
|
@ -107,7 +107,7 @@ async def sts_transmute(params: ConnectionParams):
|
|||
since = (now-params.sts.created)
|
||||
if since <= params.sts.duration:
|
||||
params.port = params.sts.port
|
||||
params.tls = TLS_VERIFYCHAIN
|
||||
params.tls = TLSVerifyChain()
|
||||
async def resume_transmute(params: ConnectionParams):
|
||||
if params.resume is not None:
|
||||
params.host = params.resume.address
|
||||
|
@ -183,7 +183,7 @@ class CAPContext(ServerContext):
|
|||
if not params.tls:
|
||||
if "port" in sts_dict:
|
||||
params.port = int(sts_dict["port"])
|
||||
params.tls = TLS_VERIFYCHAIN
|
||||
params.tls = TLSVerifyChain()
|
||||
|
||||
await self.server.bot.disconnect(self.server)
|
||||
await self.server.bot.add_server(self.server.name, params)
|
||||
|
|
|
@ -73,8 +73,7 @@ class Formatless(IMatchResponseParam):
|
|||
def __init__(self, value: TYPE_MAYBELIT_VALUE):
|
||||
self._value = _assure_lit(value)
|
||||
def __repr__(self) -> str:
|
||||
brepr = super().__repr__()
|
||||
return f"Formatless({brepr})"
|
||||
return f"Formatless({self._value!r})"
|
||||
def match(self, server: IServer, arg: str) -> bool:
|
||||
strip = formatting.strip(arg)
|
||||
return self._value.match(server, strip)
|
||||
|
|
|
@ -2,7 +2,7 @@ from re import compile as re_compile
|
|||
from typing import List, Optional
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from .security import TLS, TLS_NOVERIFY, TLS_VERIFYCHAIN
|
||||
from .security import TLS, TLSNoVerify, TLSVerifyChain
|
||||
|
||||
class SASLParams(object):
|
||||
mechanism: str
|
||||
|
@ -34,15 +34,15 @@ class ResumePolicy(object):
|
|||
RE_IPV6HOST = re_compile("\[([a-fA-F0-9:]+)\]")
|
||||
|
||||
_TLS_TYPES = {
|
||||
"+": TLS_VERIFYCHAIN,
|
||||
"~": TLS_NOVERIFY
|
||||
"+": TLSVerifyChain,
|
||||
"~": TLSNoVerify,
|
||||
}
|
||||
@dataclass
|
||||
class ConnectionParams(object):
|
||||
nickname: str
|
||||
host: str
|
||||
port: int
|
||||
tls: Optional[TLS] = TLS_VERIFYCHAIN
|
||||
tls: Optional[TLS] = field(default_factory=TLSVerifyChain)
|
||||
|
||||
username: Optional[str] = None
|
||||
realname: Optional[str] = None
|
||||
|
@ -76,7 +76,7 @@ class ConnectionParams(object):
|
|||
if not port_s:
|
||||
port_s = "6667"
|
||||
else:
|
||||
tls_type = _TLS_TYPES.get(port_s[0], None)
|
||||
tls_type = _TLS_TYPES.get(port_s[0], lambda: None)()
|
||||
if tls_type is not None:
|
||||
port_s = port_s[1:] or "6697"
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
import ssl
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Tuple
|
||||
|
||||
@dataclass
|
||||
class TLS:
|
||||
pass
|
||||
client_keypair: Optional[Tuple[str, str]] = None
|
||||
|
||||
# tls without verification
|
||||
class TLSNoVerify(TLS):
|
||||
pass
|
||||
TLS_NOVERIFY = TLSNoVerify()
|
||||
|
||||
# verify via CAs
|
||||
class TLSVerifyChain(TLS):
|
||||
pass
|
||||
TLS_VERIFYCHAIN = TLSVerifyChain()
|
||||
|
||||
# verify by a pinned hash
|
||||
class TLSVerifyHash(TLSNoVerify):
|
||||
|
|
|
@ -287,9 +287,10 @@ class Server(IServer):
|
|||
|
||||
if not self._process_queue:
|
||||
async with self._read_lwork:
|
||||
read_aw = self._read_line(PING_TIMEOUT)
|
||||
read_aw = asyncio.create_task(self._read_line(PING_TIMEOUT))
|
||||
wait_aw = asyncio.create_task(self._wait_for.wait())
|
||||
dones, notdones = await asyncio.wait(
|
||||
[read_aw, self._wait_for.wait()],
|
||||
[read_aw, wait_aw],
|
||||
return_when=asyncio.FIRST_COMPLETED
|
||||
)
|
||||
self._wait_for.clear()
|
||||
|
|
|
@ -43,6 +43,9 @@ class TCPTransport(ITCPTransport):
|
|||
cur_ssl: Optional[SSLContext] = None
|
||||
if tls is not None:
|
||||
cur_ssl = tls_context(not isinstance(tls, TLSNoVerify))
|
||||
if tls.client_keypair is not None:
|
||||
(client_cert, client_key) = tls.client_keypair
|
||||
cur_ssl.load_cert_chain(client_cert, keyfile=client_key)
|
||||
|
||||
local_addr: Optional[Tuple[str, int]] = None
|
||||
if not bindhost is None:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
anyio ~=2.0.2
|
||||
asyncio-rlock ~=0.1.0
|
||||
asyncio-throttle ~=1.0.1
|
||||
ircstates ~=0.12.0
|
||||
ircstates ~=0.12.1
|
||||
async_stagger ~=0.3.0
|
||||
async_timeout ~=3.0.1
|
||||
async_timeout ~=4.0.2
|
||||
|
|
Loading…
Reference in New Issue