Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
first useable alpha version
Browse files Browse the repository at this point in the history
* tries to detect password and username input fields
* fills in credentials on single match of credentials and input fields
  • Loading branch information
mmichaa committed Oct 26, 2014
1 parent da0ef18 commit 3318d3a
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/builds
Binary file added Icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Icon-38.png
Binary file not shown.
Binary file removed Icon-48.png
Binary file not shown.
Binary file added Icon-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
8 changes: 4 additions & 4 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleDisplayName</key>
<string>passafari</string>
<key>CFBundleIdentifier</key>
<string>so.nowak.passafari</string>
<string>com.github.mmichaa.passafari</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
Expand Down Expand Up @@ -41,13 +41,13 @@
<key>Identifier</key>
<string>passafari</string>
<key>Image</key>
<string>Icon-16.png</string>
<string>Lock.png</string>
<key>Include By Default</key>
<true/>
<key>Label</key>
<string>passafari</string>
<key>Popover</key>
<string>passafari_credentials</string>
<string></string>
</dict>
</array>
</dict>
Expand Down Expand Up @@ -82,6 +82,6 @@
</dict>
</dict>
<key>Website</key>
<string>https://nowak.so/</string>
<string>https://github.com/mmichaa/passafari.safariextension/</string>
</dict>
</plist>
Binary file added Lock-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lock-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lock-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Settings.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Key</key>
<string>hostname</string>
<key>Secure</key>
<true/>
<key>Title</key>
<string>Hostname</string>
<key>Type</key>
<string>TextField</string>
</dict>
<dict>
<key>Key</key>
<string>port</string>
<key>Secure</key>
<true/>
<key>Title</key>
<string>Port</string>
<key>Type</key>
<string>TextField</string>
</dict>
</array>
</plist>
83 changes: 82 additions & 1 deletion end.js
Original file line number Diff line number Diff line change
@@ -1 +1,82 @@
console.log('passafari: end.js');
console.log('passafari: end.js');

var passafari_injected_end;

function passafari_injected_message_handler(event) {
var name = event.name;
var data = event.message;

console.log("passafari_injected_message_handler: " + name);

if(name === "credentials") {
passafari_injected_credentials_handler(name, data);
}

return undefined;
};

function passafari_injected_credentials_handler(event_name, event_data) {
if(event_data.length === 1) {
var credentials = event_data[0];
var input_candidates = passafari_input_candidates();

if(input_candidates.length === 1) {
var inputs = input_candidates[0];

inputs.username.value = credentials.Login;
inputs.password.value = credentials.Password;
} else {
console.log("passafari_injected_credentials_handler: more than one inputs found.")
console.log(inputs);
}
} else {
console.log("passafari_injected_credentials_handler: more than one credentials found.")
console.log(event_data);
}

return undefined;
}

if(!passafari_injected_end && window.parent === window) {
console.log('passafari: passafari_injected_end');
safari.self.addEventListener("message", passafari_injected_message_handler, false);
passafari_injected_end = true;
}

function passafari_input_candidates() {
var candidates = [];

for(var form_idx=0; form_idx < document.forms.length; form_idx++) {
var form = document.forms[form_idx];

if(form.method.toLowerCase() === "get") {
continue;
}

var inputs = { "username": undefined, "password": undefined };

for(var elem_idx=0; elem_idx < form.elements.length; elem_idx++) {
var elem = form.elements[elem_idx];

if(elem.disabled || elem.readOnly) {
continue;
}

var elem_type = elem.type.toLowerCase();

if(elem_type === "password") {
inputs["password"] = elem;
}
else if(elem_type === 'email' || elem_type === 'text') {
inputs["username"] = elem;
}

if(inputs["username"] && inputs["password"]) {
candidates.push(inputs);
break;
}
}
}

return candidates;
}
3 changes: 3 additions & 0 deletions global.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>passafari</title>

<script src="javascripts/utf8.js"></script>
<script src="javascripts/aes.js"></script>
<script src="javascripts/jsHash.js"></script>
<script src="javascripts/cryptoHelpers.js"></script>
<script src="javascripts/keepass.js"></script>

Expand Down
54 changes: 30 additions & 24 deletions global.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var passafari_credentials = {};

function passafari_command_handler(event) {
console.log("passafari_command_handler: " + event.command);
if (event.command == "passafari_open") {
Expand All @@ -20,23 +18,7 @@ function passafari_message_handler(event) {

function passafari_popover_handler(event) {
console.log("passafari_popover_handler: " + event.target.identifier);
if(event.target.identifier == "passafari_credentials") {
var popover = event.target;
var popover_document = popover.contentWindow.document;

var ul = popover_document.getElementById("credentials-list");
ul.innerHTML = "";

for(var idx = 0; idx < passafari_credentials.length; idx++) {
var credential = passafari_credentials[idx];
var li = popover_document.createElement("li");
var li_text = popover_document.createTextNode(credential.Login + ' | ' + credential.Name);
li.appendChild(li_text);
ul.appendChild(li);
}


}
return undefined;
}

Expand All @@ -50,10 +32,18 @@ safari.application.addEventListener("message", passafari_message_handler, fals
safari.application.addEventListener("popover", passafari_popover_handler, true);
safari.application.addEventListener("validate", passafari_validate_handler, true);


function passafari_open(event) {
passafari_associate();
passafari_retrieve_credentials();
passafari_display_credentials();

passafari_retrieve_credentials(function(credentials) {
if (credentials.length === 0) {
} else if (credentials.length === 1) {
passafari_notify_injected(credentials);
} else {
//passafari_display_credentials(credentials);
}
});

return undefined;
}
Expand All @@ -75,21 +65,21 @@ function passafari_associate(event) {
return undefined;
}

function passafari_retrieve_credentials(event) {
var callback = function(entries) { passafari_credentials = entries; };
function passafari_retrieve_credentials(callback) {
var tab = undefined;
var url = safari.application.activeBrowserWindow.activeTab.url;
var submiturl = undefined;
var forceCallback = function() {};
var triggerUnlock = true;

if(url) {
if(callback && url) {
keepass.retrieveCredentials(callback, tab, url, submiturl, forceCallback, triggerUnlock);
}

return undefined;
}

function passafari_display_credentials(event) {
function passafari_display_credentials(credentials) {
var toolbar_item = safari.extension.toolbarItems[0];

if(!toolbar_item.popover) {
Expand All @@ -101,7 +91,23 @@ function passafari_display_credentials(event) {
toolbar_item.popover = popover;
}

var popover_document = toolbar_item.popover.contentWindow.document;
var ul = popover_document.getElementById("credentials-list");
ul.innerHTML = "";

for(var idx = 0; idx < credentials.length; idx++) {
var credential = credentials[idx];
var li = popover_document.createElement("li");
var li_text = popover_document.createTextNode(credential.Login + ' | ' + credential.Name);
li.appendChild(li_text);
ul.appendChild(li);
}

toolbar_item.showPopover();

return undefined;
}

function passafari_notify_injected(credentials) {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("credentials", credentials);
}
2 changes: 1 addition & 1 deletion javascripts/keepass.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keepass.currentKeePassHttp = {"version": 0, "versionParsed": 0};
keepass.latestKeePassHttp = {"version": 0, "versionParsed": 0, "lastChecked": null};
keepass.keySize = 8; // wtf? stupid cryptoHelpers
keepass.pluginUrlDefault = "http://localhost:19455/";
keepass.latestVersionUrl = "https://raw.githubusercontent.com/mmichaa/passafari/master/latest-version.json";
keepass.latestVersionUrl = "https://passifox.appspot.com/kph/latest-version.txt";
keepass.cacheTimeout = 30 * 1000; // milliseconds
keepass.databaseHash = "no-hash"; //no-hash = keepasshttp is too old and does not return a hash value
keepass.keyId = "passafari-name";
Expand Down
9 changes: 9 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
/*
console.log('passafari: start.js');
var passafari_injected_start;
if(!passafari_injected_start && window.parent === window) {
console.log('passafari: passafari_injected_start');
passafari_injected_start = true;
}
*/

0 comments on commit 3318d3a

Please sign in to comment.