Beispiel #1
0
static int stun_new_transaction_id(char *tid) {
   time_t now;
   /* OSIP MD5 hash lenght is 16 bytes (32 hex digits),
    * so this does fit for STUN transaction ID... */
   osip_MD5_CTX Md5Ctx;
   HASH HA1;

   time(&now);

   /* calc MD5 from servername + timestamp */
   osip_MD5Init(&Md5Ctx);
   if (plugin_cfg.server) osip_MD5Update(&Md5Ctx, 
                                         (unsigned char*)plugin_cfg.server,
                                         strlen(plugin_cfg.server));
   osip_MD5Update(&Md5Ctx, (unsigned char*)&now, sizeof(now));
   osip_MD5Final(HA1, &Md5Ctx);

   memcpy(tid, HA1, (STUN_TID_SIZE<HASHLEN)? STUN_TID_SIZE:HASHLEN);

   return STS_SUCCESS;
}
Beispiel #2
0
int
eXosip_reg_init(eXosip_reg_t ** jr, const char *from, const char *proxy,
				const char *contact)
{
	static int r_id = 0;

	*jr = (eXosip_reg_t *) osip_malloc(sizeof(eXosip_reg_t));
	if (*jr == NULL)
		return OSIP_NOMEM;

	if (r_id == 32767)			/* keep it non-negative */
		r_id = 0;

	memset(*jr, '\0', sizeof(eXosip_reg_t));

	(*jr)->r_id = ++r_id;
	(*jr)->r_reg_period = 3600;	/* delay between registration */
	(*jr)->r_aor = osip_strdup(from);	/* sip identity */
	if ((*jr)->r_aor == NULL) {
		osip_free(*jr);
		*jr = NULL;
		return OSIP_NOMEM;
	}
	(*jr)->r_contact = osip_strdup(contact);	/* sip identity */
	(*jr)->r_registrar = osip_strdup(proxy);	/* registrar */
	if ((*jr)->r_registrar == NULL) {
		osip_free((*jr)->r_contact);
		osip_free((*jr)->r_aor);
		osip_free(*jr);
		*jr = NULL;
		return OSIP_NOMEM;
	}

	{
		osip_MD5_CTX Md5Ctx;
		HASH hval;
		HASHHEX key_line;
		char localip[128];
		char firewall_ip[65];
		char firewall_port[10];

		memset(localip, '\0', sizeof(localip));
		memset(firewall_ip, '\0', sizeof(firewall_ip));
		memset(firewall_port, '\0', sizeof(firewall_port));

		eXosip_guess_localip(AF_INET, localip, 128);
		if (eXosip.eXtl != NULL && eXosip.eXtl->tl_get_masquerade_contact != NULL) {
			eXosip.eXtl->tl_get_masquerade_contact(firewall_ip,
												   sizeof(firewall_ip),
												   firewall_port,
												   sizeof(firewall_port));
		}

		osip_MD5Init(&Md5Ctx);
		osip_MD5Update(&Md5Ctx, (unsigned char *) from, strlen(from));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) proxy, strlen(proxy));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) localip, strlen(localip));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) firewall_ip,
					   strlen(firewall_ip));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) firewall_port,
					   strlen(firewall_port));
		osip_MD5Final((unsigned char *) hval, &Md5Ctx);
		CvtHex(hval, key_line);

		osip_strncpy((*jr)->r_line, key_line, sizeof((*jr)->r_line) - 1);
	}

	return OSIP_SUCCESS;
}
Beispiel #3
0
int
_eXosip_reg_init (struct eXosip_t *excontext, eXosip_reg_t ** jr, const char *from, const char *proxy, const char *contact)
{
  static int r_id = 0;

  *jr = (eXosip_reg_t *) osip_malloc (sizeof (eXosip_reg_t));
  if (*jr == NULL)
    return OSIP_NOMEM;

  if (r_id == INT_MAX)            /* keep it non-negative */
    r_id = 0;

  memset (*jr, '\0', sizeof (eXosip_reg_t));

  (*jr)->r_id = ++r_id;
  (*jr)->r_reg_period = 3600;   /* delay between registration */
  (*jr)->r_aor = osip_strdup (from);    /* sip identity */
  if ((*jr)->r_aor == NULL) {
    osip_free (*jr);
    *jr = NULL;
    return OSIP_NOMEM;
  }
  (*jr)->r_contact = osip_strdup (contact);     /* sip identity */
  (*jr)->r_registrar = osip_strdup (proxy);     /* registrar */
  if ((*jr)->r_registrar == NULL) {
    osip_free ((*jr)->r_contact);
    osip_free ((*jr)->r_aor);
    osip_free (*jr);
    *jr = NULL;
    return OSIP_NOMEM;
  }

  {
    osip_MD5_CTX Md5Ctx;
    HASH hval;
    HASHHEX key_line;
    char localip[128];
    char firewall_ip[65];
    char firewall_port[10];
    char somerandom[31];

    memset (somerandom, 0, sizeof (somerandom));
    eXosip_generate_random (somerandom, 16);

    memset (localip, '\0', sizeof (localip));
    memset (firewall_ip, '\0', sizeof (firewall_ip));
    memset (firewall_port, '\0', sizeof (firewall_port));

    eXosip_guess_localip (excontext, AF_INET, localip, 128);
    if (excontext->eXtl_transport.tl_get_masquerade_contact != NULL) {
      excontext->eXtl_transport.tl_get_masquerade_contact (excontext, firewall_ip, sizeof (firewall_ip), firewall_port, sizeof (firewall_port));
    }

    osip_MD5Init (&Md5Ctx);
    osip_MD5Update (&Md5Ctx, (unsigned char *) from, (unsigned int) strlen (from));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) proxy, (unsigned int) strlen (proxy));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) localip, (unsigned int) strlen (localip));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) firewall_ip, (unsigned int) strlen (firewall_ip));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) firewall_port, (unsigned int) strlen (firewall_port));

    /* previously, "line" was common accross several identical restart. */
    /* including random will help to read a correct "expires" parameter */
    /* from 2xx REGISTER answers */
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) somerandom, (unsigned int) strlen (somerandom));

    osip_MD5Final ((unsigned char *) hval, &Md5Ctx);
    CvtHex (hval, key_line);

    osip_strncpy ((*jr)->r_line, key_line, sizeof ((*jr)->r_line) - 1);
  }

  return OSIP_SUCCESS;
}