Skip to content

Commit d4b3f8f

Browse files
committed
v1 compiling
1 parent 36a0022 commit d4b3f8f

File tree

8 files changed

+126
-462
lines changed

8 files changed

+126
-462
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pretty_assertions = "1.0"
5151

5252
[build-dependencies]
5353
phf_codegen = "0.11"
54+
csv = "1.2"
5455

5556
[badges]
5657
travis-ci = { repository = "rusticata/tls-parser" }

build.rs

Lines changed: 77 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
extern crate phf_codegen;
2-
1+
use std::collections::HashMap;
32
use std::env;
43
use std::fs::File;
5-
use std::io::BufRead;
6-
use std::io::{BufReader, BufWriter, Write};
4+
use std::io::{BufWriter, Write};
75
use std::path::Path;
86

9-
fn titlecase_word(word: &str) -> String {
7+
use csv::Reader;
8+
use phf_codegen;
9+
10+
fn titlecase_word(word: &String) -> String {
1011
word.chars()
1112
.enumerate()
1213
.map(|(i, c)| {
@@ -21,54 +22,81 @@ fn titlecase_word(word: &str) -> String {
2122

2223
fn main() {
2324
let path_txt =
24-
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("scripts/tls-ciphersuites.txt");
25-
let display = path_txt.display();
26-
let file = match File::open(&path_txt) {
27-
// The `description` method of `io::Error` returns a string that
28-
// describes the error
29-
Err(why) => panic!("couldn't open {}: {}", display, why),
30-
Ok(file) => file,
31-
};
32-
let f = BufReader::new(file);
25+
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("scripts/all_ciphersuites.csv");
3326

3427
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
3528
let mut file = BufWriter::new(File::create(&path).unwrap());
3629

3730
let mut map = phf_codegen::Map::new();
38-
for line in f.lines() {
39-
let l = line.unwrap();
40-
let mut v: Vec<&str> = l.split(':').collect();
31+
let mut csv_reader = Reader::from_path(path_txt).unwrap();
32+
for record in csv_reader.deserialize() {
33+
let v: HashMap<String, String> = record.unwrap();
34+
println!("{:?}", v);
4135

42-
if v[5].is_empty() {
43-
v[5] = "NULL"
36+
if v["info.type"] != "IANATLSCipherSuite"
37+
|| v["info.name"].contains("GOSTR")
38+
|| v["info.name"].contains("TLS_SHA256_SHA256")
39+
|| v["info.name"].contains("TLS_SHA384_SHA384")
40+
|| v["info.name"].contains("_SCSV")
41+
|| v["info.tls.parameters.encryption.algorithm"].contains("AEGIS")
42+
{
43+
continue;
4444
}
4545

46-
let au = match v[3] {
47-
"SRP+DSS" => String::from("Srp_Dss"),
48-
"SRP+RSA" => String::from("Srp_Rsa"),
49-
_ => titlecase_word(v[3]).replace('+', "_"),
46+
let au = match v["info.tls.parameters.authentication"].as_str() {
47+
"" => String::from("Null"),
48+
_ => titlecase_word(&v["info.tls.parameters.authentication"].replace("TLS 1.3", "TLS13")),
5049
};
5150

52-
let enc = match v[4] {
51+
let enc = match v["info.tls.parameters.encryption.algorithm"].as_str() {
52+
"" => String::from("Null"),
53+
"DES40" => String::from("Des"),
5354
"3DES" => String::from("TripleDes"),
54-
"CHACHA20_POLY1305" => String::from("Chacha20_Poly1305"),
55-
_ => titlecase_word(v[4]),
55+
"CHACHA20" => String::from("Chacha20"),
56+
_ => titlecase_word(&v["info.tls.parameters.encryption.algorithm"]),
57+
};
58+
59+
let mac = String::from(
60+
match v["info.tls.parameters.integrity.message_authentication_code"].as_str() {
61+
"" => "Null",
62+
"AEAD" => "Aead",
63+
"HMAC" => match v["info.tls.parameters.integrity.pseudorandom_function"].as_str() {
64+
"MD5" => "HmacMd5",
65+
"SHA1" => "HmacSha1",
66+
"SHA256" => "HmacSha256",
67+
"SHA384" => "HmacSha384",
68+
"SHA512" => "HmacSha512",
69+
_ => continue,
70+
},
71+
_ => continue,
72+
},
73+
);
74+
let mac_size = v["info.tls.parameters.integrity.message_authentication_code_size"].clone();
75+
76+
let mode = match v["info.tls.parameters.encryption.mode"].as_str() {
77+
"" => String::from("Null"),
78+
"L" => String::from("Null"),
79+
_ => titlecase_word(&v["info.tls.parameters.encryption.mode"]),
5680
};
5781

58-
let mac = String::from(match v[7] {
59-
"NULL" => "Null",
60-
"HMAC-MD5" => "HmacMd5",
61-
"HMAC-SHA1" => "HmacSha1",
62-
"HMAC-SHA256" => "HmacSha256",
63-
"HMAC-SHA384" => "HmacSha384",
64-
"HMAC-SHA512" => "HmacSha512",
65-
"AEAD" => "Aead",
66-
_ => panic!("Unknown mac {}", v[7]),
67-
});
82+
let key_exchange = match v["info.tls.parameters.key_exchange"].as_str() {
83+
"" => String::from("Null"),
84+
_ => titlecase_word(&v["info.tls.parameters.key_exchange"].replace("TLS 1.3", "TLS13")),
85+
};
6886

69-
let prf = titlecase_word(v[9]);
87+
let prf = match v["info.tls.parameters.integrity.pseudorandom_function"].as_str() {
88+
"" => String::from("Null"),
89+
_ => titlecase_word(
90+
&v["info.tls.parameters.integrity.pseudorandom_function"]
91+
.replace(" ", "")
92+
.replace(".", "")
93+
.replace("-", "")
94+
)
95+
};
96+
let prf_size = v["info.tls.parameters.integrity.pseudorandom_function_size"].clone();
7097

71-
let key = u16::from_str_radix(v[0], 16).unwrap();
98+
let key_string = format!("{}{}", v["byte_1"], v["byte_2"]);
99+
let key = u16::from_str_radix(key_string.as_str(), 16).unwrap();
72100
let val = format!(
73101
r#"TlsCipherSuite{{
74102
name:"{}",
@@ -80,18 +108,18 @@ fn main() {
80108
enc_size:{},
81109
mac:TlsCipherMac::{},
82110
mac_size:{},
83-
prf: TlsPRF::{},
111+
prf:TlsPRF::{},
84112
}}"#,
85-
v[1],
86-
v[0],
87-
titlecase_word(v[2]), // kx
88-
au, // au
89-
enc, // enc
90-
titlecase_word(v[5]), // enc_mode
91-
v[6], // enc_key_size
92-
mac, // mac
93-
v[8], // mac_size
94-
prf, // prf
113+
v["info.name"],
114+
key_string,
115+
key_exchange,
116+
au,
117+
enc,
118+
mode,
119+
if prf_size.is_empty() {String::from("0")} else {prf_size},
120+
mac,
121+
if mac_size.is_empty() {String::from("0")} else {mac_size},
122+
prf, // prf
95123
)
96124
.clone();
97125

scripts/all_ciphersuites.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM iana_tls_parameters

scripts/ciphersuites.sqlite

6.54 MB
Binary file not shown.

scripts/extract-iana-ciphers.py

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)