File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed
Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -100,3 +100,27 @@ ENGINE = ReplacingMergeTree()
100100PARTITION BY toYYYYMM(not_after) -- Partition by month of certificate expiry
101101ORDER BY (log_id, log_index) -- Primary sorting order
102102SETTINGS storage_policy = ' s3_policy' , index_granularity = 8192 ;
103+
104+ CREATE TABLE ct_log_entries_by_name
105+ (
106+ name_rev String,
107+ log_id LowCardinality(String),
108+ log_index UInt64
109+ )
110+ ENGINE = ReplacingMergeTree()
111+ ORDER BY (name_rev, log_id, log_index)
112+ SETTINGS storage_policy = ' s3_policy' , index_granularity = 8192 ;
113+
114+ CREATE MATERIALIZED VIEW ct_log_entries_by_name_mv TO ct_log_entries_by_name AS
115+ SELECT
116+ reverse(name) AS name_rev,
117+ log_id,
118+ log_index
119+ FROM ct_log_entries
120+ ARRAY JOIN arrayDistinct(
121+ arrayConcat(
122+ subject_alternative_names,
123+ [subject_common_name]
124+ )
125+ ) AS name
126+ WHERE name != ' ' ;
Original file line number Diff line number Diff line change @@ -34,11 +34,13 @@ async function getSearchResults(
3434 switch ( queryType ) {
3535 case "domain" :
3636 whereClause = `(
37- subject_common_name = {query:String} OR
38- has(subject_alternative_names, {query:String}) OR
39- has(name_suffixes, {suffix:String})
37+ (log_id, log_index) IN (
38+ SELECT log_id, log_index FROM ct_log_entries_by_name
39+ WHERE name_rev = reverse({query:String}) OR
40+ name_rev LIKE reverse({wildcard:String})
41+ )
4042 )` ;
41- additionalParams . suffix = `.${ query } ` ;
43+ additionalParams . wildcard = `% .${ query } ` ;
4244 break ;
4345 case "commonName" :
4446 whereClause = "subject_common_name = {query:String}" ;
@@ -53,8 +55,7 @@ async function getSearchResults(
5355 whereClause = "issuer_common_name = {query:String}" ;
5456 break ;
5557 default :
56- whereClause =
57- "has(subject_alternative_names, {query:String}) OR subject_common_name = {query:String}" ;
58+ throw new Error ( `Unsupported query type: ${ queryType } ` ) ;
5859 }
5960
6061 const sql = `
@@ -74,6 +75,7 @@ async function getSearchResults(
7475 AND entry_type = 'x509_entry'
7576 ORDER BY not_after DESC
7677 LIMIT {limit:UInt32}
78+ SETTINGS max_execution_time = 30, max_memory_usage = 134217728
7779 ` ;
7880
7981 const resultSet = await client . query ( {
You can’t perform that action at this time.
0 commit comments