def authenticate(self, ident, secret, akrow): if not akrow: CONNECTION_ERROR.labels(ident, 'invalid-ident').inc() self.error(f"Authentication failed for {ident}") self.transport.close() return akhash = hashsecret(self.authrand, akrow["secret"]) if not akhash == secret: CONNECTION_ERROR.labels(ident, 'invalid-secret').inc() self.error(f"Authentication failed for {ident}") self.transport.close() return self.ak = ident self.uid = akrow["owner"] self.pubchans = akrow.get("pubchans", []) self.subchans = akrow.get("subchans", []) if hasattr(self.transport, '_sock'): self.transport._sock = MeteredSocket(self.transport._sock, self.ak) elif hasattr(self.transport, '_ssl_protocol'): self.transport._ssl_protocol._sslpipe._sslobj = MeteredSSLObject(self.transport._ssl_protocol._sslpipe._sslobj, self.ak) high = SIZES[OP_PUBLISH] * 50 self.transport.set_write_buffer_limits(high=high) CONNECTION_READY.labels(ident).inc() self.process_pending() self.transport.resume_reading()
def authkey_check(self, ident, rhash): akrow = self.srv.get_authkey(ident) if not akrow: self.error("Authentication failed.", ident=ident) raise BadClient() akhash = hashsecret(self.authrand, akrow["secret"]) if not akhash == rhash: self.error("Authentication failed.", ident=ident) raise BadClient() self.ak = ident self.uid = akrow["owner"] self.pubchans = akrow.get("pubchans", []) self.subchans = akrow.get("subchans", [])
def on_auth(self, ident, secret): akrow = self.server.get_authkey(ident) if not akrow: CONNECTION_ERROR.labels(ident, 'invalid-ident').inc() log.debug( 'Authentication failed for {} due to missing ident'.format( ident)) self.error(f"Authentication failed for {ident}") self.transport.close() return akhash = hashsecret(self.authrand, akrow["secret"]) if not akhash == secret: CONNECTION_ERROR.labels(ident, 'invalid-secret').inc() log.debug( 'Authentication failed for {} due to incorrect secret'.format( ident)) self.error(f"Authentication failed for {ident}") self.transport.close() return self.ak = ident self.uid = akrow["owner"] self.pubchans = akrow.get("pubchans", []) self.subchans = akrow.get("subchans", []) if hasattr(self.transport, '_sock'): self.transport._sock = MeteredSocket(self.transport._sock, self.ak) elif hasattr(self.transport, '_ssl_protocol'): self.transport._ssl_protocol._sslpipe._sslobj = MeteredSSLObject( self.transport._ssl_protocol._sslpipe._sslobj, self.ak) high = SIZES[OP_PUBLISH] * 50 self.transport.set_write_buffer_limits(high=high) CONNECTION_READY.labels(ident).inc()