예제 #1
0
int
_asn1_change_integer_value (asn1_node node)
{
  asn1_node p;
  unsigned char val[SIZEOF_UNSIGNED_LONG_INT];
  unsigned char val2[SIZEOF_UNSIGNED_LONG_INT + 1];
  int len;

  if (node == NULL)
    return ASN1_ELEMENT_NOT_FOUND;

  p = node;
  while (p)
    {
      if ((type_field (p->type) == ASN1_ETYPE_INTEGER)
	  && (p->type & CONST_ASSIGN))
	{
	  if (p->value)
	    {
	      _asn1_convert_integer (p->value, val, sizeof (val), &len);
	      asn1_octet_der (val, len, val2, &len);
	      _asn1_set_value (p, val2, len);
	    }
	}

      if (p->down)
	{
	  p = p->down;
	}
      else
	{
	  if (p == node)
	    p = NULL;
	  else if (p->right)
	    p = p->right;
	  else
	    {
	      while (1)
		{
		  p = _asn1_find_up (p);
		  if (p == node)
		    {
		      p = NULL;
		      break;
		    }
		  if (p->right)
		    {
		      p = p->right;
		      break;
		    }
		}
	    }
	}
    }

  return ASN1_SUCCESS;
}
ASN1_TYPE
_asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len)
{
  int len2;
  void *temp;

  if (node == NULL)
    return node;

  asn1_length_der (len, NULL, &len2);
  temp = (unsigned char *) _asn1_malloc (len + len2);
  if (temp == NULL)
    return NULL;

  asn1_octet_der (value, len, temp, &len2);
  return _asn1_set_value_m (node, temp, len2);
}
예제 #3
0
asn1_node
_asn1_set_value_lv (asn1_node node, const void *value, unsigned int len)
{
  int len2;
  void *temp;

  if (node == NULL)
    return node;

  asn1_length_der (len, NULL, &len2);
  temp = malloc (len + len2);
  if (temp == NULL)
    return NULL;

  asn1_octet_der (value, len, temp, &len2);
  return _asn1_set_value_m (node, temp, len2);
}
예제 #4
0
bool
p11_openssl_canon_string_der (p11_buffer *der)
{
	char *string;
	size_t length;
	int output_len;
	int len_len;
	bool unknown_string;
	unsigned char *output;
	int len;

	string = p11_x509_parse_directory_string (der->data, der->len, &unknown_string, &length);

	/* Just pass through all the non-string types */
	if (string == NULL)
		return unknown_string;

	p11_openssl_canon_string (string, &length);

	asn1_length_der (length, NULL, &len_len);
	output_len = 1 + len_len + length;

	if (!p11_buffer_reset (der, output_len))
		return_val_if_reached (false);

	output = der->data;
	der->len = output_len;

	output[0] = 12; /* UTF8String */
	len = output_len - 1;
	asn1_octet_der ((unsigned char *)string, length, output + 1, &len);
	assert (len == output_len - 1);

	free (string);
	return true;
}