Skip to content

PS-10068 Production code for new KMIP C++ library#23

Open
lukin-oleksiy wants to merge 4 commits intoPercona-Lab:masterfrom
lukin-oleksiy:PS-9697-POC-of-kmip-cpp
Open

PS-10068 Production code for new KMIP C++ library#23
lukin-oleksiy wants to merge 4 commits intoPercona-Lab:masterfrom
lukin-oleksiy:PS-9697-POC-of-kmip-cpp

Conversation

@lukin-oleksiy
Copy link
Copy Markdown
Contributor

The "kmipclient" C++ library implementation is added, that wraps low-level "kmip.h" calls and bypasses mid-level "kmip_bio" level. The kmip.h file was splitted in 3 to export enums, structures and functions separately.
Comparing to the 1st version (POC), The interface was simplified and uses exceptions now.
There are plans to replace C implementation of the protocol serialization/deserialization (kmip.c and others) with C++ code, so the current version of "kmipclient" library contains a lot of TODO and skeletons for future work. Ath this stage of development, the middle-level C implementation (kmip_bio.c) is removed and the library works directly with kmip.c.
Previous PR of POC is closed.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -g")

include_directories(${PROJECT_SOURCE_DIR}/include)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to target_include_directories

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +4 to +6
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Optional, but recommended for standard compliance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use target-specific options

target_compile_features(target INTERFACE cxx_std_20)
set_target_properties(my_target PROPERTIES
  CXX_STANDARD_REQUIRED YES
  CXX_EXTENSIONS NO
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Kid of. I still need 2 statements at the top of CMakeLists.txt to compile

Comment on lines +8 to +9
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -g")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionaly always enabled Address Sanitazer looks weird to me. I would declare an option

option(WITH_ASAN "Enable Address Sanitizer" OFF)
if(WITH_ASAN)
  target_compile_options(mytarget INTERFACE "-fsanitize=address")
  target_link_options(mytarget INTERFACE "-fsanitize=address")
endif()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

)

target_link_libraries(kmipclient kmip)
set_property(TARGET kmipclient PROPERTY POSITION_INDEPENDENT_CODE ON)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_target_property()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed, there's no such funtion


macro(add_example name)
add_executable(example_${name} examples/example_${name}.cpp)
target_link_libraries(example_${name} kmipclient)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_link_libraries(example_${name} kmipclient)
target_link_libraries(example_${name} PRIVATE kmipclient)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +35 to +39
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client)
{
io = std::make_unique<IOUtils> (net_client);
logger = log;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client)
{
io = std::make_unique<IOUtils> (net_client);
logger = log;
}
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client),
io(std::make_unique<IOUtils> (net_client)),
logger(log)
{}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in all constructors

Comment on lines +84 to +85
int buffer_blocks = 1;
const int buffer_block_size = 1024;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, signed types for sizes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the reason is signed types in the lower level functions (kmip.h).

inline void
KmipRequest::add_batch_item (RequestBatchItem *rbi)
{
// Sorry, C++ guys, we have to use address arithmetic here because of the lower level
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, I know... The goal of the next development iteration is to replace kmip.c with KmipSerializer and KmipDeserializer classes and get rid of all malloc's and address arithmetic. So, ... let's keep it for a while this way. You can't imageine what a mess we have in a "heritage" code.

return BIO_read (bio_, data, dlen);
}

} // namespace No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No EOL at the end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +35 to +54
static void create_get_rq (KmipCtx &ctx, const id_t &id);
static void create_activate_rq (KmipCtx &ctx, const id_t &id);
static void create_create_aes_rq (KmipCtx &ctx, const name_t &name, const name_t &group);
static void create_register_key_rq (KmipCtx &ctx, const name_t &name, const name_t &group, const Key &k);
static void create_register_secret_rq (KmipCtx &ctx, const name_t &name, const name_t &group, std::string &secret,
int secret_data_type);
static void create_revoke_rq (KmipCtx &ctx, const id_t &id, int reason, const name_t &message,
time_t occurrence_time);
static void create_destroy_rq (KmipCtx &ctx, const id_t &id);
static void create_get_attributes_rq (KmipCtx &ctx, const id_t &id, const std::vector<std::string> &attr_names);
static void create_get_attribute_list_rq (KmipCtx &ctx, const id_t &id);
static void create_locate_by_name_rq (KmipCtx &ctx, const name_t &name, enum object_type o_type, int max_items,
int offset);
static void create_locate_by_group_rq (KmipCtx &ctx, const name_t &group_name, enum object_type o_type, int max_items,
size_t offset);
static void create_locate_all_rq (KmipCtx &ctxm, enum object_type o_type, int max_items, int offset);

private:
static void create_locate_rq (KmipCtx &ctx, bool is_group, const name_t &name, enum object_type o_type, int max_items,
size_t offset);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove enum for types, use std::size_t for sizes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch 2 times, most recently from 95a4c5f to 8e534f5 Compare January 21, 2026 11:10
        https://perconadev.atlassian.net/browse/PS-9609

op_locate_secrets_by_group() and op_all_secrets()
operationos added to kmippp library
to be able to load audit log encryption passwords into
component_keyring_kmip cache. Version bumped to 0.3.2
https://perconadev.atlassian.net/browse/PS-9861

Fortanix is strict about secret usage mask, it does not allow encrypt/decryypt usage mask,
only key derivation and export. Other servers just ignore this mask. So this path fixies
libkmip  with Fortanix server. Version is 0.3.3 now
https://perconadev.atlassian.net/browse/PS-9861

The key format type RAW added besides OPAQUE to support Fortanix server.
Now "GET SECRET" operations works correct
@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch from c86e1e8 to 5c45b26 Compare March 19, 2026 07:26
based on:

PS-9697 new KMIP C++ client library that replaces midle and top levels of old one

The "kmipclient" C++ library implementation is added, that wraps low-level
"kmip.h" calls and bypasses mid-level "kmip_bio" level; Replaces old kmippp library.

-----------------------------------------------------------------------------------

PS-10068 Making KMIP C++ library productgion ready

https://perconadev.atlassian.net/browse/PS-10068

Addressing PR comments and other fixes, finallizing the interface of the library,
adding test suite
@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch from 5c45b26 to dc27384 Compare March 20, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants