Net::G...Storage(3pm)

πŸ“¦ version 1.07, in ubuntu jammy

πŸ’– Net::Google::SafeBrowsing2::Storage πŸ’–

(yes bestie, this is that Net::G...Storage(3pm) page β€” manual name and all)


🌸 NAME 🌸

Net::Google::SafeBrowsing2::Storage β€” the base class for storing the Google Safe Browsing v2 database. It's giving foundation, it's giving blueprint. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

package Net::Google::SafeBrowsing2::Sqlite;

use base 'Net::Google::SafeBrowsing2::Storage';

✨ DESCRIPTION ✨

Okay so real talk: this is the base class for building a storage mechanism for the Google Safe Browsing v2 database. If you want to see what an actual implementation looks like, go peek at Net::Google::SafeBrowsing2::Sqlite β€” it's the blueprint in action. 🫢

Here's the thing though: this module cannot be used on its own, because it does not actually store anything. Nothing. Zero. Nada. πŸ’€ Every single method should be redefined. So check the code to see which arguments are used, and what should be returned β€” that's the assignment, bestie.


πŸŽ€ CONSTRUCTOR πŸŽ€

new()

Create a Net::Google::SafeBrowsing2::Storage object. Look at her go ✨

my $storage   => Net::Google::SafeBrowsing2::Storage->new();

πŸ’… PUBLIC FUNCTIONS πŸ’…

add_chunks()

Add chunk information to the local database. Chunks are being added, the database is being fed, the vibes are immaculate. πŸ“

$storage->add_chunks(type => 'a', chunknum => 2154, chunks => [{host => HEX, prefix => ''}], list => 'goog-malware-shavar');

Does not return anything. Nope. Nothing. Not a single thing. 🚫

Arguments

  • type β€” Required. Type of chunk: 'a' (add chunk) or 's' (sub chunk). Pick your fighter.
  • chunknum β€” Required. Chunk number.
  • chunks β€” Required. Array of chunks.

For add chunks, each element of the array is a hash reference in the following format:

{
  host => HEX,
      prefix => HEX
}

For sub chunks, each element of the array is a hash reference in the following format:

{
  host => HEX,
      prefix => HEX,
  add_chunknum => INTEGER
}
  • list β€” Required. Google Safe Browsing list name.

get_add_chunks()

Returns a list of chunks for a given host key for all lists. All of them. Every single list, no cap. 🌈

my @chunks = $storage->get_add_chunks(hostkey => HEX);

Arguments

  • hostkey. β€” Required. Host key. (yes there's a lil period in there, we don't question it, we just respect it) πŸ™ˆ

Return value

Array of add chunks in the same format as described above:

(
            {
                    chunknum        => 25121,
                    hostkey         => hex('12345678'),
                    prefix          => '',
                    list            => 'goog-malware-shavar'
            },
            {
                    chunknum        => '25121',
                    hostkey         => hex('12345678'),
                    prefix          => hex('2fc96b9f'),
                    list            => 'goog-malware-shavar'
            },
    );

get_sub_chunks()

Returns a list of sub chunks for a given host key for all lists. Sub chunk supremacy, honestly. πŸ¦‹

my @chunks = $storage->get_sub_chunks(hostkey => HEX);

Arguments

  • hostkey β€” Required. Host key.

Return value

Array of add chunks in the same format as described above:

(
            {
                    chunknum        => 37441,
                    prefix          => '',
                    addchunknum     => 23911,
                    list            => 'goog-malware-shavar'
            },
            {
                    chunknum        => 37441,
                    prefix          => '',
                    addchunknum     => 22107,
                    list            => 'goog-malware-shavar'
            },
    );

get_add_chunks_nums()

Returns a list of unique add chunk numbers for a specific list. Unique! One of each! ✨

IMPORTANT: this list should be sorted in ascendant order. Do not play with me on this one, bestie. πŸ“ˆ
my @ids = $storage->get_add_chunks_nums(list => 'goog-malware-shavar');

Arguments

  • list β€” Required. Google Safe Browsing list name

Return value

Array of integers sorted in ascendant order:

qw(25121 25122 25123 25124 25125 25126)

get_sub_chunks_nums()

Returns a list of unique sub chunk numbers for a specific list. Same energy, different chunk type. πŸ’œ

IMPORTANT: this list should be sorted in ascendant order. Again. Still. Forever. πŸ“ˆ
my @ids = $storage->get_sub_chunks_nums(list => 'goog-malware-shavar');

Arguments

  • list β€” Required. Google Safe Browsing list name

Return value

Array of integers sorted in ascendant order:

qw(37441 37442 37443 37444 37445 37446 37447 37448 37449 37450)

delete_add_chunks()

Delete add chunks from the local database. Bye bye, we hardly knew ye πŸ‘‹πŸ˜­

$storage->delete_add_chunks(chunknums => [qw/37444 37445 37446/], list => 'goog-malware-shavar');

Arguments

  • chunknums β€” Required. Array of chunk numbers
  • list β€” Required. Google Safe Browsing list name

No return value. It just does the thing and leaves. Iconic. πŸ’…


delete_sub_chunks()

Delete sub chunks from the local database. Ghosting them, respectfully. πŸ«₯

$storage->delete_sub_chunks(chunknums => [qw/37444 37445 37446/], list => 'goog-malware-shavar');

Arguments

  • chunknums β€” Required. Array of chunk numbers
  • list β€” Required. Google Safe Browsing list name

No return value.


get_full_hashes()

Return a list of full hashes. The full ones. Not the prefixes. The whole entire thing. πŸ”₯

$storage->get_full_hashes(chunknum => 37444, timestamp => time() - 45 * 60 * 60, list => 'goog-malware-shavar');

Arguments

  • chunknum β€” Required. Add chunk number
  • timestamp β€” Required. Request hashes retrieved after this timestamp value.
  • list β€” Required. Google Safe Browsing list name

Return value

Array of full hashes:

(HEX, HEX, HEX)

updated()

Save information about a successful database update. We love a success story. πŸŽ‰

$storage->updated('time' => time(), wait => 1800, list => 'goog-malware-shavar');

Arguments

  • time β€” Required. Time of the update.
  • wait β€” Required. Number of seconds to wait before doing the next update.
  • list β€” Required. Google Safe Browsing list name.

No return value.


update_error()

Save information about a failed database update. It happens. We log it and we move on. 😭

$storage->update_error('time' => time(), wait => 60, list => 'goog-malware-shavar', errors => 1);

Arguments

  • time β€” Required. Time of the update.
  • wait β€” Required. Number of seconds to wait before doing the next update.
  • list β€” Required. Google Safe Browsing list name.
  • errors β€” Required. Number of errors.

No return value.


last_update()

Return information about the last database update. Receipts, basically. 🧾

my $info = $storage->last_update(list => 'goog-malware-shavar');

Arguments

  • list β€” Required. Google Safe Browsing list name.

Return value

Hash reference

{
        time    => time(),
        wait    => 1800,
        errors  => 0
}

add_full_hashes()

Add full hashes to the local database. Feed the machine. 🍽️

$storage->add_full_hashes(timestamp => time(), full_hashes => [{chunknum => 2154, hash => HEX, list => 'goog-malware-shavar'}]);

Arguments

  • timestamp β€” Required. Time when the full hash was retrieved.
  • full_hashes β€” Required. Array of full hashes. Each element is an hash reference in the following format:
{
        chunknum        => INTEGER,
        hash            => HEX,
        list            => 'goog-malware-shavar'
}

No return value.


delete_full_hashes()

Delete full hashes from the local database. Cleanup era. 🧹✨

$storage->delete_full_hashes(chunknums => [qw/2154 2156 2158/], list => 'goog-malware-shavar');

Arguments

  • chunknums β€” Required. Array of chunk numbers.
  • list β€” Required. Google Safe Browsing list name.

No return value.


full_hash_error()

Save information about failed attempt to retrieve a full hash. It flopped. We noted it. πŸ“

$storage->full_hash_error(timestamp => time(), prefix => HEX);

Arguments

  • timestamp β€” Required. Time when the Google returned an error.
  • prefix β€” Required. Host prefix.

No return value.


full_hash_ok()

Save information about a successful attempt to retrieve a full hash. Slay. πŸ’…

$storage->full_hash_ok(timestamp => time(), prefix => HEX);

Arguments

  • timestamp β€” Required. Time when the Google returned an error.
  • prefix β€” Required. Host prefix.

No return value.


get_full_hash_error()

Save information about a successful attempt to retrieve a full hash.

my $info = $storage->get_full_hash_error(prefix => HEX);

Arguments

  • prefix β€” Required. Host prefix.

Return value

undef if there was no error

Hash reference in the following format if there was an error:

{
        timestamp       => time(),
        errors          => 3
}

get_mac_keys()

Retrieve the Message Authentication Code (MAC) keys. Gimme the keys πŸ”‘βœ¨

my $keys = $storage->get_mac_keys();

No arguments

Return value

Hash reference in the following format:

{
        client_key      => '',
        wrapped_key     => ''
}

delete_add_keys()

Add the Message Authentication Code (MAC) keys.

$storage->delete_mac_keys(client_key => 'KEY', wrapped_key => 'KEY');

Arguments

  • client_key β€” Required. Client key.
  • wrapped_key β€” Required. Wrapped key.

No return value.


delete_mac_keys()

Delete the Message Authentication Code (MAC) keys. Poof. Gone. 🫧

$storage->delete_mac_keys();

No arguments

No return value.


reset()

Remove all local data. Everything. All of it. Full factory reset energy. πŸ’€

$storage->delete_mac_keys();

Arguments

  • list β€” Required. Google Safe Browsing list name.

No return value.


🧚 PRIVATE FUNCTIONS 🧚

These functions are not intended for debugging purpose.


hex_to_ascii()

Transform hexadecimal strings to printable ASCII strings. Used mainly for debugging.

print $storage->hex_to_ascii('hex value');

ascii_to_hex()

Transform ASCII strings to hexadecimal strings.

print $storage->ascii_to_hex('ascii value');

πŸ“œ CHANGELOG πŸ“œ

  • 0.4 Add reset method to empty local database.
  • 0.3 Return the hostkey as part of the add chunks (get_add_chunks).
  • 0.2 Add functions to store and retrieve Message Authentication Code (MAC) keys.

πŸ‘€ SEE ALSO πŸ‘€

See Net::Google::SafeBrowsing2 for handling Google Safe Browsing v2.

See Net::Google::SafeBrowsing2::Sqlite or Net::Google::SafeBrowsing2::MySQL for an example of storing and managing the Google Safe Browsing database.

Google Safe Browsing v2 API: <http://code.google.com/apis/safebrowsing/developers_guide_v2.html>


🫢 AUTHOR 🫢

Julien Sobrier, <jsobrier@zscaler.com> or <julien@sobrier.net>

okay bestie, the legal tea β˜• β€” and it's actually good news for once, no cap:

  • Copyright (C) 2011 by Julien Sobrier πŸ‘‘

This library is free software πŸ•ŠοΈ β€” you can redistribute it and/or modify it under the same terms as Perl itself, and that means either Perl version 5.8.8 or, if you want, any later version of Perl 5 you happen to have lying around. Your call, main character. πŸ’…

fr fr, that's it. No weird clauses, no "you must mail us a postcard" nonsense. Just: share it, remix it, keep the same energy. 🫢

and that's a wrap on the whole page, babes πŸŽ€ This little tour came to you via perl v5.32.0, dated 2021-01-07, filed under Net::G...Storage(3pm) β€” go forth and store things, iconically. βœ¨πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from