예제 #1
0
int main(int argc, char const *argv[])
{
	long value;
	int ret, len, i;
	unsigned char *bitstr = "8";
	unsigned char buf2[16];
	unsigned char *buf = NULL, *p;
	ASN1_BIT_STRING *a, *q;
	a = ASN1_BIT_STRING_new();
	printf("len = %d\n", a->length);
	ASN1_BIT_STRING_set(a, bitstr, strlen(bitstr));

	len = i2d_ASN1_BIT_STRING(a, NULL);
	p = buf =malloc(sizeof(unsigned char) * len);
	len = i2d_ASN1_BIT_STRING(a, &buf);
	printf("after i2d der content len = %d\n", len);
	printf("len = %d\n", len);

	for (i = 0; i < len; ++i)
	{
		/* code */
		printf("%02x\n", p[i]);
	}
	printf("\n");

	q = d2i_ASN1_BIT_STRING(&a, &p, len);
	printf("after d2i length = %d\n", q->length);
	for (i = 0; i < q->length; ++i)
	{
		printf("%02x\t", q->data[i]);
	}
	printf("\n");
	ASN1_BIT_STRING_free(a);
	return 0;
}
예제 #2
0
DIST_POINT* DistributionPoint::getDistPoint()
{
	DIST_POINT *ret;
	bool anyReasons;
	int i;
	ret = DIST_POINT_new();
	if (this->distributionPointName.getType() != DistributionPointName::UNDEFINED)
	{
		ret->distpoint = this->distributionPointName.getDistPointName();
	}
	anyReasons = false;
	i = 0;
	while (!anyReasons && i<7)
	{
		if (this->reasons[i])
		{
			anyReasons = true;
		}
		i++;
	}
	if (anyReasons)
	{
		ret->reasons = ASN1_BIT_STRING_new();
		for (i=0;i<7;i++)
		{
			ASN1_BIT_STRING_set_bit(ret->reasons, i, this->reasons[i]?1:0);
		}
	}
	if (this->crlIssuer.getNumberOfEntries() > 0)
	{
		ret->CRLissuer = this->crlIssuer.getInternalGeneralNames();
	}
	return ret;
}
예제 #3
0
static int bign_asn1_params2curve(BIGN_CURVE* curve, const bign_params* params)
{
	// ������� ��������
	if (!params || !curve || !curve->a || !curve->b)
	{
		BEE2EVPerr(BEE2EVP_F_BIGN_ASN1_PARAMS2CURVE, ERR_R_PASSED_NULL_PARAMETER);
		return 0;
	}

	// ���������� a � b
	if (!M_ASN1_OCTET_STRING_set(curve->a, params->a, params->l / 4) ||
	    !M_ASN1_OCTET_STRING_set(curve->b, params->b, params->l / 4))
	{
		BEE2EVPerr(BEE2EVP_F_BIGN_ASN1_PARAMS2CURVE, ERR_R_ASN1_LIB);
		return 0;
	}

	// ���������� seed (optional)
	if (!curve->seed && !(curve->seed = ASN1_BIT_STRING_new()))
	{
		BEE2EVPerr(BEE2EVP_F_BIGN_ASN1_PARAMS2CURVE, ERR_R_MALLOC_FAILURE);
		return 0;
	}
	curve->seed->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 7);
	curve->seed->flags |= ASN1_STRING_FLAG_BITS_LEFT;
	if (!ASN1_BIT_STRING_set(curve->seed, (unsigned char*)params->seed, 8))
	{
		BEE2EVPerr(BEE2EVP_F_BIGN_ASN1_PARAMS2CURVE, ERR_R_ASN1_LIB);
		return 0;
	}
	return 1;
}
예제 #4
0
static int set_reasons(ASN1_BIT_STRING **preas, char *value)
{
    STACK_OF(CONF_VALUE) *rsk = NULL;
    const BIT_STRING_BITNAME *pbn;
    const char *bnam;
    int i, ret = 0;
    rsk = X509V3_parse_list(value);
    if (!rsk)
        return 0;
    if (*preas)
        return 0;
    for (i = 0; i < sk_CONF_VALUE_num(rsk); i++) {
        bnam = sk_CONF_VALUE_value(rsk, i)->name;
        if (!*preas) {
            *preas = ASN1_BIT_STRING_new();
            if (!*preas)
                goto err;
        }
        for (pbn = reason_flags; pbn->lname; pbn++) {
            if (strcmp(pbn->sname, bnam) == 0) {
                if (!ASN1_BIT_STRING_set_bit(*preas, pbn->bitnum, 1))
                    goto err;
                break;
            }
        }
        if (!pbn->lname)
            goto err;
    }
    ret = 1;

 err:
    sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free);
    return ret;
}
예제 #5
0
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
                                     const unsigned char **pp, long len)
{
    ASN1_BIT_STRING *ret = NULL;
    const unsigned char *p;
    unsigned char *s;
    int i;

    if (len < 1) {
        i = ASN1_R_STRING_TOO_SHORT;
        goto err;
    }

    if ((a == NULL) || ((*a) == NULL)) {
        if ((ret = ASN1_BIT_STRING_new()) == NULL)
            return (NULL);
    } else
        ret = (*a);

    p = *pp;
    i = *(p++);
    if (i > 7) {
        i = ASN1_R_INVALID_BIT_STRING_BITS_LEFT;
        goto err;
    }
    /*
     * We do this to preserve the settings.  If we modify the settings, via
     * the _set_bit function, we will recalculate on output
     */
    ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
    ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */

    if (len-- > 1) {            /* using one because of the bits left byte */
        s = OPENSSL_malloc((int)len);
        if (s == NULL) {
            i = ERR_R_MALLOC_FAILURE;
            goto err;
        }
        memcpy(s, p, (int)len);
        s[len - 1] &= (0xff << i);
        p += len;
    } else
        s = NULL;

    ret->length = (int)len;
    OPENSSL_free(ret->data);
    ret->data = s;
    ret->type = V_ASN1_BIT_STRING;
    if (a != NULL)
        (*a) = ret;
    *pp = p;
    return (ret);
 err:
    ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i);
    if ((a == NULL) || (*a != ret))
        ASN1_BIT_STRING_free(ret);
    return (NULL);
}
예제 #6
0
파일: ossl_asn1.c 프로젝트: DocPsy/MacRuby
static ASN1_BIT_STRING*
obj_to_asn1bstr(VALUE obj, long unused_bits)
{
    ASN1_BIT_STRING *bstr;

    if(unused_bits < 0) unused_bits = 0;
    StringValue(obj);
    if(!(bstr = ASN1_BIT_STRING_new()))
	ossl_raise(eASN1Error, NULL);
    ASN1_BIT_STRING_set(bstr, (unsigned char *)RSTRING_PTR(obj), RSTRING_LEN(obj));
    bstr->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
    bstr->flags |= ASN1_STRING_FLAG_BITS_LEFT|(unused_bits&0x07);

    return bstr;
}
예제 #7
0
static OCSP_BASICRESP *make_dummy_resp(void)
{
    const unsigned char namestr[] = "openssl.example.com";
    unsigned char keybytes[128] = {7};
    OCSP_BASICRESP *bs = OCSP_BASICRESP_new();
    OCSP_BASICRESP *bs_out = NULL;
    OCSP_CERTID *cid = NULL;
    ASN1_TIME *thisupd = ASN1_TIME_set(NULL, time(NULL));
    ASN1_TIME *nextupd = ASN1_TIME_set(NULL, time(NULL) + 200);
    X509_NAME *name = X509_NAME_new();
    ASN1_BIT_STRING *key = ASN1_BIT_STRING_new();
    ASN1_INTEGER *serial = ASN1_INTEGER_new();

    if (!X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_ASC,
                                   namestr, -1, -1, 1)
        || !ASN1_BIT_STRING_set(key, keybytes, sizeof(keybytes))
        || !ASN1_INTEGER_set_uint64(serial, (uint64_t)1))
        goto err;
    cid = OCSP_cert_id_new(EVP_sha256(), name, key, serial);
    if (!TEST_ptr(bs)
        || !TEST_ptr(thisupd)
        || !TEST_ptr(nextupd)
        || !TEST_ptr(cid)
        || !TEST_true(OCSP_basic_add1_status(bs, cid,
                                             V_OCSP_CERTSTATUS_UNKNOWN,
                                             0, NULL, thisupd, nextupd)))
        goto err;
    bs_out = bs;
    bs = NULL;
 err:
    ASN1_TIME_free(thisupd);
    ASN1_TIME_free(nextupd);
    ASN1_BIT_STRING_free(key);
    ASN1_INTEGER_free(serial);
    OCSP_CERTID_free(cid);
    OCSP_BASICRESP_free(bs);
    X509_NAME_free(name);
    return bs_out;
}