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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4817 - (show annotations) (download)
Fri Jun 3 18:45:59 2005 UTC (14 years, 6 months ago) by daniel
Original Path: branches/b-smime-0605/dum/test/testPayloadEncrypter.cxx
File size: 6061 byte(s)
bug fixes
1 #include "resiprocate/SipStack.hxx"
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 < 3 ) {
99 cout << "usage: " << argv[0] <<"sip:sender sip:recip" << endl;
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 << 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 SipStack stack(security);
120 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
137 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