mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Moved the identity OID under NibblePoker's PEN, Added a timeout on what the server sends, Bumped to 0.3.0
- The identity extension's OID is 1.3.6.1.4.1.67681.1.1 (PEN 67681): certificates made with the placeholder aren't read any more, the warning of `bakashrot-cert` is gone. - A packet the server sends (an answer, an attachment's part, to a peer too) has 30 s: a client that stopped reading is dropped. - A peer using up a stream's ids: left as it is, why in known-issues.md. - Version 0.3.0. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -23,19 +23,12 @@ pub use revocation::{Revocations, SharedRevocations, serial};
|
||||
use std::fmt;
|
||||
use x509_parser::certificate::X509Certificate;
|
||||
|
||||
/// The identity extension's OID.
|
||||
///
|
||||
/// **A placeholder** ([`IDENTITY_OID_IS_PLACEHOLDER`]): under PEN 32473,
|
||||
/// which RFC 5612 reserves for documentation. Replace it with one under
|
||||
/// NibblePoker's own PEN once IANA gave it (`docs/oid.md`), before
|
||||
/// issuing certificates for real: certificates made with this one stop
|
||||
/// being read once it changes.
|
||||
pub const IDENTITY_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 32473, 1, 1];
|
||||
|
||||
/// Whether [`IDENTITY_OID`] is still the placeholder: `bakashrot-cert`
|
||||
/// warns when it makes a CA or a certificate then. Set it to `false` with
|
||||
/// the real OID.
|
||||
pub const IDENTITY_OID_IS_PLACEHOLDER: bool = true;
|
||||
/// The identity extension's OID: `1.3.6.1.4.1.67681.1.1`, under
|
||||
/// NibblePoker's Private Enterprise Number (67681, from IANA), BakaShrot's
|
||||
/// branch (`.1`), its identity extension (`.1`). `docs/oid.md` has the
|
||||
/// branches. It never changes: certificates made with another one aren't
|
||||
/// read (those of 0.2.0 and before had a placeholder).
|
||||
pub const IDENTITY_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 67681, 1, 1];
|
||||
|
||||
/// The DNS name every server certificate has, and every client asks for:
|
||||
/// a label, not a host. Servers are known by their certificate, wherever
|
||||
|
||||
@@ -35,6 +35,10 @@ const IDLE_TIMEOUT: Duration = Duration::from_secs(300);
|
||||
/// How long an attachment's next part may take to come.
|
||||
const PART_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// How long a packet may take to be sent (an attachment's part is 1 MiB):
|
||||
/// a client that stopped reading is dropped rather than waited for.
|
||||
pub(crate) const SEND_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// An upload's parts given to the writer and not written yet, at most: the
|
||||
/// next ones wait (the client with them, through TCP).
|
||||
const PARTS_IN_FLIGHT: usize = 4;
|
||||
@@ -535,6 +539,18 @@ pub(crate) fn refused(code: ErrorCode, reason: String) -> Packet {
|
||||
RequestRefused::new(code, reason).into()
|
||||
}
|
||||
|
||||
/// Sends a packet, within [`SEND_TIMEOUT`]: an error closes the connection.
|
||||
pub(crate) async fn send(frames: &mut Frames, packet: Packet) -> std::io::Result<()> {
|
||||
frames.send(bytes::Bytes::from(packet.encode())).await
|
||||
match timeout(
|
||||
SEND_TIMEOUT,
|
||||
frames.send(bytes::Bytes::from(packet.encode())),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(sent) => sent,
|
||||
Err(_) => Err(std::io::Error::new(
|
||||
std::io::ErrorKind::TimedOut,
|
||||
"too slow to take an answer",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//! `send_*` allow. `accept_from.rs` is the other end.
|
||||
|
||||
use crate::Shared;
|
||||
use crate::connection::SEND_TIMEOUT;
|
||||
use crate::writer::Write;
|
||||
use bakashrot_config::Permissions;
|
||||
use bakashrot_pki::tls;
|
||||
@@ -297,10 +298,11 @@ impl Link {
|
||||
}
|
||||
|
||||
async fn send(&mut self, packet: Packet) -> Result<(), String> {
|
||||
self.frames
|
||||
.send(bytes::Bytes::from(packet.encode()))
|
||||
.await
|
||||
.map_err(|error| error.to_string())
|
||||
let sending = self.frames.send(bytes::Bytes::from(packet.encode()));
|
||||
match timeout(SEND_TIMEOUT, sending).await {
|
||||
Ok(sent) => sent.map_err(|error| error.to_string()),
|
||||
Err(_) => Err("too slow to take a packet".into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn receive(&mut self) -> Result<Packet, String> {
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
//! them. Every file is PEM; keys are written once, never over an existing
|
||||
//! file. See `docs/certificates.md`.
|
||||
|
||||
use bakashrot_pki::{
|
||||
CA_DAYS, CERTIFICATE_DAYS, Ca, IDENTITY_OID_IS_PLACEHOLDER, Identity, Revocations, Usage,
|
||||
summarize,
|
||||
};
|
||||
use bakashrot_pki::{CA_DAYS, CERTIFICATE_DAYS, Ca, Identity, Revocations, Usage, summarize};
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
@@ -98,15 +95,7 @@ fn main() -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Said whenever a certificate is made while the OID is the placeholder.
|
||||
const PLACEHOLDER_WARNING: &str = "warning: the identity extension's OID is still a placeholder \
|
||||
(docs/oid.md): fine for tests, not for certificates in use";
|
||||
|
||||
fn run(command: Command) -> Result<(), String> {
|
||||
if IDENTITY_OID_IS_PLACEHOLDER && matches!(command, Command::Ca { .. } | Command::Issue { .. })
|
||||
{
|
||||
eprintln!("{PLACEHOLDER_WARNING}");
|
||||
}
|
||||
match command {
|
||||
Command::Ca { name, days, out } => {
|
||||
let ca = Ca::create(&name, days).map_err(|e| e.to_string())?;
|
||||
|
||||
@@ -36,9 +36,6 @@ fn a_ca_issues_and_revokes() {
|
||||
let folder = folder("cert-tool");
|
||||
let (ok, text) = cert(&folder, &["ca", "--name", "Test CA"]);
|
||||
assert!(ok, "{text}");
|
||||
if bakashrot_pki::IDENTITY_OID_IS_PLACEHOLDER {
|
||||
assert!(text.contains("OID is still a placeholder"), "{text}");
|
||||
}
|
||||
assert!(
|
||||
cert(
|
||||
&folder,
|
||||
|
||||
Reference in New Issue
Block a user