/[resiprocate]/main/resip/dum/test/certServer.cxx
ViewVC logotype

Diff of /main/resip/dum/test/certServer.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3546 by jason, Mon Nov 22 20:59:36 2004 UTC revision 4335 by jason, Tue Apr 12 21:40:15 2005 UTC
# Line 19  Line 19 
19  #include "resiprocate/dum/DialogUsageManager.hxx"  #include "resiprocate/dum/DialogUsageManager.hxx"
20  #include "resiprocate/dum/DumShutdownHandler.hxx"  #include "resiprocate/dum/DumShutdownHandler.hxx"
21  #include "resiprocate/dum/OutOfDialogHandler.hxx"  #include "resiprocate/dum/OutOfDialogHandler.hxx"
22  #include "resiprocate/dum/Profile.hxx"  #include "resiprocate/dum/MasterProfile.hxx"
23  #include "resiprocate/dum/PublicationHandler.hxx"  #include "resiprocate/dum/PublicationHandler.hxx"
24  #include "resiprocate/dum/RegistrationHandler.hxx"  #include "resiprocate/dum/RegistrationHandler.hxx"
25  #include "resiprocate/dum/ServerPublication.hxx"  #include "resiprocate/dum/ServerPublication.hxx"
# Line 89  Line 89 
89                              int expires)                              int expires)
90        {        {
91           add(h, contents);           add(h, contents);
          h->send(h->accept(200));  
92        }        }
93    
94        virtual void onRemoved(ServerPublicationHandle h, const Data& etag, const SipMessage& pub, int expires)        virtual void onRemoved(ServerPublicationHandle h, const Data& etag, const SipMessage& pub, int expires)
# Line 99  Line 98 
98     private:     private:
99        void add(ServerPublicationHandle h, const Contents* contents)        void add(ServerPublicationHandle h, const Contents* contents)
100        {        {
101             if (h->getDocumentKey() == h->getPublisher())
102             {
103           const X509Contents* x509 = dynamic_cast<const X509Contents*>(contents);           const X509Contents* x509 = dynamic_cast<const X509Contents*>(contents);
104           assert(x509);           assert(x509);
105           mSecurity.addUserCertDER(h->getPublisher(), x509->getBodyData());           mSecurity.addUserCertDER(h->getPublisher(), x509->getBodyData());
106                h->send(h->accept(200));
107             }
108             else
109             {
110                h->send(h->accept(403)); // !jf! is this the correct code?
111             }
112        }        }
113    
114        Security& mSecurity;        Security& mSecurity;
# Line 146  Line 153 
153                              int expires)                              int expires)
154        {        {
155           add(h, contents);           add(h, contents);
          h->send(h->accept(200));  
156        }        }
157    
158        virtual void onRemoved(ServerPublicationHandle h, const Data& etag, const SipMessage& pub, int expires)        virtual void onRemoved(ServerPublicationHandle h, const Data& etag, const SipMessage& pub, int expires)
# Line 157  Line 163 
163     private:     private:
164        void add(ServerPublicationHandle h, const Contents* contents)        void add(ServerPublicationHandle h, const Contents* contents)
165        {        {
166             if (h->getDocumentKey() == h->getPublisher())
167             {
168           const Pkcs8Contents* pkcs8 = dynamic_cast<const Pkcs8Contents*>(contents);           const Pkcs8Contents* pkcs8 = dynamic_cast<const Pkcs8Contents*>(contents);
169           assert(pkcs8);           assert(pkcs8);
170           mSecurity.addUserPrivateKeyDER(h->getPublisher(), pkcs8->getBodyData());           mSecurity.addUserPrivateKeyDER(h->getPublisher(), pkcs8->getBodyData());
171        }        }
172             else
173             {
174                h->send(h->accept(403)); // !jf! is this the correct code?
175             }
176          }
177                
178        Security& mSecurity;        Security& mSecurity;
179  };  };
# Line 174  Line 187 
187    
188        virtual void onNewSubscription(ServerSubscriptionHandle h, const SipMessage& sub)        virtual void onNewSubscription(ServerSubscriptionHandle h, const SipMessage& sub)
189        {        {
190             if (!mSecurity.hasUserCert(h->getDocumentKey()))
191             {
192                // !jf! really need to do this async. send neutral state in the meantime,
193                // blah blah blah
194                mSecurity.generateUserCert(h->getDocumentKey());
195             }
196    
197           if (mSecurity.hasUserCert(h->getDocumentKey()))           if (mSecurity.hasUserCert(h->getDocumentKey()))
198           {           {
199              X509Contents x509(mSecurity.getUserCertDER(h->getDocumentKey()));              X509Contents x509(mSecurity.getUserCertDER(h->getDocumentKey()));
# Line 215  Line 235 
235    
236        virtual void onNewSubscription(ServerSubscriptionHandle h, const SipMessage& sub)        virtual void onNewSubscription(ServerSubscriptionHandle h, const SipMessage& sub)
237        {        {
238           if (mSecurity.hasUserCert(h->getDocumentKey()))           if (h->getDocumentKey() != h->getSubscriber())
239             {
240                h->send(h->accept(403)); // !jf! is this the correct code?
241             }
242             else if (mSecurity.hasUserCert(h->getDocumentKey()))
243           {           {
244              Pkcs8Contents pkcs(mSecurity.getUserPrivateKeyDER(h->getDocumentKey()));              Pkcs8Contents pkcs(mSecurity.getUserPrivateKeyDER(h->getDocumentKey()));
245              h->send(h->update(&pkcs));              h->send(h->update(&pkcs));
# Line 241  Line 265 
265        virtual void onError(ServerSubscriptionHandle, const SipMessage& msg)        virtual void onError(ServerSubscriptionHandle, const SipMessage& msg)
266        {        {
267        }        }
268    
269     private:     private:
270        Security& mSecurity;        Security& mSecurity;
271  };  };
# Line 250  Line 275 
275  class CertServer : public OutOfDialogHandler,  public DialogUsageManager  class CertServer : public OutOfDialogHandler,  public DialogUsageManager
276  {  {
277     public:     public:
278        CertServer(const resip::NameAddr& me) :        CertServer(const resip::NameAddr& me, SipStack& stack) :
279           DialogUsageManager(),           DialogUsageManager(stack),
280           mCertServer(getSecurity()),           mCertServer(getSecurity()),
281           mPrivateKeyServer(getSecurity()),           mPrivateKeyServer(getSecurity()),
282           mCertUpdater(getSecurity()),           mCertUpdater(getSecurity()),
283           mPrivateKeyUpdater(getSecurity())           mPrivateKeyUpdater(getSecurity()),
284             mDone(false)
285        {        {
286           addTransport(UDP, 5100);           addTransport(UDP, 5100);
287           addTransport(TCP, 5100);           addTransport(TCP, 5100);
288           // addTlsTransport           addTransport(TLS, 5101, V4, Data::Empty, me.uri().host(), Data::Empty);
289                    
290           mProfile.clearSupportedMethods();           mProfile.clearSupportedMethods();
291           mProfile.addSupportedMethod(PUBLISH);           mProfile.addSupportedMethod(PUBLISH);
292           mProfile.addSupportedMethod(SUBSCRIBE);           mProfile.addSupportedMethod(SUBSCRIBE);
293           mProfile.validateAcceptEnabled() = true;           mProfile.validateAcceptEnabled() = true;
294           mProfile.validateContentEnabled() = true;           mProfile.validateContentEnabled() = true;
295           mProfile.addSupportedMimeType(Pkcs8Contents::getStaticType());           mProfile.addSupportedMimeType(PUBLISH, Pkcs8Contents::getStaticType());
296           mProfile.addSupportedMimeType(X509Contents::getStaticType());           mProfile.addSupportedMimeType(SUBSCRIBE, Pkcs8Contents::getStaticType());
297             mProfile.addSupportedMimeType(PUBLISH, X509Contents::getStaticType());
298             mProfile.addSupportedMimeType(SUBSCRIBE, X509Contents::getStaticType());
299                    
300           mProfile.setDefaultFrom(me);           mProfile.setDefaultFrom(me);
301           setProfile(&mProfile);           setMasterProfile(&mProfile);
302    
303           addServerSubscriptionHandler(Symbols::Credential, &mPrivateKeyServer);           addServerSubscriptionHandler(Symbols::Credential, &mPrivateKeyServer);
304           addServerSubscriptionHandler(Symbols::Certificate, &mCertServer);           addServerSubscriptionHandler(Symbols::Certificate, &mCertServer);
# Line 315  Line 343 
343        }        }
344    
345     private:     private:
346        Profile mProfile;        MasterProfile mProfile;
347        CertSubscriptionHandler mCertServer;        CertSubscriptionHandler mCertServer;
348        PrivateKeySubscriptionHandler mPrivateKeyServer;        PrivateKeySubscriptionHandler mPrivateKeyServer;
349        CertPublicationHandler mCertUpdater;        CertPublicationHandler mCertUpdater;
# Line 368  Line 396 
396  #endif  #endif
397    
398     NameAddr domain(myUrl);     NameAddr domain(myUrl);
399     CertServer server(domain);     SipStack stack;
400       CertServer server(domain, stack);
401     server.run();     server.run();
402     return 0;     return 0;
403  }  }

Legend:
Removed from v.3546  
changed lines
  Added in v.4335

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.26