webrisk.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // Copyright 2019 Google LLC.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. syntax = "proto3";
  16. package google.cloud.webrisk.v1beta1;
  17. import "google/api/annotations.proto";
  18. import "google/api/client.proto";
  19. import "google/api/field_behavior.proto";
  20. import "google/protobuf/timestamp.proto";
  21. option csharp_namespace = "Google.Cloud.WebRisk.V1Beta1";
  22. option go_package = "google.golang.org/genproto/googleapis/cloud/webrisk/v1beta1;webrisk";
  23. option java_multiple_files = true;
  24. option java_outer_classname = "WebRiskProto";
  25. option java_package = "com.google.webrisk.v1beta1";
  26. option objc_class_prefix = "GCWR";
  27. option php_namespace = "Google\\Cloud\\WebRisk\\V1beta1";
  28. option ruby_package = "Google::Cloud::WebRisk::V1beta1";
  29. // Web Risk v1beta1 API defines an interface to detect malicious URLs on your
  30. // website and in client applications.
  31. service WebRiskServiceV1Beta1 {
  32. option (google.api.default_host) = "webrisk.googleapis.com";
  33. option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";
  34. // Gets the most recent threat list diffs.
  35. rpc ComputeThreatListDiff(ComputeThreatListDiffRequest) returns (ComputeThreatListDiffResponse) {
  36. option (google.api.http) = {
  37. get: "/v1beta1/threatLists:computeDiff"
  38. };
  39. option (google.api.method_signature) = "threat_type,version_token,constraints";
  40. }
  41. // This method is used to check whether a URI is on a given threatList.
  42. rpc SearchUris(SearchUrisRequest) returns (SearchUrisResponse) {
  43. option (google.api.http) = {
  44. get: "/v1beta1/uris:search"
  45. };
  46. option (google.api.method_signature) = "uri,threat_types";
  47. }
  48. // Gets the full hashes that match the requested hash prefix.
  49. // This is used after a hash prefix is looked up in a threatList
  50. // and there is a match. The client side threatList only holds partial hashes
  51. // so the client must query this method to determine if there is a full
  52. // hash match of a threat.
  53. rpc SearchHashes(SearchHashesRequest) returns (SearchHashesResponse) {
  54. option (google.api.http) = {
  55. get: "/v1beta1/hashes:search"
  56. };
  57. option (google.api.method_signature) = "hash_prefix,threat_types";
  58. }
  59. }
  60. // Describes an API diff request.
  61. message ComputeThreatListDiffRequest {
  62. // The constraints for this diff.
  63. message Constraints {
  64. // The maximum size in number of entries. The diff will not contain more
  65. // entries than this value. This should be a power of 2 between 2**10 and
  66. // 2**20. If zero, no diff size limit is set.
  67. int32 max_diff_entries = 1;
  68. // Sets the maximum number of entries that the client is willing to have
  69. // in the local database. This should be a power of 2 between 2**10 and
  70. // 2**20. If zero, no database size limit is set.
  71. int32 max_database_entries = 2;
  72. // The compression types supported by the client.
  73. repeated CompressionType supported_compressions = 3;
  74. }
  75. // The ThreatList to update.
  76. ThreatType threat_type = 1 [(google.api.field_behavior) = REQUIRED];
  77. // The current version token of the client for the requested list (the
  78. // client version that was received from the last successful diff).
  79. bytes version_token = 2;
  80. // Required. The constraints associated with this request.
  81. Constraints constraints = 3 [(google.api.field_behavior) = REQUIRED];
  82. }
  83. message ComputeThreatListDiffResponse {
  84. // The expected state of a client's local database.
  85. message Checksum {
  86. // The SHA256 hash of the client state; that is, of the sorted list of all
  87. // hashes present in the database.
  88. bytes sha256 = 1;
  89. }
  90. // The type of response sent to the client.
  91. enum ResponseType {
  92. // Unknown.
  93. RESPONSE_TYPE_UNSPECIFIED = 0;
  94. // Partial updates are applied to the client's existing local database.
  95. DIFF = 1;
  96. // Full updates resets the client's entire local database. This means
  97. // that either the client had no state, was seriously out-of-date,
  98. // or the client is believed to be corrupt.
  99. RESET = 2;
  100. }
  101. // The type of response. This may indicate that an action must be taken by the
  102. // client when the response is received.
  103. ResponseType response_type = 4;
  104. // A set of entries to add to a local threat type's list.
  105. ThreatEntryAdditions additions = 5;
  106. // A set of entries to remove from a local threat type's list.
  107. // This field may be empty.
  108. ThreatEntryRemovals removals = 6;
  109. // The new opaque client version token.
  110. bytes new_version_token = 7;
  111. // The expected SHA256 hash of the client state; that is, of the sorted list
  112. // of all hashes present in the database after applying the provided diff.
  113. // If the client state doesn't match the expected state, the client must
  114. // disregard this diff and retry later.
  115. Checksum checksum = 8;
  116. // The soonest the client should wait before issuing any diff
  117. // request. Querying sooner is unlikely to produce a meaningful diff.
  118. // Waiting longer is acceptable considering the use case.
  119. // If this field is not set clients may update as soon as they want.
  120. google.protobuf.Timestamp recommended_next_diff = 2;
  121. }
  122. // Request to check URI entries against threatLists.
  123. message SearchUrisRequest {
  124. // Required. The URI to be checked for matches.
  125. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  126. // Required. The ThreatLists to search in.
  127. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  128. }
  129. message SearchUrisResponse {
  130. // Contains threat information on a matching uri.
  131. message ThreatUri {
  132. // The ThreatList this threat belongs to.
  133. repeated ThreatType threat_types = 1;
  134. // The cache lifetime for the returned match. Clients must not cache this
  135. // response past this timestamp to avoid false positives.
  136. google.protobuf.Timestamp expire_time = 2;
  137. }
  138. // The threat list matches. This may be empty if the URI is on no list.
  139. ThreatUri threat = 1;
  140. }
  141. // Request to return full hashes matched by the provided hash prefixes.
  142. message SearchHashesRequest {
  143. // A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
  144. // hash. For JSON requests, this field is base64-encoded.
  145. bytes hash_prefix = 1;
  146. // Required. The ThreatLists to search in.
  147. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  148. }
  149. message SearchHashesResponse {
  150. // Contains threat information on a matching hash.
  151. message ThreatHash {
  152. // The ThreatList this threat belongs to.
  153. // This must contain at least one entry.
  154. repeated ThreatType threat_types = 1;
  155. // A 32 byte SHA256 hash. This field is in binary format. For JSON
  156. // requests, hashes are base64-encoded.
  157. bytes hash = 2;
  158. // The cache lifetime for the returned match. Clients must not cache this
  159. // response past this timestamp to avoid false positives.
  160. google.protobuf.Timestamp expire_time = 3;
  161. }
  162. // The full hashes that matched the requested prefixes.
  163. // The hash will be populated in the key.
  164. repeated ThreatHash threats = 1;
  165. // For requested entities that did not match the threat list, how long to
  166. // cache the response until.
  167. google.protobuf.Timestamp negative_expire_time = 2;
  168. }
  169. // Contains the set of entries to add to a local database.
  170. // May contain a combination of compressed and raw data in a single response.
  171. message ThreatEntryAdditions {
  172. // The raw SHA256-formatted entries.
  173. // Repeated to allow returning sets of hashes with different prefix sizes.
  174. repeated RawHashes raw_hashes = 1;
  175. // The encoded 4-byte prefixes of SHA256-formatted entries, using a
  176. // Golomb-Rice encoding. The hashes are converted to uint32, sorted in
  177. // ascending order, then delta encoded and stored as encoded_data.
  178. RiceDeltaEncoding rice_hashes = 2;
  179. }
  180. // Contains the set of entries to remove from a local database.
  181. message ThreatEntryRemovals {
  182. // The raw removal indices for a local list.
  183. RawIndices raw_indices = 1;
  184. // The encoded local, lexicographically-sorted list indices, using a
  185. // Golomb-Rice encoding. Used for sending compressed removal indices. The
  186. // removal indices (uint32) are sorted in ascending order, then delta encoded
  187. // and stored as encoded_data.
  188. RiceDeltaEncoding rice_indices = 2;
  189. }
  190. // The type of threat. This maps dirrectly to the threat list a threat may
  191. // belong to.
  192. enum ThreatType {
  193. // Unknown.
  194. THREAT_TYPE_UNSPECIFIED = 0;
  195. // Malware targeting any platform.
  196. MALWARE = 1;
  197. // Social engineering targeting any platform.
  198. SOCIAL_ENGINEERING = 2;
  199. // Unwanted software targeting any platform.
  200. UNWANTED_SOFTWARE = 3;
  201. }
  202. // The ways in which threat entry sets can be compressed.
  203. enum CompressionType {
  204. // Unknown.
  205. COMPRESSION_TYPE_UNSPECIFIED = 0;
  206. // Raw, uncompressed data.
  207. RAW = 1;
  208. // Rice-Golomb encoded data.
  209. RICE = 2;
  210. }
  211. // A set of raw indices to remove from a local list.
  212. message RawIndices {
  213. // The indices to remove from a lexicographically-sorted local list.
  214. repeated int32 indices = 1;
  215. }
  216. // The uncompressed threat entries in hash format.
  217. // Hashes can be anywhere from 4 to 32 bytes in size. A large majority are 4
  218. // bytes, but some hashes are lengthened if they collide with the hash of a
  219. // popular URI.
  220. //
  221. // Used for sending ThreatEntryAdditons to clients that do not support
  222. // compression, or when sending non-4-byte hashes to clients that do support
  223. // compression.
  224. message RawHashes {
  225. // The number of bytes for each prefix encoded below. This field can be
  226. // anywhere from 4 (shortest prefix) to 32 (full SHA256 hash).
  227. int32 prefix_size = 1;
  228. // The hashes, in binary format, concatenated into one long string. Hashes are
  229. // sorted in lexicographic order. For JSON API users, hashes are
  230. // base64-encoded.
  231. bytes raw_hashes = 2;
  232. }
  233. // The Rice-Golomb encoded data. Used for sending compressed 4-byte hashes or
  234. // compressed removal indices.
  235. message RiceDeltaEncoding {
  236. // The offset of the first entry in the encoded data, or, if only a single
  237. // integer was encoded, that single integer's value. If the field is empty or
  238. // missing, assume zero.
  239. int64 first_value = 1;
  240. // The Golomb-Rice parameter, which is a number between 2 and 28. This field
  241. // is missing (that is, zero) if `num_entries` is zero.
  242. int32 rice_parameter = 2;
  243. // The number of entries that are delta encoded in the encoded data. If only a
  244. // single integer was encoded, this will be zero and the single value will be
  245. // stored in `first_value`.
  246. int32 entry_count = 3;
  247. // The encoded deltas that are encoded using the Golomb-Rice coder.
  248. bytes encoded_data = 4;
  249. }