-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlib.rs
More file actions
1084 lines (929 loc) · 29.1 KB
/
Copy pathlib.rs
File metadata and controls
1084 lines (929 loc) · 29.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use std::collections::HashMap;
use std::fmt::{self, Display};
use std::net::SocketAddr;
use std::time::{Duration, SystemTime};
use camino::{Utf8Path, Utf8PathBuf};
use serde::{Deserialize, Serialize};
pub use domain::base::Serial;
pub mod dep;
//----------- ZoneName ---------------------------------------------------------
/// The name of a zone.
pub type ZoneName = domain::base::Name<bytes::Bytes>;
//----------- ZoneReview -------------------------------------------------------
/// Review a version of a zone.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneReview {}
/// A stage for reviewing a zone.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneReviewStage {
/// Before signing.
Unsigned,
/// After signing.
Signed,
}
/// A decision upon reviewing a zone.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneReviewDecision {
/// Approve the zone.
Approve,
/// Reject the zone.
Reject,
}
/// The result of a [`ZoneReview`] command.
pub type ZoneReviewResult = Result<ZoneReviewOutput, ZoneReviewError>;
/// The output of a [`ZoneReview`] command.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneReviewOutput {}
/// An error from a [`ZoneReview`] command.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneReviewError {
/// The specified zone could not be found.
NoSuchZone,
/// The specified version of the zone was not being reviewed.
NotUnderReview,
}
impl std::fmt::Display for ZoneReviewError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ZoneReviewError::NoSuchZone => f.write_str("No such zone"),
ZoneReviewError::NotUnderReview => f.write_str("Zone not under review"),
}
}
}
//----------- ZoneReset --------------------------------------------------------
/// The result of a `zone reset` command.
pub type ZoneResetResult = Result<ZoneResetOutput, ZoneResetError>;
/// The output of a `zone reset` command.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneResetOutput {
pub zone: ZoneName,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneResetError {
NoSuchZone,
NotHalted,
}
impl std::fmt::Display for ZoneResetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoSuchZone => f.write_str("No such zone"),
Self::NotHalted => f.write_str("Zone is not halted"),
}
}
}
//----------- ZoneOverride -----------------------------------------------------
/// The result of a `zone override` command.
pub type ZoneOverrideResult = Result<ZoneOverrideOutput, ZoneOverrideError>;
/// The output of a `zone override` command.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneOverrideOutput {
pub zone: ZoneName,
pub review_stage: ZoneReviewStage,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneOverrideError {
NoSuchZone,
NotRejected,
}
impl std::fmt::Display for ZoneOverrideError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoSuchZone => f.write_str("No such zone"),
Self::NotRejected => f.write_str("Zone has not been rejected"),
}
}
}
//----------- ChangeLogging ----------------------------------------------------
/// Change how Cascade logs information.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ChangeLogging {
/// The new log level to use, if any.
pub level: Option<LogLevel>,
/// The new trace targets to use, if any.
pub trace_targets: Option<Vec<TraceTarget>>,
}
/// A logging level.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum LogLevel {
/// A function or variable was interacted with, for debugging.
Trace,
/// Something occurred that may be relevant to debugging.
Debug,
/// Things are proceeding as expected.
Info,
/// Something does not appear to be correct.
Warning,
/// Something is wrong (but Cascade can recover).
Error,
/// Something is wrong and Cascade can't function at all.
Critical,
}
/// A trace target.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TraceTarget(pub String);
/// The result of a [`ChangeLogging`] command.
pub type ChangeLoggingResult = ();
//------------------------------------------------------------------------------
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum KeyImport {
PublicKey(Utf8PathBuf),
Kmip(KmipKeyImport),
File(FileKeyImport),
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct FileKeyImport {
pub key_type: KeyType,
pub path: Utf8PathBuf,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KmipKeyImport {
pub key_type: KeyType,
pub server: String,
pub public_id: String,
pub private_id: String,
pub algorithm: String,
pub flags: String,
}
//----------- TsigKeyName -----------------------------------------------------
/// The name of a TSIG key.
pub type TsigKeyName = domain::base::Name<domain::dep::octseq::Array<255>>;
//----------- TsigAdd ---------------------------------------------------------
/// Add a TSIG key to Cascade.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TsigAdd {
/// The name of the TSIG key to add.
pub name: TsigKeyName,
/// The algorithm of the TSIG key.
pub alg: TsigAlgorithm,
/// The base64 encoded key material bytes.
pub secret: String,
}
/// The successful result of adding a TSIG key to Cascade.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TsigAddResult;
/// An error result indicating why an attempt to add a TSIG key to Cascade
/// failed.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum TsigAddError {
/// A TSIG key by the given name already exists in Cascade.
AlreadyExists,
/// The provided TSIG key secret was not correctly base64 encoded.
InvalidBase64Secret,
}
impl Display for TsigAddError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TsigAddError::AlreadyExists => write!(f, "TSIG key already exists"),
TsigAddError::InvalidBase64Secret => write!(f, "invalid TSIG base64 encoded secret"),
}
}
}
//------------ TsigRemove ----------------------------------------------------
/// The successful result of removing a TSIG key from Cascade.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TsigRemoveResult;
/// An error result indicating why an attempt to remove a TSIG key from
/// Cascade failed.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum TsigRemoveError {
/// The specified TSIG key name was not found in Cascade.
NotFound,
/// The specified TSIG key cannot be removed as it is in use.
InUse,
}
impl fmt::Display for TsigRemoveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
TsigRemoveError::NotFound => "no such TSIG key was found",
TsigRemoveError::InUse => "the TSIG key cannot be removed as it is in use",
})
}
}
//------------ TsigListResult ------------------------------------------------
/// The successful result of listing TSIG Cascade keys known to Cascade.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TsigListResult {
/// The set of TSIG keys known to Cascade plus information about each key.
pub tsig_keys: HashMap<TsigKeyName, TsigKeyInfo>,
}
/// Information about a single listed TSIG key.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TsigKeyInfo {
/// The set of zones with which this TSIG key is used.
pub zones: Vec<ZoneName>,
}
//----------- ZoneAdd --------------------------------------------------------
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneAdd {
pub name: ZoneName,
pub source: ZoneSource,
pub policy: String,
pub key_imports: Vec<KeyImport>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneAddResult {
pub name: ZoneName,
pub status: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneAddError {
AlreadyExists,
NoSuchPolicy,
PolicyMidDeletion,
NoSuchTsigKey,
Other(String),
}
impl fmt::Display for ZoneAddError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::AlreadyExists => "a zone of this name already exists",
Self::NoSuchPolicy => "no policy with that name exists",
Self::PolicyMidDeletion => "the specified policy is being deleted",
Self::NoSuchTsigKey => "no TSIG key with that name exists",
Self::Other(reason) => reason,
})
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneRemoveResult {
pub name: ZoneName,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneRemoveError {
NotFound,
}
impl fmt::Display for ZoneRemoveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::NotFound => "no such zone was found",
})
}
}
/// How to load the contents of a zone.
#[derive(Deserialize, Serialize, Debug, Clone)]
// Allow the large enum variant caused by TsigKeyName using Name<Array<255>>
// to avoid the conversions that would be needed if Name<Bytes> were to be
// used instead.
#[allow(clippy::large_enum_variant)]
pub enum ZoneSource {
/// Don't load the zone at all.
None,
/// From a zonefile on disk.
Zonefile {
/// The path to the zonefile.
path: Box<Utf8Path>,
},
/// From a DNS server via XFR.
Server {
/// The address of the server.
addr: SocketAddr,
/// The name of a TSIG key, if any.
tsig_key: Option<TsigKeyName>,
},
}
#[derive(Copy, Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
pub enum ZoneRefreshStatus {
/// Refreshing according to the SOA REFRESH interval.
#[default]
RefreshPending,
RefreshInProgress(usize),
/// Periodically retrying according to the SOA RETRY interval.
RetryPending,
RetryInProgress,
/// Refresh triggered by NOTIFY currently in progress.
NotifyInProgress,
}
impl Display for ZoneSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ZoneSource::None => f.write_str("<none>"),
ZoneSource::Zonefile { path } => path.fmt(f),
ZoneSource::Server { addr, .. } => addr.fmt(f),
}
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZonesListResult {
pub zones: Vec<ZoneName>,
}
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ZoneStage {
Unsigned,
// TODO: Signed is not strictly correct as it is currently set based on
// the presence of a zone in the signed zones collection, but that happens
// at the start of the signing process, not only once a zone has finished
// being signed.
Signed,
Published,
}
impl Display for ZoneStage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
ZoneStage::Unsigned => "loader",
ZoneStage::Signed => "signer",
ZoneStage::Published => "publication server",
};
f.write_str(str)
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneStatusError {
ZoneDoesNotExist,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneStatus {
pub name: ZoneName,
pub source: ZoneSource,
pub policy: String,
pub last_published: Option<LastPublishedZone>,
pub progress: Progress,
pub keys: Vec<KeyInfo>,
pub key_status: String,
pub error: Option<String>,
pub receipt_report: Option<ZoneLoaderReport>,
pub unsigned_serial: Option<Serial>,
pub unsigned_review_status: Option<TimestampedZoneReviewStatus>,
pub unsigned_review_addr: Option<SocketAddr>,
pub signed_serial: Option<Serial>,
pub signed_review_status: Option<TimestampedZoneReviewStatus>,
pub signed_review_addr: Option<SocketAddr>,
pub signing_report: Option<SigningReport>,
pub published_serial: Option<Serial>,
pub publish_addr: SocketAddr,
pub halted_reason: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct LastPublishedZone {
pub loaded_serial: Serial,
pub signed_serial: Serial,
// TODO:
// - time of publish
// - number of records
// - size in bytes
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Progress {
Waiting,
Loading,
LoadedReview,
HaltLoaded,
Signing,
SigningFailed,
SignedReview,
HaltSigned,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ZoneLoaderReport {
pub started_at: SystemTime,
pub finished_at: Option<SystemTime>,
pub byte_count: usize,
pub total_byte_count: Option<usize>,
pub record_count: usize,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct TimestampedZoneReviewStatus {
pub status: ZoneReviewStatus,
pub when: SystemTime,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum ZoneReviewStatus {
Pending,
Approved,
Rejected,
}
//----------- SigningReport ------------------------------------------------
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SigningReport {
pub current_action: String,
pub stage_report: SigningStageReport,
}
//------------ SigningQueueReport -------------------------------------------
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SigningQueueReport {
pub zone_name: ZoneName,
pub signing_report: SigningReport,
}
//------------ SigningStageReport -------------------------------------------
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum SigningStageReport {
Requested(SigningRequestedReport),
InProgress(SigningInProgressReport),
Finished(SigningFinishedReport),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SigningRequestedReport {
pub requested_at: SystemTime,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SigningInProgressReport {
pub requested_at: SystemTime,
pub zone_serial: Serial,
pub started_at: SystemTime,
pub unsigned_rr_count: Option<usize>,
pub walk_time: Option<Duration>,
pub sort_time: Option<Duration>,
pub denial_rr_count: Option<usize>,
pub denial_time: Option<Duration>,
pub rrsig_count: Option<usize>,
pub rrsig_reused_count: Option<usize>,
pub rrsig_time: Option<Duration>,
pub total_time: Option<Duration>,
pub threads_used: Option<usize>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SigningFinishedReport {
pub requested_at: SystemTime,
pub zone_serial: Serial,
pub started_at: SystemTime,
pub unsigned_rr_count: usize,
pub walk_time: Duration,
pub sort_time: Duration,
pub denial_rr_count: usize,
pub denial_time: Duration,
pub rrsig_count: usize,
pub rrsig_reused_count: usize,
pub rrsig_time: Duration,
pub total_time: Duration,
pub threads_used: usize,
pub finished_at: SystemTime,
pub succeeded: bool,
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct KeyInfo {
pub pubref: String,
pub key_type: KeyType,
pub key_tag: u16,
pub signer: bool,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum KeyType {
Ksk,
Zsk,
Csk,
}
impl Display for KeyType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
KeyType::Ksk => "ksk",
KeyType::Csk => "csk",
KeyType::Zsk => "zsk",
}
.fmt(f)
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum TsigAlgorithm {
HmacSha1,
HmacSha256,
HmacSha384,
HmacSha512,
}
impl Display for TsigAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TsigAlgorithm::HmacSha1 => "hmac-sha1",
TsigAlgorithm::HmacSha256 => "hmac-sha256",
TsigAlgorithm::HmacSha384 => "hmac-sha384",
TsigAlgorithm::HmacSha512 => "hmac-sha512",
}
.fmt(f)
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneHistory {
pub history: Vec<HistoryItem>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
pub enum PipelineMode {
/// Newly received zone data will flow through the pipeline.
#[default]
Running,
/// The current zone data could not be fully processed through the
/// pipeline. When new zone data is received it will flow through the
/// pipeline as normal.
SoftHalt(String),
/// The current zone data could not be fully processed through the
/// pipeline. The pipeline for this zone will remain halted until manually
/// restarted.
HardHalt(String),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HistoryItem {
pub when: SystemTime,
pub serial: Option<Serial>,
pub event: HistoricalEvent,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum HistoricalEventType {
StartedLoad,
StartedResign,
Added,
Removed,
PolicyChanged,
SourceChanged,
NewVersionReceived,
SigningSucceeded,
SigningFailed,
UnsignedZoneReview,
SignedZoneReview,
UnsignedHookFailed,
SignedHookFailed,
KeySetCommand,
KeySetError,
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum HistoricalEvent {
StartedLoad,
StartedResign,
Added,
Removed,
PolicyChanged,
SourceChanged,
NewVersionReceived,
SigningSucceeded {
trigger: SigningTrigger,
},
SigningFailed {
trigger: SigningTrigger,
reason: String,
},
UnsignedZoneReview {
status: ZoneReviewStatus,
},
SignedZoneReview {
status: ZoneReviewStatus,
},
UnsignedHookFailed {
err: String,
},
SignedHookFailed {
err: String,
},
KeySetCommand {
cmd: String,
warning: Option<String>,
elapsed: Duration,
},
KeySetError {
cmd: String,
err: String,
elapsed: Duration,
},
LoadingFailed {
reason: String,
},
}
/// The trigger for a (re-)signing operation.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum SigningTrigger {
/// A new instance of a zone has been loaded.
Load,
/// A trigger for re-signing.
Resign(ResigningTrigger),
}
/// The trigger for a re-signing operation.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ResigningTrigger {
/// Whether zone signing keys have changed.
pub keys_changed: bool,
/// Whether signatures need to be refreshed.
pub sigs_need_refresh: bool,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneHistoryError {
ZoneDoesNotExist,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ZoneReloadResult {
pub name: ZoneName,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum ZoneReloadError {
ZoneDoesNotExist,
ZoneWithoutSource,
ZoneHalted(String),
}
impl fmt::Display for ZoneReloadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::ZoneDoesNotExist => "no zone with this name exist",
Self::ZoneWithoutSource => "the specified zone has no source configured",
Self::ZoneHalted(reason) => {
return write!(f, "the zone has been halted (reason: {reason})");
}
})
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerStatusResult {
pub halted_zones: Vec<(ZoneName, String)>,
pub signing_queue: Vec<SigningQueueReport>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KeyStatusResult {
pub expirations: Vec<KeyExpiration>,
pub zones: Vec<KeysPerZone>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KeyExpiration {
pub zone: String,
pub key: String,
pub time_left: Option<Duration>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KeysPerZone {
pub zone: String,
pub keys: Vec<KeyMsg>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KeyMsg {
pub name: String,
pub msg: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
// Allow the large enum variant caused by TsigKeyName using Name<Array<255>>
// to avoid the conversions that would be needed if Name<Bytes> were to be
// used instead.
#[allow(clippy::large_enum_variant)]
pub enum PolicyReloadError {
Io(Utf8PathBuf, String),
NoSuchTsigKey(TsigKeyName),
}
impl Display for PolicyReloadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PolicyReloadError::Io(p, e) => write!(f, "{p}: {e}"),
PolicyReloadError::NoSuchTsigKey(k) => write!(f, "no TSIG key with name '{k}' exists"),
}
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PolicyChanges {
pub changes: Vec<(String, PolicyChange)>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PolicyListResult {
pub policies: Vec<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PolicyInfo {
pub name: Box<str>,
pub zones: Vec<ZoneName>,
pub loader: LoaderPolicyInfo,
pub key_manager: KeyManagerPolicyInfo,
pub signer: SignerPolicyInfo,
pub server: ServerPolicyInfo,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct LoaderPolicyInfo {
pub review: ReviewPolicyInfo,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KeyManagerPolicyInfo {
pub hsm_server_id: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ReviewPolicyInfo {
pub required: bool,
pub cmd_hook: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct SignerPolicyInfo {
pub serial_policy: SignerSerialPolicyInfo,
// TODO: These fields should have a type that explains that they represent durations.
pub sig_inception_offset: u32,
pub sig_validity_offset: u32,
pub denial: SignerDenialPolicyInfo,
pub review: ReviewPolicyInfo,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum SignerSerialPolicyInfo {
Keep,
Counter,
UnixTime,
DateCounter,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum SignerDenialPolicyInfo {
NSec,
NSec3 { opt_out: bool },
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum Nsec3OptOutPolicyInfo {
Disabled,
FlagOnly,
Enabled,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerPolicyInfo {
pub outbound: OutboundPolicyInfo,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct OutboundPolicyInfo {
pub accept_xfr_requests_from: Vec<NameserverCommsPolicyInfo>,
pub send_notify_to: Vec<NameserverCommsPolicyInfo>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct NameserverCommsPolicyInfo {
pub addr: SocketAddr,
}
impl std::fmt::Display for NameserverCommsPolicyInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.addr)
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum PolicyInfoError {
PolicyDoesNotExist,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum PolicyChange {
Added,
Removed,
Updated,
Unchanged,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct HsmServerAdd {
pub server_id: String,
pub ip_host_or_fqdn: String,
pub port: u16,
pub username: Option<String>,
pub password: Option<String>,
pub client_cert: Option<Vec<u8>>,
pub client_key: Option<Vec<u8>>,
pub insecure: bool,
pub server_cert: Option<Vec<u8>>,
pub ca_cert: Option<Vec<u8>>,
pub connect_timeout: Duration,
pub read_timeout: Duration,
pub write_timeout: Duration,
pub max_response_bytes: u32,
pub key_label_prefix: Option<String>,
pub key_label_max_bytes: u8,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct HsmServerAddResult {
pub vendor_id: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum HsmServerAddError {
UnableToConnect {
server_id: String,
host: String,
port: u16,
err: String,
},
UnableToQuery {
server_id: String,
host: String,
port: u16,
err: String,
},
CredentialsFileCouldNotBeOpenedForWriting {
// Path is not needed as the error already contains it.
err: String,
},
CredentialsFileCouldNotBeSaved {
// Path is not needed as the error already contains it.
err: String,
},
KmipServerStateFileCouldNotBeCreated {
path: String,
err: String,
},
KmipServerStateFileCouldNotBeSaved {
path: String,
err: String,
},
}
impl std::fmt::Display for HsmServerAddError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HsmServerAddError::UnableToConnect {
server_id,
host,
port,
err,
} => write!(
f,
"Unable to connect to HSM '{server_id}' at {host}:{port}: {err}"
),
HsmServerAddError::UnableToQuery {
server_id,
host,
port,
err,
} => write!(
f,
"Unable to query HSM '{server_id}' at {host}:{port}: {err}"
),
HsmServerAddError::CredentialsFileCouldNotBeOpenedForWriting { err } => {
// The error already contains everything we want to say so
// don't duplicate it.
f.write_str(err)
}
HsmServerAddError::CredentialsFileCouldNotBeSaved { err } => {
// The error already contains everything we want to say so
// don't duplicate it.
f.write_str(err)
}
HsmServerAddError::KmipServerStateFileCouldNotBeCreated { path, err } => {
write!(f, "Unable to create KMIP server state file '{path}': {err}")
}
HsmServerAddError::KmipServerStateFileCouldNotBeSaved { path, err } => {
write!(f, "Unable to save KMIP server state file '{path}': {err}")
}
}
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct HsmServerListResult {
pub servers: Vec<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct HsmServerGetResult {
pub server: KmipServerState,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct KmipServerState {
pub server_id: String,
pub ip_host_or_fqdn: String,
pub port: u16,
pub insecure: bool,
pub connect_timeout: Duration,