Esempio n. 1
0
 private string URIanalysis(string sipURI) {
   string ForwardUrl = "";
   try {
     if (sipURI.StartsWith("+")) {
       ReloadConfigResolve res = new ReloadConfigResolve(myManager.m_ReloadConfig);
       ForwardUrl = res.ResolveNaptr(sipURI);
       if (ForwardUrl == null) {
         myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, "DNS Enum fallback to sip uri analysis");
         ForwardUrl = sipURI;
         ForwardUrl = ForwardUrl.TrimStart(' ');
         ForwardUrl = ForwardUrl.Replace(" ", "");
         ForwardUrl = "sip:" + ForwardUrl + "@" + myManager.m_ReloadConfig.OverlayName;
       }
     }
     else if (sipURI.StartsWith("sip:")) {
       ForwardUrl = sipURI;
     }
     else {
       throw new ArgumentException("Unsupported URI format! Must start with, e.g., +49 or sip:");
     }
   }
   catch (Exception e) {
     myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, e.Message);
   }
   return ForwardUrl;
 }
Esempio n. 2
0
    public bool Init() {

      try {
        if (ReloadGlobals.IgnoreSSLErrors)
          IgnoreSSLErrors();

        m_transport = new MessageTransport();

        if (ReloadGlobals.TLS)
          m_interface_flm = new ReloadFLM(ReloadConfig);
        else
          m_interface_flm = new SimpleFLM(ReloadConfig);

        ReloadConfig.Statistics.SetParams(m_interface_flm);
        m_interface_flm.ReloadFLMEventHandler += 
          new ReloadFLMEvent(m_transport.rfm_ReloadFLMEventHandler);

        ReloadConfig.State = ReloadConfig.RELOAD_State.Init;
        stateUpdates(ReloadConfig.RELOAD_State.Init);

        ReloadConfigResolve resolve = new ReloadConfigResolve(ReloadConfig);

        resolve.ReadConfig();
        if (ReloadGlobals.TLS)
          resolve.EnrollmentProcedure();
        else
          resolve.SimpleNodeIdRequest();

        m_interface_flm.Init();
        m_ReloadConfig.AccessController = new AccessController(m_ReloadConfig);
        m_topology = new TopologyPlugin(this);
        if (!m_topology.Init(this))
          return false;

        m_forwarding = new ForwardingLayer(this);
        m_transport.Init(this);

        //ReloadConfig.State = ReloadConfig.RELOAD_State.Configured;
        //stateUpdates(ReloadConfig.RELOAD_State.Configured);
        BootStrapConfig();

        m_ReloadConfig.StartJoining = DateTime.Now;
        if (m_ReloadConfig.IamClient)
          m_ReloadConfig.StartJoinMobile = DateTime2.Now;
        if (!ReloadConfig.IsBootstrap)
          Arbiter.Activate(ReloadConfig.DispatcherQueue, 
            new IterativeTask<List<BootstrapServer>>(m_BootstrapServerList,
            m_transport.PreJoinProdecure));

//        m_worker_thread.ReportProgress(100); --joscha
        InitUsageManager();
        ReloadConfig.State = ReloadConfig.RELOAD_State.Configured;
        stateUpdates(ReloadConfig.RELOAD_State.Configured);

        /* reporting service */
        Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask(Reporting));
        /* chord-ping-interval */
        Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask(Maintenance));
        /* chord-update-interval */
        Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask(UpdateCycle));
        Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask(CommandCheckTask));
      }
      catch (Exception ex) {
        ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "Init: " + ex.Message);
      }
      return true;
    }
Esempio n. 3
0
    public void GatherCommandsInQueue(string command, Usage_Code_Point codePoint, int type, NodeId viaGateway, bool CommandFinished = false, params object[] arguments)  //TODO: combine to one single method
    {
      IUsage usage = null;
      StoredDataSpecifier specifier = null;

      if (command.Equals("Store"))
      {
			StoreKindData kindData;
			usage = m_UsageManager.CreateUsage(codePoint, type, arguments);
			//foreach (UInt32 kindId in usage.Kinds)    TODO:
			{
                //kindData = new StoreKindData(kindId, 0, new StoredData(usage.Encapsulate(kindId, true)));
                kindData = new StoreKindData(usage.KindId, 0, new StoredData(usage.Encapsulate(true)));
				gatheredStoreDatas.Add(kindData);
				//m_ReloadConfig.GatheringList.Add(kindData);
			}
			if (CommandFinished == true)
			{
				if (viaGateway != null)
					storeViaGateway.Add(gatheredStoreDatas, viaGateway);
				gatheredStoreDatasQueue.Post(gatheredStoreDatas);
				gatheredStoreDatas = new List<StoreKindData>();
			}
		}
		if (command.Equals("Fetch"))
		{
            //UInt32[] kinds = UsageManager.CreateUsage(codePoint, null, null).Kinds; TODO: cleanup
            UInt32 kind = UsageManager.CreateUsage(codePoint, null, null).KindId;
			// To further garantee SIP Usage with Telefonenumbers
			if (codePoint == Usage_Code_Point.SIP_REGISTRATION && arguments[0].ToString().StartsWith("+"))
			{
				string FetchUrl = "";
				ReloadConfigResolve res = new ReloadConfigResolve(m_ReloadConfig);
                FetchUrl = res.ResolveNaptr(arguments[0].ToString());
				if (FetchUrl == null)
				{
					ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, "DNS Enum fallback to sip uri analysis");
                    FetchUrl = arguments[0].ToString();
					FetchUrl = FetchUrl.TrimStart(' ');
					FetchUrl = FetchUrl.Replace(" ", "");
          FetchUrl = "sip:" + FetchUrl + "@" + m_ReloadConfig.OverlayName;
					arguments[0] = FetchUrl;
				}
			}
            //foreach (UInt32 kindId in kinds)      TODO: cleanup
			{
                specifier = m_UsageManager.createSpecifier(kind, arguments);
				gatheredSpecifiers.Add(specifier);
			}
			if (CommandFinished == true)
			{
				if (viaGateway != null)
					fetchViaGateway.Add(gatheredSpecifiers, viaGateway);
				gatheredSpecifiersQueue.Post(gatheredSpecifiers);
				gatheredSpecifiers = new List<StoredDataSpecifier>();
			}
			
		}     
	}
Esempio n. 4
0
 /// <summary>
 /// This method gathers all Kinds that will be sent withon one single request.
 /// @precondition: The storing data MUST have the same Resource Name.
 /// @precondition: The the command MUST be the same. (e.g., ONLY store | fetch)
 /// </summary>
 /// <param name="command">Store | Fetch</param>
 /// <param name="codePoint">The Identifier for the Usage to be performed</param>
 /// <param name="type">Some Usages define differents types (see sip usage). Place here that value in Usage spec.</param>
 /// <param name="arguments">argument[0] Resource Name
 /// 
 ///                         If SIP Registration: args[1] = uri | contact prefs
 ///                         If DisCo Registration: args[1] TODO
 ///                         If Access List: args[1] = kinId
 ///                                         args[2] = from_user
 ///                                         args[3] = to_user
 ///                                         args[4] = allow_delegation</param>
 public void GatherCommands(string command, Usage_Code_Point codePoint,
     int type, params object[] arguments) {
   IUsage usage = null;
   StoredDataSpecifier specifier = null;
   /* Check  plausibility of user commands */
   if (m_ReloadConfig.CommandQueuePort.ItemCount > 0 &&
      command != (string)m_ReloadConfig.CommandQueuePort.Test()) {
     throw new ArgumentException(String.Format(
         "Your command {0} is not the same as previews command {1}.",
         command,
         (string)m_ReloadConfig.CommandQueuePort.Test()));
   }
   /* Process store command */
   if (command.Equals("Store")) {
     StoreKindData kindData;
     usage = m_UsageManager.CreateUsage(codePoint, type, arguments);
     kindData = new StoreKindData(usage.KindId,
                                  0, // mok! TODO generation management
                                  new StoredData(usage.Encapsulate(true)));
     gatheredStoreDatas.Add(kindData);
   }
   /* Process fetch command */
   if (command.Equals("Fetch")) {
     string[] str_arguments = arguments.Select(item => (string)item).ToArray();
     UInt32 kind = UsageManager.CreateUsage(codePoint, null, null).KindId;
     // To further garantee SIP Usage with Telefonenumbers
     if (codePoint == Usage_Code_Point.SIP_REGISTRATION &&
         str_arguments[0].StartsWith("+")) {
       string FetchUrl = "";
       ReloadConfigResolve res = new ReloadConfigResolve(m_ReloadConfig);          
       FetchUrl = res.ResolveNaptr(str_arguments[0]);
       if (FetchUrl == null) {
         ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING,
           "DNS Enum fallback to sip uri analysis");
         FetchUrl = str_arguments[0];
         FetchUrl = FetchUrl.TrimStart(' ');
         FetchUrl = FetchUrl.Replace(" ", "");
         FetchUrl = "sip:" + FetchUrl + "@" + m_ReloadConfig.OverlayName;
       }
       arguments[0] = FetchUrl;
     }
     specifier = m_UsageManager.createSpecifier(kind, str_arguments);
     gatheredSpecifiers.Add(specifier);
   }
 }
Esempio n. 5
0
    public void SimpleNodeIdRequest() {
      try {

        if (EnrollmentserverAvailable) {
          HttpWebRequest httpWebPost;

          /* get node id */
          if (m_ReloadConfig.IMSI != null && m_ReloadConfig.IMSI != "")
            httpWebPost = (HttpWebRequest)WebRequest.Create(new Uri(EnrollmentUrl + "?type=imsi&IMSI=" + m_ReloadConfig.IMSI));
          else
            httpWebPost = (HttpWebRequest)WebRequest.Create(new Uri(EnrollmentUrl + "?type=vnode"));

          /* As of RELOAD draft, use POST */
          httpWebPost.Method = "POST";

#if !WINDOWS_PHONE
          // Additional HttpWebRequest parameters are not supported
          httpWebPost.Timeout = ReloadGlobals.WEB_REQUEST_TIMEOUT;
#endif

          HttpWebResponse httpPostResponse = null;
          //Send Web-Request and receive a Web-Response
          httpPostResponse = (HttpWebResponse)httpWebPost.GetResponse();
          //Translate data from the Web-Response to a string
          Stream dataStream2 = httpPostResponse.GetResponseStream();

          TextReader tr_xml2 = new StreamReader(dataStream2, Encoding.UTF8);
          string response = tr_xml2.ReadToEnd();

          string[] words = response.Split(':', ',', '/', '@');

          if (m_ReloadConfig.IMSI != null && m_ReloadConfig.IMSI != "") {
            m_ReloadConfig.E64_Number = words[1];

            ReloadConfigResolve res = new ReloadConfigResolve(m_ReloadConfig);
            m_ReloadConfig.SipUri = res.ResolveNaptr(m_ReloadConfig.E64_Number);

            if (m_ReloadConfig.SipUri == null) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, "DNS Enum fallback to sip uri analysis");
              m_ReloadConfig.SipUri = m_ReloadConfig.E64_Number;
              m_ReloadConfig.SipUri = m_ReloadConfig.SipUri.TrimStart(' ');
              m_ReloadConfig.SipUri = m_ReloadConfig.SipUri.Replace(" ", "");
              m_ReloadConfig.SipUri = m_ReloadConfig.SipUri + "@" + m_ReloadConfig.OverlayName;
            }

            m_ReloadConfig.LocalNodeID = new NodeId(HexStringConverter.ToByteArray(words[7]));

            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, String.Format("Enrollment Server assigned: NodeId = '{0}' SipUri = '{1}' ", m_ReloadConfig.LocalNodeID, m_ReloadConfig.SipUri));
          }
          else {
            m_ReloadConfig.LocalNodeID = new NodeId(HexStringConverter.ToByteArray(words[4]));
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, String.Format("Enrollment Server assigned: NodeId = '{0}'", m_ReloadConfig.LocalNodeID));
          }
        }
      }
      catch (Exception ex) {
        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "SimpleNodeIdRequest: " + ex.Message);
      }
    }
Esempio n. 6
0
    public TextReader GetConfigDocument() {
      TextReader tr_xml = null;

      if (!ReloadGlobals.ForceLocalConfig) {
        /* load static settings of enrollment server, in this case dynamic resolution is skipped */
        configuration_url = ReloadGlobals.ConfigurationServer;

        /* Determine Configuration server */
        if (configuration_url == "" || configuration_url == null) {
          int iRetries = 3;

          for (int i = 0; i < iRetries; i++) {
            configuration_url = new ReloadConfigResolve(m_ReloadConfig).ResolveConfigurationServer(m_ReloadConfig.OverlayName);

            if (configuration_url != null) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TLS, String.Format("Configuration server URL as of DNS SRV: '{0}'", configuration_url));
              break;
            }
          }
        }

        HttpWebResponse httpWebesponse = null;

        if (configuration_url == null) {
          configuration_url = String.Format("https://{0}/.well-known/p2psip-enroll", m_ReloadConfig.OverlayName);
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, String.Format("DNS SRV failed, set configuration server URL to {0}.", configuration_url));
        }

        try {
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Calling configuration server: {0}", configuration_url));
          //Create a Web-Request to an URL

          // HTTPS is required as specified in draft-ietf-p2psip-base-26 section 3.6.1

          HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(configuration_url);

#if !WINDOWS_PHONE
          // Additional HttpWebRequest parameters are not supported
          httpWebRequest.Timeout = ReloadGlobals.WEB_REQUEST_TIMEOUT;

          // SSL is also not supported

          if (ReloadGlobals.IgnoreSSLErrors)
            httpWebRequest.AuthenticationLevel = AuthenticationLevel.None;

          // Test for MITM Attacks!
          //if (m_ReloadConfig.DontCheckSSLCert)
          //  ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(OnCheckSSLCert);
#endif

          //Send Web-Request and receive a Web-Response
          httpWebesponse = (HttpWebResponse)httpWebRequest.GetResponse();

          m_fEnrollmentserverAvailable = true;
        }
        catch (WebException ex) {
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "Configuration server not available: " + ex.Message + "using local configuration");
        }

        //Translate data from the Web-Response to a string
        if (m_fEnrollmentserverAvailable) {
          Stream dataStream = httpWebesponse.GetResponseStream();
          tr_xml = new StreamReader(dataStream, Encoding.UTF8);
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, "Successfully downloaded Configuration document");
        }
      }

      // if Configuration file retrieval failed, then read from local file
      if (tr_xml == null) {
#if COMPACT_FRAMEWORK
                // Check for OsVersion to remove URI prefix if it is not WindowsCE.
                string basex = Assembly.GetExecutingAssembly().GetName().CodeBase.ToString();
                string applicationDirectory = Path.GetDirectoryName(basex);
                tr_xml = new StreamReader(applicationDirectory + @"\\reload_enroll_config.xml");
#else
        //tr_xml = new StreamReader(@"reload_enroll_config.xml");
          tr_xml = new StreamReader(@"..\..\config\config-reload-selfsigned.xml");
#endif
      }

      return tr_xml;
    }