Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/src/main/assets/pnv.wasm
Binary file not shown.
33 changes: 27 additions & 6 deletions matcher/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CXX = g++
CC = gcc
CXXFLAGS = -std=c++17 -Wall -Wextra -g -I. -I/usr/include/doctest -I/usr/include/nlohmann
CFLAGS = -Wall -Wextra -g -I. -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-overflow
CXX ?= g++
CC ?= gcc
CXXFLAGS ?= -std=c++17 -Wall -Wextra -g -I. -I/usr/include/doctest -I/usr/include/nlohmann
CFLAGS ?= -Wall -Wextra -g -I. -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-overflow

# Common objects
COMMON_OBJS = dcql.o openid4vp1_0.o base64.o cJSON/cJSON.o issuance/provision.o
Expand All @@ -13,6 +13,27 @@ test_runner: test_runner.o dcql.o openid4vp1_0.o base64.o cJSON/cJSON.o
test: test_runner
./test_runner

# PNV tests
PNV_OBJS = pnv/dcql.o pnv/openid4vp1_0.o base64.o cJSON/cJSON.o

pnv_test: pnv/test/openid4vp1_0_test.o pnv/test/common.o $(PNV_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^

pnv/test/openid4vp1_0_test.o: pnv/test/openid4vp1_0_test.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

pnv/test/common.o: pnv/test/common.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

pnv/dcql.o: pnv/dcql.c
$(CC) $(CFLAGS) -c $< -o $@

pnv/openid4vp1_0.o: pnv/openid4vp1_0.c
$(CC) $(CFLAGS) -c $< -o $@

test_pnv: pnv_test
./pnv_test

test_runner.o: test_runner.cc
$(CXX) $(CXXFLAGS) -c $< -o $@

Expand All @@ -32,6 +53,6 @@ issuance/provision.o: issuance/provision.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -f *.o cJSON/*.o issuance/*.o test_runner
rm -f *.o cJSON/*.o issuance/*.o pnv/*.o pnv/test/*.o test_runner pnv_test

.PHONY: test clean
.PHONY: test test_pnv clean
5 changes: 5 additions & 0 deletions matcher/credentialmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ __attribute__((import_module("credman_v5"), import_name("AddMetadataDisplayTextT
#endif
void AddMetadataDisplayTextToEntrySet(const char *cred_id, const char *metadata_display_text, const char *set_id, int set_index);

#if defined(__wasm__)
__attribute__((import_module("credman_v7"), import_name("SetDelegationTypeForEntryInSet")))
#endif
void SetDelegationTypeForEntryInSet(const char* cred_id, int delegation_type, const char* set_id, int set_index);

#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 22 additions & 13 deletions matcher/pnv/dcql.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ MatchCredential(cJSON *credential, cJSON *credential_store)
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_consent", aggregator_consent);
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_policy_text", aggregator_policy_text);
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_policy_url", aggregator_policy_url);
cJSON_AddItemReferenceToObject(matched_credential, "delegation_type", cJSON_GetObjectItemCaseSensitive(candidate, "delegation_type"));
cJSON *matched_claim_names = cJSON_CreateArray();
// printf("candidate %s\n", cJSON_Print(candidate));
cJSON_AddItemReferenceToArray(matched_claim_names, cJSON_GetObjectItemCaseSensitive(candidate, "shared_attribute_display_name"));
Expand Down Expand Up @@ -217,6 +218,7 @@ MatchCredential(cJSON *credential, cJSON *credential_store)
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_consent", aggregator_consent);
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_policy_text", aggregator_policy_text);
cJSON_AddItemReferenceToObject(matched_credential, "aggregator_policy_url", aggregator_policy_url);
cJSON_AddItemReferenceToObject(matched_credential, "delegation_type", cJSON_GetObjectItemCaseSensitive(candidate, "delegation_type"));
cJSON *matched_claim_names = cJSON_CreateArray();
cJSON_AddItemReferenceToArray(matched_claim_names, cJSON_GetObjectItemCaseSensitive(candidate, "shared_attribute_display_name"));

Expand Down Expand Up @@ -411,7 +413,6 @@ cJSON *dcql_query(cJSON *query, cJSON *credential_store)
cJSON_ArrayForEach(matched_credential, credentials) {
cJSON_AddItemReferenceToArray(matched_cred_ids, cJSON_GetObjectItemCaseSensitive(matched_credential, "id"));
}
char set_id_buffer[16];
cJSON_AddItemReferenceToObject(single_matched_credential_set, "matched_credential_ids", matched_cred_ids);
cJSON* curr_matched_credential_sets = cJSON_CreateArray(); // For consistency with the credential_sets case
cJSON_AddItemReferenceToArray(curr_matched_credential_sets, single_matched_credential_set);
Expand Down Expand Up @@ -440,29 +441,37 @@ cJSON *dcql_query(cJSON *query, cJSON *credential_store)
cJSON* curr_matched_credential_sets = cJSON_CreateArray();
cJSON* options = cJSON_GetObjectItemCaseSensitive(credential_set, "options");
cJSON* option;
int credential_set_matched = 0;
int option_idx = 0;
cJSON_ArrayForEach(option, options) {
cJSON* matched_cred_ids = cJSON_CreateArray();
cJSON* matched_indices = cJSON_CreateArray();
cJSON* cred_id;
credential_set_matched = 1;
int cred_idx = 0;
cJSON_ArrayForEach(cred_id, option) {
if (cJSON_GetObjectItemCaseSensitive(candidate_matched_credentials, cJSON_GetStringValue(cred_id)) == NULL) {
credential_set_matched = 0;
break;
} // Remove for multi-provider support
cJSON_AddItemReferenceToArray(matched_cred_ids, cred_id);
if (cJSON_GetObjectItemCaseSensitive(candidate_matched_credentials, cJSON_GetStringValue(cred_id)) != NULL) {
cJSON_AddItemReferenceToArray(matched_cred_ids, cred_id);
cJSON_AddItemToArray(matched_indices, cJSON_CreateNumber(cred_idx));
}
++cred_idx;
}
if (credential_set_matched != 0) {
int option_length = cJSON_GetArraySize(option);
int matched_count = cJSON_GetArraySize(matched_cred_ids);
if (matched_count > 0) {
cJSON* cred_set_info = cJSON_CreateObject();
char set_id_buffer[4];
char option_id_buffer[4];
int chars_written = sprintf(set_id_buffer, "%d", set_idx);
chars_written = sprintf(option_id_buffer, "%d", option_idx);
char set_id_buffer[16];
char option_id_buffer[16];
sprintf(set_id_buffer, "%d", set_idx);
sprintf(option_id_buffer, "%d", option_idx);
cJSON_AddStringToObject(cred_set_info, "set_id", set_id_buffer);
cJSON_AddStringToObject(cred_set_info, "option_id", option_id_buffer);
cJSON_AddItemReferenceToObject(cred_set_info, "matched_credential_ids", matched_cred_ids);
cJSON_AddNumberToObject(cred_set_info, "option_length", option_length);
cJSON_AddItemToObject(cred_set_info, "matched_indices", matched_indices);
cJSON_AddBoolToObject(cred_set_info, "is_partial", matched_count < option_length);
cJSON_AddItemReferenceToArray(curr_matched_credential_sets, cred_set_info);
} else {
cJSON_Delete(matched_cred_ids);
cJSON_Delete(matched_indices);
}
++option_idx;
}
Expand Down
Loading
Loading