safebrowsing

package
v0.0.0-...-ff3b5ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package safebrowsing provides access to the Safe Browsing API.

For product documentation, see: https://developers.google.com/safe-browsing/

Library status

These client libraries are officially supported by Google. However, this library is considered complete and is in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

When possible, we recommend using our newer [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go) that are still actively being worked and iterated on.

Creating a client

Usage example:

import "google.golang.org/api/safebrowsing/v5"
...
ctx := context.Background()
safebrowsingService, err := safebrowsing.NewService(ctx)

In this example, Google Application Default Credentials are used for authentication. For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.

Other authentication options

To use an API key for authentication (note: some APIs do not support API keys), use google.golang.org/api/option.WithAPIKey:

safebrowsingService, err := safebrowsing.NewService(ctx, option.WithAPIKey("AIza..."))

To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow, use google.golang.org/api/option.WithTokenSource:

config := &oauth2.Config{...}
// ...
token, err := config.Exchange(ctx, ...)
safebrowsingService, err := safebrowsing.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))

See google.golang.org/api/option.ClientOption for details on options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoogleSecuritySafebrowsingV5FullHash

type GoogleSecuritySafebrowsingV5FullHash struct {
	// FullHash: The matching full hash. This is the SHA256 hash. The length
	// will be exactly 32 bytes.
	FullHash string `json:"fullHash,omitempty"`

	// FullHashDetails: Unordered list. A repeated field identifying the
	// details relevant to this full hash.
	FullHashDetails []*GoogleSecuritySafebrowsingV5FullHashFullHashDetail `json:"fullHashDetails,omitempty"`

	// ForceSendFields is a list of field names (e.g. "FullHash") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "FullHash") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

GoogleSecuritySafebrowsingV5FullHash: The full hash identified with one or more matches.

func (*GoogleSecuritySafebrowsingV5FullHash) MarshalJSON

func (s *GoogleSecuritySafebrowsingV5FullHash) MarshalJSON() ([]byte, error)

type GoogleSecuritySafebrowsingV5FullHashFullHashDetail

type GoogleSecuritySafebrowsingV5FullHashFullHashDetail struct {
	// Attributes: Unordered list. Additional attributes about those full
	// hashes. This may be empty.
	//
	// Possible values:
	//   "THREAT_ATTRIBUTE_UNSPECIFIED" - Unknown attribute. If this is
	// returned by the server, the client shall disregard the enclosing
	// `FullHashDetail` altogether.
	//   "CANARY" - Indicates that the threat_type should not be used for
	// enforcement.
	//   "FRAME_ONLY" - Indicates that the threat_type should only be used
	// for enforcement on frames.
	Attributes []string `json:"attributes,omitempty"`

	// ThreatType: The type of threat. This field will never be empty.
	//
	// Possible values:
	//   "THREAT_TYPE_UNSPECIFIED" - Unknown threat type. If this is
	// returned by the server, the client shall disregard the enclosing
	// `FullHashDetail` altogether.
	//   "MALWARE" - Malware threat type.
	//   "SOCIAL_ENGINEERING" - Social engineering threat type.
	//   "UNWANTED_SOFTWARE" - Unwanted software threat type.
	//   "POTENTIALLY_HARMFUL_APPLICATION" - Potentially harmful application
	// threat type.
	ThreatType string `json:"threatType,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Attributes") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Attributes") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

GoogleSecuritySafebrowsingV5FullHashFullHashDetail: Details about a matching full hash. An important note about forward compatibility: new threat types and threat attributes may be added by the server at any time; those additions are considered minor version changes. It is Google's policy not to expose minor version numbers in APIs (see https://cloud.google.com/apis/design/versioning for the versioning policy), so clients MUST be prepared to receive `FullHashDetail` messages containing `ThreatType` enum values or `ThreatAttribute` enum values that are considered invalid by the client. Therefore, it is the client's responsibility to check for the validity of all `ThreatType` and `ThreatAttribute` enum values; if any value is considered invalid, the client MUST disregard the entire `FullHashDetail` message.

func (*GoogleSecuritySafebrowsingV5FullHashFullHashDetail) MarshalJSON

type GoogleSecuritySafebrowsingV5SearchHashesResponse

type GoogleSecuritySafebrowsingV5SearchHashesResponse struct {
	// CacheDuration: The client-side cache duration. The client MUST add
	// this duration to the current time to determine the expiration time.
	// The expiration time then applies to every hash prefix queried by the
	// client in the request, regardless of how many full hashes are
	// returned in the response. Even if the server returns no full hashes
	// for a particular hash prefix, this fact MUST also be cached by the
	// client. Important: the client MUST NOT assume that the server will
	// return the same cache duration for all responses. The server MAY
	// choose different cache durations for different responses depending on
	// the situation.
	CacheDuration string `json:"cacheDuration,omitempty"`

	// FullHashes: Unordered list. The unordered list of full hashes found.
	FullHashes []*GoogleSecuritySafebrowsingV5FullHash `json:"fullHashes,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "CacheDuration") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "CacheDuration") to include
	// in API requests with the JSON null value. By default, fields with
	// empty values are omitted from API requests. However, any field with
	// an empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

GoogleSecuritySafebrowsingV5SearchHashesResponse: The response returned after searching threat hashes. If nothing is found, the server will return an OK status (HTTP status code 200) with the `full_hashes` field empty, rather than returning a NOT_FOUND status (HTTP status code 404). **What's new in V5**: There is a separation between FullHash and FullHashDetail. In the case when a hash represents a site having multiple threats (e.g. both MALWARE and SOCIAL_ENGINEERING), the full hash does not need to be sent twice as in V4. Furthermore, the cache duration has been simplified into a single `cache_duration` field.

func (*GoogleSecuritySafebrowsingV5SearchHashesResponse) MarshalJSON

type HashesSearchCall

type HashesSearchCall struct {
	// contains filtered or unexported fields
}

func (*HashesSearchCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*HashesSearchCall) Do

Do executes the "safebrowsing.hashes.search" call. Exactly one of *GoogleSecuritySafebrowsingV5SearchHashesResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *GoogleSecuritySafebrowsingV5SearchHashesResponse.ServerResponse.Heade r or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*HashesSearchCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*HashesSearchCall) HashPrefixes

func (c *HashesSearchCall) HashPrefixes(hashPrefixes ...string) *HashesSearchCall

HashPrefixes sets the optional parameter "hashPrefixes": Required. The hash prefixes to be looked up. Clients MUST NOT send more than 1000 hash prefixes. However, following the URL processing procedure, clients SHOULD NOT need to send more than 30 hash prefixes. Currently each hash prefix is required to be exactly 4 bytes long. This MAY be relaxed in the future.

func (*HashesSearchCall) Header

func (c *HashesSearchCall) Header() http.Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

func (*HashesSearchCall) IfNoneMatch

func (c *HashesSearchCall) IfNoneMatch(entityTag string) *HashesSearchCall

IfNoneMatch sets the optional parameter which makes the operation fail if the object's ETag matches the given value. This is useful for getting updates only after the object has changed since the last request. Use googleapi.IsNotModified to check whether the response error from Do is the result of In-None-Match.

type HashesService

type HashesService struct {
	// contains filtered or unexported fields
}

func NewHashesService

func NewHashesService(s *Service) *HashesService

func (*HashesService) Search

func (r *HashesService) Search() *HashesSearchCall

Search: Search for full hashes matching the specified prefixes. This is a custom method as defined by https://google.aip.dev/136 (the custom method refers to this method having a custom name within Google's general API development nomenclature; it does not refer to using a custom HTTP method).

type Service

type Service struct {
	BasePath  string // API endpoint base URL
	UserAgent string // optional additional User-Agent fragment

	Hashes *HashesService
	// contains filtered or unexported fields
}

func New deprecated

func New(client *http.Client) (*Service, error)

New creates a new Service. It uses the provided http.Client for requests.

Deprecated: please use NewService instead. To provide a custom HTTP client, use option.WithHTTPClient. If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.

func NewService

func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error)

NewService creates a new Service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL