summaryrefslogtreecommitdiff
path: root/lib/safe-browsing/ephy-gsb-utils.h
blob: 3acb0182d410bb6bbd2e1ef4f20e88ebcd84dd74 (plain)
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
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2017 Gabriel Ivascu <gabrielivascu@gnome.org>
 *
 *  This file is part of Epiphany.
 *
 *  Epiphany is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Epiphany is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define GSB_HASH_TYPE G_CHECKSUM_SHA256
#define GSB_HASH_SIZE (g_checksum_type_get_length (GSB_HASH_TYPE))

typedef struct {
  char   *threat_type;
  char   *platform_type;
  char   *threat_entry_type;
  char   *client_state;
  gint64  timestamp;
} EphyGSBThreatList;

typedef struct {
  GBytes   *prefix; /* The first 4-32 bytes of the hash */
  char     *threat_type;
  char     *platform_type;
  char     *threat_entry_type;
  gboolean  negative_expired;
} EphyGSBHashPrefixLookup;

typedef struct {
  guint8   *hash; /* The 32 bytes full hash */
  char     *threat_type;
  char     *platform_type;
  char     *threat_entry_type;
  gboolean  expired;
} EphyGSBHashFullLookup;

EphyGSBThreatList       *ephy_gsb_threat_list_new                 (const char *threat_type,
                                                                   const char *platform_type,
                                                                   const char *threat_entry_type,
                                                                   const char *client_state,
                                                                   gint64      timestamp);
void                     ephy_gsb_threat_list_free                (EphyGSBThreatList *list);

EphyGSBHashPrefixLookup *ephy_gsb_hash_prefix_lookup_new          (const guint8 *prefix,
                                                                   gsize         length,
                                                                   const char   *threat_type,
                                                                   const char   *platform_type,
                                                                   const char   *threat_entry_type,
                                                                   gboolean      negative_expired);
void                     ephy_gsb_hash_prefix_lookup_free         (EphyGSBHashPrefixLookup *lookup);

EphyGSBHashFullLookup   *ephy_gsb_hash_full_lookup_new            (const guint8 *hash,
                                                                   const char   *threat_type,
                                                                   const char   *platform_type,
                                                                   const char   *threat_entry_type,
                                                                   gboolean      expired);
void                     ephy_gsb_hash_full_lookup_free           (EphyGSBHashFullLookup *lookup);

char                    *ephy_gsb_utils_make_list_updates_request (GList *threat_lists);
char                    *ephy_gsb_utils_make_full_hashes_request  (GList *threat_lists,
                                                                   GList *hash_prefixes);

char                    *ephy_gsb_utils_canonicalize              (const char  *url,
                                                                   char       **host_out,
                                                                   char       **path_out,
                                                                   char       **query_out);
GList                   *ephy_gsb_utils_compute_hashes            (const char *url);

G_END_DECLS