Ejemplo n.º 1
0
bool
SipRegistrar::isValidDomain(const Url& uri) const
{
   bool isValid = false;

   UtlString domain;
   uri.getHostAddress(domain);
   domain.toLower();

   int port = uri.getHostPort();
   if (port == PORT_NONE)
   {
      port = SIP_PORT;
   }
   char portNum[15];
   sprintf(portNum,"%d",port);

   domain.append(":");
   domain.append(portNum);

   if ( mValidDomains.contains(&domain) )
   {
      isValid = true;
      Os::Logger::instance().log(FAC_AUTH, PRI_DEBUG,
                    "SipRegistrar::isValidDomain(%s) VALID",
                    domain.data()) ;
   }
   return isValid;
}
Ejemplo n.º 2
0
// Pseudo factory
HttpBody* HttpBody::createBody(const char* bodyBytes_,
                               ssize_t bodyLength,
                               const char* contentType,
                               const char* contentEncoding)
{
    UtlString buff(bodyBytes_, bodyLength);
    const char* bodyBytes = buff.data();
    
    HttpBody* body = NULL;

    UtlString contentTypeString;
    if(contentType)
    {
        contentTypeString.append(contentType);
        contentTypeString.toLower();
    }
    if(contentType &&
       strcmp(contentTypeString.data(), SDP_CONTENT_TYPE) == 0)
    {
        body = new SdpBody(bodyBytes, bodyLength);
    }
    else if(contentType &&
            strcmp(contentTypeString.data(), CONTENT_SMIME_PKCS7) == 0)
    {
        body = new SmimeBody(bodyBytes, bodyLength, contentEncoding);
    }
    else if ((bodyLength  > 1) ||
             (bodyBytes[0] != '\n'))
    {
        body = new HttpBody(bodyBytes, bodyLength,
                            contentType);
    }

    return(body);
}
Ejemplo n.º 3
0
void HttpConnectionMap::getPersistentUriKey(const Url& url, UtlString& key)
{
    UtlString urlType;
    UtlString httpHost;
    UtlString httpPort;
    
    url.getUrlType(urlType);
    url.getHostAddress(httpHost);
    
    int tempPort = url.getHostPort();
    
    UtlString httpType = (url.getScheme() == Url::HttpsUrlScheme) ? "https" : "http";
    if (tempPort == PORT_NONE)
    {
        if (httpType == "https")
        {
            httpPort = "443";
        }
        else
        {
            httpPort = "80";
        }
    }
    else
    {
        char t[10];
        sprintf(t, "%d", tempPort);
        httpPort = t;
    }
    key = httpType + ":" + httpHost + ":" + httpPort;
    key.toLower();
}
Ejemplo n.º 4
0
void
SipRegistrar::addValidDomain(const UtlString& host, int port)
{
   UtlString* valid = new UtlString(host);
   valid->toLower();

   char explicitPort[20];
   sprintf(explicitPort,":%d", PORT_NONE==port ? SIP_PORT : port );
   valid->append(explicitPort);

   Os::Logger::instance().log(FAC_AUTH, PRI_DEBUG, "SipRegistrar::addValidDomain(%s)",valid->data()) ;

   mValidDomains.insert(valid);
}
Ejemplo n.º 5
0
/* Get the validated names for the connection peer.
 *
 * Usually, the names in the altNames will be easier to parse and use than commonName
 * Returns
 * - true if the connection peer is validated by a trusted authority
 * - false if not, in which case no names are returned.
 */
bool OsSSL::peerIdentity( SSL*       connection ///< SSL connection to be described
                         ,UtlSList*  altNames   /**< UtlStrings for verfied subjectAltNames
                                                 *   are added to this - caller must free them.
                                                 */
                         ,UtlString* commonName ///< the Subject name is returned here
                         )
{
   bool peerCertTrusted = false;

#  ifdef TEST_DEBUG
   UtlString debugMsg;
#  endif

   if (altNames)
   {
      altNames->destroyAll();
   }
   if (commonName)
   {
      commonName->remove(0);
   }

   if (connection)
   {
      // Extract the subject and issuer information about the peer
      // and the certificate validation result.  Neither of these
      // are meaningful without the other.
      //    (note various dynamically allocated items - freed below)
      X509* peer_cert = SSL_get_peer_certificate(connection);
      if (peer_cert)
      {
         if (X509_V_OK == SSL_get_verify_result(connection))
         {
            peerCertTrusted = true;

            char* subjectStr = X509_NAME_oneline(X509_get_subject_name(peer_cert),NULL,0);

            // @TODO this should also enforce any extendedKeyUsage limitations

#           ifdef TEST_DEBUG
            debugMsg.append("OsSSL::peerIdentity verified");
#           endif
            if (subjectStr)
            {
               // this should always be true, I think...
               if (commonName)
               {
                  commonName->append(subjectStr);
               }

#              ifdef TEST_DEBUG
               debugMsg.append(" '");
               debugMsg.append(subjectStr);
               debugMsg.append("'");
#              endif
               OPENSSL_free(subjectStr);
            }

            if (altNames)
            {
               // Look for the subjectAltName attributes
               GENERAL_NAMES* names;
               names = (GENERAL_NAMES*)X509_get_ext_d2i(peer_cert, NID_subject_alt_name, NULL, NULL);

               for(int i = 0; i < sk_GENERAL_NAME_num(names); i++)
               {
                  GENERAL_NAME*   name = sk_GENERAL_NAME_value(names, i);
                  ASN1_IA5STRING* nameValue;
                  UtlString*      normalizedName;

                  switch (name->type)
                  {
                  case GEN_DNS:
                  case GEN_URI:
                     nameValue = name->d.uniformResourceIdentifier;
                     normalizedName
                        = new UtlString((const char*)(nameValue->data),nameValue->length);
                     // @TODO: We should parse this value before adjusting the case,
                     //        but that requires doing it at a higher level in the stack
                     //        where we can parse a URL, and we don't yet have selection
                     //        based on type anyway.
                     normalizedName->toLower();
#                    ifdef TEST_DEBUG
                     debugMsg.append(" '");
                     debugMsg.append(*normalizedName);
                     debugMsg.append("'");
#                    endif
                     altNames->append(normalizedName);
                     break;

                  default:
                     // don't care about any other values
                     break;
                  }
               }
               sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
            }
#           ifdef TEST_DEBUG
            OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "%s", debugMsg.data());
#           endif
         }
         else
         {
            OsSysLog::add(FAC_KERNEL, PRI_ERR, "OsSSL::peerIdentity peer not validated");
         }

         X509_free(peer_cert);
      }
      else
      {
         OsSysLog::add(FAC_KERNEL, PRI_WARNING, "OsSSL::peerIdentity no peer certificate");
      }
   }
   else
   {
      OsSysLog::add(FAC_KERNEL, PRI_CRIT, "OsSSL::peerIdentity called with NULL connection");
   }

   return peerCertTrusted;
}
Ejemplo n.º 6
0
UtlBoolean 
DialByNameDB::getDigitStrings (
    const UtlString& displayName, 
    UtlSList& rDTMFStrings ) const
{
    UtlString lowerString = displayName;
    lowerString.toLower();
    lowerString = lowerString.strip(UtlString::both, '"');
    UtlTokenizer next( lowerString );
    UtlString token;
    UtlSList names;

    // Parse the Display name into a list of names
    // The algorithm for breaking up the string is as follows
    // if the string has > 2 tokens (forget about , separators)
    // create multiple entries in the IMDB for the all combinations
    // so for example
    // John Peter Smith Jr would result in DTMF entries for
    // PeterSmithJrJohn, SmithJrJohnPeter and JrJohnPeterSmith
    // @JC Added - separator for MIT's Avery-Smith example
   
    while (next.next(token, "\t\n,- ")) 
    {
        names.insert ( new UtlString ( token ) );
    }

    size_t numNames = names.entries();

    if ( numNames > 0 ) 
    {
        UtlString reorderedString;
        unsigned int splitPosition = 1;
        do 
        {
            unsigned int i;
            UtlString firstNames;
            for ( i=0; i<splitPosition; i++ ) 
            {
                firstNames += *(UtlString*)names.at(i);
            }

            UtlString lastNames;
            for ( i = splitPosition; i<numNames; i++) 
            {
                lastNames += *(UtlString*)names.at(i);
            }

            // add the new string
            reorderedString = lastNames + firstNames;

            unsigned int len = reorderedString.length();
            
            // calculate thd DTMF digits for the display name
            // firstly strip all , 's and spaces
            UtlString digitString;
            for ( i = 0; i<len; i++ )
            {
                int offset = (int) ( reorderedString(i) - 'a' );
                // filter out white space and comma separators
                if ( (offset >= 0) && (offset < 26) )
                    digitString += digitmap[ offset ];
            }

            rDTMFStrings.insert ( new UtlString (digitString) );

            splitPosition++;
        } while ( splitPosition<numNames );
    }

    // call the desctuctors on all the temp strings
    names.destroyAll();
    return TRUE;
}
Ejemplo n.º 7
0
//
// The main entry point to the sipXpark
//
int main(int argc, char* argv[])
{
   // Configuration Database (used for OsSysLog)
   OsConfigDb configDb;

   // Register Signal handlers so we can perform graceful shutdown
   pt_signal(SIGINT,   sigHandler);    // Trap Ctrl-C on NT
   pt_signal(SIGILL,   sigHandler);
   pt_signal(SIGABRT,  sigHandler);    // Abort signal 6
   pt_signal(SIGFPE,   sigHandler);    // Floading Point Exception
   pt_signal(SIGSEGV,  sigHandler);    // Address access violations signal 11
   pt_signal(SIGTERM,  sigHandler);    // Trap kill -15 on UNIX
#if defined(__pingtel_on_posix__)
   pt_signal(SIGHUP,   sigHandler);    // Hangup
   pt_signal(SIGQUIT,  sigHandler);
   pt_signal(SIGPIPE,  SIG_IGN);    // Handle TCP Failure
   pt_signal(SIGBUS,   sigHandler);
   pt_signal(SIGSYS,   sigHandler);
   pt_signal(SIGXCPU,  sigHandler);
   pt_signal(SIGXFSZ,  sigHandler);
   pt_signal(SIGUSR1,  sigHandler);
   pt_signal(SIGUSR2,  sigHandler);
#endif

   UtlString argString;
   for(int argIndex = 1; argIndex < argc; argIndex++)
   {
      osPrintf("arg[%d]: %s\n", argIndex, argv[argIndex]);
      argString = argv[argIndex];
      NameValueTokenizer::frontBackTrim(&argString, "\t ");
      if(argString.compareTo("-v") == 0)
      {
         osPrintf("Version: %s (%s)\n", SIPXCHANGE_VERSION, SIPXCHANGE_VERSION_COMMENT);
         return(1);
      }
      else
      {
         osPrintf("usage: %s [-v]\nwhere:\n -v provides the software version\n",
         argv[0]);
         return(1);
      }
   }

   // Load configuration file file
   OsPath workingDirectory;
   if (OsFileSystem::exists(CONFIG_ETC_DIR))
   {
      workingDirectory = CONFIG_ETC_DIR;
      OsPath path(workingDirectory);
      path.getNativePath(workingDirectory);
   }
   else
   {
      OsPath path;
      OsFileSystem::getWorkingDirectory(path);
      path.getNativePath(workingDirectory);
   }

   UtlString fileName =  workingDirectory +
                         OsPathBase::separator +
                         CONFIG_SETTINGS_FILE;

   if (configDb.loadFromFile(fileName) != OS_SUCCESS)
   {
      exit(1);
   }

   // Initialize log file
   initSysLog(&configDb);

   // Read the user agent parameters from the config file.
   int UdpPort;
   if (configDb.get(CONFIG_SETTING_UDP_PORT, UdpPort) != OS_SUCCESS)
   {
      UdpPort = PRESENCE_DEFAULT_UDP_PORT;
   }

   int TcpPort;
   if (configDb.get(CONFIG_SETTING_TCP_PORT, TcpPort) != OS_SUCCESS)
   {
      TcpPort = PRESENCE_DEFAULT_TCP_PORT;
   }

   UtlString bindIp;
   if (configDb.get(CONFIG_SETTING_BIND_IP, bindIp) != OS_SUCCESS ||
         !OsSocket::isIp4Address(bindIp))
   {
      bindIp = PRESENCE_DEFAULT_BIND_IP;
   }

   // Bind the SIP user agent to a port and start it up
   SipUserAgent* userAgent = new SipUserAgent(TcpPort, UdpPort, PORT_NONE,
         NULL, NULL, bindIp );
   userAgent->start();

   if (!userAgent->isOk())
   {
      OsSysLog::add(LOG_FACILITY, PRI_EMERG, "SipUserAgent failed to initialize; requesting shutdown");
      gShutdownFlag = TRUE;
   }

   UtlString domainName;
   configDb.get(CONFIG_SETTING_DOMAIN_NAME, domainName);
   // Normalize SIP domain name to all lower case.
   domainName.toLower();

   // Create the SipPersistentSubscriptionMgr.
   SipPersistentSubscriptionMgr subscriptionMgr(SUBSCRIPTION_COMPONENT_PRESENCE,
                                                domainName);

   // Determine the name of the persistent file.
   UtlString pathName = SipXecsService::Path(SipXecsService::VarDirType,
                                             sPersistentFileName.data());

   // Create the Sip Presence Monitor, which handles all of the processing.
   SipPresenceMonitor presenceMonitor(userAgent,
                                      &subscriptionMgr,
                                      domainName,
                                      TcpPort,
                                      &configDb,
                                      true,
                                      pathName.data());

   // Loop forever until signaled to shut down
   while (!gShutdownFlag)
   {
      OsTask::delay(2000);
   }

   // Shut down the sipUserAgent
   userAgent->shutdown(FALSE);

   while(!userAgent->isShutdownDone())
   {
      ;
   }

   delete userAgent;

   // Flush the log file
   OsSysLog::flush();

   // Say goodnight Gracie...
   return 0;
}
Ejemplo n.º 8
0
UtlBoolean SipConfigServerAgent::handleMessage(OsMsg& eventMessage)
{

        osPrintf("---> SipConfigServerAgent: handleMessage...\r\n") ;

    int msgType = eventMessage.getMsgType();
    int msgSubType = eventMessage.getMsgSubType();

    // if this is a SIP message
    if(msgType == OsMsg::PHONE_APP &&
                msgSubType == SipMessage::NET_SIP_MESSAGE)
        {
                const SipMessage* sipMessage = ((SipMessageEvent&)eventMessage).getMessage();
                int messageType = ((SipMessageEvent&)eventMessage).getMessageStatus();
                osPrintf("SipConfigServerAgent::messageType: %d\n", messageType);
        UtlString method;

        // This is a request which failed to get sent
                if(messageType == SipMessageEvent::TRANSPORT_ERROR)
                {
            sipMessage->getRequestMethod(&method);
            osPrintf("SipConfigServerAgent:: Processing message transport error method: %s\n",
                sipMessage->isResponse() ? method.data() : "response");

            if(sipMessage->isResponse())
            {
                int seqNum;
                sipMessage->getCSeqField(&seqNum, &method);
                // SUBSCIBE (enrollment) response
                if(method.compareTo(SIP_SUBSCRIBE_METHOD))
                {
                    // We are sad the device is not there
                    osPrintf("SipConfigServerAgent::handleMessage enroll FAILURE: no response\n");
                }

            }
        }

        else if(messageType == SipMessageEvent::AUTHENTICATION_RETRY)
        {
        }

        // If this is a response
        else if(sipMessage->isResponse())
        {
            int seqNum;
            sipMessage->getCSeqField(&seqNum, &method);
            // SUBSCIBE (enrollment) response
            if(method.compareTo(SIP_NOTIFY_METHOD) &&
                mfpNotifyResponseCallbackFunc)
            {
                mfpNotifyResponseCallbackFunc(*sipMessage);
            }

        }

        // This is a request
        else
        {
            sipMessage->getRequestMethod(&method);
            UtlString eventType;
            sipMessage->getEventField(eventType);
            eventType.toLower();
            // SUBSRIBE (enrollment) request
            if(method.compareTo(SIP_SUBSCRIBE_METHOD) == 0 &&
                eventType.index(SIP_EVENT_CONFIG) >= 0 &&
                mfpEnrollmentCallbackFunc)
            {
               SipMessage response;
               SipMessage copyOfRequest(*sipMessage);

               // add a to tag to the sip message. This to tag will
               // be bubbled up to the Java layer. Also the same to tag will
               // be sent back in the response
               UtlString toAddr;
               UtlString toProto;
               int toPort;
               UtlString toTag;
               sipMessage->getToAddress(&toAddr, &toPort, &toProto, NULL, NULL, &toTag);
               if( toTag.isNull())
               {
                  int epochTime = (int)OsDateTime::getSecsSinceEpoch();
                  // Build a to tag
                  char tagBuffer[100];
                  sprintf(tagBuffer, "%dasd", epochTime);
                  copyOfRequest.setToFieldTag(tagBuffer);
               }

                int responseCode = mfpEnrollmentCallbackFunc(copyOfRequest);
                switch(responseCode)
                {
                    case SIP_ACCEPTED_CODE:
                       {
                          response.setExpiresField(DEFAULT_EXPIRES);
                          response.setResponseData(&copyOfRequest, SIP_ACCEPTED_CODE,
                            SIP_ACCEPTED_TEXT);
                       }
                        break;

                    default:
                        response.setResponseData(&copyOfRequest, SIP_BAD_REQUEST_CODE,
                            SIP_BAD_REQUEST_TEXT);
                        break;

                }
                if(mpSipUserAgent) mpSipUserAgent->send(response);
            }
        }
    }

    return(TRUE);
}
Ejemplo n.º 9
0
OsStatus
DepositCGI::execute(UtlString* out)
{
   // Contains the dynamically generated VXML script.
   UtlString dynamicVxml = getVXMLHeader() + "<form> ";

   // Get the base URL of the mediaserver - "http://*****:*****@' ) != UTL_NOT_FOUND )
            {
               useridOrExtension =
                  useridOrExtension(0, useridOrExtension.first( '@' ));
            }
         }
         useridOrExtension.toLower();
         dynamicVxml +=
            "<var name=\"msgurl\" expr=\"'" + useridOrExtension + "'\" />\n" \
            "<var name=\"msgurltype\" expr=\"'alphanumeric'\"/>\n";
      }

      // If mailboxpath/savemessage.vxml exists, use it, otherwise use the 
      // generic version
      UtlString src ;
      UtlString vxmlScript ;
      pMailboxManager->getMailboxPath(m_mailboxIdentity, vxmlScript);
      vxmlScript += OsPath::separator + "savemessage.vxml" ;
      if (OsFileSystem::exists(vxmlScript))
      {
         // use the user specific one 
         pMailboxManager->getMailboxURL(m_mailboxIdentity, src, false);
         src += "/savemessage.vxml" ;
         OsSysLog::add(FAC_MEDIASERVER_CGI, PRI_DEBUG,
                 "DepositCGI::execute: using user specific vxml script %s",
                 src.data()) ;
      }
      else
      {
         // use the generic one
         src =  mediaserverUrl + "/vm_vxml/savemessage.vxml" ;
         OsSysLog::add(FAC_MEDIASERVER_CGI, PRI_DEBUG,
                 "DepositCGI::execute: using generic vxml script %s",
                 src.data()) ;
      }

      // Be careful here as the the vxmlFriendlyFrom will be sent back to us again
      UtlString vxmlFriendlyFrom = m_from.toString();
      MailboxManager::convertUrlStringToXML( vxmlFriendlyFrom );
      // HttpMessage::escape( vxmlFriendlyFrom );

      dynamicVxml +=
         "<subdialog name=\"send_msg\" src=\"" + src + "\">\n" +
         "<param name=\"called_by\" value=\"incoming\"/>\n" \
         "<param name=\"mailbox\" value=\"" + m_mailboxIdentity + "\"/>\n" \
         "<param name=\"from\" value=\"" + vxmlFriendlyFrom + "\"/>\n" \
         "<param name=\"msgurl\" expr=\"msgurl\" />\n" \
         "<param name=\"msgurltype\" expr=\"msgurltype\" />\n" \
         "<param name=\"mediaserverurl\" expr=\"'" + ivrPromptUrl + "'\"/>\n" \
         "<param name=\"securemediaserverurl\" expr=\"'" + secureMediaserverUrl + "'\"/>\n" \
         "</subdialog>";
   } else
   {
      dynamicVxml +=    "<subdialog src=\"" + mediaserverUrl + "/vm_vxml/error_handler.vxml\" >\n" \
         "<param name=\"errortype\" expr=\"'invalidextn'\" />\n" \
         "<param name=\"mediaserverurl\" expr=\"'" + ivrPromptUrl + "'\" />\n" \
         "<param name=\"securemediaserverurl\" expr=\"'" + secureMediaserverUrl + "'\"/>\n" \
         "</subdialog>\n";
   }

   dynamicVxml += "</form>" + UtlString( VXML_END );

   // Write out the dynamic VXML script to be processed by OpenVXI
   if (out)
   {
      out->remove(0);
      UtlString responseHeaders;
      MailboxManager::getResponseHeaders(dynamicVxml.length(), responseHeaders);

      out->append(responseHeaders.data());
      out->append(dynamicVxml.data());
   }

   return OS_SUCCESS;
}