Exemple #1
0
static SilcBool silc_client_udp_accept(SilcPacketEngine engine,
                                       SilcPacketStream stream,
                                       SilcPacket packet,
                                       void *callback_context,
                                       void *stream_context)
{
  SilcClientListener listener = callback_context;
  SilcPacketStream packet_stream;
  SilcUInt16 port;
  const char *ip;

  SILC_LOG_DEBUG(("New incoming UDP connection"));

  /* We want only key exchange packet.  Eat other packets so that default
     packet callback doesn't get them. */
  if (packet->type != SILC_PACKET_KEY_EXCHANGE) {
    silc_packet_free(packet);
    return TRUE;
  }

  /* Create packet stream for this remote UDP session */
  if (!silc_packet_get_sender(packet, &ip, &port)) {
    silc_packet_free(packet);
    return TRUE;
  }
  packet_stream = silc_packet_stream_add_remote(stream, ip, port, packet);
  if (!packet_stream) {
    silc_packet_free(packet);
    return TRUE;
  }

  /* Process session */
  silc_client_listener_new_connection(listener, packet_stream);
  return TRUE;
}
Exemple #2
0
static void silc_client_private_message_key_cb(SilcClient client,
					       SilcClientConnection conn,
					       SilcStatus status,
					       SilcDList clients,
					       void *context)
{
  SilcFSMThread thread = context;
  SilcPacket packet = silc_fsm_get_state_context(thread);
  unsigned char *cipher = NULL, *hmac = NULL;
  SilcClientEntry client_entry;
  int ret;

  if (!clients) {
    silc_packet_free(packet);
    silc_fsm_finish(thread);
    return;
  }

  /* Parse the private message key payload */
  ret = silc_buffer_unformat(&packet->buffer,
			     SILC_STR_UI16_STRING_ALLOC(&cipher),
			     SILC_STR_UI16_STRING_ALLOC(&hmac),
			     SILC_STR_END);
  if (!ret)
    goto out;

  /* Mark that we are responder */
  client_entry = silc_dlist_get(clients);
  client_entry->internal.prv_resp = TRUE;

  /* XXX we should notify application that remote wants to set up the
     static key.  And we should tell if we already have key with remote.
     Application should return status telling whether to delete the key
     or not. */

 out:
  silc_free(cipher);
  silc_free(hmac);
  silc_packet_free(packet);
  silc_fsm_finish(thread);
}
Exemple #3
0
SilcBool silc_client_private_message_wait(SilcClient client,
					  SilcClientConnection conn,
					  SilcClientEntry client_entry,
					  SilcMessagePayload *payload)
{
  SilcPacket packet;

  if (!client_entry->internal.prv_waiter)
    return FALSE;

  /* Block until private message arrives */
  do {
    if ((silc_packet_wait(client_entry->internal.prv_waiter, 0, &packet)) < 0)
      return FALSE;

    /* Parse the payload and decrypt it also if private message key is set */
    *payload =
      silc_message_payload_parse(silc_buffer_data(&packet->buffer),
				 silc_buffer_len(&packet->buffer),
				 TRUE, !client_entry->internal.generated,
				 client_entry->internal.receive_key,
				 client_entry->internal.hmac_receive,
				 packet->src_id, packet->src_id_len,
				 packet->dst_id, packet->dst_id_len,
				 NULL, FALSE, NULL);
    if (!(*payload)) {
      silc_packet_free(packet);
      continue;
    }

    break;
  } while (1);

  silc_packet_free(packet);
  return TRUE;
}
Exemple #4
0
static void silc_client_ftp_client_resolved(SilcClient client,
					    SilcClientConnection conn,
					    SilcStatus status,
					    SilcDList clients,
					    void *context)
{
  SilcFSMThread thread = context;
  SilcPacket packet = silc_fsm_get_state_context(thread);

  /* If no client found, ignore the packet, a silent error */
  if (!clients) {
    silc_packet_free(packet);
    silc_fsm_finish(thread);
    return;
  }

  /* Continue processing the packet */
  SILC_FSM_CALL_CONTINUE(context);
}
void silc_server_command_free(SilcServerCommand cmd)
{
  SilcServerThread thread = cmd->thread;

  silc_mutex_lock(thread->server->lock);

#if defined(SILC_DEBUG)
  /* Check for double free */
  assert(cmd->packet != NULL);
#endif /* SILC_DEBUG */

  if (cmd->packet)
    silc_packet_free(cmd->packet);
  cmd->packet = NULL;

  if (cmd->pending)
    silc_server_command_pending_free(thread, cmd->pending);

  /* Put the packet back to freelist */
  silc_list_add(thread->server->command_pool, cmd);

  silc_mutex_unlock(thread->server->lock);
}