Skip to main content

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]: net::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]: net::Client::do_request
72//!
73//! # Selecting a TLS plugin to use
74//!
75#![cfg_attr(
76    feature = "tls",
77    doc = "See the [net::tls] module for information about selecting a TLS plugin to use."
78)]
79#![cfg_attr(
80    not(feature = "tls"),
81    doc = "TLS support is disabled. Enable the `tls` feature to use a TLS plugin. See the net::tls module for information about selecting a TLS plugin to use."
82)]
83//!
84//! # KMIP operations supported
85//!
86//! _Note: Supported operations may lack support for some attribute or managed object types. Vendor specific extensions are ignored._
87//!
88//! | KMIP Version | Operation | Support |
89//! |---|---|---|
90//! | 1.0 | Create               | ✓ |
91//! | 1.0 | Create Key Pair      | ✓ _(lacks response public/private key attribute lists support)_ |
92//! | 1.0 | Register             | ✓ _(only supports a subset of managed object types at present)_ |
93//! | 1.0 | Re-key               |  |
94//! | 1.1 | Re-key Key Pair      |  |
95//! | 1.0 | Derive Key           |  |
96//! | 1.0 | Certify              |  |
97//! | 1.0 | Re-certify           |  |
98//! | 1.0 | Locate               | ✓ _(lacks Maximum Items and Storage Status Mask support)_ |
99//! | 1.0 | Check                |  |
100//! | 1.0 | Get                  | ✓ _(lacks Key Wrapping Specification, TransparentXXX, SplitKey, Template, SecretData and OpaqueObject support)_ |
101//! | 1.0 | Get Attributes       | ✓ _(lacks Big Integer and Interval support)_ |
102//! | 1.0 | Get Attribute List   | ✓ |
103//! | 1.0 | Add Attribute        | ✓ _(lacks Big Integer and Interval support)_ |
104//! | 1.0 | Modify Attribute     | ✓ _(lacks Big Integer and Interval support)_ |
105//! | 1.0 | Delete Attribute     | ✓ |
106//! | 1.0 | Obtain Lease         |  |
107//! | 1.0 | Get Usage Allocation |  |
108//! | 1.0 | Activate             | ✓ |
109//! | 1.0 | Revoke               | ✓ |
110//! | 1.0 | Destroy              | ✓ |
111//! | 1.0 | Archive              |  |
112//! | 1.0 | Recover              |  |
113//! | 1.0 | Validate             |  |
114//! | 1.0 | Query                | ✓ _(lacks Query Application Namespaces support)_ |
115//! | 1.1 | Discover Versions    | ✓ |
116//! | 1.0 | Cancel               |  |
117//! | 1.0 | Poll                 |  |
118//! | 1.2 | Encrypt              |  |
119//! | 1.2 | Decrypt              |  |
120//! | 1.2 | Sign                 | ✓ |
121//! | 1.2 | Signature Verify     |  |
122//! | 1.2 | MAC                  |  |
123//! | 1.2 | MAC Verify           |  |
124//! | 1.2 | RNG Retrieve         | ✓ |
125//! | 1.2 | RNG Seed             |  |
126//! | 1.2 | Hash                 |  |
127//! | 1.2 | Create Split Key     |  |
128//! | 1.2 | Join Split Key       |  |
129//!
130//! # KMIP use/test case coverage
131//!
132//! Each KMIP specification document is accompanied by a separate document that defines a set of use cases, renamed in KMIP
133//! 1.1 to test cases. These show complete KMIP requests and responses. In the v1.0 and v1.1 versions each test case is
134//! broken down into its constituent TTLV parts with the matching numeric values and an accompanying hexadecimal
135//! representation of the serialized form. From v1.2 onwards the test case representation was changed from TTLV/hex based to
136//! XML based.
137//!
138//! The subset of the TTLV/hex format test cases that this crate
139//! [demonstrates compliance with](https://github.com/NLnetLabs/kmip-protocol/tree/main/src/tests) are represented below by
140//! ticked boxes:
141//!
142//! **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):**
143//!
144//! - 3 Centralized Management
145//!   - 3.1 Basic Functionality
146//!     - [ ] 3.1.1 Use-case: Create / Destroy
147//!     - [x] 3.1.2 Use-case: Register / Create / Get attributes / Destroy
148//!     - [ ] 3.1.3 Use-case: Create / Locate / Get / Destroy
149//!     - [ ] 3.1.4 Use-case: Dual client use-case, ID Placeholder linked Locate & Get batch
150//!     - [ ] 3.1.5 Use-case: Register / Destroy Secret Data
151//!   - [ ] 3.2 Use-case: Asynchronous Locate
152//! - 4 Key life cycle support
153//!   - [x] 4.1 Use-case: Revoke scenario
154//! - 5 Auditing and reporting
155//!   - [ ] 5.1 Use-case: Get usage allocation scenario
156//! - 6 Key Interchange, Key Exchange
157//!   - [ ] 6.1 Use-case: Import of a Third-party Key
158//! - 7 Vendor Extensions
159//!   - [ ] 7.1 Use-case: Unrecognized Message Extension with Criticality Indicator false
160//!   - [ ] 7.2 Use-case: Unrecognized Message Extension with Criticality Indicator true
161//! - 8 Asymmetric keys
162//!   - [x] 8.1 Use-case: Create a Key Pair
163//!   - [ ] 8.2 Use-case: Register Both Halves of a Key Pair
164//! - 9 Key Roll-over
165//!   - [ ] 9.1 Use-case: Create a Key, Re-key
166//!   - [ ] 9.2 Use-case: Existing Key Expired, Re-key with Same lifecycle
167//!   - [ ] 9.3 Use-case: Existing Key Compromised, Re-key with same lifecycle
168//!   - [ ] 9.4 Use-case: Create key, Re-key with new lifecycle
169//!   - [ ] 9.5 Use-case: Obtain Lease for Expired Key
170//! - 10 Archival
171//!   - [ ] 10.1 Use-case: Create a Key, Archive and Recover it
172//! - 11 Access Control, Policies
173//!   - [x] 11.1 Use-case: Credential, Operation Policy, Destroy Date _**(step 1 only for username/password auth test)**_
174//!   - [ ] 11.2 Test Case: Device Credential, Operation Policy, Destroy Date _(Added in KMIP v1.1)_
175//! - 12 Query, Maximum Response Size
176//!   - [x] 12.1 Use-case: Query, Maximum Response Size _**(Implemented for both KMIP v1.0 and v1.1 test variants)**_
177//!   - [ ] 12.2 Test Case: Query Vendor Extensions _(Added in KMIP v1.1)_
178//! - 13     Asymmetric Keys and Certificates _(Added in KMIP v1.1)_
179//!   - [ ] 13.1 Test Case: Register an Asymmetric Key Pair in PKCS#1 Format
180//!   - [ ] 13.2 Test Case: Register an Asymmetric Key Pair and a Corresponding X.509 Certificate
181//!   - [ ] 13.3 Test Case: Create, Re-key Key Pair
182//!   - [ ] 13.4 Test Case: Register Key Pair, Certify and Re-certify Public Key
183//! - 14     Key Wrapping _(Added in KMIP v1.1)_
184//!   - [ ] 14.1 Test Case: Key Wrapping using AES Key Wrap and No Encoding
185//!   - [ ] 14.2 Test Case: Key Wrapping using AES Key Wrap with Attributes
186//! - 15     Groups _(Added in KMIP v1.1)_
187//!   - [ ] 15.1 Test Case: Locate a Fresh Object from the Default Group
188//!   - [ ] 15.2 Test Case: Client-side Group Management
189//!   - [ ] 15.3 Test Case: Default Object Group Member
190//! - 16     Discover Versions _(Added in KMIP v1.1)_
191//!   - [x] 16.1 Test Case: Discover Versions
192//! - 17     Attribute Handling _(Added in KMIP v1.1)_
193//!   - [x] 17.1 Test Case: Handling of Attributes and Attribute Index Values
194//! - 18     Digest _(Added in KMIP v1.1)_
195//!   - [ ] 18.1 Test Case: Digests of Symmetric Keys
196//!   - [ ] 18.2 Test Case: Digests of RSA Private Keys
197//!
198//! **Other (partially) implemented KMIP test cases:**
199//!
200//! - [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)_
201//! - [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)
202// #![forbid(unsafe_code)]
203
204#[cfg(all(feature = "sync", feature = "async-with-tokio"))]
205compile_error!("feature \"sync\" cannot be enabled at the same time as \"async-with-tokio\" features");
206
207#[cfg(any(
208    feature = "tls-with-openssl",
209    feature = "tls-with-openssl-vendored",
210    feature = "tls-with-rustls",
211    feature = "tls-with-tokio-rustls",
212    doc
213))]
214pub mod net;
215
216pub mod ttlv;
217pub mod types;
218
219#[cfg(test)]
220mod tests;