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

Annotation of /main/resip/dum/test/testPayloadEncrypter.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5283 - (hide annotations) (download)
Fri Aug 19 01:27:14 2005 UTC (14 years, 3 months ago) by derek
Original Path: branches/b-directory-reorg/resip/dum/test/testPayloadEncrypter.cxx
File size: 6013 byte(s)
finished resip/sip -> resip/stack rename
1 derek 5283 #include "resip/stack/SipStack.hxx"
2     #include "resip/stack/TransactionUser.hxx"
3     #include "resip/stack/Security.hxx"
4 jason 5276 #include "resip/dum/Handles.hxx"
5     #include "resip/dum/MasterProfile.hxx"
6     #include "resip/dum/UserProfile.hxx"
7     #include "resip/dum/PayloadEncrypter.hxx"
8     #include "resip/dum/DumEncrypted.hxx"
9 derek 5283 #include "resip/stack/PlainContents.hxx"
10     #include "resip/stack/Pkcs7Contents.hxx"
11     #include "resip/stack/MultipartSignedContents.hxx"
12     #include "resip/stack/Mime.hxx"
13 daniel 4816
14 derek 5283 #include "resip/stack/SecurityAttributes.hxx"
15     #include "resip/stack/Helper.hxx"
16 daniel 4816
17 jason 5276 #include "rutil/Log.hxx"
18     #include "rutil/Logger.hxx"
19 daniel 4816
20     #ifdef WIN32
21 derek 5283 #include "resip/stack/WinSecurity.hxx"
22 daniel 4816 #endif
23    
24     #include <iostream>
25     #include <string>
26     #include <sstream>
27    
28     using namespace std;
29     using namespace resip;
30    
31     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
32    
33    
34    
35     /*****************************************************************************/
36    
37     class Tu : public TransactionUser
38     {
39     public:
40     Tu(Security* security, const Data& sender, const Data& recip)
41     : mSecurity(security),
42     mSender(sender),
43     mRecip(recip)
44     {
45     }
46    
47     const Data& name() const
48     {
49     static Data name("Tu");
50     return name;
51     }
52    
53     bool process();
54     private:
55     Security* mSecurity;
56     Data mSender;
57     Data mRecip;
58     };
59    
60     bool Tu::process()
61     {
62     if (mFifo.empty()) return false;
63     DumEncrypted* encrypted = dynamic_cast<DumEncrypted*>(mFifo.getNext());
64     if (encrypted->success())
65     {
66     /*Contents* contents = encrypted->encrypted()->clone();
67     Data txt(
68     "To: sip:fluffy@h1.cs.sipit.net\r\n"
69     "From: tofu <sip:tofu@ua.ntt.sipit.net>;tag=5494179792598219348\r\n"
70     "CSeq: 1 SUBSCRIBE\r\n"
71     "Call-ID: 1129541551360711705\r\n"
72     "Contact: sip:tofu@ua.ntt.sipit.net:5060\r\n"
73     "Event: presence\r\n"
74     "Content-Length: 0\r\n"
75     "Expires: 3600\r\n"
76     "User-Agent: NTT SecureSession User-Agent\r\n"
77     "\r\n");
78    
79     SipMessage* msg = SipMessage::make(txt, false);
80     msg->setContents(std::auto_ptr<Contents>(contents));
81     Helper::ContentsSecAttrs csa(Helper::extractFromPkcs7(msg, *mSecurity));
82     InfoLog( << "Body: " << *csa.mContents << "\n" );
83     delete msg;
84     */
85     InfoLog(<<"Message has been successfully encrypted." << endl);
86     }
87     else
88     {
89     InfoLog(<<"Failed to encrypte message: " << encrypted->error() << endl);
90     }
91     delete encrypted;
92     return true;
93     }
94    
95     int main(int argc, char *argv[])
96     {
97    
98 daniel 4817 if ( argc < 3 ) {
99     cout << "usage: " << argv[0] <<"sip:sender sip:recip" << endl;
100     return 0;
101 daniel 4816 }
102    
103     Log::initialize(Log::Cout, Log::Debug, argv[0]);
104    
105     NameAddr senderAor(argv[1]);
106     NameAddr recipAor(argv[2]);
107 daniel 4817 //Data passwd(argv[3]);
108 daniel 4816
109 daniel 4817 InfoLog(<< "sender: " << senderAor << endl);
110 daniel 4816 InfoLog(<< "recipient: " << recipAor << endl);
111    
112     #ifdef WIN32
113     Security* security = new WinSecurity;
114     #else
115     Security* security = new Security;
116     #endif
117    
118     assert(security);
119 daniel 4817 SipStack stack(security);
120 daniel 4816 Tu tu(security, senderAor.uri().getAor(), recipAor.uri().getAor());
121     BaseUsageHandle handle;
122     PayloadEncrypter encrypter(tu, security);
123    
124     Contents* contents1 = new PlainContents(Data("message signing"));
125     // sign the message
126     encrypter.encrypt(std::auto_ptr<Contents>(contents1), senderAor.uri().getAor(), handle);
127    
128     Contents* contents2 = new PlainContents(Data("message signing and encrypting"));
129     // sign and encrypt the message
130     encrypter.encrypt(std::auto_ptr<Contents>(contents2), senderAor.uri().getAor(), recipAor.uri().getAor(), handle);
131    
132     while (tu.process())
133     {
134     }
135    
136 daniel 4817
137 daniel 4816 return 0;
138     }
139    
140     /* ====================================================================
141     * The Vovida Software License, Version 1.0
142     *
143     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
144     *
145     * Redistribution and use in source and binary forms, with or without
146     * modification, are permitted provided that the following conditions
147     * are met:
148     *
149     * 1. Redistributions of source code must retain the above copyright
150     * notice, this list of conditions and the following disclaimer.
151     *
152     * 2. Redistributions in binary form must reproduce the above copyright
153     * notice, this list of conditions and the following disclaimer in
154     * the documentation and/or other materials provided with the
155     * distribution.
156     *
157     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
158     * and "Vovida Open Communication Application Library (VOCAL)" must
159     * not be used to endorse or promote products derived from this
160     * software without prior written permission. For written
161     * permission, please contact vocal@vovida.org.
162     *
163     * 4. Products derived from this software may not be called "VOCAL", nor
164     * may "VOCAL" appear in their name, without prior written
165     * permission of Vovida Networks, Inc.
166     *
167     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
168     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
170     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
171     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
172     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
173     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
174     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
175     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
176     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
178     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
179     * DAMAGE.
180     *
181     * ====================================================================
182     *
183     * This software consists of voluntary contributions made by Vovida
184     * Networks, Inc. and many individuals on behalf of Vovida Networks,
185     * Inc. For more information on Vovida Networks, Inc., please see
186     * <http://www.vovida.org/>.
187     *
188     */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27