CH-J Toolsupravljanje poslužiteljima preko SSH
Meni
Objavljen izvor

CH-J Tools

Pregledaj direktorije i datoteke za određeni programski izdanje.

Preuzmi ZIP izvora
CH-J / Server Manager 1704 datoteke
0.1.2-beta Dodano: · Izgrađeno:
historical.rs Dodano: Datum nije zabilježen 3,6 KB · 113 linije
Oznaka Preuzmi datoteku
1//! Explicitly confirmed historical generation; never used as a modern fallback.
2use super::{
3 certificate::{certificate_data, Certificate},
4 key, protect, signature,
5 wire::*,
6};
7use crate::core::error::{CoreError, CoreResult};
8use pgp::types::Timestamp;
9use serde_json::Value;
11pub fn build(
12 payload: &Value,
13 uid: &str,
14 progress: &dyn Fn(&str) -> CoreResult<()>,
15) -> CoreResult<(Certificate, String)> {
16 let version = payload["version"].as_u64().unwrap_or(0) as u8;
17 if ![2, 3].contains(&version) {
18 return Err(invalid());
19 }
20 if payload["legacyConfirmed"] != true {
21 return Err(CoreError::new(
22 "OPENPGP_LEGACY_CONFIRMATION_REQUIRED",
23 "Historical PGP uses obsolete MD5/IDEA protection and requires explicit confirmation.",
24 ));
25 }
26 let password = payload["passphrase"].as_str().unwrap_or("");
27 if !uid.is_ascii()
28 || uid.is_empty()
29 || uid.len() > 255
30 || !password.is_ascii()
31 || password.len() > 1024
32 {
33 return Err(CoreError::new(
34 "OPENPGP_LEGACY_INPUT_INVALID",
35 "Historical PGP requires an ASCII identity (up to 255 bytes) and ASCII passphrase.",
36 ));
37 }
38 if payload["subkeys"].as_array().is_some_and(|s| !s.is_empty()) {
39 return Err(CoreError::new(
40 "OPENPGP_LEGACY_INPUT_INVALID",
41 "Historical PGP primary keys do not support subkeys.",
42 ));
43 }
44 if payload["primaryCapabilities"]
45 .as_str()
46 .is_some_and(|c| c != "CSE")
47 {
48 return Err(CoreError::new("OPENPGP_LEGACY_INPUT_INVALID","Historical RSA C/S/E capabilities are derived, not selectable flags; A is unavailable."));
49 }
50 let now = Timestamp::now().as_secs();
51 let days = match payload
52 .get("expiresAt")
53 .filter(|v| !v.is_null() && **v != 0)
54 {
55 None => 0,
56 Some(v) => {
57 let at = v.as_u64().ok_or_else(invalid)?;
58 let delta = at
59 .checked_sub(now as u64)
60 .filter(|n| *n > 0)
61 .ok_or_else(invalid)?;
62 u16::try_from(delta.div_ceil(86400)).map_err(|_| invalid())?
63 }
64 };
65 if version == 2 && days != 0 {
66 return Err(CoreError::new("OPENPGP_LEGACY_INPUT_INVALID", "The RFC 1991 V2 profile uses unlimited validity. Use V3 for historical validity in days."));
67 }
68 progress("primary")?;
69 let generated = key::generate(
70 version,
71 now,
72 days,
73 payload["algorithm"].as_str().unwrap_or("rsa1024"),
74 )?;
75 let key = &generated.key;
76 let self_sig = signature::create(
77 version,
78 0x10,
79 key.algorithm,
80 now,
81 &key.key_id()?,
82 Vec::new(),
83 Vec::new(),
84 &certificate_data(key, uid.as_bytes())?,
85 &generated.parameters,
86 )?;
87 progress("revocation")?;
88 let revocation = signature::create(
89 version,
90 0x20,
91 key.algorithm,
92 now,
93 &key.key_id()?,
94 Vec::new(),
95 Vec::new(),
96 &key.prefix()?,
97 &generated.parameters,
98 )?;
99 progress("protect")?;
100 let secret = protect::seal(key, &generated.plain, password, 5)?;
101 let certificate = Certificate::parse(&encode(
102 &[secret, Packet::new(13, uid.as_bytes().to_vec()), self_sig],
103 version,
104 )?)?;
105 let mut revoked = certificate.public_packets()?;
106 revoked.insert(1, revocation);
107 let revocation = armor("PUBLIC KEY BLOCK", &encode(&revoked, version)?);
108 progress("verify")?;
109 if certificate.metadata()?["usable"] != true {
110 return Err(invalid());
111 }
112 Ok((certificate, revocation))
SHA-256f6f616409998a02cc3792658ef4b1cd935c86c2de8e6af54593c8a8f8a2cea47

CH-J Proprietary Software License 1.14 · Izvor je osiguran pod CH-J Proprietary Software License 1.14. Njena dostupnost ne mijenja uvjete licenciranja niti daje dodatna prava.

Arhiv SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Datoteke