Panda3D
 All Classes Functions Variables Enumerations
httpDigestAuthorization.h
1 // Filename: httpDigestAuthorization.h
2 // Created by: drose (25Oct02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef HTTPDIGESTAUTHORIZATION_H
16 #define HTTPDIGESTAUTHORIZATION_H
17 
18 #include "pandabase.h"
19 
20 // This module requires OpenSSL to compile, even though it doesn't
21 // actually use any OpenSSL code, because it is a support module for
22 // HTTPChannel, which *does* use OpenSSL code.
23 
24 #ifdef HAVE_OPENSSL
25 
26 #include "httpAuthorization.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : HTTPDigestAuthorization
30 // Description : Implements the "Digest" type of HTTP authorization.
31 // This is designed to be an improvement over "Basic"
32 // authorization, in that it does not send passwords
33 // over the net in cleartext, and it is harder to spoof.
34 ////////////////////////////////////////////////////////////////////
35 class HTTPDigestAuthorization : public HTTPAuthorization {
36 public:
37  HTTPDigestAuthorization(const Tokens &tokens, const URLSpec &url,
38  bool is_proxy);
39  virtual ~HTTPDigestAuthorization();
40 
41  virtual const string &get_mechanism() const;
42  virtual bool is_valid();
43 
44  virtual string generate(HTTPEnum::Method method, const string &request_path,
45  const string &username, const string &body);
46 
47 public:
48  enum Algorithm {
49  A_unknown,
50  A_md5,
51  A_md5_sess,
52  };
53  enum Qop {
54  // These are used as a bitfield.
55  Q_unused = 0x000,
56  Q_auth = 0x001,
57  Q_auth_int = 0x002,
58  };
59 
60 private:
61  static int match_qop_token(const string &token);
62 
63  string calc_request_digest(const string &username, const string &password,
64  HTTPEnum::Method method,
65  const string &request_path, const string &body);
66  string calc_h(const string &data) const;
67  string calc_kd(const string &secret, const string &data) const;
68  string get_a1(const string &username, const string &password);
69  string get_a2(HTTPEnum::Method method, const string &request_path,
70  const string &body);
71  string get_hex_nonce_count() const;
72 
73  static string calc_md5(const string &source);
74  INLINE static char hexdigit(int value);
75 
76  string _cnonce;
77  string _nonce;
78  int _nonce_count;
79  string _opaque;
80 
81  Algorithm _algorithm;
82  string _a1;
83 
84  int _qop;
85  Qop _chosen_qop;
86 
87  static const string _mechanism;
88 };
89 
90 ostream &operator << (ostream &out, HTTPDigestAuthorization::Algorithm algorithm);
91 ostream &operator << (ostream &out, HTTPDigestAuthorization::Qop qop);
92 
93 #include "httpDigestAuthorization.I"
94 
95 #endif // HAVE_OPENSSL
96 
97 #endif
98 
A container for a URL, e.g.
Definition: urlSpec.h:29