kmip_protocol/
lib.rs

1//! KMIP protocol library
2//!
3//! This library provides:
4//!
5//!   - Strongly-typed interfaces for a subset of the [Oasis Key Management Interoperability Protocol] aka KMIP.
6//!   - A pluggable [Client] interface for sending KMIP TTLV requests to and receiving responses from a KMIP server.
7//!   - Sample "plugins" for the [Client] interface for connecting to the KMIP server (a)synchronously via TCP+TLS.
8//!
9//! **WARNING:**
10//! Although this crate aims to offer a production quality KMIP client capability it is still immature and being
11//! constantly evolved and improved. The provided TLS "plugins" are intended primarily for use by the [example demo]
12//! to demonstrate that the library can be successfully integrated with sample client code. Please submit any feedback
13//! regarding this crate to the project [issue tracker]. Use of this code is at your own risk.
14//!
15//! [Client]: client::Client
16//! [Oasis Key Management Interoperability Protocol]: http://docs.oasis-open.org/kmip/spec/v1.0/os/kmip-spec-1.0-os.html
17//! [example demo]: https://github.com/NLnetLabs/kmip-protocol/tree/main/examples/demo
18//! [issue tracker]: https://github.com/NLnetLabs/kmip-protocol/issues/
19//!
20//! # Usage
21//!
22//! The exact features to use depend on your needs, read below to learn more about the available features. In this
23//! example the [Client] interface will read & write messages synchronously to/from a [Rustls] managed TCP+TLS
24//! connection:
25//!
26//! ```toml
27//! [dependencies]
28//! kmip-protocol = { version = "0.4.3", features = ["tls-with-rustls"] }
29//! ```
30//!
31//! [Rustls]: https://github.com/rustls/rustls
32//!
33//! Using this library you can then connect to a KMIP server and send a KMIP request something like this:
34//!
35//! ```ignore
36//! // Where 'settings' defines the hostname, port number, and other settings needed to establish a connection.
37//! let client = kmip_protocol::client::tls::rustls::connect(&settings)?;
38//!
39//! let bit_len = 2048;
40//! let private_key_name = "priv".to_string();
41//! let public_key_name = "pub".to_string();
42//! let some_bytes_to_sign = [1u8, 2u8, 3u8, 4u8, 5u8];
43//!
44//! if let Ok(res) = client.create_rsa_key_pair(bit_len, private_key_name, public_key_name) {
45//!     let (private_key_id, public_key_id) = res;
46//!     if client.activate_key(&private_key_id).is_ok() {
47//!         if let Ok(payload) = client.sign(&private_key_id, &some_bytes_to_sign) {
48//!             // ...
49//!         }
50//!         client.revoke_key(&private_key_id).ok();
51//!     }
52//!     client.destroy_key(&public_key_id).ok();
53//!     client.destroy_key(&private_key_id).ok();
54//! }
55//! ```
56//!
57//! # Advanced usage
58//!
59//! If none of the helper functions offered by the [Client] struct fit your needs you can use [Client::do_request]
60//! directly to handle the request construction and response parsing yourself, for example:
61//!
62//! ```ignore
63//! let payload = RequestPayload::Query(vec![QueryFunction::QueryOperations]);
64//! let result = client.do_request(payload)?;
65//!
66//! if let ResponsePayload::Query(payload) = result {
67//!     ...
68//! }
69//! ```
70//!
71//! [Client::do_request]: client::Client::do_request
72//!
73//! # Selecting a TLS plugin to use
74//!
75//! See the [client::tls] module for information about selecting a TLS plugin to use.
76//!
77//! # KMIP operations supported
78//!
79//! _Note: Supported operations may lack support for some attribute or managed object types. Vendor specific extensions are ignored._
80//!
81//! | KMIP Version | Operation | Support |
82//! |---|---|---|
83//! | 1.0 | Create               | ✓ |
84//! | 1.0 | Create Key Pair      | ✓ _(lacks response public/private key attribute lists support)_ |
85//! | 1.0 | Register             | ✓ _(only supports a subset of managed object types at present)_ |
86//! | 1.0 | Re-key               |  |
87//! | 1.1 | Re-key Key Pair      |  |
88//! | 1.0 | Derive Key           |  |
89//! | 1.0 | Certify              |  |
90//! | 1.0 | Re-certify           |  |
91//! | 1.0 | Locate               | ✓ _(lacks Maximum Items and Storage Status Mask support)_ |
92//! | 1.0 | Check                |  |
93//! | 1.0 | Get                  | ✓ _(lacks Key Wrapping Specification, TransparentXXX, SplitKey, Template, SecretData and OpaqueObject support)_ |
94//! | 1.0 | Get Attributes       | ✓ _(lacks Big Integer and Interval support)_ |
95//! | 1.0 | Get Attribute List   | ✓ |
96//! | 1.0 | Add Attribute        | ✓ _(lacks Big Integer and Interval support)_ |
97//! | 1.0 | Modify Attribute     | ✓ _(lacks Big Integer and Interval support)_ |
98//! | 1.0 | Delete Attribute     | ✓ |
99//! | 1.0 | Obtain Lease         |  |
100//! | 1.0 | Get Usage Allocation |  |
101//! | 1.0 | Activate             | ✓ |
102//! | 1.0 | Revoke               | ✓ |
103//! | 1.0 | Destroy              | ✓ |
104//! | 1.0 | Archive              |  |
105//! | 1.0 | Recover              |  |
106//! | 1.0 | Validate             |  |
107//! | 1.0 | Query                | ✓ _(lacks Query Application Namespaces support)_ |
108//! | 1.1 | Discover Versions    | ✓ |
109//! | 1.0 | Cancel               |  |
110//! | 1.0 | Poll                 |  |
111//! | 1.2 | Encrypt              |  |
112//! | 1.2 | Decrypt              |  |
113//! | 1.2 | Sign                 | ✓ |
114//! | 1.2 | Signature Verify     |  |
115//! | 1.2 | MAC                  |  |
116//! | 1.2 | MAC Verify           |  |
117//! | 1.2 | RNG Retrieve         | ✓ |
118//! | 1.2 | RNG Seed             |  |
119//! | 1.2 | Hash                 |  |
120//! | 1.2 | Create Split Key     |  |
121//! | 1.2 | Join Split Key       |  |
122//!
123//! # KMIP use/test case coverage
124//!
125//! Each KMIP specification document is accompanied by a separate document that defines a set of use cases, renamed in KMIP
126//! 1.1 to test cases. These show complete KMIP requests and responses. In the v1.0 and v1.1 versions each test case is
127//! broken down into its constituent TTLV parts with the matching numeric values and an accompanying hexadecimal
128//! representation of the serialized form. From v1.2 onwards the test case representation was changed from TTLV/hex based to
129//! XML based.
130//!
131//! The subset of the TTLV/hex format test cases that this crate
132//! [demonstrates compliance with](https://github.com/NLnetLabs/kmip-protocol/tree/main/src/tests) are represented below by
133//! ticked boxes:
134//!
135//! **KMIP Use Cases [v1.0](https://docs.oasis-open.org/kmip/usecases/v1.0/cs01/kmip-usecases-1.0-cs-01.html)/[v1.1](https://docs.oasis-open.org/kmip/testcases/v1.1/kmip-testcases-v1.1.html):**
136//!
137//! - 3 Centralized Management
138//!   - 3.1 Basic Functionality
139//!     - [ ] 3.1.1 Use-case: Create / Destroy
140//!     - [x] 3.1.2 Use-case: Register / Create / Get attributes / Destroy
141//!     - [ ] 3.1.3 Use-case: Create / Locate / Get / Destroy
142//!     - [ ] 3.1.4 Use-case: Dual client use-case, ID Placeholder linked Locate & Get batch
143//!     - [ ] 3.1.5 Use-case: Register / Destroy Secret Data
144//!   - [ ] 3.2 Use-case: Asynchronous Locate
145//! - 4 Key life cycle support
146//!   - [x] 4.1 Use-case: Revoke scenario
147//! - 5 Auditing and reporting
148//!   - [ ] 5.1 Use-case: Get usage allocation scenario
149//! - 6 Key Interchange, Key Exchange
150//!   - [ ] 6.1 Use-case: Import of a Third-party Key
151//! - 7 Vendor Extensions
152//!   - [ ] 7.1 Use-case: Unrecognized Message Extension with Criticality Indicator false
153//!   - [ ] 7.2 Use-case: Unrecognized Message Extension with Criticality Indicator true
154//! - 8 Asymmetric keys
155//!   - [x] 8.1 Use-case: Create a Key Pair
156//!   - [ ] 8.2 Use-case: Register Both Halves of a Key Pair
157//! - 9 Key Roll-over
158//!   - [ ] 9.1 Use-case: Create a Key, Re-key
159//!   - [ ] 9.2 Use-case: Existing Key Expired, Re-key with Same lifecycle
160//!   - [ ] 9.3 Use-case: Existing Key Compromised, Re-key with same lifecycle
161//!   - [ ] 9.4 Use-case: Create key, Re-key with new lifecycle
162//!   - [ ] 9.5 Use-case: Obtain Lease for Expired Key
163//! - 10 Archival
164//!   - [ ] 10.1 Use-case: Create a Key, Archive and Recover it
165//! - 11 Access Control, Policies
166//!   - [x] 11.1 Use-case: Credential, Operation Policy, Destroy Date _**(step 1 only for username/password auth test)**_
167//!   - [ ] 11.2 Test Case: Device Credential, Operation Policy, Destroy Date _(Added in KMIP v1.1)_
168//! - 12 Query, Maximum Response Size
169//!   - [x] 12.1 Use-case: Query, Maximum Response Size _**(Implemented for both KMIP v1.0 and v1.1 test variants)**_
170//!   - [ ] 12.2 Test Case: Query Vendor Extensions _(Added in KMIP v1.1)_
171//! - 13     Asymmetric Keys and Certificates _(Added in KMIP v1.1)_
172//!   - [ ] 13.1 Test Case: Register an Asymmetric Key Pair in PKCS#1 Format
173//!   - [ ] 13.2 Test Case: Register an Asymmetric Key Pair and a Corresponding X.509 Certificate
174//!   - [ ] 13.3 Test Case: Create, Re-key Key Pair
175//!   - [ ] 13.4 Test Case: Register Key Pair, Certify and Re-certify Public Key
176//! - 14     Key Wrapping _(Added in KMIP v1.1)_
177//!   - [ ] 14.1 Test Case: Key Wrapping using AES Key Wrap and No Encoding
178//!   - [ ] 14.2 Test Case: Key Wrapping using AES Key Wrap with Attributes
179//! - 15     Groups _(Added in KMIP v1.1)_
180//!   - [ ] 15.1 Test Case: Locate a Fresh Object from the Default Group
181//!   - [ ] 15.2 Test Case: Client-side Group Management
182//!   - [ ] 15.3 Test Case: Default Object Group Member
183//! - 16     Discover Versions _(Added in KMIP v1.1)_
184//!   - [x] 16.1 Test Case: Discover Versions
185//! - 17     Attribute Handling _(Added in KMIP v1.1)_
186//!   - [x] 17.1 Test Case: Handling of Attributes and Attribute Index Values
187//! - 18     Digest _(Added in KMIP v1.1)_
188//!   - [ ] 18.1 Test Case: Digests of Symmetric Keys
189//!   - [ ] 18.2 Test Case: Digests of RSA Private Keys
190//!
191//! **Other (partially) implemented KMIP test cases:**
192//!
193//! - [Advanced Cryptographic Mandatory Test Cases KMIP v1.3 5.9.8.1 CS-AC-M-1-13](https://docs.oasis-open.org/kmip/profiles/v1.3/os/test-cases/kmip-v1.3/mandatory/CS-AC-M-1-13.xml) _(steps 1 & 2 only for sign operation test)_
194//! - [RNG Cryptographic Mandatory Test Cases KMIP v1.3 5.9.9.1 CS-RNG-M-1-13](ttps://docs.oasis-open.org/kmip/profiles/v1.3/os/test-cases/kmip-v1.3/mandatory/CS-RNG-M-1-13.xml)
195#![forbid(unsafe_code)]
196
197#[cfg(all(
198    feature = "sync",
199    any(feature = "async-with-async-std", feature = "async-with-tokio")
200))]
201compile_error!("feature \"sync\" cannot be enabled at the same time as either of the \"async-with-async-std\" or \"async-with-tokio\" features");
202
203pub mod auth;
204pub mod request;
205pub mod response;
206pub mod tag_map;
207
208#[cfg(any(
209    feature = "tls-with-async-tls",
210    feature = "tls-with-openssl",
211    feature = "tls-with-openssl-vendored",
212    feature = "tls-with-rustls",
213    feature = "tls-with-tokio-native-tls",
214    feature = "tls-with-tokio-rustls",
215    doc
216))]
217pub mod client;
218
219pub mod types;
220
221#[cfg(test)]
222mod tests;
223
224pub use kmip_ttlv::Config;