/[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 4816 - (hide annotations) (download)
Fri Jun 3 17:13:09 2005 UTC (14 years, 6 months ago) by daniel
Original Path: branches/b-smime-0605/dum/test/testPayloadEncrypter.cxx
File size: 6013 byte(s)
added two new classes, PayloadEncrypter and DumEncryped.
1 daniel 4816
2     #include "resiprocate/TransactionUser.hxx"
3     #include "resiprocate/Security.hxx"
4     #include "resiprocate/dum/Handles.hxx"
5     #include "resiprocate/dum/MasterProfile.hxx"
6     #include "resiprocate/dum/UserProfile.hxx"
7     #include "resiprocate/dum/PayloadEncrypter.hxx"
8     #include "resiprocate/dum/DumEncrypted.hxx"
9     #include "resiprocate/PlainContents.hxx"
10     #include "resiprocate/Pkcs7Contents.hxx"
11     #include "resiprocate/MultipartSignedContents.hxx"
12     #include "resiprocate/Mime.hxx"
13    
14     #include "resiprocate/SecurityAttributes.hxx"
15     #include "resiprocate/Helper.hxx"
16    
17     #include "resiprocate/os/Log.hxx"
18     #include "resiprocate/os/Logger.hxx"
19    
20     #ifdef WIN32
21     #include "resiprocate/WinSecurity.hxx"
22     #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     if ( argc < 4 ) {
99     cout << "usage: " << argv[0] << " sip:user passwd\n";
100     return 0;
101     }
102    
103     Log::initialize(Log::Cout, Log::Debug, argv[0]);
104    
105     NameAddr senderAor(argv[1]);
106     NameAddr recipAor(argv[2]);
107     Data passwd(argv[3]);
108    
109     InfoLog(<< "sender: " << senderAor << ", passwd: " << passwd << endl);
110     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     Tu tu(security, senderAor.uri().getAor(), recipAor.uri().getAor());
120     BaseUsageHandle handle;
121     PayloadEncrypter encrypter(tu, security);
122    
123     Contents* contents1 = new PlainContents(Data("message signing"));
124     // sign the message
125     encrypter.encrypt(std::auto_ptr<Contents>(contents1), senderAor.uri().getAor(), handle);
126    
127     Contents* contents2 = new PlainContents(Data("message signing and encrypting"));
128     // sign and encrypt the message
129     encrypter.encrypt(std::auto_ptr<Contents>(contents2), senderAor.uri().getAor(), recipAor.uri().getAor(), handle);
130    
131     while (tu.process())
132     {
133     }
134    
135     return 0;
136     }
137    
138     /* ====================================================================
139     * The Vovida Software License, Version 1.0
140     *
141     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
142     *
143     * Redistribution and use in source and binary forms, with or without
144     * modification, are permitted provided that the following conditions
145     * are met:
146     *
147     * 1. Redistributions of source code must retain the above copyright
148     * notice, this list of conditions and the following disclaimer.
149     *
150     * 2. Redistributions in binary form must reproduce the above copyright
151     * notice, this list of conditions and the following disclaimer in
152     * the documentation and/or other materials provided with the
153     * distribution.
154     *
155     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
156     * and "Vovida Open Communication Application Library (VOCAL)" must
157     * not be used to endorse or promote products derived from this
158     * software without prior written permission. For written
159     * permission, please contact vocal@vovida.org.
160     *
161     * 4. Products derived from this software may not be called "VOCAL", nor
162     * may "VOCAL" appear in their name, without prior written
163     * permission of Vovida Networks, Inc.
164     *
165     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
166     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
167     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
168     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
169     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
170     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
171     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
172     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
173     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
174     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
175     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
176     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
177     * DAMAGE.
178     *
179     * ====================================================================
180     *
181     * This software consists of voluntary contributions made by Vovida
182     * Networks, Inc. and many individuals on behalf of Vovida Networks,
183     * Inc. For more information on Vovida Networks, Inc., please see
184     * <http://www.vovida.org/>.
185     *
186     */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27