Skip to content

Commit 58edcb5

Browse files
committed
[PKI] Client implementation for pki_enrollment_info.
1 parent 3035ab0 commit 58edcb5

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

libparsec/crates/client/src/client/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
mod list_frozen_users;
66
mod organization_info;
77
mod pki_enrollment_accept;
8+
mod pki_enrollment_info;
89
mod pki_enrollment_list;
910
mod pki_enrollment_reject;
1011
mod pki_enrollment_submit;
@@ -51,6 +52,7 @@ pub use self::{
5152
};
5253
use crate::{
5354
certif::{CertifPollServerError, CertificateOps},
55+
client::pki_enrollment_info::{PKIInfoItem, PkiEnrollmentInfoError},
5456
config::{ClientConfig, ServerConfig},
5557
event_bus::EventBus,
5658
monitors::{
@@ -690,6 +692,14 @@ impl Client {
690692
pki_enrollment_list::list_enrollments(&self.cmds).await
691693
}
692694

695+
pub async fn pki_enrollment_info(
696+
config: Arc<ClientConfig>,
697+
addr: ParsecPkiEnrollmentAddr,
698+
id: PKIEnrollmentID,
699+
) -> Result<PKIInfoItem, PkiEnrollmentInfoError> {
700+
pki_enrollment_info::info(config, addr, id).await
701+
}
702+
693703
pub async fn pki_enrollment_reject(
694704
&self,
695705
enrollment_id: PKIEnrollmentID,
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
2+
3+
use crate::ClientConfig;
4+
pub use anonymous_cmds::latest::pki_enrollment_info::PkiEnrollmentInfoStatus;
5+
use libparsec_client_connection::{protocol::anonymous_cmds, AnonymousCmds, ConnectionError};
6+
use libparsec_platform_pki::{load_answer_payload, SignedMessage};
7+
use libparsec_types::prelude::*;
8+
use std::sync::Arc;
9+
10+
#[derive(Debug, thiserror::Error)]
11+
pub enum PkiEnrollmentInfoError {
12+
#[error("Cannot communicate with the server: {0}")]
13+
Offline(#[from] ConnectionError),
14+
#[error("No enrollment found with that id")]
15+
EnrollmentNotFound,
16+
#[error("Invalid accept payload")]
17+
InvalidAcceptPayload,
18+
#[error(transparent)]
19+
Internal(#[from] anyhow::Error),
20+
}
21+
22+
pub enum PKIInfoItem {
23+
Accepted {
24+
// Serialized version of the provided payload
25+
// signature should have been checked before loading it
26+
answer: PkiEnrollmentAnswerPayload,
27+
accepted_on: DateTime,
28+
submitted_on: DateTime,
29+
},
30+
Submitted {
31+
submitted_on: DateTime,
32+
},
33+
Rejected {
34+
rejected_on: DateTime,
35+
submitted_on: DateTime,
36+
},
37+
Cancelled {
38+
submitted_on: DateTime,
39+
cancelled_on: DateTime,
40+
},
41+
}
42+
43+
pub async fn info(
44+
config: Arc<ClientConfig>,
45+
addr: ParsecPkiEnrollmentAddr,
46+
enrollment_id: PKIEnrollmentID,
47+
) -> Result<PKIInfoItem, PkiEnrollmentInfoError> {
48+
use anonymous_cmds::latest::pki_enrollment_info::{Rep, Req};
49+
let cmds = AnonymousCmds::new(
50+
&config.config_dir,
51+
ParsecAnonymousAddr::ParsecPkiEnrollmentAddr(addr.clone()),
52+
config.proxy.clone(),
53+
)?;
54+
let rep = cmds.send(Req { enrollment_id }).await?;
55+
56+
let status = match rep {
57+
Rep::Ok(status) => status,
58+
Rep::EnrollmentNotFound => return Err(PkiEnrollmentInfoError::EnrollmentNotFound),
59+
rep @ Rep::UnknownStatus { .. } => {
60+
return Err(anyhow::anyhow!("Unexpected server response: {:?}", rep).into())
61+
}
62+
};
63+
64+
// Check that the payload is valid
65+
let answer = match status {
66+
PkiEnrollmentInfoStatus::Submitted { submitted_on } => {
67+
PKIInfoItem::Submitted { submitted_on }
68+
}
69+
PkiEnrollmentInfoStatus::Rejected {
70+
rejected_on,
71+
submitted_on,
72+
} => PKIInfoItem::Rejected {
73+
rejected_on,
74+
submitted_on,
75+
},
76+
PkiEnrollmentInfoStatus::Cancelled {
77+
submitted_on,
78+
cancelled_on,
79+
} => PKIInfoItem::Cancelled {
80+
submitted_on,
81+
cancelled_on,
82+
},
83+
PkiEnrollmentInfoStatus::Accepted {
84+
accept_payload,
85+
accept_payload_signature,
86+
accepted_on,
87+
accepter_der_x509_certificate,
88+
submitted_on,
89+
} => {
90+
let message = SignedMessage {
91+
algo: PkiSignatureAlgorithm::RsassaPssSha256, // TODO update after #https://github.com/Scille/parsec-cloud/pull/11604
92+
signature: accept_payload_signature.to_vec(),
93+
message: accept_payload.to_vec(),
94+
};
95+
let answer = load_answer_payload(&accepter_der_x509_certificate, &message, accepted_on)
96+
.map_err(|_| PkiEnrollmentInfoError::InvalidAcceptPayload)?;
97+
PKIInfoItem::Accepted {
98+
answer,
99+
accepted_on,
100+
submitted_on,
101+
}
102+
}
103+
};
104+
Ok(answer)
105+
}

0 commit comments

Comments
 (0)