Initial commit for Jujitsu (JJ) vcs
This commit is contained in:
commit
df1d7e54ca
14 changed files with 2004 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
45
.vscode/launch.json
vendored
Normal file
45
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'ct'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=ct",
|
||||||
|
"--package=ct"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "ct",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'ct'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=ct",
|
||||||
|
"--package=ct"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "ct",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"Merkle",
|
||||||
|
"Precertificate"
|
||||||
|
],
|
||||||
|
"rust-analyzer.rustfmt.extraArgs": ["+nightly"]
|
||||||
|
}
|
1551
Cargo.lock
generated
Normal file
1551
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
18
Cargo.toml
Normal file
18
Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
[package]
|
||||||
|
name = "ct"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.90"
|
||||||
|
der-parser = "9.0.0"
|
||||||
|
nom = "7.1.3"
|
||||||
|
num-traits = "0.2.19"
|
||||||
|
reqwest = { version = "0.12.8", features = ["json"] }
|
||||||
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
|
serde_json = "1.0.132"
|
||||||
|
sha2 = "0.10.8"
|
||||||
|
x509-parser = "0.16.0"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
base64ct = "1.6.0"
|
36
rustfmt.toml
Normal file
36
rustfmt.toml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
binop_separator = "Front"
|
||||||
|
brace_style = "SameLineWhere"
|
||||||
|
combine_control_expr = false
|
||||||
|
condense_wildcard_suffixes = true
|
||||||
|
control_brace_style = "AlwaysSameLine"
|
||||||
|
empty_item_single_line = true
|
||||||
|
error_on_line_overflow = true
|
||||||
|
fn_single_line = true
|
||||||
|
force_multiline_blocks = false
|
||||||
|
format_code_in_doc_comments = true
|
||||||
|
format_generated_files = false
|
||||||
|
format_strings = true
|
||||||
|
hard_tabs = true
|
||||||
|
imports_indent = "Block"
|
||||||
|
imports_layout = "HorizontalVertical"
|
||||||
|
indent_style = "Block"
|
||||||
|
match_arm_blocks = false
|
||||||
|
max_width = 90
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
newline_style = "Unix"
|
||||||
|
normalize_comments = true
|
||||||
|
normalize_doc_attributes = true
|
||||||
|
overflow_delimited_expr = true
|
||||||
|
reorder_impl_items = true
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
reorder_modules = true
|
||||||
|
space_after_colon = true
|
||||||
|
space_before_colon = false
|
||||||
|
spaces_around_ranges = false
|
||||||
|
trailing_comma = "Never"
|
||||||
|
trailing_semicolon = true
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_small_heuristics = "Default"
|
||||||
|
use_try_shorthand = true
|
||||||
|
where_single_line = false
|
||||||
|
wrap_comments = true
|
10
src/lib.rs
Normal file
10
src/lib.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//! A crate implementing aspects of Certificate Transparency as defined in
|
||||||
|
//! [RFC6926] in rust.
|
||||||
|
//!
|
||||||
|
//! Parsing logic for CT structures is defined in the [`parsing`] module. This
|
||||||
|
//! primarily uses the [`nom`] crate for parsing
|
||||||
|
//!
|
||||||
|
//! [RFC6926]: https://datatracker.ietf.org/doc/html/rfc6962
|
||||||
|
|
||||||
|
pub mod merkle;
|
||||||
|
pub mod parsing;
|
74
src/merkle/consts.rs
Normal file
74
src/merkle/consts.rs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
pub const LEAF_BASE64_BUFFER_SIZE: usize = 3072;
|
||||||
|
|
||||||
|
pub const LEAF_HASH_PREFIX: u8 = 0x00;
|
||||||
|
pub const INTERIOR_HASH_PREFIX: u8 = 0x01;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) mod test_constants {
|
||||||
|
// TODO Write a script to populate this with random entries
|
||||||
|
pub(crate) const LEAF_INPUT_EXAMPLES: &[(&str, &str, u64)] = &[
|
||||||
|
(
|
||||||
|
"AAAAAAGSnKkrxAAAAAOJMIIDhTCCAwygAwIBAgISBIMWztGBRQE+UJezy64M233lMAoGCCqGSM49BAMDMDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJFNjAeFw0yNDEwMTcyMTQ3NTRaFw0yNTAxMTUyMTQ3NTNaMB0xGzAZBgNVBAMTEnRlc3Qub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QEBCwUAA4ICAQABe/kV4PedePHdRo/zTdCzPym6oPuPlOSBW76PvnX/TMcZSjbyis8ILrZ/DWlelVXFN44FTjQyh0gjOig06EgW20cF9pFuKPncskJLAu7FSOo3cYbRe/gySiWx17p6adkpbQo7jt0bctiFe2G/qXq5fr3p24+Ap7J7UmJ8ihcOVhKGVjj0tV2X7Q7LGQnzL1nK8uP61onh8uECI31YZ42CdqxDLxSSVvfLT4huZqy/QzWgva3dyVg62itefDePrgMHudPRijSfCuANbAA6bSlbpjNWkbNxRvuqygOuso14CzcJDF2eCPjfF0IxzxifWKbTge6Fd9C8XHavCEz1oWtJoBrXKQE0hsRcFfSFeV1xkxNXGAtUf0VA9PNZaZ4Z9+ghOQDnqeQQw6qxzp1AeR+DWUVUeBQDKt1/eYN0VXTpmMNisl3tEwRdmxTmSw2uFFRgHgAIFWDgKfNVg1PnTGje8frPOA7fTYqLFzeeDAUfaNXmizQoDB25ifJIhvRqX+gl6Ff+i+uXIeHc097UbRK2bPKIf8XtqD94n48OnfmJBvcGnTl5PaI4Bec3J4tpZ/w6FhZ17FIvP3hxaERmFt89SyYKzCLC2bhnVByHi2f8/jYJVv2nMycjoDxMTJUFRDCn+3BAcAyYbibc+BQLNlGMS04YDZerEJ4BmWTDd1nQZgAA",
|
||||||
|
"C=GB, L=London, O=Google Certificate Transparency, serialNumber=1692183670230477",
|
||||||
|
1692183670314
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"AAAAAAGKCs8mKgAAAAU2MIIFMjCCAxqgAwIBAgIJAPXCmTa0J/XPMA0GCSqGSIb3DQEBCwUAMH8xCzAJBgNVBAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xFzAVBgNVBAoMDkdvb2dsZSBVSyBMdGQuMSEwHwYDVQQLDBhDZXJ0aWZpY2F0ZSBUcmFuc3BhcmVuY3kxIzAhBgNVBAMMGk1lcmdlIERlbGF5IEludGVybWVkaWF0ZSAxMB4XDTI1MDgxNzA5NDIyMloXDTI1MDgxODA5ND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AEljiyksHKdOcxoPDlchTRvPAn+FngkELiR80HbHsi703UG3KGBSNrDiQCHNCmO/lF6c1kN+/Ij29zu+Wle8Q8veJAanKE8WDGnlU1pFw9nuCaIAtxX8AiMUDuLrAHj38Mj7MIQS4CzloAp4UMqvaupOc+cxJ/8psbUy+MkI6dMww3N5gZE6EV6WCF21Ogm/zqMQwy/Fj1P7dpl+BFYEmJzP0yhiZMh2a9okbpienKL8zaiz/b/27ffO/IxaxT5IwJ60k6Bj9kB9M3H9leFA5EgSpe7buoK86z8LQJ+KHCWErl616TsW2KocycD+dAyNsGk9OlSL8WpKDV5KFmyO1HWDCIpC8WYE/miWH1zwKbmDVJJOEVUBbfNWwy9EbgxHdDvwYChC9/EfIOxCOEj/JQZoEiHjVUy0PGsO59JaxG/citHaQr5Uv48AAA==",
|
||||||
|
"C=GB, L=London, O=Google, OU=Certificate Transparency, CN=flowers-to-the-world.com",
|
||||||
|
1692398462506
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"AAAAAAGKDLItnQAB43aJADBzoMZJzGVt6UbAMXTSXFZv48OAW4RvUjaUN5gAAx0wggMZoAMCAQICCHHWBy81SwwSMA0GCSqGSIb3DQEBCwUAMH8xCzAJBgNVBAYTAkdCMQ8wDQYDVQQIDAZMb25kb24xFzAVBgNVBAoMDkdvb2dsZSBVSyBMdGQuMSEwHwYDVQQLDBhDZXJ0aWZpY2F0ZSBUcmFuc3BhcmVuY3kxIzAhBgNVBAMMGk1lcmdlIERlbGF5IEludGVybWVkaWF0ZSAxMB4XDTI2MDEwNTE4MDkwNVoXDTI2MDEwNjE4MDkwNVowdTELMAkGA1UEBhMCR0IxDzANBgNVBAcTBkxvbmRvbjEPMA0GA1UEChMGR29vZ2xlMSEwHwYDVQQLExhDZXJ0aWZpY2F0ZSBUcmFuc3BhcmVuY3kxITAfBgNVBAMTGGZsb3dlcnMtdG8tdGhlLXdvcmxkLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALlyEW37k0qzzAURkI8auNwkyG/p8lh802KPRueNahXxaf73M9vTMIl2czqosnYxhGKmcXdi8jgtRrUJ69+/qmxX7sG454Odz2ocWKGWcwNvhw/roqbATUBYG32sPpUkUTuyeB6nJY1aEQnDDTTIkbx8zBlKo9e3E9lkYVi5rLvbdGBwm+YaopW9TaVSl/npkPXCDUv5LDvMyKDREu2GW/NRLWErP9eg0FB9RpdaXRcAvrNh3/a+NMxRhjJX0oH3xhIvlkoCADJX2dU1V1Bd/QUuvSW/0BjdXRjl9ivmcN3WhhTE+ZpVUusJHJ6wB0bYLlWR5bCxqYbpmsRsov49tZ8CAwEAAaOBujCBtzAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBTpPAThgC/ChBMtJnCe8v0az6r+xjBhBgNVHREEWjBYghhmbG93ZXJzLXRvLXRoZS13b3JsZC5jb22CPDA3LjE5LjA4LjIwMjMubGV0c2VuY3J5cHRfb2FrMjAyNWgyLmZsb3dlcnMtdG8tdGhlLXdvcmxkLmNvbQAA",
|
||||||
|
"C=GB, L=London, O=Google, OU=Certificate Transparency, CN=flowers-to-the-world.com",
|
||||||
|
1692430118301
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"AAAAAAGKDNNwjwAB43aJADBzoMZJzGVt6UbAMXTSXFZv48OAW4RvUjaUN5gAAx4wggMaoAMCAQICCQCQAkpeGcWGRjANBgkqhkiG9w0BAQsFADB/MQswCQYDVQQGEwJHQjEPMA0GA1UECAwGTG9uZG9uMRcwFQYDVQQKDA5Hb29nbGUgVUsgTHRkLjEhMB8GA1UECwwYQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5MSMwIQYDVQQDDBpNZXJnZSBEZWxheSBJbnRlcm1lZGlhdGUgMTAeFw0yNjAxMTgyMTU3MjNaFw0yNjAxMTkyMTU3MjNaMHUxCzAJBgNVBAYTAkdCMQ8wDQYDVQQHEwZMb25kb24xDzANBgNVBAoTBkdvb2dsZTEhMB8GA1UECxMYQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5MSEwHwYDVQQDExhmbG93ZXJzLXRvLXRoZS13b3JsZC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDZm2mTxtaoH0AIZ0ZVTduHeCIo0kC8M6T6OPQw07Ock+mhtMblMnk7KZAsmgCFWSa6sFQ/IdLuDreWAVSdYJqeNHtDb+Hrla+sDUXDheNEqBFFav5o/G3kO+csbp3sR9If6dZiGHwzLC8ismQT2QDUgvqw/sb/7GrojArouVbvhFR2HBjD73qF5/cOzmOuoLg1OhHIsn5dBtEmK5izkgrrk0CULanGiDzAcGP6i+ldAOnES8Y1hTkKyT1d9woxmBHmVZ/wyKXiL//6h6A6qTVQ0QGGf4RvhW9+v6LhBMQcZEyoSMc164cvc6iaThcbS3koAr9nUuMyG2XpLo5TCexvAgMBAAGjgbowgbcwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwHwYDVR0jBBgwFoAU6TwE4YAvwoQTLSZwnvL9Gs+q/sYwYQYDVR0RBFowWIIYZmxvd2Vycy10by10aGUtd29ybGQuY29tgjwwOC4xOS4wOC4yMDIzLmxldHNlbmNyeXB0X29hazIwMjVoMi5mbG93ZXJzLXRvLXRoZS13b3JsZC5jb20AAA==",
|
||||||
|
"C=GB, L=London, O=Google, OU=Certificate Transparency, CN=flowers-to-the-world.com",
|
||||||
|
1692432298127
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"AAAAAAGKX6GKQwAAAAU1MIIFMTCCAxmgAwIBAgIIUh+QcsMl2wgwDQYJKoZIhvcNAQELBQAwfzELMAkGA1UEBhMCR0IxDzANBgNVBAgMBkxvbmRvbjEXMBUGA1UECgwOR29vZ2xlIFVLIEx0ZC4xITAfBgNVBAsMGENlcnRpZmljYXRlIFRyYW5zcGFyZW5jeTEjMCEGA1UEAwwa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ip5j9ZqhUuMPaR8f+K0S6y8NlRjPgwXtJXIQMwuIvSfWIHPgwnf16v9p/eW8vcoLPD2aM5VD2XUZJrA/AT6EjVRH2rvdF0urDODFtm4EP6dDvRpcCAgAmmFUEyrTQIlvC0S6+c4PsIDcdI3TiF+XrAree54jBXGYH2pBqShH/sVfEKSJw17DTvat1tNgyBxIHWl+7AKH23L0W1w4xR35eZVyGsEkGi8EFQT70V7VFuGiUw53W1NF/2GxBet/ywDD5x/R6XyrbNP56B/KGSE24Z7iIyIl3FRKE4LHZ97fH2o8SkLHSskSwiVSQd3/gk9jf6d8fVIyFj2ZDvzFks0ACepvJ2hVbTJHvqVWoRyT5lxJ6Mmb01bhocJsxgcCgvs361lBSa4URS5a7u2jULcsFnx8niHjhMJHjXnhc+Me3UduIYGA/c2gJ+IX8dpPBeL/eYx+3bsCmcVH2w94j3IiC49APA6ZMhuBXh351/X4RcHODDiNLqe0rLPqPbfdl+d3r+pVLuRnb4lKygAA",
|
||||||
|
"C=GB, L=London, O=Google, OU=Certificate Transparency, CN=flowers-to-the-world.com",
|
||||||
|
1693821536835
|
||||||
|
),
|
||||||
|
// Entries from https://oak.ct.letsencrypt.org/2024h1
|
||||||
|
(
|
||||||
|
"AAAAAAGEy7byEAABJSMzqOOrtyOT1kmau6zKhgT676hGgczD5VMdRMyJZFAAA38wggN7oAMCAQICEAx1UGAuOrXH8cPGn545U3kwDQYJKoZIhvcNAQELBQAwRjELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEVMBMGA1UECxMMU2VydmVyIENBIDFCMQ8wDQYDVQQDEwZBbWF6b24wHhcNMjIxMjAxMDAwMDAwWhcNMjMxMjMxMjM1OTU5WjAqMSgwJgYDVQQDDB8qLmQzcHgwd3Y3ZjF0cTdrLmFtcGxpZnlhcHAuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwOoOv6C59kRAOoUxIP5jsxS2hVqKWV4BAPuZEz1b2s2riCGJRD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139MZdfpcq6+OQMmxbsO0a9UkyXjyObBcgJzQ+g8KtUdvQQptLmN++pqfnxmI18IyqtZyekpH/enlbEVIdcJ9O0hSMtTM92CaHudKLpV46SEhJcbzwUd9u1w7EdnKjjUq6gmj9zckOjTg09KJyJ95EKbv0ZpYFhsMOeTyhHidYy2wNCNJhO9nx3YE/cnQ9UVo8R3m9dlcDRgHtdQwMjMjPomKgsmJgEXVPPwjKMhVR25O2u21cqsVxItOgEa8WyeR/0awkm1+OMUdEtv0CDSqc5mwKc63dNAnHjJjVq68LJAPfzbR72lW0CxZETOIKI5Hd/jSrL96Cu57RXsC7YRQIDAQABo4GLMIGIMBMGA1UdJQQMMAoGCCsGAQUFBwMBMCMGA1UdEQQcMBqCGGZsb3dlcnMtdG8tdGhlLXdvcmxkLmNvbTAMBgNVHRMBAf8EAjAAMB8GA1UdIwQYMBaAFOk8BOGAL8KEEy0mcJ7y/RrPqv7GMB0GA1UdDgQWBBSRIw7tu+hiIeKf0gO+lTZfhwxK6gAA",
|
||||||
|
"C=GB, L=London, O=Google Certificate Transparency, serialNumber=1662691058295545",
|
||||||
|
1662691058345
|
||||||
|
),
|
||||||
|
// Entries from https://ct.googleapis.com/logs/eu1/xenon2025h1
|
||||||
|
(
|
||||||
|
"AAAAAAGSl0salwAAAAPKMIIDxjCCA0ygAwIBAgISBPmkPV0s/bLTwy6BR95mo9omMAoGCCqGSM49BAMDMDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJFNTAeFw0yNDEwMTYyMDQ3MDNaFw0yNTAxMTQyMDQ3MDJaMD4xPDA6BgNVBAMTM3BvY2h0YWJhbmsuby5hdml0by5yeWdpbm1sZDFhd28wdmUuZWlwLmVuc2ltcG9jLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKY6DHnXvMW2xICZcpJ//cr2ttCyBjUk8xonMewjCUPqXS0z79qgCaqFzbaOrqDc61LoOux19e3nhyIBL6QrM3WjggI0MIICMDAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFMlIByYCus9M860DtNvXARmDYBjJMB8GA1UdIwQYMBaAFJ8rX888IU+dBLftKyzExnCL0tcNMFUGCCsGAQUFBwEBBEkwRzAhBggrBgEFBQcwAYYVaHR0cDovL2U1Lm8ubGVuY3Iub3JnMCIGCCsGAQUFBzAChhZodHRwOi8vZTUuaS5sZW5jci5vcmcvMD4GA1UdEQQ3MDWCM3BvY2h0YWJhbmsuby5hdml0by5yeWdpbm1sZDFhd28wdmUuZWlwLmVuc2ltcG9jLmNvbTATBgNVHSAEDDAKMAgGBmeBDAECATCCAQMGCisGAQQB1nkCBAIEgfQEgfEA7wB1AM8RVu7VLnyv84db2Wkum+kacWdKsBfsrAHSW3fOzDsIAAABkpdLGCsAAAQDAEYwRAIgSUOJf8l6+Tzmv+ClWY4C3MaDztQMXt6G1HGHlctLUawCIFa+17WSp6uk4RqCiY1e1LVUaNmbIDUhiR2AX05MhdQQAHYAE0rfGrWYQgl4DG/vTHqRpBa3I0nOWFdq367ap8Kr4CIAAAGSl0sZMwAABAMARzBFAiEAlN9seh/z9GSf2nMwvEOpx1noTqxv6yPKhB276U6jd0YCIE6L4TKVHY+7FIwSjP73VT+AJfzsss4f2KsqMlgHx1LVMAoGCCqGSM49BAMDA2gAMGUCMCNwRE9tv2JA3iIdpagARFw64TGL/4yec0YwknBvECnafyPwwkYo7mbvowPS4QowOgIxAKvb2zBO/+ykpeWBBOJ4wvoGAHCHcGUKeszXXBycjfvlSeh+l4DhXiLpAD6fn4ANfwAA",
|
||||||
|
"CN=pochtabank.o.avito.ryginmld1awo0ve.eip.ensimpoc.com",
|
||||||
|
1729115134615
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
1
src/merkle/hash.rs
Normal file
1
src/merkle/hash.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
3
src/merkle/mod.rs
Normal file
3
src/merkle/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod consts;
|
||||||
|
pub mod hash;
|
||||||
|
pub mod types;
|
37
src/merkle/types.rs
Normal file
37
src/merkle/types.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
use x509_parser::prelude::TbsCertificate;
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum Version {
|
||||||
|
V1 = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CtExtensions = Vec<u8>;
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MerkleLeafType<'a> {
|
||||||
|
TimeStampedEntry {
|
||||||
|
timestamp: u64,
|
||||||
|
entry_type: LogEntryType<'a>,
|
||||||
|
extensions: CtExtensions
|
||||||
|
} = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(u16)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum LogEntryType<'a> {
|
||||||
|
X509Entry(x509_parser::certificate::X509Certificate<'a>) = 0,
|
||||||
|
PrecertEntry {
|
||||||
|
issuer_key_hash: [u8; 32],
|
||||||
|
tbs_certificate: TbsCertificate<'a>
|
||||||
|
} = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct MerkleTreeLeaf<'a> {
|
||||||
|
pub version: Version,
|
||||||
|
pub leaf_type: MerkleLeafType<'a>
|
||||||
|
}
|
115
src/parsing/leaf.rs
Normal file
115
src/parsing/leaf.rs
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
use super::{
|
||||||
|
structures::{parse_tbs_certificate_der, parse_x509_der},
|
||||||
|
LeafParsingEnumType,
|
||||||
|
LeafParsingError
|
||||||
|
};
|
||||||
|
use crate::merkle::types::{LogEntryType, MerkleLeafType, MerkleTreeLeaf, Version};
|
||||||
|
|
||||||
|
/// Parses a MerkleTreeLeaf structure as specified in [RFC6962](https://datatracker.ietf.org/doc/html/rfc6962):
|
||||||
|
/// ```txt
|
||||||
|
/// struct {
|
||||||
|
/// Version version;
|
||||||
|
/// MerkleLeafType leaf_type;
|
||||||
|
/// select (leaf_type) {
|
||||||
|
/// case timestamped_entry: TimestampedEntry;
|
||||||
|
/// }
|
||||||
|
/// } MerkleTreeLeaf;
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// This function assumes a binary format for the leaf, rather than a
|
||||||
|
/// base64-encoded version, so make sure to manually decode it from the HTTP
|
||||||
|
/// response before use.
|
||||||
|
pub fn parse_merkle_tree_leaf(
|
||||||
|
input: &[u8]
|
||||||
|
) -> nom::IResult<&[u8], MerkleTreeLeaf, LeafParsingError<&[u8]>> {
|
||||||
|
let (input, version /* Version version; */) = nom::number::complete::u8(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
let (input, leaf_type /* MerkleLeafType leaf_type; */) =
|
||||||
|
nom::number::complete::u8(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
|
||||||
|
Ok((input, MerkleTreeLeaf {
|
||||||
|
version: match version {
|
||||||
|
0 => Version::V1,
|
||||||
|
_ =>
|
||||||
|
return Err(nom::Err::Failure(LeafParsingError::InvalidEnum {
|
||||||
|
input,
|
||||||
|
enum_type: LeafParsingEnumType::Version
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
leaf_type: match leaf_type {
|
||||||
|
// struct {
|
||||||
|
// uint64 timestamp;
|
||||||
|
// LogEntryType entry_type; /* 2 bytes */
|
||||||
|
// select(entry_type) {
|
||||||
|
// case x509_entry: ASN.1Cert;
|
||||||
|
// case precert_entry: PreCert;
|
||||||
|
// } signed_entry;
|
||||||
|
// CtExtensions extensions;
|
||||||
|
// } TimestampedEntry;
|
||||||
|
0 => {
|
||||||
|
let (input, timestamp /* uint64 timestamp; */) =
|
||||||
|
nom::number::complete::u64(nom::number::Endianness::Big)(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
let (input, entry_type /* LogEntryType entry_type; */) =
|
||||||
|
nom::number::complete::u16(nom::number::Endianness::Big)(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
|
||||||
|
let (input, entry_type) = match entry_type {
|
||||||
|
0 => {
|
||||||
|
let (input, der /* opaque ASN.1Cert<1..2^24-1> */) =
|
||||||
|
parse_x509_der(input).map_err(|e| {
|
||||||
|
e.map(|e| LeafParsingError::DerParsing(e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
(input, LogEntryType::X509Entry(der))
|
||||||
|
}
|
||||||
|
// case precert_entry: PreCert;
|
||||||
|
1 => {
|
||||||
|
let (
|
||||||
|
input,
|
||||||
|
issuer_key_hash // opaque issuer_key_hash[32];
|
||||||
|
) = nom::bytes::complete::take(32usize)(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
let (
|
||||||
|
input,
|
||||||
|
tbs_certificate // TBSCertificate tbs_certificate;
|
||||||
|
) = parse_tbs_certificate_der(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::DerParsing(e)))?;
|
||||||
|
|
||||||
|
(input, LogEntryType::PrecertEntry {
|
||||||
|
issuer_key_hash: issuer_key_hash.try_into().map_err(
|
||||||
|
|_| {
|
||||||
|
nom::Err::Failure(LeafParsingError::InvalidTakeLength)
|
||||||
|
}
|
||||||
|
)?,
|
||||||
|
tbs_certificate
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ =>
|
||||||
|
return Err(nom::Err::Failure(LeafParsingError::InvalidEnum {
|
||||||
|
input,
|
||||||
|
enum_type: LeafParsingEnumType::LogEntryType
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
let (
|
||||||
|
_, // no more to parse
|
||||||
|
ct_extensions // opaque CtExtensions<0..2^16-1>
|
||||||
|
) = nom::multi::length_data(nom::number::complete::be_u16)(input)
|
||||||
|
.map_err(|e| e.map(|e| LeafParsingError::Nom(e)))?;
|
||||||
|
|
||||||
|
MerkleLeafType::TimeStampedEntry {
|
||||||
|
timestamp,
|
||||||
|
entry_type,
|
||||||
|
extensions: ct_extensions.to_vec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ =>
|
||||||
|
return Err(nom::Err::Failure(LeafParsingError::InvalidEnum {
|
||||||
|
input,
|
||||||
|
enum_type: LeafParsingEnumType::MerkleLeafType
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
85
src/parsing/mod.rs
Normal file
85
src/parsing/mod.rs
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
pub mod leaf;
|
||||||
|
pub mod structures;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum LeafParsingError<I> {
|
||||||
|
Nom(nom::error::Error<I>),
|
||||||
|
InvalidEnum {
|
||||||
|
input: I,
|
||||||
|
enum_type: LeafParsingEnumType
|
||||||
|
},
|
||||||
|
DerParsing(x509_parser::error::X509Error),
|
||||||
|
InvalidTakeLength
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum LeafParsingEnumType {
|
||||||
|
Version,
|
||||||
|
MerkleLeafType,
|
||||||
|
LogEntryType
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use base64ct::Encoding;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
merkle::{
|
||||||
|
consts::{test_constants, LEAF_BASE64_BUFFER_SIZE},
|
||||||
|
types::{LogEntryType, MerkleLeafType}
|
||||||
|
},
|
||||||
|
parsing::leaf::parse_merkle_tree_leaf
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_leaf_inputs() {
|
||||||
|
let mut decoded_base64 = [0u8; LEAF_BASE64_BUFFER_SIZE];
|
||||||
|
for (i, (leaf_input, subject, timestamp)) in
|
||||||
|
test_constants::LEAF_INPUT_EXAMPLES.into_iter().enumerate()
|
||||||
|
{
|
||||||
|
decoded_base64[..leaf_input.len()].copy_from_slice(leaf_input.as_bytes());
|
||||||
|
let decoded_base64 = base64ct::Base64::decode_in_place(
|
||||||
|
&mut decoded_base64[..leaf_input.len()]
|
||||||
|
)
|
||||||
|
.expect("Should parse base64 properly");
|
||||||
|
|
||||||
|
let (_, parsed) =
|
||||||
|
parse_merkle_tree_leaf(decoded_base64).expect("should complete");
|
||||||
|
|
||||||
|
let MerkleLeafType::TimeStampedEntry {
|
||||||
|
timestamp: parsed_timestamp,
|
||||||
|
entry_type,
|
||||||
|
extensions: _
|
||||||
|
} = parsed.leaf_type;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
*timestamp, parsed_timestamp,
|
||||||
|
"leaf_input should have expected timestamp"
|
||||||
|
);
|
||||||
|
|
||||||
|
match entry_type {
|
||||||
|
LogEntryType::X509Entry(x509_cert) => {
|
||||||
|
assert_eq!(
|
||||||
|
&x509_cert.subject.to_string(),
|
||||||
|
subject,
|
||||||
|
"leaf_entry x509 cert should have expected subject field"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
LogEntryType::PrecertEntry {
|
||||||
|
issuer_key_hash: _,
|
||||||
|
tbs_certificate
|
||||||
|
} => {
|
||||||
|
assert_eq!(
|
||||||
|
&tbs_certificate.subject.to_string(),
|
||||||
|
subject,
|
||||||
|
"leaf_entry tbs cert should have expected subject field"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!(
|
||||||
|
"[{i}] Correctly parsed leaf_input for subject '{subject}' issued at \
|
||||||
|
{timestamp}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
src/parsing/structures.rs
Normal file
21
src/parsing/structures.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use x509_parser::{
|
||||||
|
error::X509Result,
|
||||||
|
prelude::{TbsCertificate, X509Certificate}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Parses a type `opaque ASN.1Cert<1..2^24-1>;`
|
||||||
|
pub fn parse_x509_der(input: &[u8]) -> X509Result<X509Certificate> {
|
||||||
|
nom::combinator::map_parser(
|
||||||
|
nom::multi::length_data(nom::number::complete::be_u24),
|
||||||
|
x509_parser::parse_x509_certificate
|
||||||
|
)(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a type `opaque TBSCertificate<1..2^24-1>;`
|
||||||
|
pub fn parse_tbs_certificate_der(input: &[u8]) -> X509Result<TbsCertificate> {
|
||||||
|
nom::combinator::map_parser(
|
||||||
|
nom::multi::length_data(nom::number::complete::be_u24),
|
||||||
|
x509_parser::certificate::TbsCertificateParser::new()
|
||||||
|
.with_deep_parse_extensions(true)
|
||||||
|
)(input)
|
||||||
|
}
|
Loading…
Reference in a new issue