Exemple #1
0
/**
 * Parses Authorization request header.
 *
 * @param[in] connp
 */
int htp_parse_authorization(htp_connp_t *connp) {
    htp_header_t *auth_header = htp_table_get_c(connp->in_tx->request_headers, "authorization");
    if (auth_header == NULL) {
        connp->in_tx->request_auth_type = HTP_AUTH_NONE;
        return HTP_OK;
    }

    if (bstr_begins_with_c_nocase(auth_header->value, "basic")) {
        // Basic authentication
        connp->in_tx->request_auth_type = HTP_AUTH_BASIC;
        return htp_parse_authorization_basic(connp, auth_header);
    } else if (bstr_begins_with_c_nocase(auth_header->value, "digest")) {
        // Digest authentication
        connp->in_tx->request_auth_type = HTP_AUTH_DIGEST;
        return htp_parse_authorization_digest(connp, auth_header);
    } else {
        // Unrecognized authentication method
        connp->in_tx->request_auth_type = HTP_AUTH_UNRECOGNIZED;        
    }

    return HTP_OK;
}
Exemple #2
0
TEST(BstrTest, BeginsWith) {
    bstr *haystack = bstr_dup_mem("ABCDEFGHIJKL\000NOPQRSTUVWXYZ", 20);
    bstr *p1 = bstr_dup_c("ABCD");
    bstr *p2 = bstr_dup_c("aBcD");

    EXPECT_EQ(1, bstr_begins_with(haystack,p1));
    EXPECT_NE(1, bstr_begins_with(haystack,p2));
    EXPECT_EQ(1, bstr_begins_with_nocase(haystack,p2));

    EXPECT_EQ(1, bstr_begins_with_c(haystack, "AB"));
    EXPECT_NE(1, bstr_begins_with_c(haystack, "ab"));
    EXPECT_EQ(1, bstr_begins_with_c_nocase(haystack, "ab"));

    EXPECT_EQ(1, bstr_begins_with_mem(haystack, "ABq",2));
    EXPECT_NE(1, bstr_begins_with_mem(haystack, "abq",2));
    EXPECT_EQ(1, bstr_begins_with_mem_nocase(haystack, "abq",2));

    bstr_free(p1);
    bstr_free(p2);
    bstr_free(haystack);
}