Skip to content

Commit 0134c81

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

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

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

Lines changed: 12 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::PkiEnrollmentInfoError,
5456
config::{ClientConfig, ServerConfig},
5557
event_bus::EventBus,
5658
monitors::{
@@ -64,6 +66,7 @@ use crate::{
6466
use libparsec_client_connection::AuthenticatedCmds;
6567
use libparsec_platform_async::lock::Mutex as AsyncMutex;
6668

69+
use libparsec_protocol::anonymous_cmds::v5::pki_enrollment_info::PkiEnrollmentInfoStatus;
6770
use libparsec_types::prelude::*;
6871
pub use organization_info::{
6972
ClientGetOrganizationBootstrapDateError, ClientOrganizationInfoError, OrganizationInfo,
@@ -690,6 +693,15 @@ impl Client {
690693
pki_enrollment_list::list_enrollments(&self.cmds).await
691694
}
692695

696+
pub async fn pki_enrollment_info(
697+
config: Arc<ClientConfig>,
698+
addr: ParsecPkiEnrollmentAddr,
699+
id: PKIEnrollmentID,
700+
) -> Result<(PkiEnrollmentInfoStatus, Option<PkiEnrollmentAnswerPayload>), PkiEnrollmentInfoError>
701+
{
702+
pki_enrollment_info::info(config, addr, id).await
703+
}
704+
693705
pub async fn pki_enrollment_reject(
694706
&self,
695707
enrollment_id: PKIEnrollmentID,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
2+
3+
use std::sync::Arc;
4+
5+
use libparsec_platform_pki::{load_answer_payload, SignedMessage};
6+
use libparsec_types::prelude::*;
7+
8+
use libparsec_client_connection::{protocol::anonymous_cmds, AnonymousCmds, ConnectionError};
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 use anonymous_cmds::latest::pki_enrollment_info::PkiEnrollmentInfoStatus;
23+
24+
use crate::ClientConfig;
25+
26+
pub async fn info(
27+
config: Arc<ClientConfig>,
28+
addr: ParsecPkiEnrollmentAddr,
29+
enrollment_id: PKIEnrollmentID,
30+
) -> Result<(PkiEnrollmentInfoStatus, Option<PkiEnrollmentAnswerPayload>), PkiEnrollmentInfoError> {
31+
use anonymous_cmds::latest::pki_enrollment_info::{Rep, Req};
32+
let cmds = AnonymousCmds::new(
33+
&config.config_dir,
34+
ParsecAnonymousAddr::ParsecPkiEnrollmentAddr(addr.clone()),
35+
config.proxy.clone(),
36+
)?;
37+
let rep = cmds.send(Req { enrollment_id }).await?;
38+
39+
let status = match rep {
40+
Rep::Ok(status) => status,
41+
Rep::EnrollmentNotFound => return Err(PkiEnrollmentInfoError::EnrollmentNotFound),
42+
rep @ Rep::UnknownStatus { .. } => {
43+
return Err(anyhow::anyhow!("Unexpected server response: {:?}", rep).into())
44+
}
45+
};
46+
47+
// Check that the payload is valid
48+
let answer = match &status {
49+
PkiEnrollmentInfoStatus::Submitted { .. }
50+
| PkiEnrollmentInfoStatus::Rejected { .. }
51+
| PkiEnrollmentInfoStatus::Cancelled { .. } => None, // nothing to check
52+
PkiEnrollmentInfoStatus::Accepted {
53+
accept_payload,
54+
accept_payload_signature,
55+
accepted_on,
56+
accepter_der_x509_certificate,
57+
..
58+
} => {
59+
let message = SignedMessage {
60+
algo: PkiSignatureAlgorithm::RsassaPssSha256, // TODO update after #https://github.com/Scille/parsec-cloud/pull/11604
61+
signature: accept_payload_signature.to_vec(),
62+
message: accept_payload.to_vec(),
63+
};
64+
Some(
65+
load_answer_payload(accepter_der_x509_certificate, &message, *accepted_on)
66+
.map_err(|_| PkiEnrollmentInfoError::InvalidAcceptPayload)?,
67+
)
68+
}
69+
};
70+
Ok((status, answer))
71+
}

0 commit comments

Comments
 (0)