Google Safe Browsing Library for .NET Beta 2

Photo taken from http://www.thesecryption.com/email-encryption/Phishing.jpg Last Friday I released the first Beta of my Google Safe Browsing API library for .NET with some limitations that I listed there.

During the last week I worked on this library to solve those limitation and improve the code and design and the result was what I'm now announcing as the Beta 2 with some major updates and bug fixes that can make the library much better and stable.

Phil's idea on having a single library to fight against spam and badware stuff in .NET applications was a great idea and I'm interested to help it as much as I can.

In my opinion .NET open source should move from writing many blogging engines or data and code generation applications to more specific projects that can be helpful for .NET developers. Subkismet is one of them and a unique project in .NET community.

What's New in Beta 2?

Last week I outlined some limitations with Beta 1 and stated that this version isn't appropriate for production and all its API is subject to change. For new Beta 2 version I added some new features:

Limitations

While these changes have made the library completely different from the Beta 1 but there are still four things that I need to pay attention to them for the final release:

How to Use

However, the current version (Beta 2) is stable and most likely public API won't change after this. So you can feel free to use it. I updated the sample Windows Application included in the Subkismet solution to let you test the library and see how to use it in your own code. Now it's integrated with Phil's form and you can enjoy testing your data in a single Windows Form with Akismet implementation.

If you're looking for a sample code on how to use this library, here I give new samples to teach you the answer. If you compare this code with what I had provided for Beta 1, can believe the changes in the API.

First of all you need to add appropriate elements to your application configuration file (App.Config or Web.Config) to define your data provider and Google Safe Browsing API key.

Following is all the code that you need to add to your configuration files:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <section name="GoogleSafeBrowsingProvider"

            type="Subkismet.Services.GoogleSafeBrowsing.Provider.DataProviderConfiguration, Subkismet" />

  </configSections>

 

  <appSettings>

    <add key="apiKey" value="ABQIAAAAHmeOB6h5POEjgHbmfLJGzxS6yEDbsEeEJ6eL17v7yJ9rbkUbMA"/>

  </appSettings>

 

  <GoogleSafeBrowsingProvider default="XmlProvider">

    <providers>

      <add name="XmlProvider"

          type="Subkismet.Services.GoogleSafeBrowsing.Provider.XmlDataProvider, Subkismet"

          phishingFilePath="C:\Data\phishing.xml"

          malwareFilePath="C:\Data\malware.xml" />

    </providers>

  </GoogleSafeBrowsingProvider>

</configuration>

Here I defined the configuration section for my data provider and then inserted the Google Safe Browsing API key in <appSettings /> and added appropriate elements to declare my data provider and file paths. The default data provider is XmlProvider but you can implement your own provider as well.

After this, you just need to write a simple code to check your comments or links with local data.

To update a local black list, you need to create an instance of the GoogleSafeBrowsing class and call its UpdateList method by passing the appropriate list name.

private void btnGoogleSafeUpdate_Click(object sender, EventArgs e)

{

    // Create an instance of the GoogleSafeBrowsing

    GoogleSafeBrowsing gsb = new GoogleSafeBrowsing();

 

    // Update phishing black list

    gsb.UpdateList(BlackListType.Phishing);

 

    // Update malware black list

    gsb.UpdateList(BlackListType.Malware);

 

    // Display the response

    txtResponse.Text += "Update done!\n";

}

To check all links in a comment, you need to create an instance of the GoogleSafeBrowsing and call its CheckPost method by passing an IComment object and two out parameters that will be updated with the number of phishing and malware links respectively.

private void btnGoogleSafeCheck_Click(object sender, EventArgs e)

{

    // Create an instance of the GoogleSafeBrowsing

    GoogleSafeBrowsing gsb = new GoogleSafeBrowsing();

 

    int phishingCount = 0;

    int malwareCount = 0;

 

    // Peform a check and get the number of bad URLs

    gsb.CheckPost(GetComment(), out phishingCount, out malwareCount);

 

    // Display the number of bad URLs

    txtResponse.Text += string.Format("Phishing URLs: {0}\nMalware URLs: {1}\n",

        phishingCount, malwareCount);

}

In new Beta 2 version you have two alternative approaches to check a single link or a list of links by passing their string values to CheckLink and CheckLinks methods. In this new version you can also enjoy the result of XML code comments as descriptions for classes, methods and their parameters that guide you.

Download

You can download the Beta 2 from the CodePlex workspace. I can consider change set 14737 as Beta 2.

Hopefully the next version will be the final version and as a part of a new version for Subkismet project. I'm going to ask Phil how should we release it, as a Beta or as a final version. I think we'll be able to release this version in next couple of weeks, though.

[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.

No Comments : 12.28.07

Feedbacks

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment