reSIProcate/DialogUsageManager  9694
testPayloadEncrypter.cxx
Go to the documentation of this file.
00001 #include "resip/stack/SipStack.hxx"
00002 #include "resip/stack/TransactionUser.hxx"
00003 #include "resip/stack/ssl/Security.hxx"
00004 #include "resip/dum/Handles.hxx"
00005 #include "resip/dum/MasterProfile.hxx"
00006 #include "resip/dum/UserProfile.hxx"
00007 #include "resip/dum/PayloadEncrypter.hxx"
00008 #include "resip/dum/DumEncrypted.hxx"
00009 #include "resip/stack/PlainContents.hxx"
00010 #include "resip/stack/Pkcs7Contents.hxx"
00011 #include "resip/stack/MultipartSignedContents.hxx"
00012 #include "resip/stack/Mime.hxx"
00013 
00014 #include "resip/stack/SecurityAttributes.hxx"
00015 #include "resip/stack/Helper.hxx"
00016 
00017 #include "rutil/Log.hxx"
00018 #include "rutil/Logger.hxx"
00019 
00020 #ifdef WIN32
00021 #include "resip/stack/ssl/WinSecurity.hxx"
00022 #endif
00023 
00024 #include <iostream>
00025 #include <string>
00026 #include <sstream>
00027 
00028 using namespace std;
00029 using namespace resip;
00030 
00031 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
00032 
00033 
00034 
00035 /*****************************************************************************/
00036 
00037 class Tu : public TransactionUser
00038 {
00039    public:
00040       Tu(Security* security, const Data& sender, const Data& recip) 
00041          : mSecurity(security),
00042            mSender(sender),
00043            mRecip(recip)
00044       {
00045       }
00046 
00047       const Data& name() const
00048       {
00049          static Data name("Tu");
00050          return name;
00051       }
00052 
00053       bool process();
00054    private:
00055       Security* mSecurity;
00056       Data mSender;
00057       Data mRecip;
00058 };
00059 
00060 bool Tu::process()
00061 {
00062    if (mFifo.empty()) return false;
00063    DumEncrypted* encrypted = dynamic_cast<DumEncrypted*>(mFifo.getNext());
00064    if (encrypted->success())
00065    {
00066       /*Contents* contents = encrypted->encrypted()->clone();
00067       Data txt(
00068         "To: sip:fluffy@h1.cs.sipit.net\r\n"
00069         "From: tofu <sip:tofu@ua.ntt.sipit.net>;tag=5494179792598219348\r\n"
00070         "CSeq: 1 SUBSCRIBE\r\n"
00071         "Call-ID: 1129541551360711705\r\n"
00072         "Contact: sip:tofu@ua.ntt.sipit.net:5060\r\n"
00073         "Event: presence\r\n"
00074         "Content-Length: 0\r\n"
00075         "Expires: 3600\r\n"
00076         "User-Agent: NTT SecureSession User-Agent\r\n"
00077         "\r\n");
00078 
00079         SipMessage* msg = SipMessage::make(txt, false);
00080         msg->setContents(std::auto_ptr<Contents>(contents));
00081         Helper::ContentsSecAttrs csa(Helper::extractFromPkcs7(msg, *mSecurity));
00082         InfoLog( << "Body: " << *csa.mContents << "\n" );
00083         delete msg;
00084       */
00085       InfoLog(<<"Message has been successfully encrypted." << endl);
00086    }
00087    else
00088    {
00089       InfoLog(<<"Failed to encrypte message: " << encrypted->error() << endl);
00090    }
00091    delete encrypted;
00092    return true;
00093 }
00094 
00095 int main(int argc, char *argv[])
00096 {
00097 
00098    if ( argc < 3 ) {
00099      cout << "usage: " << argv[0] <<"sip:sender sip:recip" << endl;
00100      return 0;
00101    }
00102 
00103    Log::initialize(Log::Cout, Log::Debug, argv[0]);
00104 
00105    NameAddr senderAor(argv[1]);
00106    NameAddr recipAor(argv[2]);
00107    //Data passwd(argv[3]);
00108 
00109    InfoLog(<< "sender: " << senderAor << endl);
00110    InfoLog(<< "recipient: " << recipAor << endl);
00111 
00112 #ifdef WIN32
00113    Security* security = new WinSecurity;
00114 #else
00115    Security* security = new Security;
00116 #endif
00117 
00118    assert(security);
00119    SipStack stack(security);
00120    Tu tu(security, senderAor.uri().getAor(), recipAor.uri().getAor());
00121    BaseUsageHandle handle;
00122    PayloadEncrypter encrypter(tu, security);
00123 
00124    Contents* contents1 = new PlainContents(Data("message signing"));
00125    // sign the message
00126    encrypter.encrypt(std::auto_ptr<Contents>(contents1), senderAor.uri().getAor(), handle);
00127 
00128    Contents* contents2 = new PlainContents(Data("message signing and encrypting"));
00129    // sign and encrypt the message
00130    encrypter.encrypt(std::auto_ptr<Contents>(contents2), senderAor.uri().getAor(), recipAor.uri().getAor(), handle);
00131 
00132    while (tu.process())
00133    {
00134    }
00135 
00136 
00137    return 0;
00138 }
00139 
00140 /* ====================================================================
00141  * The Vovida Software License, Version 1.0 
00142  * 
00143  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00144  * 
00145  * Redistribution and use in source and binary forms, with or without
00146  * modification, are permitted provided that the following conditions
00147  * are met:
00148  * 
00149  * 1. Redistributions of source code must retain the above copyright
00150  *    notice, this list of conditions and the following disclaimer.
00151  * 
00152  * 2. Redistributions in binary form must reproduce the above copyright
00153  *    notice, this list of conditions and the following disclaimer in
00154  *    the documentation and/or other materials provided with the
00155  *    distribution.
00156  * 
00157  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00158  *    and "Vovida Open Communication Application Library (VOCAL)" must
00159  *    not be used to endorse or promote products derived from this
00160  *    software without prior written permission. For written
00161  *    permission, please contact vocal@vovida.org.
00162  *
00163  * 4. Products derived from this software may not be called "VOCAL", nor
00164  *    may "VOCAL" appear in their name, without prior written
00165  *    permission of Vovida Networks, Inc.
00166  * 
00167  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00168  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00169  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00170  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00171  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00172  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00173  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00174  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00175  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00176  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00177  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00178  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00179  * DAMAGE.
00180  * 
00181  * ====================================================================
00182  * 
00183  * This software consists of voluntary contributions made by Vovida
00184  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00185  * Inc.  For more information on Vovida Networks, Inc., please see
00186  * <http://www.vovida.org/>.
00187  *
00188  */