Reverted POST profile API to return pointers.
[shibboleth/cpp-sp.git] / shib / shib.h
1 /*
2  * The Shibboleth License, Version 1.
3  * Copyright (c) 2002
4  * University Corporation for Advanced Internet Development, Inc.
5  * All rights reserved
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution, if any, must include
17  * the following acknowledgment: "This product includes software developed by
18  * the University Corporation for Advanced Internet Development
19  * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20  * may appear in the software itself, if and wherever such third-party
21  * acknowledgments normally appear.
22  *
23  * Neither the name of Shibboleth nor the names of its contributors, nor
24  * Internet2, nor the University Corporation for Advanced Internet Development,
25  * Inc., nor UCAID may be used to endorse or promote products derived from this
26  * software without specific prior written permission. For written permission,
27  * please contact shibboleth@shibboleth.org
28  *
29  * Products derived from this software may not be called Shibboleth, Internet2,
30  * UCAID, or the University Corporation for Advanced Internet Development, nor
31  * may Shibboleth appear in their name, without prior written permission of the
32  * University Corporation for Advanced Internet Development.
33  *
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36  * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39  * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40  * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41  * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  */
49
50
51 /* shib.h - Shibboleth header file
52
53    Scott Cantor
54    6/4/02
55
56    $History:$
57 */
58
59 #ifndef __shib_h__
60 #define __shib_h__
61
62 #include <saml/saml.h>
63
64 #ifdef WIN32
65 # ifndef SHIB_EXPORTS
66 #  define SHIB_EXPORTS __declspec(dllimport)
67 # endif
68 #else
69 # define SHIB_EXPORTS
70 #endif
71
72 namespace shibboleth
73 {
74     #define DECLARE_SHIB_EXCEPTION(name,base) \
75         class SHIB_EXPORTS name : public saml::base \
76         { \
77         public: \
78             name(const char* msg) : saml::base(msg) {} \
79             name(const std::string& msg) : saml::base(msg) {} \
80             name(const saml::Iterator<saml::QName>& codes, const char* msg) : saml::base(codes,msg) {} \
81             name(const saml::Iterator<saml::QName>& codes, const std::string& msg) : saml::base(codes, msg) {} \
82             name(const saml::QName& code, const char* msg) : saml::base(code,msg) {} \
83             name(const saml::QName& code, const std::string& msg) : saml::base(code, msg) {} \
84             name(DOMElement* e) : saml::base(e) {} \
85             name(std::istream& in) : saml::base(in) {} \
86             virtual ~name() throw () {} \
87         }
88
89     DECLARE_SHIB_EXCEPTION(UnsupportedProtocolException,SAMLException);
90     DECLARE_SHIB_EXCEPTION(OriginSiteMapperException,SAMLException);
91
92     struct SHIB_EXPORTS IOriginSiteMapper
93     {
94         virtual saml::Iterator<saml::xstring> getHandleServiceNames(const XMLCh* originSite)=0;
95         virtual const saml::Key* getHandleServiceKey(const XMLCh* handleService)=0;
96         virtual saml::Iterator<saml::xstring> getSecurityDomains(const XMLCh* originSite)=0;
97         virtual const char* getTrustedRoots()=0;
98     };
99
100     class SHIB_EXPORTS XMLOriginSiteMapper : public IOriginSiteMapper
101     {
102     public:
103         XMLOriginSiteMapper(const char* registryURI, const char* calist=NULL, const saml::X509Certificate* verifyKey=NULL);
104         ~XMLOriginSiteMapper();
105
106         virtual saml::Iterator<saml::xstring> getHandleServiceNames(const XMLCh* originSite);
107         virtual const saml::Key* getHandleServiceKey(const XMLCh* handleService);
108         virtual saml::Iterator<saml::xstring> getSecurityDomains(const XMLCh* originSite);
109         virtual const char* getTrustedRoots();
110
111     private:
112         void validateSignature(const saml::X509Certificate* verifyKey, DOMElement* e);
113
114         struct OriginSite
115         {
116             std::vector<saml::xstring> m_handleServices;
117             std::vector<saml::xstring> m_domains;
118         };
119
120         std::string m_calist;
121         std::map<saml::xstring,OriginSite*> m_sites;
122         std::map<saml::xstring,saml::Key*> m_hsKeys;
123     };
124
125     class SHIB_EXPORTS ShibPOSTProfile
126     {
127     public:
128         ShibPOSTProfile(const saml::Iterator<const XMLCh*>& policies, const XMLCh* receiver, int ttlSeconds);
129         ShibPOSTProfile(const saml::Iterator<const XMLCh*>& policies, const XMLCh* issuer);
130         virtual ~ShibPOSTProfile();
131
132         virtual saml::SAMLAssertion* getSSOAssertion(const saml::SAMLResponse& r);
133         virtual saml::SAMLAuthenticationStatement* getSSOStatement(const saml::SAMLAssertion& a);
134         virtual saml::SAMLResponse* accept(const XMLByte* buf);
135         virtual saml::SAMLResponse* prepare(const XMLCh* recipient,
136                                             const XMLCh* name,
137                                             const XMLCh* nameQualifier,
138                                             const XMLCh* subjectIP,
139                                             const XMLCh* authMethod,
140                                             time_t authInstant,
141                                             const saml::Iterator<saml::SAMLAuthorityBinding*>& bindings,
142                                             const saml::Key& responseKey, const saml::X509Certificate* responseCert=NULL,
143                                             const saml::Key* assertionKey=NULL, const saml::X509Certificate* assertionCert=NULL);
144         virtual bool checkReplayCache(const saml::SAMLAssertion& a);
145
146     protected:
147         virtual void verifySignature(const saml::SAMLSignedObject& obj, const XMLCh* signerName, const saml::Key* knownKey);
148
149         saml::SAMLSignedObject::sigs_t m_algorithm;
150         std::vector<const XMLCh*> m_policies;
151         XMLCh* m_issuer;
152         XMLCh* m_receiver;
153         int m_ttlSeconds;
154
155     private:
156         ShibPOSTProfile(const ShibPOSTProfile&) {}
157         ShibPOSTProfile& operator=(const ShibPOSTProfile&) {return *this;}
158     };
159
160     class SHIB_EXPORTS ClubShibPOSTProfile : public ShibPOSTProfile
161     {
162     public:
163         ClubShibPOSTProfile(const saml::Iterator<const XMLCh*>& policies, const XMLCh* receiver, int ttlSeconds);
164         ClubShibPOSTProfile(const saml::Iterator<const XMLCh*>& policies, const XMLCh* issuer);
165         virtual ~ClubShibPOSTProfile();
166
167         virtual saml::SAMLResponse* prepare(const XMLCh* recipient,
168                                             const XMLCh* name,
169                                             const XMLCh* nameQualifier,
170                                             const XMLCh* subjectIP,
171                                             const XMLCh* authMethod,
172                                             time_t authInstant,
173                                             const saml::Iterator<saml::SAMLAuthorityBinding*>& bindings,
174                                             const saml::Key& responseKey, const saml::X509Certificate* responseCert=NULL,
175                                             const saml::Key* assertionKey=NULL, const saml::X509Certificate* assertionCert=NULL);
176
177     protected:
178         virtual void verifySignature(const saml::SAMLSignedObject& obj, const XMLCh* signerName, const saml::Key* knownKey);
179     };
180
181     class SHIB_EXPORTS ShibPOSTProfileFactory
182     {
183     public:
184         static ShibPOSTProfile* getInstance(const saml::Iterator<const XMLCh*>& policies, const XMLCh* receiver, int ttlSeconds);
185         static ShibPOSTProfile* getInstance(const saml::Iterator<const XMLCh*>& policies, const XMLCh* issuer);
186     };
187
188     class SHIB_EXPORTS ShibConfig
189     {
190     public:
191         // global per-process setup and shutdown of Shibboleth runtime
192         virtual bool init()=0;
193         virtual void term()=0;
194
195         // enables runtime and clients to access configuration
196         static ShibConfig& getConfig();
197
198     /* start of external configuration */
199         IOriginSiteMapper* origin_mapper;
200     /* end of external configuration */
201     };
202
203     struct SHIB_EXPORTS Constants
204     {
205         static const XMLCh POLICY_CLUBSHIB[];
206         static const XMLCh SHIB_ATTRIBUTE_NAMESPACE_URI[];
207     };
208
209     class SHIB_EXPORTS XML
210     {
211     public:
212         // URI constants
213         static const XMLCh SHIB_NS[];
214         static const XMLCh SHIB_SCHEMA_ID[];
215
216         struct SHIB_EXPORTS Literals
217         {
218             // Shibboleth vocabulary
219             static const XMLCh Domain[];
220             static const XMLCh HandleService[];
221             static const XMLCh InvalidHandle[];
222             static const XMLCh Name[];
223             static const XMLCh OriginSite[];
224             static const XMLCh Sites[];
225
226             // XML vocabulary
227             static const XMLCh xmlns_shib[];
228         };
229     };
230
231
232     class SHIB_EXPORTS SAMLBindingFactory
233     {
234     public:
235         static saml::SAMLBinding* getInstance(const XMLCh* protocol=saml::SAMLBinding::SAML_SOAP_HTTPS);
236     };
237 }
238
239 #endif