def register_request_verify(reg_req): """ Verify that a user (SyndicateUser) sent a registration request (ms_pb2.ms_register_request) Return the user on success; None if the user doesn't exist; False if the signature doesn't match. """ username = reg_req.username sig_b64 = reg_req.signature reg_req.signature = "" reg_req_str = reg_req.SerializeToString() sig = base64.b64decode(sig_b64) user = SyndicateUser.Authenticate(username, reg_req_str, sig) return user
def pubkey_verifier(cls, method, args, kw, request_body, syndicate_data, data, **verifier_kw): """ Verify a request from a user, using public-key signature verification. """ if not isinstance(method, AuthMethod): log.error("Invalid method '%s'" % method) return False username = syndicate_data.get("username") sig = syndicate_data.get("signature") authenticated_user = SyndicateUser.Authenticate( username, request_body, sig) if not authenticated_user: # failed to authenticate via keys. log.error("Failed to authenticate user %s" % (username)) return False method.authenticated_user = authenticated_user return True