author | Michael Krelin <hacker@klever.net> | 2008-02-12 23:37:05 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-02-12 23:37:05 (UTC) |
commit | 2048be862b8619ddec90163af05e6472bf5175e4 (patch) (unidiff) | |
tree | 74ab3384a2a088abe5748ab93cd2f65fa121e1ae | |
parent | a3eba4c33fee80fcf152dcbd198586e12b687e54 (diff) | |
download | libopkele-2048be862b8619ddec90163af05e6472bf5175e4.zip libopkele-2048be862b8619ddec90163af05e6472bf5175e4.tar.gz libopkele-2048be862b8619ddec90163af05e6472bf5175e4.tar.bz2 |
slight api improvement to ease caching of discovery information
* added opend_endpoint_output_iterator to types.h
* changed endpoint_discovery_iterator to the aforementioned iterator typedef
* added discover() virtual to prequeue_RP and made use thereof.
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/discovery.h | 3 | ||||
-rw-r--r-- | include/opkele/prequeue_rp.h | 8 | ||||
-rw-r--r-- | include/opkele/types.h | 3 | ||||
-rw-r--r-- | lib/prequeue_rp.cc | 9 |
4 files changed, 19 insertions, 4 deletions
diff --git a/include/opkele/discovery.h b/include/opkele/discovery.h index 4471597..f2721a6 100644 --- a/include/opkele/discovery.h +++ b/include/opkele/discovery.h | |||
@@ -1,115 +1,114 @@ | |||
1 | #ifndef __OPKELE_DISCOVERY_H | 1 | #ifndef __OPKELE_DISCOVERY_H |
2 | #define __OPKELE_DISCOVERY_H | 2 | #define __OPKELE_DISCOVERY_H |
3 | 3 | ||
4 | #include <string> | 4 | #include <string> |
5 | #include <opkele/types.h> | 5 | #include <opkele/types.h> |
6 | 6 | ||
7 | namespace opkele { | 7 | namespace opkele { |
8 | using std::string; | 8 | using std::string; |
9 | 9 | ||
10 | namespace xrd { | 10 | namespace xrd { |
11 | 11 | ||
12 | struct priority_compare { | 12 | struct priority_compare { |
13 | inline bool operator()(long a,long b) const { | 13 | inline bool operator()(long a,long b) const { |
14 | return (a<0) ? false : (b<0) ? true : (a<b); | 14 | return (a<0) ? false : (b<0) ? true : (a<b); |
15 | } | 15 | } |
16 | }; | 16 | }; |
17 | 17 | ||
18 | template <typename _DT> | 18 | template <typename _DT> |
19 | class priority_map : public multimap<long,_DT,priority_compare> { | 19 | class priority_map : public multimap<long,_DT,priority_compare> { |
20 | typedef multimap<long,_DT,priority_compare> map_type; | 20 | typedef multimap<long,_DT,priority_compare> map_type; |
21 | public: | 21 | public: |
22 | 22 | ||
23 | inline _DT& add(long priority,const _DT& d) { | 23 | inline _DT& add(long priority,const _DT& d) { |
24 | return insert(typename map_type::value_type(priority,d))->second; | 24 | return insert(typename map_type::value_type(priority,d))->second; |
25 | } | 25 | } |
26 | 26 | ||
27 | bool has_value(const _DT& d) const { | 27 | bool has_value(const _DT& d) const { |
28 | for(typename map_type::const_iterator i=this->begin();i!=this->end();++i) | 28 | for(typename map_type::const_iterator i=this->begin();i!=this->end();++i) |
29 | if(i->second==d) return true; | 29 | if(i->second==d) return true; |
30 | return false; | 30 | return false; |
31 | } | 31 | } |
32 | }; | 32 | }; |
33 | 33 | ||
34 | typedef priority_map<string> canonical_ids_t; | 34 | typedef priority_map<string> canonical_ids_t; |
35 | typedef priority_map<string> local_ids_t; | 35 | typedef priority_map<string> local_ids_t; |
36 | typedef set<string> types_t; | 36 | typedef set<string> types_t; |
37 | struct uri_t { | 37 | struct uri_t { |
38 | string uri; | 38 | string uri; |
39 | string append; | 39 | string append; |
40 | 40 | ||
41 | uri_t() { } | 41 | uri_t() { } |
42 | uri_t(const string& u) : uri(u) { } | 42 | uri_t(const string& u) : uri(u) { } |
43 | uri_t(const string& u,const string& a) : uri(u), append(a) { } | 43 | uri_t(const string& u,const string& a) : uri(u), append(a) { } |
44 | }; | 44 | }; |
45 | typedef priority_map<uri_t> uris_t; | 45 | typedef priority_map<uri_t> uris_t; |
46 | 46 | ||
47 | class service_t { | 47 | class service_t { |
48 | public: | 48 | public: |
49 | types_t types; | 49 | types_t types; |
50 | uris_t uris; | 50 | uris_t uris; |
51 | local_ids_t local_ids; | 51 | local_ids_t local_ids; |
52 | string provider_id; | 52 | string provider_id; |
53 | 53 | ||
54 | void clear() { | 54 | void clear() { |
55 | types.clear(); | 55 | types.clear(); |
56 | uris.clear(); local_ids.clear(); | 56 | uris.clear(); local_ids.clear(); |
57 | provider_id.clear(); | 57 | provider_id.clear(); |
58 | } | 58 | } |
59 | }; | 59 | }; |
60 | typedef priority_map<service_t> services_t; | 60 | typedef priority_map<service_t> services_t; |
61 | 61 | ||
62 | class XRD_t { | 62 | class XRD_t { |
63 | public: | 63 | public: |
64 | time_t expires; | 64 | time_t expires; |
65 | 65 | ||
66 | canonical_ids_t canonical_ids; | 66 | canonical_ids_t canonical_ids; |
67 | local_ids_t local_ids; | 67 | local_ids_t local_ids; |
68 | services_t services; | 68 | services_t services; |
69 | string provider_id; | 69 | string provider_id; |
70 | 70 | ||
71 | void clear() { | 71 | void clear() { |
72 | expires = 0; | 72 | expires = 0; |
73 | canonical_ids.clear(); local_ids.clear(); | 73 | canonical_ids.clear(); local_ids.clear(); |
74 | services.clear(); | 74 | services.clear(); |
75 | provider_id.clear(); | 75 | provider_id.clear(); |
76 | } | 76 | } |
77 | bool empty() const { | 77 | bool empty() const { |
78 | return | 78 | return |
79 | canonical_ids.empty() | 79 | canonical_ids.empty() |
80 | && local_ids.empty() | 80 | && local_ids.empty() |
81 | && services.empty(); | 81 | && services.empty(); |
82 | } | 82 | } |
83 | 83 | ||
84 | }; | 84 | }; |
85 | 85 | ||
86 | } | 86 | } |
87 | 87 | ||
88 | typedef util::output_iterator_proxy<openid_endpoint_t> | 88 | typedef openid_endpoint_output_iterator endpoint_discovery_iterator; |
89 | endpoint_discovery_iterator; | ||
90 | 89 | ||
91 | string idiscover( | 90 | string idiscover( |
92 | endpoint_discovery_iterator oi, | 91 | endpoint_discovery_iterator oi, |
93 | const string& identity); | 92 | const string& identity); |
94 | void yadiscover( | 93 | void yadiscover( |
95 | endpoint_discovery_iterator oi, | 94 | endpoint_discovery_iterator oi, |
96 | const string& yurl, | 95 | const string& yurl, |
97 | const char **types, bool redirs=false); | 96 | const char **types, bool redirs=false); |
98 | 97 | ||
99 | struct idiscovery_t { | 98 | struct idiscovery_t { |
100 | bool xri_identity; | 99 | bool xri_identity; |
101 | string normalized_id; | 100 | string normalized_id; |
102 | string canonicalized_id; | 101 | string canonicalized_id; |
103 | xrd::XRD_t xrd; | 102 | xrd::XRD_t xrd; |
104 | 103 | ||
105 | idiscovery_t() { } | 104 | idiscovery_t() { } |
106 | 105 | ||
107 | void clear() { | 106 | void clear() { |
108 | normalized_id.clear(); canonicalized_id.clear(); | 107 | normalized_id.clear(); canonicalized_id.clear(); |
109 | xrd.clear(); | 108 | xrd.clear(); |
110 | } | 109 | } |
111 | 110 | ||
112 | }; | 111 | }; |
113 | } | 112 | } |
114 | 113 | ||
115 | #endif /* __OPKELE_DISCOVERY_H */ | 114 | #endif /* __OPKELE_DISCOVERY_H */ |
diff --git a/include/opkele/prequeue_rp.h b/include/opkele/prequeue_rp.h index 68fe03d..6f1fda9 100644 --- a/include/opkele/prequeue_rp.h +++ b/include/opkele/prequeue_rp.h | |||
@@ -1,88 +1,96 @@ | |||
1 | #ifndef __OPKELE_RP_H | 1 | #ifndef __OPKELE_RP_H |
2 | #define __OPKELE_RP_H | 2 | #define __OPKELE_RP_H |
3 | 3 | ||
4 | #include <string> | 4 | #include <string> |
5 | #include <set> | 5 | #include <set> |
6 | #include <iterator> | 6 | #include <iterator> |
7 | #include <opkele/basic_rp.h> | 7 | #include <opkele/basic_rp.h> |
8 | 8 | ||
9 | namespace opkele { | 9 | namespace opkele { |
10 | using std::string; | 10 | using std::string; |
11 | using std::set; | 11 | using std::set; |
12 | using std::iterator; | 12 | using std::iterator; |
13 | using std::output_iterator_tag; | 13 | using std::output_iterator_tag; |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * discovery-enabled RP implementation, prequeueing discovered endpoints | 16 | * discovery-enabled RP implementation, prequeueing discovered endpoints |
17 | */ | 17 | */ |
18 | class prequeue_RP : public basic_RP { | 18 | class prequeue_RP : public basic_RP { |
19 | public: | 19 | public: |
20 | /** | 20 | /** |
21 | * @name Session persistent store API | 21 | * @name Session persistent store API |
22 | * @{ | 22 | * @{ |
23 | */ | 23 | */ |
24 | /** | 24 | /** |
25 | * Called before queueing discovered endpoints. Typically happens | 25 | * Called before queueing discovered endpoints. Typically happens |
26 | * while initiating authentication session. | 26 | * while initiating authentication session. |
27 | * @see queue_endpoint() | 27 | * @see queue_endpoint() |
28 | * @see end_queueing() | 28 | * @see end_queueing() |
29 | */ | 29 | */ |
30 | virtual void begin_queueing() { } | 30 | virtual void begin_queueing() { } |
31 | /** | 31 | /** |
32 | * Used to queue discovered endpoint. It is implementors | 32 | * Used to queue discovered endpoint. It is implementors |
33 | * responsibility to store the endpoint wherever he choses to store | 33 | * responsibility to store the endpoint wherever he choses to store |
34 | * it. | 34 | * it. |
35 | * @param oep the endpoint to queue | 35 | * @param oep the endpoint to queue |
36 | * @see begin_queueing() | 36 | * @see begin_queueing() |
37 | * @see end_queueing() | 37 | * @see end_queueing() |
38 | */ | 38 | */ |
39 | virtual void queue_endpoint(const openid_endpoint_t& oep) = 0; | 39 | virtual void queue_endpoint(const openid_endpoint_t& oep) = 0; |
40 | /** | 40 | /** |
41 | * Called after all discovered endpoints were queued. Implementor | 41 | * Called after all discovered endpoints were queued. Implementor |
42 | * may chose to use this virtual to commit endpoints queue to | 42 | * may chose to use this virtual to commit endpoints queue to |
43 | * persistent store. | 43 | * persistent store. |
44 | * @see begin_queueing() | 44 | * @see begin_queueing() |
45 | * @see queue_endpoint() | 45 | * @see queue_endpoint() |
46 | */ | 46 | */ |
47 | virtual void end_queueing() { } | 47 | virtual void end_queueing() { } |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Used to store normalized id when initiating request. | 50 | * Used to store normalized id when initiating request. |
51 | * The default implementation does nothing, because implementor | 51 | * The default implementation does nothing, because implementor |
52 | * doesn't have to care. | 52 | * doesn't have to care. |
53 | * @param nid normalized id | 53 | * @param nid normalized id |
54 | * @see get_normalzied_id() | 54 | * @see get_normalzied_id() |
55 | */ | 55 | */ |
56 | virtual void set_normalized_id(const string& nid); | 56 | virtual void set_normalized_id(const string& nid); |
57 | /** | 57 | /** |
58 | * Return the normalized id previously set by set_normalized_id(). | 58 | * Return the normalized id previously set by set_normalized_id(). |
59 | * Provided for the sake of completeness because default | 59 | * Provided for the sake of completeness because default |
60 | * implementation doesn't use it. | 60 | * implementation doesn't use it. |
61 | * @return the normalized identity | 61 | * @return the normalized identity |
62 | */ | 62 | */ |
63 | virtual const string get_normalized_id() const; | 63 | virtual const string get_normalized_id() const; |
64 | /** | 64 | /** |
65 | * @} | 65 | * @} |
66 | */ | 66 | */ |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * @name Actions | 69 | * @name Actions |
70 | * @{ | 70 | * @{ |
71 | */ | 71 | */ |
72 | /** | 72 | /** |
73 | * In addition to base class implementation it does endpoints | 73 | * In addition to base class implementation it does endpoints |
74 | * discovery and queueing | 74 | * discovery and queueing |
75 | * @param usi User-suppled identifier | 75 | * @param usi User-suppled identifier |
76 | */ | 76 | */ |
77 | void initiate(const string& usi); | 77 | void initiate(const string& usi); |
78 | /** | 78 | /** |
79 | * @} | 79 | * @} |
80 | */ | 80 | */ |
81 | 81 | ||
82 | void verify_OP(const string& OP, | 82 | void verify_OP(const string& OP, |
83 | const string& claimed_id,const string& identity) const; | 83 | const string& claimed_id,const string& identity) const; |
84 | |||
85 | /** | ||
86 | * Perform full discovery on identity | ||
87 | * @param it iterator used for feeding discovered endpoints back to caller | ||
88 | * @param id user supplied identity | ||
89 | * @returns normalized identity (canonical identifier can be found in endpoints) | ||
90 | */ | ||
91 | virtual const string discover(openid_endpoint_output_iterator it,const string& id) const; | ||
84 | }; | 92 | }; |
85 | 93 | ||
86 | } | 94 | } |
87 | 95 | ||
88 | #endif /* __OPKELE_RP_H */ | 96 | #endif /* __OPKELE_RP_H */ |
diff --git a/include/opkele/types.h b/include/opkele/types.h index 1f48362..1fab869 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -1,230 +1,233 @@ | |||
1 | #ifndef __OPKELE_TYPES_H | 1 | #ifndef __OPKELE_TYPES_H |
2 | #define __OPKELE_TYPES_H | 2 | #define __OPKELE_TYPES_H |
3 | 3 | ||
4 | /** | 4 | /** |
5 | * @file | 5 | * @file |
6 | * @brief various types declarations | 6 | * @brief various types declarations |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <cstring> | 9 | #include <cstring> |
10 | #include <ostream> | 10 | #include <ostream> |
11 | #include <vector> | 11 | #include <vector> |
12 | #include <string> | 12 | #include <string> |
13 | #include <map> | 13 | #include <map> |
14 | #include <set> | 14 | #include <set> |
15 | #include <list> | 15 | #include <list> |
16 | #include <opkele/iterator.h> | 16 | #include <opkele/iterator.h> |
17 | #include <opkele/tr1-mem.h> | 17 | #include <opkele/tr1-mem.h> |
18 | 18 | ||
19 | namespace opkele { | 19 | namespace opkele { |
20 | using std::vector; | 20 | using std::vector; |
21 | using std::string; | 21 | using std::string; |
22 | using std::map; | 22 | using std::map; |
23 | using std::ostream; | 23 | using std::ostream; |
24 | using std::multimap; | 24 | using std::multimap; |
25 | using std::set; | 25 | using std::set; |
26 | using std::list; | 26 | using std::list; |
27 | using std::iterator; | 27 | using std::iterator; |
28 | using std::forward_iterator_tag; | 28 | using std::forward_iterator_tag; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * the OpenID operation mode | 31 | * the OpenID operation mode |
32 | */ | 32 | */ |
33 | typedef enum _mode_t { | 33 | typedef enum _mode_t { |
34 | mode_unknown = 0, | 34 | mode_unknown = 0, |
35 | mode_associate, | 35 | mode_associate, |
36 | mode_checkid_immediate, | 36 | mode_checkid_immediate, |
37 | mode_checkid_setup, | 37 | mode_checkid_setup, |
38 | mode_check_association | 38 | mode_check_association |
39 | } mode_t; | 39 | } mode_t; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * the association secret container | 42 | * the association secret container |
43 | */ | 43 | */ |
44 | class secret_t : public vector<unsigned char> { | 44 | class secret_t : public vector<unsigned char> { |
45 | public: | 45 | public: |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * xor the secret and hmac together and encode, using base64 | 48 | * xor the secret and hmac together and encode, using base64 |
49 | * @param key_d pointer to the message digest | 49 | * @param key_d pointer to the message digest |
50 | * @param rv reference to the return value | 50 | * @param rv reference to the return value |
51 | */ | 51 | */ |
52 | void enxor_to_base64(const unsigned char *key_d,string& rv) const; | 52 | void enxor_to_base64(const unsigned char *key_d,string& rv) const; |
53 | /** | 53 | /** |
54 | * decode base64-encoded secret and xor it with the message digest | 54 | * decode base64-encoded secret and xor it with the message digest |
55 | * @param key_d pointer to the message digest | 55 | * @param key_d pointer to the message digest |
56 | * @param b64 base64-encoded secret value | 56 | * @param b64 base64-encoded secret value |
57 | */ | 57 | */ |
58 | void enxor_from_base64(const unsigned char *key_d,const string& b64); | 58 | void enxor_from_base64(const unsigned char *key_d,const string& b64); |
59 | /** | 59 | /** |
60 | * plainly encode to base64 representation | 60 | * plainly encode to base64 representation |
61 | * @param rv reference to the return value | 61 | * @param rv reference to the return value |
62 | */ | 62 | */ |
63 | void to_base64(string& rv) const; | 63 | void to_base64(string& rv) const; |
64 | /** | 64 | /** |
65 | * decode cleartext secret from base64 | 65 | * decode cleartext secret from base64 |
66 | * @param b64 base64-encoded representation of the secret value | 66 | * @param b64 base64-encoded representation of the secret value |
67 | */ | 67 | */ |
68 | void from_base64(const string& b64); | 68 | void from_base64(const string& b64); |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Interface to the association. | 72 | * Interface to the association. |
73 | */ | 73 | */ |
74 | class association_t { | 74 | class association_t { |
75 | public: | 75 | public: |
76 | 76 | ||
77 | virtual ~association_t() { } | 77 | virtual ~association_t() { } |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * retrieve the server with which association was established. | 80 | * retrieve the server with which association was established. |
81 | * @return server name | 81 | * @return server name |
82 | */ | 82 | */ |
83 | virtual string server() const = 0; | 83 | virtual string server() const = 0; |
84 | /** | 84 | /** |
85 | * retrieve the association handle. | 85 | * retrieve the association handle. |
86 | * @return handle | 86 | * @return handle |
87 | */ | 87 | */ |
88 | virtual string handle() const = 0; | 88 | virtual string handle() const = 0; |
89 | /** | 89 | /** |
90 | * retrieve the association type. | 90 | * retrieve the association type. |
91 | * @return association type | 91 | * @return association type |
92 | */ | 92 | */ |
93 | virtual string assoc_type() const = 0; | 93 | virtual string assoc_type() const = 0; |
94 | /** | 94 | /** |
95 | * retrieve the association secret. | 95 | * retrieve the association secret. |
96 | * @return association secret | 96 | * @return association secret |
97 | */ | 97 | */ |
98 | virtual secret_t secret() const = 0; | 98 | virtual secret_t secret() const = 0; |
99 | /** | 99 | /** |
100 | * retrieve the number of seconds the association expires in. | 100 | * retrieve the number of seconds the association expires in. |
101 | * @return seconds till expiration | 101 | * @return seconds till expiration |
102 | */ | 102 | */ |
103 | virtual int expires_in() const = 0; | 103 | virtual int expires_in() const = 0; |
104 | /** | 104 | /** |
105 | * check whether the association is stateless. | 105 | * check whether the association is stateless. |
106 | * @return true if stateless | 106 | * @return true if stateless |
107 | */ | 107 | */ |
108 | virtual bool stateless() const = 0; | 108 | virtual bool stateless() const = 0; |
109 | /** | 109 | /** |
110 | * check whether the association is expired. | 110 | * check whether the association is expired. |
111 | * @return true if expired | 111 | * @return true if expired |
112 | */ | 112 | */ |
113 | virtual bool is_expired() const = 0; | 113 | virtual bool is_expired() const = 0; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * the shared_ptr<> for association_t object type | 117 | * the shared_ptr<> for association_t object type |
118 | */ | 118 | */ |
119 | typedef tr1mem::shared_ptr<association_t> assoc_t; | 119 | typedef tr1mem::shared_ptr<association_t> assoc_t; |
120 | 120 | ||
121 | class basic_openid_message { | 121 | class basic_openid_message { |
122 | public: | 122 | public: |
123 | typedef list<string> fields_t; | 123 | typedef list<string> fields_t; |
124 | typedef util::forward_iterator_proxy< | 124 | typedef util::forward_iterator_proxy< |
125 | string,const string&,const string* | 125 | string,const string&,const string* |
126 | > fields_iterator; | 126 | > fields_iterator; |
127 | 127 | ||
128 | basic_openid_message() { } | 128 | basic_openid_message() { } |
129 | virtual ~basic_openid_message() { } | 129 | virtual ~basic_openid_message() { } |
130 | basic_openid_message(const basic_openid_message& x); | 130 | basic_openid_message(const basic_openid_message& x); |
131 | void copy_to(basic_openid_message& x) const; | 131 | void copy_to(basic_openid_message& x) const; |
132 | 132 | ||
133 | virtual bool has_field(const string& n) const = 0; | 133 | virtual bool has_field(const string& n) const = 0; |
134 | virtual const string& get_field(const string& n) const = 0; | 134 | virtual const string& get_field(const string& n) const = 0; |
135 | 135 | ||
136 | virtual bool has_ns(const string& uri) const; | 136 | virtual bool has_ns(const string& uri) const; |
137 | virtual string get_ns(const string& uri) const; | 137 | virtual string get_ns(const string& uri) const; |
138 | 138 | ||
139 | virtual fields_iterator fields_begin() const = 0; | 139 | virtual fields_iterator fields_begin() const = 0; |
140 | virtual fields_iterator fields_end() const = 0; | 140 | virtual fields_iterator fields_end() const = 0; |
141 | 141 | ||
142 | virtual string append_query(const string& url) const; | 142 | virtual string append_query(const string& url) const; |
143 | virtual string query_string() const; | 143 | virtual string query_string() const; |
144 | 144 | ||
145 | 145 | ||
146 | virtual void reset_fields(); | 146 | virtual void reset_fields(); |
147 | virtual void set_field(const string& n,const string& v); | 147 | virtual void set_field(const string& n,const string& v); |
148 | virtual void reset_field(const string& n); | 148 | virtual void reset_field(const string& n); |
149 | 149 | ||
150 | virtual void from_keyvalues(const string& kv); | 150 | virtual void from_keyvalues(const string& kv); |
151 | virtual void to_keyvalues(ostream& o) const; | 151 | virtual void to_keyvalues(ostream& o) const; |
152 | 152 | ||
153 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; | 153 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; |
154 | 154 | ||
155 | void add_to_signed(const string& fields); | 155 | void add_to_signed(const string& fields); |
156 | string find_ns(const string& uri,const char *pfx) const; | 156 | string find_ns(const string& uri,const char *pfx) const; |
157 | string allocate_ns(const string& uri,const char *pfx); | 157 | string allocate_ns(const string& uri,const char *pfx); |
158 | }; | 158 | }; |
159 | 159 | ||
160 | class openid_message_t : public basic_openid_message, public map<string,string> { | 160 | class openid_message_t : public basic_openid_message, public map<string,string> { |
161 | public: | 161 | public: |
162 | openid_message_t() { } | 162 | openid_message_t() { } |
163 | openid_message_t(const basic_openid_message& x) | 163 | openid_message_t(const basic_openid_message& x) |
164 | : basic_openid_message(x) { } | 164 | : basic_openid_message(x) { } |
165 | 165 | ||
166 | void copy_to(basic_openid_message& x) const; | 166 | void copy_to(basic_openid_message& x) const; |
167 | 167 | ||
168 | bool has_field(const string& n) const; | 168 | bool has_field(const string& n) const; |
169 | const string& get_field(const string& n) const; | 169 | const string& get_field(const string& n) const; |
170 | virtual fields_iterator fields_begin() const; | 170 | virtual fields_iterator fields_begin() const; |
171 | virtual fields_iterator fields_end() const; | 171 | virtual fields_iterator fields_end() const; |
172 | 172 | ||
173 | void reset_fields(); | 173 | void reset_fields(); |
174 | void set_field(const string& n,const string& v); | 174 | void set_field(const string& n,const string& v); |
175 | void reset_field(const string& n); | 175 | void reset_field(const string& n); |
176 | }; | 176 | }; |
177 | 177 | ||
178 | /** | 178 | /** |
179 | * request/response parameters map | 179 | * request/response parameters map |
180 | */ | 180 | */ |
181 | class params_t : public openid_message_t { | 181 | class params_t : public openid_message_t { |
182 | public: | 182 | public: |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * check whether the parameter is present. | 185 | * check whether the parameter is present. |
186 | * @param n the parameter name | 186 | * @param n the parameter name |
187 | * @return true if yes | 187 | * @return true if yes |
188 | */ | 188 | */ |
189 | bool has_param(const string& n) const { | 189 | bool has_param(const string& n) const { |
190 | return has_field(n); } | 190 | return has_field(n); } |
191 | /** | 191 | /** |
192 | * retrieve the parameter (const version) | 192 | * retrieve the parameter (const version) |
193 | * @param n the parameter name | 193 | * @param n the parameter name |
194 | * @return the parameter value | 194 | * @return the parameter value |
195 | * @throw failed_lookup if there is no such parameter | 195 | * @throw failed_lookup if there is no such parameter |
196 | */ | 196 | */ |
197 | const string& get_param(const string& n) const { | 197 | const string& get_param(const string& n) const { |
198 | return get_field(n); } | 198 | return get_field(n); } |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * parse the OpenID key/value data. | 201 | * parse the OpenID key/value data. |
202 | * @param kv the OpenID key/value data | 202 | * @param kv the OpenID key/value data |
203 | */ | 203 | */ |
204 | void parse_keyvalues(const string& kv) { | 204 | void parse_keyvalues(const string& kv) { |
205 | from_keyvalues(kv); } | 205 | from_keyvalues(kv); } |
206 | 206 | ||
207 | string append_query(const string& url,const char *prefix="openid.") const; | 207 | string append_query(const string& url,const char *prefix="openid.") const; |
208 | 208 | ||
209 | }; | 209 | }; |
210 | 210 | ||
211 | struct openid_endpoint_t { | 211 | struct openid_endpoint_t { |
212 | string uri; | 212 | string uri; |
213 | string claimed_id; | 213 | string claimed_id; |
214 | string local_id; | 214 | string local_id; |
215 | 215 | ||
216 | openid_endpoint_t() { } | 216 | openid_endpoint_t() { } |
217 | openid_endpoint_t(const string& u,const string& cid,const string& lid) | 217 | openid_endpoint_t(const string& u,const string& cid,const string& lid) |
218 | : uri(u), claimed_id(cid), local_id(lid) { } | 218 | : uri(u), claimed_id(cid), local_id(lid) { } |
219 | 219 | ||
220 | bool operator==(const openid_endpoint_t& x) const { | 220 | bool operator==(const openid_endpoint_t& x) const { |
221 | return uri==x.uri && local_id==x.local_id; } | 221 | return uri==x.uri && local_id==x.local_id; } |
222 | bool operator<(const openid_endpoint_t& x) const { | 222 | bool operator<(const openid_endpoint_t& x) const { |
223 | int c; | 223 | int c; |
224 | return (c=strcmp(uri.c_str(),x.uri.c_str())) | 224 | return (c=strcmp(uri.c_str(),x.uri.c_str())) |
225 | ? (c<0) : (strcmp(local_id.c_str(),x.local_id.c_str())<0); } | 225 | ? (c<0) : (strcmp(local_id.c_str(),x.local_id.c_str())<0); } |
226 | }; | 226 | }; |
227 | 227 | ||
228 | typedef util::output_iterator_proxy<openid_endpoint_t> | ||
229 | openid_endpoint_output_iterator; | ||
230 | |||
228 | } | 231 | } |
229 | 232 | ||
230 | #endif /* __OPKELE_TYPES_H */ | 233 | #endif /* __OPKELE_TYPES_H */ |
diff --git a/lib/prequeue_rp.cc b/lib/prequeue_rp.cc index 3aa960f..ed1ddfe 100644 --- a/lib/prequeue_rp.cc +++ b/lib/prequeue_rp.cc | |||
@@ -1,81 +1,86 @@ | |||
1 | #include <iostream> | 1 | #include <iostream> |
2 | #include <openssl/sha.h> | 2 | #include <openssl/sha.h> |
3 | #include <openssl/hmac.h> | 3 | #include <openssl/hmac.h> |
4 | #include <opkele/exception.h> | 4 | #include <opkele/exception.h> |
5 | #include <opkele/prequeue_rp.h> | 5 | #include <opkele/prequeue_rp.h> |
6 | #include <opkele/discovery.h> | 6 | #include <opkele/discovery.h> |
7 | #include <opkele/uris.h> | 7 | #include <opkele/uris.h> |
8 | #include <opkele/data.h> | 8 | #include <opkele/data.h> |
9 | #include <opkele/util.h> | 9 | #include <opkele/util.h> |
10 | #include <opkele/curl.h> | 10 | #include <opkele/curl.h> |
11 | #include <opkele/debug.h> | 11 | #include <opkele/debug.h> |
12 | 12 | ||
13 | namespace opkele { | 13 | namespace opkele { |
14 | 14 | ||
15 | class __OP_verifier_good_input : public exception { | 15 | class __OP_verifier_good_input : public exception { |
16 | public: | 16 | public: |
17 | __OP_verifier_good_input(OPKELE_E_PARS) | 17 | __OP_verifier_good_input(OPKELE_E_PARS) |
18 | : exception(OPKELE_E_CONS) { } | 18 | : exception(OPKELE_E_CONS) { } |
19 | }; | 19 | }; |
20 | 20 | ||
21 | class OP_verifier : public iterator<output_iterator_tag,openid_endpoint_t,void> { | 21 | class OP_verifier : public iterator<output_iterator_tag,openid_endpoint_t,void> { |
22 | public: | 22 | public: |
23 | const string& OP; | 23 | const string& OP; |
24 | const string& id; | 24 | const string& id; |
25 | 25 | ||
26 | OP_verifier(const string& o,const string& i) | 26 | OP_verifier(const string& o,const string& i) |
27 | : OP(o), id(i) { } | 27 | : OP(o), id(i) { } |
28 | 28 | ||
29 | OP_verifier& operator*() { return *this; } | 29 | OP_verifier& operator*() { return *this; } |
30 | OP_verifier& operator=(const openid_endpoint_t& oep) { | 30 | OP_verifier& operator=(const openid_endpoint_t& oep) { |
31 | if(oep.uri==OP) { | 31 | if(oep.uri==OP) { |
32 | if(oep.claimed_id==IDURI_SELECT20 | 32 | if(oep.claimed_id==IDURI_SELECT20 |
33 | || oep.local_id==IDURI_SELECT20 ) | 33 | || oep.local_id==IDURI_SELECT20 ) |
34 | throw bad_input(OPKELE_CP_ "claimed_id is an OP-Id"); | 34 | throw bad_input(OPKELE_CP_ "claimed_id is an OP-Id"); |
35 | if(oep.local_id==id) | 35 | if(oep.local_id==id) |
36 | throw __OP_verifier_good_input(OPKELE_CP_ "Found corresponding endpoint"); | 36 | throw __OP_verifier_good_input(OPKELE_CP_ "Found corresponding endpoint"); |
37 | } | 37 | } |
38 | return *this; | 38 | return *this; |
39 | } | 39 | } |
40 | 40 | ||
41 | OP_verifier& operator++() { return *this; } | 41 | OP_verifier& operator++() { return *this; } |
42 | OP_verifier& operator++(int) { return *this; } | 42 | OP_verifier& operator++(int) { return *this; } |
43 | }; | 43 | }; |
44 | 44 | ||
45 | void prequeue_RP::verify_OP(const string& OP,const string& claimed_id,const string& identity) const { | 45 | void prequeue_RP::verify_OP(const string& OP,const string& claimed_id,const string& identity) const { |
46 | try { | 46 | try { |
47 | idiscover(OP_verifier(OP,identity),claimed_id); | 47 | discover(OP_verifier(OP,identity),claimed_id); |
48 | throw id_res_unauthorized(OPKELE_CP_ | 48 | throw id_res_unauthorized(OPKELE_CP_ |
49 | "OP is not authorized to make an assertion regarding the identity"); | 49 | "OP is not authorized to make an assertion regarding the identity"); |
50 | }catch(__OP_verifier_good_input& ovgi) { | 50 | }catch(__OP_verifier_good_input& ovgi) { |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | class endpoint_queuer : public iterator<output_iterator_tag,openid_endpoint_t,void> { | 54 | class endpoint_queuer : public iterator<output_iterator_tag,openid_endpoint_t,void> { |
55 | public: | 55 | public: |
56 | prequeue_RP& rp; | 56 | prequeue_RP& rp; |
57 | 57 | ||
58 | endpoint_queuer(prequeue_RP& r) : rp(r) { } | 58 | endpoint_queuer(prequeue_RP& r) : rp(r) { } |
59 | 59 | ||
60 | endpoint_queuer& operator*() { return *this; } | 60 | endpoint_queuer& operator*() { return *this; } |
61 | endpoint_queuer& operator=(const openid_endpoint_t& oep) { | 61 | endpoint_queuer& operator=(const openid_endpoint_t& oep) { |
62 | rp.queue_endpoint(oep); return *this; } | 62 | rp.queue_endpoint(oep); return *this; } |
63 | 63 | ||
64 | endpoint_queuer& operator++() { return *this; } | 64 | endpoint_queuer& operator++() { return *this; } |
65 | endpoint_queuer& operator++(int) { return *this; } | 65 | endpoint_queuer& operator++(int) { return *this; } |
66 | }; | 66 | }; |
67 | 67 | ||
68 | void prequeue_RP::initiate(const string& usi) { | 68 | void prequeue_RP::initiate(const string& usi) { |
69 | begin_queueing(); | 69 | begin_queueing(); |
70 | set_normalized_id( idiscover(endpoint_queuer(*this),usi) ); | 70 | set_normalized_id( discover(endpoint_queuer(*this),usi) ); |
71 | end_queueing(); | 71 | end_queueing(); |
72 | } | 72 | } |
73 | 73 | ||
74 | void prequeue_RP::set_normalized_id(const string&) { | 74 | void prequeue_RP::set_normalized_id(const string&) { |
75 | } | 75 | } |
76 | 76 | ||
77 | const string prequeue_RP::get_normalized_id() const { | 77 | const string prequeue_RP::get_normalized_id() const { |
78 | throw not_implemented(OPKELE_CP_ "get_normalized_id() is not implemented"); | 78 | throw not_implemented(OPKELE_CP_ "get_normalized_id() is not implemented"); |
79 | } | 79 | } |
80 | 80 | ||
81 | const string prequeue_RP::discover(openid_endpoint_output_iterator it, | ||
82 | const string& id) const { | ||
83 | return idiscover(it,id); | ||
84 | } | ||
85 | |||
81 | } | 86 | } |