-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PS-9609: locate_secrets_* operations added to kmippp #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
#include "kmippp.h" | ||
#include <iostream> | ||
|
||
int | ||
main (int argc, char **argv) | ||
{ | ||
|
||
if (argc < 6) | ||
{ | ||
std::cerr << "Usage: demo_locate <host> <port> <client_cert> " | ||
"<client_key> <server_cert> [group_name]" | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
kmippp::context ctx (argv[1], argv[2], argv[3], argv[4], argv[5]); | ||
// auto keys = ctx.op_all_secrets(); | ||
const std::string group = argv[6]!=nullptr? argv[6] : "TestGroup"; | ||
auto keys = ctx.op_locate_secrets_by_group (group); | ||
if(keys.empty ()) | ||
{ | ||
std::cerr << "No Secret Data found" << std::endl; | ||
std::cerr << ctx.get_last_result () << std::endl; | ||
return 1; | ||
} | ||
for (auto id : keys) | ||
{ | ||
std::cout << "Key: " << id << " "; | ||
auto secret = ctx.op_get_secret (id); | ||
auto secret_name = ctx.op_get_name_attr (id); | ||
std::cout << secret_name << " 0x"; | ||
for (auto const &c : secret) | ||
{ | ||
std::cout << std::hex << ((int)c); | ||
} | ||
std::cout << std::endl; | ||
} | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,67 @@ context::op_locate_by_group (context::name_t group) | |
return ret; | ||
} | ||
|
||
context::ids_t | ||
context::op_locate_secrets_by_group (context::name_t group) | ||
{ | ||
Attribute a[2]; | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
kmip_init_attribute (&a[i]); | ||
} | ||
|
||
object_type loctype = KMIP_OBJTYPE_SECRET_DATA; | ||
a[0].type = KMIP_ATTR_OBJECT_TYPE; | ||
a[0].value = &loctype; | ||
|
||
TextString ts2 = { 0, 0 }; | ||
ts2.value = const_cast<char *> (group.c_str ()); | ||
ts2.size = kmip_strnlen_s (ts2.value, 250); | ||
a[1].type = KMIP_ATTR_OBJECT_GROUP; | ||
a[1].value = &ts2; | ||
|
||
TemplateAttribute ta = { 0 }; | ||
ta.attributes = a; | ||
ta.attribute_count = ARRAY_LENGTH (a); | ||
|
||
int upto = 0; | ||
int all = 1; // TMP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does |
||
ids_t ret; | ||
|
||
LocateResponse locate_result; | ||
|
||
while (upto < all) | ||
{ | ||
int result = kmip_bio_locate (bio_, a, 2, &locate_result, 16, upto); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use a named constant (e.g. |
||
|
||
if (result != 0) | ||
{ | ||
return {}; | ||
} | ||
|
||
for (int i = 0; i < locate_result.ids_size; ++i) | ||
{ | ||
ret.push_back (locate_result.ids[i]); | ||
} | ||
if (locate_result.located_items != 0) | ||
{ | ||
all = locate_result.located_items; // shouldn't change after its != 1 | ||
} | ||
else | ||
{ | ||
// Dummy server sometimes returns 0 for located_items | ||
all += locate_result.ids_size; | ||
if (locate_result.ids_size == 0) | ||
{ | ||
--all; | ||
} | ||
} | ||
Comment on lines
+425
to
+437
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic with |
||
upto += locate_result.ids_size; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
context::ids_t | ||
context::op_all () | ||
{ | ||
|
@@ -431,6 +492,57 @@ context::op_all () | |
return ret; | ||
} | ||
|
||
context::ids_t | ||
context::op_all_secrets () | ||
{ | ||
Attribute a[1]; | ||
for (int i = 0; i < 1; i++) | ||
{ | ||
kmip_init_attribute (&a[i]); | ||
} | ||
|
||
object_type loctype = KMIP_OBJTYPE_SECRET_DATA; | ||
a[0].type = KMIP_ATTR_OBJECT_TYPE; | ||
a[0].value = &loctype; | ||
|
||
LocateResponse locate_result; | ||
|
||
int upto = 0; | ||
int all = 1; // TMP | ||
ids_t ret; | ||
|
||
while (upto < all) | ||
{ | ||
int result = kmip_bio_locate (bio_, a, 1, &locate_result, 16, upto); | ||
|
||
if (result != 0) | ||
{ | ||
return {}; | ||
} | ||
|
||
for (int i = 0; i < locate_result.ids_size; ++i) | ||
{ | ||
ret.push_back (locate_result.ids[i]); | ||
} | ||
if (locate_result.located_items != 0) | ||
{ | ||
all = locate_result.located_items; // shouldn't change after its != 1 | ||
} | ||
else | ||
{ | ||
// Dummy server sometimes returns 0 for located_items | ||
all += locate_result.ids_size; | ||
if (locate_result.ids_size == 0) | ||
{ | ||
--all; | ||
} | ||
} | ||
upto += locate_result.ids_size; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
bool | ||
context::op_revoke (id_t id, int reason, name_t message, time_t occurrence_time) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems these two lines have excessive indent of one space.