Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/downloader/httpDigestAuthorization.h

Go to the documentation of this file.
00001 // Filename: httpDigestAuthorization.h
00002 // Created by:  drose (25Oct02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef HTTPDIGESTAUTHORIZATION_H
00020 #define HTTPDIGESTAUTHORIZATION_H
00021 
00022 #include "pandabase.h"
00023 
00024 // This module requires OpenSSL to compile, even though it doesn't
00025 // actually use any OpenSSL code, because it is a support module for
00026 // HTTPChannel, which *does* use OpenSSL code.
00027 
00028 #ifdef HAVE_SSL
00029 
00030 #include "httpAuthorization.h"
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : HTTPDigestAuthorization
00034 // Description : Implements the "Digest" type of HTTP authorization.
00035 //               This is designed to be an improvement over "Basic"
00036 //               authorization, in that it does not send passwords
00037 //               over the net in cleartext, and it is harder to spoof.
00038 ////////////////////////////////////////////////////////////////////
00039 class HTTPDigestAuthorization : public HTTPAuthorization {
00040 public:
00041   HTTPDigestAuthorization(const Tokens &tokens, const URLSpec &url,
00042                           bool is_proxy);
00043   virtual ~HTTPDigestAuthorization();
00044 
00045   virtual const string &get_mechanism() const;
00046   virtual bool is_valid();
00047 
00048   virtual string generate(HTTPEnum::Method method, const string &request_path,
00049                           const string &username, const string &body);
00050 
00051 public:
00052   enum Algorithm {
00053     A_unknown,
00054     A_md5,
00055     A_md5_sess,
00056   };
00057   enum Qop {
00058     // These are used as a bitfield.
00059     Q_unused   = 0x000,
00060     Q_auth     = 0x001,
00061     Q_auth_int = 0x002,
00062   };
00063 
00064 private:
00065   static int match_qop_token(const string &token);
00066 
00067   string calc_request_digest(const string &username, const string &password,
00068                              HTTPEnum::Method method, 
00069                              const string &request_path, const string &body);
00070   string calc_h(const string &data) const;
00071   string calc_kd(const string &secret, const string &data) const;
00072   string get_a1(const string &username, const string &password);
00073   string get_a2(HTTPEnum::Method method, const string &request_path, 
00074                 const string &body);
00075   string get_hex_nonce_count() const;
00076 
00077   static string calc_md5(const string &source);
00078   INLINE static char hexdigit(int value);
00079 
00080   string _cnonce;
00081   string _nonce;
00082   int _nonce_count;
00083   string _opaque;
00084 
00085   Algorithm _algorithm;
00086   string _a1;
00087 
00088   int _qop;
00089   Qop _chosen_qop;
00090 
00091   static const string _mechanism;
00092 };
00093 
00094 ostream &operator << (ostream &out, HTTPDigestAuthorization::Algorithm algorithm);
00095 ostream &operator << (ostream &out, HTTPDigestAuthorization::Qop qop);
00096 
00097 #include "httpDigestAuthorization.I"
00098 
00099 #endif  // HAVE_SSL
00100 
00101 #endif
00102 

Generated on Fri May 2 00:36:50 2003 for Panda by doxygen1.3