Gsb4j Parent

Gsb4j is a Java client implementation of Google Safe Browsing API v4. It includes both Lookup API and Update API implementations. Gsb4j is a more or less complete implementation of the Safe Browsing API protocol. There are some missing or unsupported parts which can be found on project's site but those do not influence the overall usability of the API.

License

License

Categories

Categories

Net
GroupId

GroupId

kg.net.bazi.gsb4j
ArtifactId

ArtifactId

gsb4j-parent
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

pom
Description

Description

Gsb4j Parent
Gsb4j is a Java client implementation of Google Safe Browsing API v4. It includes both Lookup API and Update API implementations. Gsb4j is a more or less complete implementation of the Safe Browsing API protocol. There are some missing or unsupported parts which can be found on project's site but those do not influence the overall usability of the API.
Project URL

Project URL

https://github.com/bazi/gsb4j
Source Code Management

Source Code Management

https://github.com/bazi/gsb4j

Download gsb4j-parent

Filename Size
gsb4j-parent-1.0.6.pom 20 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/kg.net.bazi.gsb4j/gsb4j-parent/ -->
<dependency>
    <groupId>kg.net.bazi.gsb4j</groupId>
    <artifactId>gsb4j-parent</artifactId>
    <version>1.0.6</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/kg.net.bazi.gsb4j/gsb4j-parent/
implementation 'kg.net.bazi.gsb4j:gsb4j-parent:1.0.6'
// https://jarcasting.com/artifacts/kg.net.bazi.gsb4j/gsb4j-parent/
implementation ("kg.net.bazi.gsb4j:gsb4j-parent:1.0.6")
'kg.net.bazi.gsb4j:gsb4j-parent:pom:1.0.6'
<dependency org="kg.net.bazi.gsb4j" name="gsb4j-parent" rev="1.0.6">
  <artifact name="gsb4j-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='kg.net.bazi.gsb4j', module='gsb4j-parent', version='1.0.6')
)
libraryDependencies += "kg.net.bazi.gsb4j" % "gsb4j-parent" % "1.0.6"
[kg.net.bazi.gsb4j/gsb4j-parent "1.0.6"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • core
  • http

gsb4j

Build Status Maven Central Javadoc Maintainability Rating

Gsb4j is a Java client implementation of Google Safe Browsing API v4. It has both Lookup API and Update API implementations.

Gsb4j requires Java 8 or newer.

Refer to Feedback section of this page if you have questions regarding this project.

Get started

You can use Gsb4j by including dependency declaration in your project. If you use Maven, include the following in your POM file:

<dependency>
    <groupId>kg.net.bazi.gsb4j</groupId>
    <artifactId>gsb4j-core</artifactId>
    <version>1.0.6</version>
</dependency>

Gsb4j happily uses Guice dependency injection framework. Don't be afraid if you are not familiar with Guice -- Gsb4j handles it all and provides methods to bootstrap Gsb4j modules and to get instances of API client implementations. Code fragment below illustrates sample usage of Gsb4j.

Gsb4j gsb4j = Gsb4j.bootstrap(); // (1)
SafeBrowsingApi api = gsb4j.getApiClient(SafeBrowsingApi.Type.LOOKUP_API); // (2)
ThreatMatch threat = api.check(url); // (3)
if (threat != null) {
    // URL is not safe
} else {
    // URL is safe
}
gsb4j.shutdown(); // (4)
  1. Bootstrap Gsb4j when starting up your application. This shall be done exactly once! Note that when Gsb4j is bootstrapped this way (i.e. without specifying any properties), it expects configuration parameters be specified as system properties (-Dapi.key=...). Read below about configurations.
  2. Get an API client implementation instance, either Lookup API (as shown above) or Update API.
  3. Check your URL. If URL is recognized as unsafe by Google Safe Browsing, then non-null object representing the threat is returned. Otherwise, null is returned which means URL is safe and does not impose any threat.
  4. Shutdown is optional but highly recommended so that we are all clean. It releases resources held by Gsb4j. Usually such methods are called prior to application exit, e.g. in JVM shutdown hooks. Shutdown Gsb4j only when you are all done and will NOT be using Gsb4j anymore.

Configuration

Gsb4j needs API key to access Google Safe Browsing API. It can be obtained as described in API docs here. At this time, API key is the only required configuration parameter for Gsb4j.

Configuration parameter keys

  • api.key (required): API key to access the Safe Browsing API; read this page to setup and obtain API key
  • api.http.referrer (optional): if you have specified HTTP Referrer value for your API key, then you should supply it here
  • data.dir (optional, defaults to gsb4j directory in home directory of the current user): this is the directory where Gsb4j will store its data. All kind of API related metadata and local database files will be stored in this directory.

There are two ways you can set configuration parameters: (1) using system properties, and (2) using properties file which should be compatible with standard Properties class.

System properties are set as VM options in a command line as shown below. Almost all IDEs provide ways to set VM options as well.

java -Dapi.key=AIza...qwSg -Ddata.dir=/home/user1/other/gsb4j -jar app.jar

Properties file should be maintained and located by you. To bootstrap Gsb4j using your properties file, first you have to create an instance of Properties class and load your properties file into that instance. Then you bootstrap Gsb4j with this Properties instance as shown below.

Properties properties = new Properties();
try (Reader reader = new FileReader("/path/to/your/file.properties")) {
    properties.load(reader);
}
Gsb4j gsb4j = Gsb4j.bootstrap(properties);

HTTP Proxy

There is a ready HTTP proxy for Gsb4j. This is handy for those who want a quick run to see all things working. You can download an archive, extract it, and launch it right away - and you are ready to check URLs. Here is how to launch HTTP proxy and how to check URLs.

Download tarball or zip archive from releases page and extract it to your desired location (example uses tarball):

tar xzf gsb4j-http-${version}-bundle.tgz -C /home/user1/test/

Change current directory to the location where you extracted archive contents and launch jar file with your API key:

java -Dapi.key=AIza...qwSg -jar gsb4j-http-${version}.jar 

This will start up a web server on port 8080. Now you can send GET requests to /gsb4j/api/lookup endpoint with query parameter named url which should contain a URL string value you want to check against Google Safe Browsing API. Below is a sample request from command line:

curl http://localhost:8080/gsb4j/api/lookup?url=http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/

Please note that your URL supplied as a query parameter must be URL-encoded to avoid confusions. In the above example, URL is not encoded as curl takes care of it but ideally that URL should be URL-encoded.

More details on wiki page.

What's missing

Gsb4j is more or less a complete implementation of the API v4. But there are some parts that are not supported. Those parts do not influence the overall usability of the API but, nevertheless, they are not supported for now :)

  • Google Safe Browsing Lookup API supports queries of up to 500 URLs in a single request but we query one URL at a time. One usually checks only one URL in hand and this is the sole reason we support single URL queries. This may change in future if needed. (doc reference)
  • Rice compression of payloads (doc reference)
  • Back-off mode for unsuccessful HTTP responses from API (doc reference)

Feedback

Your feedback and comments are welcome and appreciated. You can use Gsb4j mailing list to ask any kind of questions or to share your thoughts on various topics related to Gsb4j. This mailing list is open to everything Gsb4j related.

If you find any bugs or issues related to working of Gsb4j, then you should be creating an issue in Github. Contributions are always welcome!

SonarCloud

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0