NodeJS Script Filter for Alfred.

Download

Chrome Session

Because we need request Web Server with our Chrome seesion, so we need get in Computer.

Chrome Session stroge in ~/Library/Application Support/Google/Chrome/Default, formated with SQLLite.

SQLLite

cd to your chrome seesion path, then open it with sqllite3 command.

$ cd ~/Library/Application\ Support/Google/Chrome/Default
$ sqlite3

Query data fellow steps below:

sqlite> ATTACH DATABASE "Cookies" as "Cookies";
sqlite> .database
sqlite> .header on
sqlite> .mode column
sqlite> select host_key, name, hex(encrypted_value) from Cookies where name = 'cookie2';

See more commands

Encryption

Chrome cookies encryption with AES-128, more information can find here

Implement with NodeJS, you can check it in chrome-cookies-secure

image

Chrome Safe Storage

See Decrypting Google Chrome Passwords on macOS / OS X

And the Source Code

Encrypted By Chrome

namespace {

// Salt for Symmetric key derivation.
constexpr char kSalt[] = "saltysalt";

// Key size required for 128 bit AES.
constexpr size_t kDerivedKeySizeInBits = 128;

// Constant for Symmetic key derivation.
constexpr size_t kEncryptionIterations = 1003;

// Prefix for cypher text returned by current encryption version.  We prefix
// the cypher text with this string so that future data migration can detect
// this and migrate to different encryption without data loss.
constexpr char kEncryptionVersionPrefix[] = "v10";

}  // namespace

...

  // Create an encryption key from our password and salt.
  cached_encryption_key_ =
      crypto::SymmetricKey::DeriveKeyFromPasswordUsingPbkdf2(
          crypto::SymmetricKey::AES, password, salt, kEncryptionIterations,
          kDerivedKeySizeInBits);
  DCHECK(cached_encryption_key_);
  return cached_encryption_key_.get();

Decrypted by NodeJS

So we have the fellow code in NodeJS

var	KEYLENGTH = 16,
	SALT = 'saltysalt'

...

ITERATIONS = 1003;

...

function getDerivedKey(callback) {

	var keytar,
		chromePassword;

	if (process.platform === 'darwin') {

		keytar = require('keytar');
		keytar.getPassword('Chrome Safe Storage', 'Chrome').then(function(chromePassword) {

      // KEYLENGTH = 16 BYTES = 16 * 8 = 128 bits
			crypto.pbkdf2(chromePassword, SALT, ITERATIONS, KEYLENGTH, 'sha1', callback);
		});

  ...
  }
}

...

function decrypt(key, encryptedData) {

	var decipher,
		decoded,
		final,
		padding,
		iv = new Buffer.from(new Array(KEYLENGTH + 1).join(' '), 'binary');

	decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
	decipher.setAutoPadding(false);

	encryptedData = encryptedData.slice(3);

  ...

}

NodeJS Filter

Node Arch

You need check NodeJS Arch first. Because you may have x64 in your VSCode Terminal and get arm64 in your standalone Terminal;

Alfred run node with arm64, so that if you install deps in your different terminal, you will fail in alfred.

$ node -e "console.log(process.arch)"

Reinstall VSCode (arm64) will fix it.

Hello World

A simplest Script Filter:

console.log(JSON.stringify({
  items: [
    {
      title: 'hello',
      subtitle: 'world',
      arg: 'https://www.google.com',
    }
  ]
}))