|
reSIProcate/stack
9694
|
00001 00002 00003 #include "resip/stack/BasicNonceHelper.hxx" 00004 #include "rutil/Logger.hxx" 00005 #include "rutil/ParseBuffer.hxx" 00006 #include "rutil/Random.hxx" 00007 00008 using namespace resip; 00009 00010 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP 00011 00012 00025 BasicNonceHelper::BasicNonceHelper() 00026 { 00027 //privateKey = Data("asdfklsadflkj"); 00028 privateKey = Random::getRandomHex(24); 00029 } 00030 00031 BasicNonceHelper::~BasicNonceHelper() 00032 { 00033 } 00034 00035 void 00036 BasicNonceHelper::setPrivateKey(const Data& pprivateKey) 00037 { 00038 this->privateKey = pprivateKey; 00039 } 00040 00041 Data 00042 BasicNonceHelper::makeNonce(const SipMessage& request, const Data& timestamp) 00043 { 00044 Data nonce(100, Data::Preallocate); 00045 nonce += timestamp; 00046 nonce += Symbols::COLON; 00047 Data noncePrivate(100, Data::Preallocate); 00048 noncePrivate += timestamp; 00049 noncePrivate += Symbols::COLON; 00050 // !jf! don't include the Call-Id since it might not be the same. 00051 // noncePrivate += request.header(h_CallId).value(); 00052 noncePrivate += request.header(h_From).uri().user(); 00053 noncePrivate += privateKey; 00054 nonce += noncePrivate.md5(); 00055 return nonce; 00056 } 00057 00058 NonceHelper::Nonce 00059 BasicNonceHelper::parseNonce(const Data& nonce) 00060 { 00061 ParseBuffer pb(nonce.data(), nonce.size()); 00062 if (!pb.eof() && !isdigit(*pb.position())) 00063 { 00064 DebugLog(<< "Invalid nonce; expected timestamp."); 00065 return BasicNonceHelper::Nonce(0); 00066 } 00067 const char* anchor = pb.position(); 00068 pb.skipToChar(Symbols::COLON[0]); 00069 if (pb.eof()) 00070 { 00071 DebugLog(<< "Invalid nonce; expected timestamp terminator."); 00072 return BasicNonceHelper::Nonce(0); 00073 } 00074 Data creationTime; 00075 pb.data(creationTime, anchor); 00076 return BasicNonceHelper::Nonce(creationTime.convertUInt64()); 00077 } 00078 00079 00080 /* ==================================================================== 00081 * The Vovida Software License, Version 1.0 00082 * 00083 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00084 * 00085 * Redistribution and use in source and binary forms, with or without 00086 * modification, are permitted provided that the following conditions 00087 * are met: 00088 * 00089 * 1. Redistributions of source code must retain the above copyright 00090 * notice, this list of conditions and the following disclaimer. 00091 * 00092 * 2. Redistributions in binary form must reproduce the above copyright 00093 * notice, this list of conditions and the following disclaimer in 00094 * the documentation and/or other materials provided with the 00095 * distribution. 00096 * 00097 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00098 * and "Vovida Open Communication Application Library (VOCAL)" must 00099 * not be used to endorse or promote products derived from this 00100 * software without prior written permission. For written 00101 * permission, please contact vocal@vovida.org. 00102 * 00103 * 4. Products derived from this software may not be called "VOCAL", nor 00104 * may "VOCAL" appear in their name, without prior written 00105 * permission of Vovida Networks, Inc. 00106 * 00107 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00108 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00109 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00110 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00111 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00112 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00113 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00114 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00115 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00116 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00117 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00118 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00119 * DAMAGE. 00120 * 00121 * ==================================================================== 00122 * 00123 * This software consists of voluntary contributions made by Vovida 00124 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00125 * Inc. For more information on Vovida Networks, Inc., please see 00126 * <http://www.vovida.org/>. 00127 * 00128 */ 00129
1.7.5.1