Skip to content

Commit 13b6989

Browse files
committed
remove sqlite db
1 parent 36a0022 commit 13b6989

File tree

7 files changed

+136
-462
lines changed

7 files changed

+136
-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: 87 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,83 @@ 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+
_ => {
49+
titlecase_word(&v["info.tls.parameters.authentication"].replace("TLS 1.3", "TLS13"))
50+
}
5051
};
5152

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

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-
});
84+
let key_exchange = match v["info.tls.parameters.key_exchange"].as_str() {
85+
"" => String::from("Null"),
86+
_ => titlecase_word(&v["info.tls.parameters.key_exchange"].replace("TLS 1.3", "TLS13")),
87+
};
6888

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

71-
let key = u16::from_str_radix(v[0], 16).unwrap();
100+
let key_string = format!("{}{}", v["byte_1"], v["byte_2"]);
101+
let key = u16::from_str_radix(key_string.as_str(), 16).unwrap();
72102
let val = format!(
73103
r#"TlsCipherSuite{{
74104
name:"{}",
@@ -80,18 +110,26 @@ fn main() {
80110
enc_size:{},
81111
mac:TlsCipherMac::{},
82112
mac_size:{},
83-
prf: TlsPRF::{},
113+
prf:TlsPRF::{},
84114
}}"#,
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
115+
v["info.name"],
116+
key_string,
117+
key_exchange,
118+
au,
119+
enc,
120+
mode,
121+
if prf_size.is_empty() {
122+
String::from("0")
123+
} else {
124+
prf_size
125+
},
126+
mac,
127+
if mac_size.is_empty() {
128+
String::from("0")
129+
} else {
130+
mac_size
131+
},
132+
prf, // prf
95133
)
96134
.clone();
97135

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/extract-iana-ciphers.py

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

0 commit comments

Comments
 (0)