public Client(TcpClient c, Server s, Config.AuthConfig a) { client = c; server = s; authconfig = a; stream = client.GetStream(); stream.BeginRead(read_buffer, 0, 1024, new AsyncCallback(callbackRead), this); }
public Server(IPAddress ip, Int32 port, Config.AuthConfig a) { Console.WriteLine("Server: Starting on {0}:{1}.", ip.ToString(), port); authconfig = a; listener = new TcpListener(port); listener.Start(); thread = new Thread(new ThreadStart(Loop)); thread.Start(); }
public static Response Get401Response(Config.AuthConfig authconfig) { Response res = new Response(); res.Status = Status.NotAuthorized; res.Mime = "text/html"; res.Body = @"<html> <head> <title>401 Not authorized.</title> </head> <body> 401: You are not authorized to view this resource. </body> </html>"; res.AddHeader("WWW-Authenticate", authconfig.Type.ToString() + " realm=\"" + authconfig.Realm + "\""); return(res); }
public bool VerifyAuth(Config.AuthConfig auth) { if (auth.Type == Config.AuthType.Basic) { string[] pair; if (Headers.ContainsKey("Authorization")) { pair = Headers["Authorization"].Split(' '); if (pair.Length == 2) { string temp = Util.DecodeBase64(pair[1]); if (pair[0] == "Basic" && Util.DecodeBase64(pair[1]) == auth.Username + ":" + auth.Password) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else if (auth.Type == Config.AuthType.Digest) { //TODO: Handle digest authenticaion return(false); } else { return(true); } }