Example #1
0
/* The Modular Exponentation operation. */
SshOperationHandle
ssh_acc_device_modexp_op(SshAccDevice device,
                         SshMPIntegerConst base,
                         SshMPIntegerConst exponent,
                         SshMPIntegerConst modulus,
                         SshAccDeviceReplyCB callback,
                         void *reply_context)
{
  SshOperationHandle op;
  unsigned char *b, *e, *m;
  size_t b_len, e_len, mod_len;

  if (!device || !device->is_initialized)
    {
      (*callback)(SSH_CRYPTO_OPERATION_FAILED, NULL, 0, reply_context);
      return NULL;
    }

  /* convert the MP Integers to buffers */
  b_len = ssh_mprz_byte_size(base);
  e_len = ssh_mprz_byte_size(exponent);
  mod_len = ssh_mprz_byte_size(modulus);

  /* allocate memory */
  b = ssh_malloc(b_len);
  e = ssh_malloc(e_len);
  m = ssh_malloc(mod_len);

  /* if no memory */
  if (b == NULL || e == NULL || m == NULL)
    {
      /* free b, e, m buffers */
      ssh_free(b);
      ssh_free(e);
      ssh_free(m);

      (*callback)(SSH_CRYPTO_NO_MEMORY, NULL, 0, reply_context);
      return NULL;
    }

  /* mp integers -->  buf  */
  ssh_mprz_get_buf(b, b_len,  base);
  ssh_mprz_get_buf(e, e_len,  exponent);
  ssh_mprz_get_buf(m, mod_len,  modulus);

  op = ssh_acc_device_modexp_op_buf(device,
                                    b, b_len,
                                    e, e_len, 
                                    m, mod_len,
                                    callback, 
                                    reply_context);

  ssh_free(b);
  ssh_free(e);
  ssh_free(m);

  return op;
}
Example #2
0
SshFastMemoryAllocator ssh_fastalloc_initialize(int blob_size,
                                                int blob_quant)
{
  SshFastMemoryAllocator newp;

  SSH_VERIFY(blob_size > 0);
  SSH_VERIFY(blob_quant > 0);

  /* Ensure correct alignment: round the `blob_size' up to be a
     multiple of sizeof(void *). */
  if (blob_size % sizeof(void *))
    {
      blob_size += sizeof(void *) - (blob_size % sizeof(void *));
    }

  if ((newp = ssh_malloc(sizeof(*newp))) == NULL)
    return NULL;

  newp->blob_size = blob_size;
  newp->blob_quant = blob_quant;
  newp->allocated = 0;
  newp->total_size = 0;
  newp->blobs = NULL;
  newp->free_chain = NULL;
  return newp;
}
Example #3
0
static void
ssh_eap_md5_client_recv_msg(SshEapProtocol protocol,
                            SshEap eap,
                            SshBuffer buf)
{
  SshEapMd5State state;
  unsigned char *ucp = NULL;

  state = ssh_eap_protocol_get_state(protocol);

  if (state == NULL)
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "EAP MD5 state uninitialized");
      return;
    }

  if (state->challenge_buffer != NULL)
    {
      ssh_free(state->challenge_buffer);
      state->challenge_buffer =  NULL;
    }

  ucp = ssh_buffer_ptr(buf);

  if (ucp == NULL || (ssh_buffer_len(buf) < 6))
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "packet length incorrect for EAP MD5 packet");
      return;
    }

  state->challenge_length = ucp[5];

  /* Note that RFC 1994 requires the challenge to be at least one octet */

  if (state->challenge_length == 0
      || (state->challenge_length + 6) > ssh_buffer_len(buf))
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "EAP MD5 incorrect challenge length");
      return;
    }

  state->challenge_buffer = ssh_malloc(state->challenge_length);

  if (state->challenge_buffer == NULL)
    {
      ssh_eap_fatal(eap, protocol,
                    "Could not allocate buffer for challenge");
      return;
    }

  memcpy(state->challenge_buffer, ucp + 6, state->challenge_length);

  state->response_id = ssh_eap_packet_get_identifier(buf);

  ssh_eap_protocol_request_token(eap, protocol->impl->id,
                                 SSH_EAP_TOKEN_SHARED_SECRET);
}
Boolean
ssh_pm_cfgmode_client_store_init(SshPm pm)
{
  int i;

#ifdef SSH_IPSEC_PREALLOCATE_TABLES
  for (i = 0; i < SSH_PM_MAX_CONFIG_MODE_CLIENTS; i++)
    {
      ssh_pm_active_cfgmode_clients[i].peer_handle = SSH_IPSEC_INVALID_INDEX;
      ssh_pm_active_cfgmode_clients[i].next = pm->cfgmode_clients_freelist;
      pm->cfgmode_clients_freelist = &ssh_pm_active_cfgmode_clients[i];
    }
#else /* not SSH_IPSEC_PREALLOCATE_TABLES */
  for (i = 0; i < SSH_PM_MAX_CONFIG_MODE_CLIENTS; i++)
    {
      SshPmActiveCfgModeClient client = ssh_malloc(sizeof(*client));
      
      if (client == NULL)
        {
          SSH_DEBUG(SSH_D_ERROR, ("Could not allocate client structures"));
          ssh_pm_cfgmode_client_store_uninit(pm);
          return FALSE;
        }
      client->peer_handle = SSH_IPSEC_INVALID_INDEX;
      client->next = pm->cfgmode_clients_freelist;
      pm->cfgmode_clients_freelist = client;
    }
#endif /* not SSH_IPSEC_PREALLOCATE_TABLES */

  return TRUE;
}
Example #5
0
/* Initialize the obstack context. Clear all buckets. */
SshObStackContext ssh_obstack_create(SshObStackConf config)
{
  SshObStackContext created;
  size_t prealloc;

  prealloc  = ((config != NULL) ? config->prealloc_size : 4000);
  prealloc += sizeof(SshObStackContextStruct);

  if (config != NULL && config->max_size != 0 && prealloc > config->max_size)
    {
      SSH_DEBUG(SSH_D_ERROR,
		("prealloc_size + sizeof(SshObStackContextStruct) "
		 "is larger than max_size allowed for the object"));
      return NULL;
    }
  created = ssh_malloc(prealloc);

  if (created != NULL)
    {
      created->current_alloc_size = 4096;
      created->first = &created->internal_first;
      created->first->next = NULL;
      created->first->ptr = (void *) &(created[1]);
      created->first->free_bytes = ((unsigned char *) created + prealloc) -
	created->first->ptr;
      created->first->alloc_bytes = created->first->free_bytes;
      created->memory_limit = ((config != NULL) ? config->max_size : 0);
      created->memory_allocated = prealloc;
      created->memory_used = sizeof(SshObStackContextStruct);
    }
  return created;
}
Example #6
0
static void
pkix_http_receive_data_operate(SshHttpClientContext ctx,
                               SshHttpResult result,
                               SshTcpError ip_error,
                               SshStream stream,
                               void *context)
{
  PkixHttpReadContext c = (PkixHttpReadContext)ssh_malloc(sizeof(*c));
  SshFSMThread thread = (SshFSMThread)context;
  SshPkiThreadData tdata = ssh_fsm_get_tdata(thread);
  SshPkiGlobalData gdata = ssh_fsm_get_gdata(thread);

  tdata->transport_op = NULL;
  if (c && result == SSH_HTTP_RESULT_SUCCESS)
    {
      c->http_stream = stream;
      c->upper_context = context;
      if ((c->input = ssh_buffer_allocate()) != NULL)
        {
          ssh_stream_set_callback(stream,
                                  pkix_http_stream_callback, (void *)c);
          pkix_http_stream_callback(SSH_STREAM_INPUT_AVAILABLE, (void *)c);
          return;
        }
    }
  ssh_free(c);
  tdata->input_type = SSH_PKI_MSG_ERRORREP;
  tdata->input_len = 1;
  ssh_fsm_continue(gdata->input_thread);
}
Example #7
0
SshEapConfiguration
ssh_eap_config_create(void)
{
  SshEapConfiguration params;

  params = ssh_malloc(sizeof(*params));

  if (params == NULL)
    return NULL;

  memset(params,0,sizeof(*params));

  /* Initialize parameter values to defaults */

  params->num_retransmit = ssh_eap_config_get_ulong(NULL,
                              SSH_EAP_PARAM_MAX_RETRANSMIT);

  params->retransmit_delay_sec = ssh_eap_config_get_ulong(NULL,
                         SSH_EAP_PARAM_RETRANSMIT_DELAY_SEC);

  params->auth_timeout_sec = ssh_eap_config_get_ulong(NULL,
                         SSH_EAP_PARAM_AUTH_TIMEOUT_SEC);

  params->signal_cb = NULL_FNPTR;
  params->refcount = 0;
#ifdef SSHDIST_RADIUS
  params->radius_buffer_identity = FALSE;
  params->radius_req_cb =  NULL_FNPTR;
#endif /* SSHDIST_RADIUS */

  return params;
}
Example #8
0
SshRDN ssh_rdn_alloc(unsigned char *oid, SshCharset charset,
                     unsigned char *c, size_t c_len)
{
  SshRDN rdn = ssh_malloc(sizeof(*rdn));

  if (rdn)
    {
      ssh_rdn_init(rdn);
      rdn->oid = oid;

      if (c != NULL)
        {
          /* Convert to the internal representation. */
          rdn->c = ssh_str_make(charset, c, c_len);
          if (rdn->c == NULL)
            {
              ssh_free(rdn);
              return NULL;
            }
        }
    }
  else
    {
      ssh_free(c);
    }
  return rdn;
}
Example #9
0
Boolean
ssh_sieve_allocate(SshSieve sieve,
                   unsigned int memory_limit)
{

  SSH_ASSERT(sieve != NULL);

  sieve->len = memory_limit / (SSH_WORD_BITS / 8);


  if (SSH_MP_SIEVE_STATIC_BYTE_SIZE >= sieve->len * (SSH_WORD_BITS / 8))
    {
      sieve->dynamic_table = FALSE;
      sieve->table = sieve->table_array;
    }
  else
    {
      sieve->dynamic_table = TRUE;

      if ((sieve->table = ssh_malloc(sieve->len * (SSH_WORD_BITS/8))) == NULL)
        return FALSE;
    }

  ssh_sieve_generate_primes(sieve->table, sieve->len);
  /* count the primes */
  sieve->count = ssh_sieve_prime_counter(sieve->table, sieve->len);
  return TRUE;
}
Example #10
0
void ssh_pm_dpd_peer_dead(SshPm pm, const SshIpAddr addr,
                          Boolean down)
{
  SshPmDpdDeadPeerEntry e;
  unsigned char addrstring[SSH_IP_ADDR_STRING_SIZE];

  if (pm->dpd_dead_bag &&
      !ssh_pm_dpd_peer_dead_p(pm, addr))
    {
      if ((e = ssh_malloc(sizeof(*e))) != NULL)
        {
          e->addr = *addr;
          e->down = down;
          e->ttl = pm->dpd_dead_ttl;

          ssh_adt_insert(pm->dpd_dead_bag, e);

          if (ssh_adt_num_objects(pm->dpd_dead_bag) == 1)
            ssh_register_timeout(&pm->dpd_timer,
                                 10L, 0L,
                                 pm_dpd_dead_peer_timer, pm);

          SSH_DEBUG(SSH_D_HIGHSTART,
                    ("DPD; Peer %@: marked as dead", ssh_ipaddr_render, addr));

	  ssh_ipaddr_print(addr, addrstring, sizeof(addrstring));
	  if (pm->dpd_status_callback)
	    (*pm->dpd_status_callback)(pm,
				       addrstring,
				       pm->dpd_status_callback_context);
        }
    }
}
SshAppgwHttpConfig
ssh_appgw_http_create_config(void)
{
  SshAppgwHttpConfig c;

  /* Look up based on service_id */

  c = ssh_malloc(sizeof(*c));
  if (c == NULL)
    return NULL;

  c->rules = NULL;
  c->blocks = NULL;
  c->clauses = NULL;
  c->nclauses = 0;
  c->service_id = 0;
  c->service_name = NULL;
  c->regex_ctx = ssh_regex_create_context();

  if (c->regex_ctx == NULL)
    {
      SSH_DEBUG(SSH_D_ERROR,("Could not allocate regex context"));
      ssh_free(c);
      return NULL;
    }
  return c;
}
static int
ssh_appgw_http_unmarshal_string(SshBuffer buf, unsigned char **ptr)
{
  int len;

  *ptr = NULL;

  if (ssh_appgw_http_unmarshal_int(buf, &len) == 0)
    return 0;

  if (len == 0)
    return 1;

  if (ssh_buffer_len(buf) < len)
    return 0;

  *ptr = ssh_malloc(len+1);
  if (ptr == NULL)
    return 0;

  memcpy(*ptr,ssh_buffer_ptr(buf),len);
  (*ptr)[len] = '\0';
  ssh_buffer_consume(buf,len);
  return 1;

}
Example #13
0
/* For a self-signed certificates the subject identifier should match
   the value in the authority key id, if present. */
void
ssh_x509_cert_set_subject_key_id(SshX509Certificate c,
                                 const unsigned char *key_id,
                                 size_t key_id_len,
                                 Boolean critical)
{
  SshX509ExtKeyId subject_id;

  /* Build the subject key id. */
  if ((subject_id = ssh_malloc(sizeof(*subject_id))) != NULL)
    {
      ssh_x509_key_id_init(subject_id);
      if ((subject_id->key_id = ssh_memdup(key_id, key_id_len)) != NULL)
        {
          subject_id->key_id_len = key_id_len;
          if (c->extensions.subject_key_id != NULL)
            ssh_x509_key_id_free(c->extensions.subject_key_id);
          c->extensions.subject_key_id = subject_id;
          ssh_x509_ext_info_set(&c->extensions.ext_available,
                                &c->extensions.ext_critical,
                                SSH_X509_EXT_SUBJECT_KEY_ID, critical);
        }
      else
        ssh_free(subject_id);
    }
}
Example #14
0
static SshX509Status
cmp_decode_cert(SshAsn1Context context,
                SshAsn1Node node,
                SshGList glist)
{
  SshGListNode gnode;
  SshCmpCertificate c;

  if ((c = ssh_malloc(sizeof(*c))) != NULL)
    {
      cmp_cert_init(c);
      if (ssh_asn1_node_get_data(node, &c->cert, &c->cert_len)
          == SSH_ASN1_STATUS_OK)
        {
          if ((gnode = ssh_glist_allocate_n(glist)) != NULL)
            {
              gnode->data = c;
              gnode->data_length = sizeof(*c);
              ssh_glist_add_n(gnode, NULL, SSH_GLIST_TAIL);
              return SSH_X509_OK;
            }
          ssh_free(c->cert);
        }
      ssh_free(c);
    }
  return SSH_X509_FAILURE;
}
Example #15
0
/* Read hexl encoded file from the disk. Return mallocated buffer and
   the size of the buffer. If the reading of file failes return
   FALSE. If the file name is NULL or "-" then read from the
   stdin. The size_limit is in bytes. If zero is used, the read file
   will try to read the whole file.

   If the file size exceeds the size_limit (given in bytes), FALSE
   is returned. */
Boolean ssh_read_file_hexl_with_limit(const char *file_name,
                                      SshUInt32 size_limit,
                                      unsigned char **buf,
                                      size_t *buf_len)
{
  unsigned char *tmp, *p, *q;
  size_t len, i = 0;
  int state, l = 0;

  if (!ssh_read_file_with_limit(file_name, size_limit, &tmp, &len))
    return FALSE;

  *buf_len = 0;
  if ((*buf = ssh_malloc(len + 1)) == NULL)
    {
      ssh_free(tmp);
      return FALSE;
    }

  for (state = 0, p = *buf, q = tmp; len > 0; len--, q++)
    {
      if (state == 0)
        {
          i = 0;
          l = 0;
          if (*q == ':')
            state++;
          continue;
        }
      if (state == 1)
        {
          if (isxdigit(*q))
            {
              if (isdigit(*q))
                l = (l << 4) | (*q - '0');
              else
                l = (l << 4) | (tolower(*q) - 'a' + 10);
              i++;
              if ((i & 1) == 0)
                {
                  *p++ = l;
                  (*buf_len)++;
                  l = 0;
                }
              if (i == 32)
                state++;
            }
          else
            if (q[0] == ' ' && q[1] == ' ')
              state++;
          continue;
        }
      if (*q == '\n' || *q == '\r')
        state = 0;
    }

  ssh_free(tmp);
  return TRUE;
}
Example #16
0
void ssh_mp2az_set_prec(SshMP2AdicInteger op, unsigned int prec)
{
  /* This is needed since we don't always want to unset NaN values. */
  if (ssh_mp2az_isnan(op))
    return;

  if (op->v == NULL)
    {
      op->v = ssh_malloc(sizeof(SshWord) * prec);
      if (!op->v)
        goto failure;
      ssh_mpk_memzero(op->v, prec);
      op->m = prec;
      op->n = prec;
      return;
    }

  if (op->m < prec)
    {
      SshWord *nv;

      if ((nv = ssh_malloc(sizeof(SshWord) * prec)) != NULL)
        memcpy(nv, op->v, sizeof(SshWord) * op->m);

      memset(op->v, 0, sizeof(SshWord) * op->m);
      ssh_free(op->v);
      op->v = nv;

      if (!op->v)
        goto failure;
      op->m = prec;
    }

  if (op->n < prec)
    ssh_mpk_memzero(op->v + op->n, prec - op->n);
  op->n = prec;
  return;

 failure:
  op->n = 0;
  op->m = 0;
  op->isnan = TRUE;
  op->nankind = SSH_MP2AZ_NAN_ENOMEM;
}
Example #17
0
/* This routine works also when a->free_chain != NULL. This is necessary for
   `ssh_fastalloc_reserve'. */
static Boolean make_more_blobs(SshFastMemoryAllocator a)
{
  SshFastallocBlobs *newp;

  newp = ssh_malloc(sizeof(*newp));

  /* Check the return value. */
  if (newp == NULL)
    {
      return FALSE;
    }

  newp->blobs = ssh_malloc(a->blob_quant * a->blob_size);

  /* Check the return value. */
  if (newp->blobs == NULL)
    {
      ssh_free(newp);
      return FALSE;
    }

  newp->next = a->blobs;
  a->blobs = newp;
  a->total_size += a->blob_quant;

  /* Add the new blobs to the chain of free blobs. */
  {
    unsigned char *ptr = newp->blobs;
    unsigned char *end = ptr + a->blob_size * (a->blob_quant - 1);
    int step = a->blob_size;

    while (ptr < end)
      {
        ((SshFastallocProtoBlob *)ptr)->free_chain =
          (ptr + step);
        ptr += step;
      }
    ((SshFastallocProtoBlob *)ptr)->free_chain = a->free_chain;
    a->free_chain = newp->blobs;
  }

  return TRUE;
}
Example #18
0
static SshRegData
ssh_registry_platform_get_value(SshRegKey registry_key,
                                SshRegUnicodeString value_name,
                                SshRegSize *size_return)
{
  PKEY_VALUE_PARTIAL_INFORMATION info;
  ULONG data_size;
  SshRegData ret_ptr = NULL;

  SSH_ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);

  if (ZwQueryValueKey(registry_key, value_name, KeyValuePartialInformation,
                      NULL, 0, &data_size) != STATUS_BUFFER_TOO_SMALL)
    goto error;

  info = ssh_malloc(data_size);
  if (info == NULL)
    goto error;

  if (NT_SUCCESS(ZwQueryValueKey(registry_key, value_name,
                                 KeyValuePartialInformation, info,
                                 data_size, &data_size)))
    {
      if (data_size > info->DataLength)
        {
          ret_ptr = ssh_malloc(info->DataLength);
          if (ret_ptr)
            {
              memcpy(ret_ptr, info->Data, info->DataLength);

              if (size_return)
                *size_return = info->DataLength;
            }
        }
    }

  ssh_free(info);

 error:
  
  return ret_ptr;
}
Example #19
0
static Boolean avl_ranges_init(SshADTContainer c)
{
  if (!avl_init(c, ssh_malloc(sizeof(SshADTRangesCRootStruct))))
    return FALSE;

  if ((RROOT(c)->merge_additions = ssh_buffer_allocate()) == NULL ||
      (RROOT(c)->merge_deletions = ssh_buffer_allocate()) == NULL)
    return FALSE;

  return TRUE;
}
Example #20
0
__inline SshDeviceBuffer
ssh_iodevice_buffer_alloc(SshInterceptorIoDevice io_dev,
                          Boolean reliable)
{
  SshDeviceBuffer buf = NULL;
  PLIST_ENTRY entry;

  /* 1. Try to get a SshDeviceBuffer from a free list */
  entry = NdisInterlockedRemoveHeadList(&io_dev->free_list,
                                        &io_dev->free_list_lock);
  if (entry)
    buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, link);

  /* 2. If failed and this is a reliable message, try to replace
     an existing unreliable one */
  if ((buf == NULL) && (reliable))
    {
      NdisAcquireSpinLock(&io_dev->output_queue_lock);
      if (!IsListEmpty(&io_dev->unreliable_output_queue))
        {
          /* We found an existing unreliable message */
          entry = RemoveHeadList(&io_dev->unreliable_output_queue);

          /* We must remove the entry from output_queue too */
          buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct,
                                  unreliable_list_link);

          SSH_ASSERT(buf != io_dev->current_read_buf);

          /* This removes the entry from output_queue */
          RemoveEntryList(&(buf->link));
        }
      NdisReleaseSpinLock(&io_dev->output_queue_lock);

      /* If found, we must delete the old message */
      if (buf != NULL)
        ssh_free(buf->addr);
    }

  /* 3. If still failed, try to allocate memory for a new
     SshDeviceBuffer */
  if ((buf == NULL) && (reliable))
    {
      buf = ssh_malloc(sizeof(*buf));
      if (buf)
        {
          /* This buffer will be deleted after use */
          buf->pre_allocated = 0;
        }
    }

  return buf;
}
Example #21
0
SshStream ssh_stream_fd_wrap2(SshIOHandle readfd, SshIOHandle writefd,
                              Boolean close_on_destroy)
{
  SshFdStream sdata;
  SshStream str;

  sdata = ssh_malloc(sizeof(*sdata));

  if (sdata == NULL)
    return NULL;

  memset(sdata, 0, sizeof(*sdata));
  sdata->readfd = readfd;
  sdata->writefd = writefd;
  sdata->close_on_destroy = close_on_destroy;
  sdata->read_has_failed = FALSE;
  sdata->write_has_failed = FALSE;
  sdata->destroyed = FALSE;
  sdata->keep_nonblocking = FALSE;
  sdata->callback = NULL_FNPTR;
  if (readfd >= 0)
    {
      if (ssh_io_register_fd(readfd, ssh_stream_fd_callback, (void *)sdata)
           == FALSE )
        {
          ssh_free(sdata);
          return NULL;
        }
    }
  if (readfd != writefd && writefd >= 0)
    {
      if (ssh_io_register_fd(writefd, ssh_stream_fd_callback, (void *)sdata)
           == FALSE )
        {
          if (readfd >= 0)
            ssh_io_unregister_fd(readfd,TRUE);
          ssh_free(sdata);
          return NULL;
        }
    }
  str = ssh_stream_create(&ssh_stream_fd_methods, (void *)sdata);
  if (str == NULL)
    {
      ssh_free(sdata);
      if (readfd >= 0)
        ssh_io_unregister_fd(readfd, TRUE);
      if (readfd != writefd && writefd >= 0)
        ssh_io_unregister_fd(writefd, TRUE);
      return NULL;
    }
  return str;

}
Example #22
0
SshEapToken
ssh_eap_create_token(void)
{
  SshEapToken t;

  t = ssh_malloc(sizeof(*t));

  if (t == NULL)
    return NULL;

  ssh_eap_init_token(t);
  return t;
}
void *ssh_memdup(const void * p, size_t len)
{
  void        * cp;

  if ((cp = ssh_malloc(len + 1)) == NULL)
    return NULL;

  memcpy(cp, p, (size_t)len);

  ((unsigned char *) cp)[len] = '\0';

  return cp;
}
Example #24
0
static void
ssh_eap_md5_server_recv_msg(SshEapProtocol protocol,
                            SshEap eap,
                            SshBuffer buf)
{
  SshEapMd5State state;
  unsigned char *ucp = NULL;

  state = ssh_eap_protocol_get_state(protocol);

  if (state == NULL)
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "eap md5 auth state not initialized");
      return;
    }
  ucp = ssh_buffer_ptr(buf);

  if (ucp == NULL || (ssh_buffer_len(buf) < 6))
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "packet too short to be eap md5 response");
      return;
    }

  state->response_length = ucp[5] & 0xFF;

  if (state->response_length < 1
      || (state->response_length + 6) > ssh_buffer_len(buf))
    {
      ssh_eap_discard_packet(eap, protocol, buf,
                             "invalid ressponse value length");
      return;
    }

  SSH_ASSERT(state->response_buffer == NULL);

  state->response_buffer = ssh_malloc(state->response_length);

  if (state->response_buffer == NULL)
    {
      ssh_eap_fatal(eap, protocol,
                    "Could not cache challenge response. Out of memory");
      return;
    }

  memcpy(state->response_buffer, ucp + 6, state->response_length);

  ssh_eap_protocol_request_token(eap, protocol->impl->id,
                                 SSH_EAP_TOKEN_SHARED_SECRET);
}
Example #25
0
static SshX509Status
cmp_decode_poll(SshAsn1Context context,
                SshAsn1Node node,
                SshGList poll_req_rep,
                Boolean is_response)
{
  SshGListNode gnode;
  SshCmpPollMsg pm;
  SshAsn1Node list, freetext;
  Boolean freetext_found, poll_when_found, content_found;

  if (ssh_asn1_read_node(context, node, "(sequence (*) (any ()))", &list)
      == SSH_ASN1_STATUS_OK)
    {
      content_found = FALSE;
      for (; list; list = ssh_asn1_node_next(list))
        {
          pm = ssh_malloc(sizeof(*pm));
          cmp_poll_init(pm);

          if (ssh_asn1_read_node(context, list,
                                 "(sequence ()"
                                 "  (integer ())"
                                 "  (optional (integer-short ()))"
                                 "  (optional (any ())))",
                                 &pm->request_id,
                                 &poll_when_found, &pm->poll_when,
                                 &freetext_found, &freetext)
              == SSH_ASN1_STATUS_OK)
            {
              if ((freetext_found || poll_when_found) && !is_response)
                {
                  cmp_poll_clear(pm);
                  ssh_free(pm);
                  return SSH_X509_FAILED_ASN1_DECODE;
                }
              if (freetext_found)
                pm->reason = cmp_decode_freetext(context, freetext);

              gnode = ssh_glist_allocate_n(poll_req_rep);
              gnode->data = pm;
              gnode->data_length = sizeof(*pm);
              ssh_glist_add_n(gnode, NULL, SSH_GLIST_TAIL);
              content_found = TRUE;
            }
        }
      return content_found ? SSH_X509_OK : SSH_X509_FAILED_UNKNOWN_VALUE;
    }
  return SSH_X509_FAILED_ASN1_DECODE;
}
static inline SshInterceptorInternalPacket
ssh_freelist_packet_get(SshInterceptor interceptor,
			Boolean may_borrow)
{
  SshInterceptorInternalPacket p;
  unsigned int cpu;

  icept_preempt_disable();

  cpu = smp_processor_id();

  p = ssh_packet_freelist_head[cpu];
  if (p)
    {
      p->cpu = cpu;

      ssh_packet_freelist_head[p->cpu] =
	(SshInterceptorInternalPacket) p->packet.next;
    }
  else
    {
      /* Try getting a packet from the shared freelist */
      ssh_kernel_mutex_lock(interceptor->packet_lock);

      p = ssh_packet_freelist_head[SSH_LINUX_INTERCEPTOR_NR_CPUS];
      if (p)
	{
	  p->cpu = cpu;

	  ssh_packet_freelist_head[SSH_LINUX_INTERCEPTOR_NR_CPUS] =
	    (SshInterceptorInternalPacket) p->packet.next;

	  ssh_kernel_mutex_unlock(interceptor->packet_lock);
	  goto done;
	}
      ssh_kernel_mutex_unlock(interceptor->packet_lock);

      p = ssh_malloc(sizeof(*p));
      if (!p)
	goto done;

      p->cpu = cpu;
    }

 done:
  icept_preempt_enable();

  return p;
}
Example #27
0
static Boolean
interceptor_ipm_proc_entry_init(SshInterceptor interceptor)
{
  /* Assert that parent dir exists. */
  SSH_ASSERT(interceptor->proc_dir != NULL);

  /* Initialize proc entry structure. */
  init_waitqueue_head(&interceptor->ipm_proc_entry.wait_queue);
  rwlock_init(&interceptor->ipm_proc_entry.lock);

  write_lock(&interceptor->ipm_proc_entry.lock);
  interceptor->ipm_proc_entry.open = TRUE;
  interceptor->ipm_proc_entry.write_active = TRUE;
  interceptor->ipm_proc_entry.read_active = TRUE;  
  write_unlock(&interceptor->ipm_proc_entry.lock);

  interceptor->ipm_proc_entry.recv_buf_size = SSH_LINUX_IPM_RECV_BUFFER_SIZE;
  interceptor->ipm_proc_entry.recv_buf = 
    ssh_malloc(interceptor->ipm_proc_entry.recv_buf_size);
  if (interceptor->ipm_proc_entry.recv_buf == NULL)
    return FALSE;

  /* Create entry to procfs. */
  interceptor->ipm_proc_entry.entry =
    create_proc_entry(SSH_PROC_ENGINE, S_IFREG | S_IRUSR | S_IWUSR,
                      interceptor->proc_dir);

  if (interceptor->ipm_proc_entry.entry == NULL)
    return FALSE;

#ifdef LINUX_HAS_PROC_DIR_ENTRY_OWNER
  interceptor->ipm_proc_entry.entry->owner = THIS_MODULE;
#endif

  interceptor->ipm_proc_entry.entry->proc_iops = &common_proc_entry_iops;
  interceptor->ipm_proc_entry.entry->proc_fops = &ipm_proc_entry_fops;
  interceptor->ipm_proc_entry.entry->uid = (uid_t) ssh_procfs_uid;
  interceptor->ipm_proc_entry.entry->gid = (uid_t) ssh_procfs_gid;
  interceptor->ipm_proc_entry.entry->size = 0;

  /* Mark proc entry ready for use. */
  write_lock(&interceptor->ipm_proc_entry.lock);
  interceptor->ipm_proc_entry.open = FALSE;
  interceptor->ipm_proc_entry.write_active = FALSE;
  interceptor->ipm_proc_entry.read_active = FALSE;
  write_unlock(&interceptor->ipm_proc_entry.lock);

  return TRUE;
}
Example #28
0
static Boolean
interceptor_ipm_proc_entry_init(SshInterceptor interceptor)
{
  /* Assert that parent dir exists. */
  SSH_ASSERT(interceptor->proc_dir != NULL);

  /* Initialize proc entry structure. */
  init_waitqueue_head(&interceptor->ipm_proc_entry.wait_queue);
  rwlock_init(&interceptor->ipm_proc_entry.lock);

  interceptor->ipm_proc_entry.open = TRUE;
  interceptor->ipm_proc_entry.write_active = TRUE;
  interceptor->ipm_proc_entry.read_active = TRUE;  

  interceptor->ipm_proc_entry.recv_buf_size = SSH_LINUX_IPM_RECV_BUFFER_SIZE;
  interceptor->ipm_proc_entry.recv_buf = 
    ssh_malloc(interceptor->ipm_proc_entry.recv_buf_size);
  if (interceptor->ipm_proc_entry.recv_buf == NULL)
    return FALSE;

  /* Create entry to procfs. */
  interceptor->ipm_proc_entry.entry =
    create_proc_entry(SSH_PROC_ENGINE, S_IFREG | S_IRUSR | S_IWUSR,
                      interceptor->proc_dir);

  if (interceptor->ipm_proc_entry.entry == NULL)
    return FALSE;

#ifdef LINUX_HAS_PROC_DIR_ENTRY_OWNER
  interceptor->ipm_proc_entry.entry->owner = THIS_MODULE;
#endif

  /* Leave the file operations initially unset so that all operations
     on the proc entry fail initially. The file operations are set later
     in ssh_interceptor_proc_enable(). */
  interceptor->ipm_proc_entry.entry->proc_iops = NULL;
  interceptor->ipm_proc_entry.entry->proc_fops = NULL;
  interceptor->ipm_proc_entry.entry->uid = 0;
  interceptor->ipm_proc_entry.entry->gid = 0;
  interceptor->ipm_proc_entry.entry->size = 0;

  /* Mark proc entry ready for use. */
  interceptor->ipm_proc_entry.open = FALSE;
  interceptor->ipm_proc_entry.write_active = FALSE;
  interceptor->ipm_proc_entry.read_active = FALSE;

  return TRUE;
}
void *ssh_strdup (const void * p)
{
  const char  * str;
  char        * cp;

  SSH_PRECOND(p != NULL);

  str = (const char *) p;

  if ((cp = (char *) ssh_malloc(strlen(str) + 1)) == NULL)
    return NULL;

  strcpy(cp, str);

  return (void *) cp;
}
Example #30
0
SshX509RevokedCerts ssh_x509_revoked_allocate(void)
{
  SshX509RevokedCerts rc = ssh_malloc(sizeof(*rc));

  if (rc)
    {
      /* Place NULLs. */
      rc->next = NULL;
      ssh_mprz_init_set_ui(&rc->serial_number, 0);
      ssh_ber_time_zero(&rc->revocation_date);

      /* Initialize the extensions. */
      ssh_x509_crl_rev_extensions_init(&rc->extensions);
    }
  return rc;
}