Common keyring implementation infrastructure provides useful parts to minimize efforts involved in writing a new component.
This page will provide details about how a new keyring component can be implemented using the common infrastructure
Any keyring component can be divided in 3 parts:
- Configuration Management
- Service Implementation
- Backend Management
Configuration Management
A binary must be able to load a keyring component on top of minimal chassis. Hence, the component cannot use option management provided by underlying binary to read configuration for the keyring.
One way to read configuration is to accept it as a JSON file. A sample configuration file may look like following:
{
"version" : "1.0.0"
"config_key_1" : "config_data_1",
"config_key_2" : "config_data_2",
"config_key_3" : "config_data_3"
}
Various (key, value) pair would help component get details required to communicate with backend and initialize keyring.
You can use keyring_common::config::Config_reader to read a JSON file and extract value of individual configuration parameters.
Depending upon the services implemented by the component, it is possible that:
A> Configuration data can be queried at runtime
B> Configuration can be changed at runtime
Service Implementation
Please refer to Keyring Component for description of various services that a keyring component should implement. You may take a look at Keyring component services for details about specific services and various APIs.
If you are writing a keyring component that should work with MySQL server, the component must implement following services.
- Keyring reader service: s_mysql_keyring_reader_with_status Use keyring_common::service_definition::Keyring_reader_service_impl for service class declaration. Use KEYRING_READER_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring writer service: s_mysql_keyring_writer Use keyring_common::service_definition::Keyring_writer_service_impl for service class declaration. Use KEYRING_WRITER_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring generator service: s_mysql_keyring_generator Use keyring_common::service_definition::Keyring_generator_service_impl for service class declaration. Use KEYRING_GENERATOR_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring keys metadata iterator service: s_mysql_keyring_keys_metadata_iterator Use keyring_common::service_definition::Keyring_keys_metadata_iterator_service_impl for service class declaration. Use KEYRING_KEYS_METADATA_FORWARD_ITERATOR_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring component metadata query service: s_mysql_keyring_component_metadata_query Use keyring_common::service_definition::Keyring_metadata_query_service_impl for service class declaration. Use KEYRING_COMPONENT_METADATA_QUERY_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring load service: s_mysql_keyring_load Use keyring_common::service_definition::Keyring_load_service_impl for service class declaration. Use KEYRING_LOAD_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring AES service: s_mysql_keyring_aes Use keyring_common::service_definition::Keyring_aes_service_impl for service class declaration. Use KEYRING_AES_IMPLEMENTOR to add service implementation details required by component infrastructure.
- Keyring status service: s_mysql_keyring_component_status Use keyring_common::service_definition::Keyring_metadata_query_service_impl for service class declaration. Use KEYRING_COMPONENT_STATUS_IMPLEMENTOR to add service implementation details required by component infrastructure.
Please note that key of type AES and SECRET must be supported.
In addition, you will also need to implement log_builtins and log_builtins_string services if you are planning to use keyring common's implementation templates. The common keyring infrastrcture has a bare-minimum implementation of these services. You can use keyring_common::service_definition::Log_builtins_keyring for service class declaration. Use KEYRING_LOG_BUILTINS_IMPLEMENTOR and KEYRING_LOG_BUILTINS_STRING_IMPLEMENTOR to add service implementation details required by component infrastrcture.
Common keyring infrastructure also provides implementation for some of the above mentioned services. This will allow implementor to create a minimal definition of service APIs and use templates provided by common infra.
In order to do that, common keyring infrastrcture requires following:
- A handle to keyring_common::operations::Keyring_operations object This class provides a wrapper over keyring backend and expect that implementor provides handle to a backend class with set of APIs required to manage keys. Please see Backend Management for more details.
- A handle to keyring_common::service_implementation::Component_callbacks object This class provides callback methods which are implemented by individual component. For example: Keyring state, Maximum supported data length, metadata vector creation etc.
Assumping that above mentioned dependencies are satisfied, following are some inputs on how various services can be implemented.
- Keyring reader service: s_mysql_keyring_reader_with_status See keyring_common::service_implementation::init_reader_template See keyring_common::service_implementation::deinit_reader_template See keyring_common::service_implementation::fetch_length_template See keyring_common::service_implementation::fetch_template
- Keyring writer service: s_mysql_keyring_writer See keyring_common::service_implementation::store_template See keyring_common::service_implementation::remove_template
- Keyring generator service: s_mysql_keyring_generator See keyring_common::service_implementation::generate_template
- Keyring keys metadata iterator service: s_mysql_keyring_keys_metadata_iterator See keyring_common::service_implementation::init_keys_metadata_iterator_template See keyring_common::service_implementation::deinit_keys_metadata_iterator_template See keyring_common::service_implementation::keys_metadata_iterator_is_valid See keyring_common::service_implementation::keys_metadata_iterator_next See keyring_common::service_implementation::keys_metadata_get_length_template See keyring_common::service_implementation::keys_metadata_get_template
- Keyring component metadata query service: s_mysql_keyring_component_metadata_query See keyring_common::service_implementation::keyring_metadata_query_init_template See keyring_common::service_implementation::keyring_metadata_query_deinit_template See keyring_common::service_implementation::keyring_metadata_query_is_valid_template See keyring_common::service_implementation::keyring_metadata_query_next_template See keyring_common::service_implementation::keyring_metadata_query_get_length_template See keyring_common::service_implementation::keyring_metadata_query_get_template
- Keyring load service: s_mysql_keyring_load This service is specific to individual keyring component because it has strong dependency on component specific configuration details. The component should implement it as per its own requirement.
- Keyring AES service: s_mysql_keyring_aes See keyring_common::service_implementation::aes_get_encrypted_size_template See keyring_common::service_implementation::aes_encrypt_template See keyring_common::service_implementation::aes_decrypt_template
- Keyring status service: s_mysql_keyring_component_status See keyring_common::service_implementation::keyring_metadata_query_keyring_initialized_template
Backend Management
This part would be different for each keyring component. Backend can be a remote server, something that stored locally or a combination of both. Regardless of the backend, if keyring_common::operations::Keyring_operations is to be used, component must implement a class similar to following:
template <typename Data_extension>
class Backend {
public:
bool load_cache(
size_t maximum_data_length() const;
};
Sensitive data storage.
Definition: data.h:39
Keyring operations A class to perform operations on keyring.
Definition: operations.h:482
bool store(THD *thd, const Table *tp)
Stores the SDI for a table.
Definition: sdi.cc:607
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
size_t size(const char *const c)
Definition: base64.h:46
Common keyring infrastructure includes implementation that may help file management. It provides a content agnostic, backup aware file reader and writer.
Writer works in following manner:
- Write content to backup file
- If backup file exists, copy its content to main file
- Remove backup file
Reader works in following manner:
- Invoke writer to process backup file, if it exists
- Read from main file
Please see keyring_common::data_file::File_writer for writer details and keyring_common::data_file::File_reader for reader details.
In-memory Data Management
Common keyring infrastructure also provides useful classes to manage data in memory.
- To cache metadata related to data, use keyring_common::meta::Metadata
- To cache data in memory, use keyring_common::data::Data
- To cache backend specific details for data (e.g. ID generated by backend), use keyring_common::data::Data_extension
A reader/writer pair for JSON data that can be used to store data, related metadata and data extension if any. See keyring_common::json_data::Json_reader and keyring_common::json_data::Json_writer.
Expected JSON format is specified below:
{
"version": "1.0",
"elements": [
{
"user": "<user_name>",
"data_id": "<name>",
"data_type": "<data_type>",
"data": "<hex_of_data>",
"extension": [
]
},
...
...
]
}