summaryrefslogtreecommitdiffstats
path: root/toolkit/components/url-classifier/nsIUrlClassifierUtils.idl
blob: d98340e9a73eaa0df143f11559698cff79a97e8c (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
/**
 * Some utility methods used by the url classifier.
 */

interface nsIURI;
interface nsIChannel;

/**
 * Interface for parseFindFullHashResponseV4 callback
 */
[scriptable, uuid(fbb9684a-a0aa-11e6-88b0-08606e456b8a)]
interface nsIUrlClassifierParseFindFullHashCallback : nsISupports {
  /**
   * Callback when a match is found in full hash response. This callback may be
   * called multiple times when there are more than one matches in response.
   *
   * @param aCompleteHash A 32-byte complete hash string.
   * @param aTableNames The table names that this complete hash is associated with.
   *                    Since the server responded with a threat type, multiple
   *                    list names can be returned. The caller is reponsible
   *                    for filtering out the unrequested table names.
   *                    See |convertThreatTypeToListNames| for the format.
   * @param aPerHashCacheDuration See "FindFullHashesResponse" in safebrowsing.proto.
   *
   */
  void onCompleteHashFound(in ACString aCompleteHash,
                           in ACString aTableNames,
                           in unsigned long aPerHashCacheDuration);

  /**
   * Callback when full hash response is received.
   *
   * @param aMinWaitDuration See "FindFullHashesResponse" in safebrowsing.proto.
   * @param aNegCacheDuration See "FindFullHashesResponse" in safebrowsing.proto.
   *
   */
  void onResponseParsed(in unsigned long aMinWaitDuration,
                        in unsigned long aNegCacheDuration);
};

[scriptable, uuid(e4f0e59c-b922-48b0-a7b6-1735c1f96fed)]
interface nsIUrlClassifierUtils : nsISupports
{
  /**
   * Get the lookup string for a given URI.  This normalizes the hostname,
   * url-decodes the string, and strips off the protocol.
   *
   * @param uri URI to get the lookup key for.
   *
   * @returns String containing the canonicalized URI.
   */
  ACString getKeyForURI(in nsIURI uri);

  /**
   * Get the provider by table name.
   *
   * @param tableName The table name that we want to lookup
   *
   * @returns the provider name that the given table belongs.
   */
  ACString getProvider(in ACString tableName);

  /**
   * Get the provider used for Telemetry.
   * Because recording Telemetry will leak user-controlled strings,
   * only built-in providers should be recorded.
   *
   * @param tableName The table name that we want to lookup
   *
   * @returns the filtered provider for telemetry.
   *
   */
  ACString getTelemetryProvider(in ACString tableName);

  /**
   * Get the protocol version for the given provider.
   *
   * @param provider String the provider name. e.g. "google"
   *
   * @returns String to indicate the protocol version. e.g. "2.2"
   */
  ACString getProtocolVersion(in ACString provider);

  /**
   * Convert threat type to list name.
   *
   * @param Integer to indicate threat type.
   *
   * @returns The list names separated by ','. For example,
   *          'goog-phish-proto,test-phish-proto'.
   */
  ACString convertThreatTypeToListNames(in uint32_t threatType);

  /**
   * Convert list name to threat type.
   *
   * @param The list name.
   *
   * @returns The threat type in integer.
   */
  uint32_t convertListNameToThreatType(in ACString listName);

  /**
   * Make update request for given lists and their states.
   *
   * @param aListNames An array of list name represented in string.
   * @param aState An array of states (encoded in base64 format) for each list.
   *
   * The two argument arrays must be the same length.
   *
   * @returns A base64url encoded string.
   */
  ACString makeUpdateRequestV4(in Array<ACString> aListNames,
                               in Array<ACString> aStatesBase64);

    /**
   * Make "find full hash" request by for the given prefixes.
   *
   * @param aListNames An array of list names represented in string.
   * @param aListStatesBase64 An array of list states represented in base64.
   * @param aPrefixes An array of prefixes for which we'd like to find full hashes..
   *
   * The aListNames and aListStatesBase64 arrays must be the same length.
   *
   * @returns A base64url encoded string.
   */
  ACString makeFindFullHashRequestV4(in Array<ACString> aListNames,
                                     in Array<ACString> aListStatesBase64,
                                     in Array<ACString> aPrefixes);

  /**
   * Make ThreatHit report request body.
   *
   * @param aChannel channel which encountered the threat.
   * @param aListName listname represented in string.
   * @param aHashBase64 hash-based hit represented in base64.
   *
   * @returns A base64 encoded string.
   */
  ACString makeThreatHitReport(in nsIChannel aChannel,
                               in ACString aListName,
                               in ACString aHashBase64);

  /**
   * Parse V4 FindFullHash response.
   *
   * @param aResponse Byte stream from the server.
   * @param aCallback The callback function on each complete hash parsed.
   *                  Can be called multiple times in one parsing.
   */
  void parseFindFullHashResponseV4(in ACString aResponse,
                                   in nsIUrlClassifierParseFindFullHashCallback aCallback);
};