Beispiel #1
0
/**
 * \test Check we handle events correctly
 */
int DecodeAsn1Test09(void) {
    uint8_t *str = (uint8_t *) "\x3F\x84\x06\x80\xAB\xCD\xEF";

    Asn1Ctx *ac = SCAsn1CtxNew();
    if (ac == NULL)
        return 0;
    uint8_t ret = 1;

    uint16_t len = 7;

    SCAsn1CtxInit(ac, str, len);

    SCAsn1Decode(ac, ac->cur_frame);
    Asn1Node *node = ASN1CTX_GET_NODE(ac, 0);
    if ( !(ac->ctx_flags & ASN1_BER_EVENT_EOC_NOT_FOUND)
        || !(node->flags & ASN1_BER_EVENT_EOC_NOT_FOUND))
    {
        ret = 0;
        printf("Error, expected eoc not found, got flags %"PRIu8": ", ac->ctx_flags);
        goto end;
    }

end:
    SCAsn1CtxDestroy(ac);
    return ret;
}
/**
 * \test Check we handle short lengths correctly
 */
int DecodeAsn1Test06(void)
{
    uint8_t *str = (uint8_t *) "\x3F\x84\x06\x26";

    Asn1Ctx *ac = SCAsn1CtxNew();
    if (ac == NULL)
        return 0;
    uint8_t ret = 1;

    uint16_t len = 4;

    SCAsn1CtxInit(ac, str, len);

    SCAsn1Decode(ac, ac->cur_frame);
    Asn1Node *node = ASN1CTX_GET_NODE(ac, 0);
    if (node->len.len != 38) {
        ret = 0;
        printf("Error, expected length 10, got %"PRIu32": ", node->len.len);
        goto end;
    }

end:
    SCAsn1CtxDestroy(ac);
    return ret;
}
Beispiel #3
0
/**
 * \test Check we handle events correctly
 */
int DecodeAsn1Test08(void) {
    uint8_t *str = (uint8_t *) "\x3F\x84\x06\x81\xFF";

    Asn1Ctx *ac = SCAsn1CtxNew();
    if (ac == NULL)
        return 0;
    uint8_t ret = 1;

    uint16_t len = 5;

    SCAsn1CtxInit(ac, str, len);

    SCAsn1Decode(ac, ac->cur_frame);
    Asn1Node *node = ASN1CTX_GET_NODE(ac, 0);
    if ( !(ac->ctx_flags & ASN1_BER_EVENT_INVALID_LEN)
        || !(node->flags & ASN1_BER_EVENT_INVALID_LEN))
    {
        ret = 0;
        printf("Error, expected invalid length, got flags %"PRIu8": ", ac->ctx_flags);
        goto end;
    }

end:
    SCAsn1CtxDestroy(ac);
    return ret;
}
/**
 * \test Check we handle short identifiers correctly
 */
int DecodeAsn1Test03(void)
{
    uint8_t *str = (uint8_t *) "\x28";

    Asn1Ctx *ac = SCAsn1CtxNew();
    if (ac == NULL)
        return 0;
    uint8_t ret = 1;

    uint16_t len = 1;

    SCAsn1CtxInit(ac, str, len);

    SCAsn1Decode(ac, ac->cur_frame);
    Asn1Node *node = ASN1CTX_GET_NODE(ac, 0);
    if (node->id.tag_num != 8) {
        ret = 0;
        printf("Error, expected tag_num 10, got %"PRIu32": ", node->id.tag_num);
        goto end;
    }

end:
    SCAsn1CtxDestroy(ac);
    return ret;
}
Beispiel #5
0
/**
 * \test Decode a big chunk of data
 */
int DecodeAsn1Test10(void) {
    // Example from the specification X.690-0207 Appendix A.3
    uint8_t *str = (uint8_t *) "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
                   "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
                   "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
                   "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
                   "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
                   "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
                   "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
                   "Jones""\xA0\x0A\x43\x08""19590717"
                   "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
                   "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
                   "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
                   "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
                   "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
                   "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
                   "\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05""Jones"
                   "\xA0\x0A\x43\x08""19590717";

    Asn1Ctx *ac = SCAsn1CtxNew();
    if (ac == NULL)
        return 0;
    uint8_t ret = 1;

    uint16_t len = strlen((char *)str)-1;

    SCAsn1CtxInit(ac, str, len);

    ret = SCAsn1Decode(ac, ac->cur_frame);

    /* General checks */
    if (ret != ASN1_PARSER_OK) {
        printf("Error decoding asn1 data: ");
        ret = 0;
        goto end;
    }

    if (ac->cur_frame != 59) {
        printf("Error decoding asn1 data, not all the nodes"
               "were correctly decoded: ");
        ret = 0;
        goto end;
    }

    if (ac->iter != ac->end) {
        printf("Error decoding asn1 data, not all the nodes"
               "were correctly decoded: ");
        ret = 0;
        goto end;
    }

    Asn1Node *node = ASN1CTX_GET_NODE(ac, 0);
    if (node->len.len != 133) {
        printf("Error decoding asn1 data, not all the nodes"
               "were correctly decoded: ");
        ret = 0;
        goto end;
    }

    node = ASN1CTX_GET_NODE(ac, 30);
    if (node->len.len != 133) {
        printf("Error decoding asn1 data, not all the nodes"
               "were correctly decoded: ");
        ret = 0;
        goto end;
    }

end:
    SCAsn1CtxDestroy(ac);
    return ret;
}