Skip to content

Commit

Permalink
Major refactoring and Firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Oberndörfer committed Oct 12, 2012
1 parent 574c9d3 commit 2039f03
Show file tree
Hide file tree
Showing 511 changed files with 8,618 additions and 5,923 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*~
.directory
*.sublime*
.svn
.svn
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "dep/chrome/openpgpjs"]
path = dep/chrome/openpgpjs
url = git://github.com/toberndo/openpgpjs.git
[submodule "firefox/packages/ppg-api"]
path = firefox/packages/ppg-api
url = git://github.com/invi/ppg-api.git
9 changes: 7 additions & 2 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@

0.4.3.1 / 04.10.2012
0.5.0 / 12.10.2012
==================

* Fix: content script not injected in main frame of GMail
* Major refactoring
* Add Firefox support
* [Chrome] Use Require.js for background scripts
* Update jQuery to 1.8.2
* CommonJS wrapper for Google Closure library
* Add submodules: OpenPGP.js, ppg-api

0.4.3 / 07.09.2012
==================
Expand Down
46 changes: 40 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@

PROFILEDIR = ~/dev/firefox/mailvelope

default: help

help:
@echo "pack - concatenate content script files"
@echo "minify - minify content script files"
@echo "build-cs - pack & minify content script files"
@echo "copy-common - copy common folder to Chrome and Firefox directories"
@echo "copy-dep - copy openpgp.js library to Chrome directory"
@echo "test-build - pack content scripts and copy common folder"
@echo "build - build content scripts and copy common folder"
@echo "start-ff - run addon in Firefox"
@echo "test-ff - do test-build & run addon in Firefox"

pack:
@echo Concatenate content script files...
@cat src/lib/jquery-1.8.custom.js src/content_scripts/decryptFrame.js src/content_scripts/encryptFrame.js src/content_scripts/main-cs.js > src/content_scripts/build/cs-mailvelope.js
@cat common/dep/jquery.js common/ui/inline/mvelo.js common/ui/inline/main-cs.js common/ui/inline/decryptFrame.js common/ui/inline/encryptFrame.js > common/ui/inline/build/cs-mailvelope.js
@echo Appending //@ sourceURL=cs-mailvelope.js...
@echo '//@ sourceURL=cs-mailvelope.js' >> src/content_scripts/build/cs-mailvelope.js
@echo '//@ sourceURL=cs-mailvelope.js' >> common/ui/inline/build/cs-mailvelope.js

compile:
minify:
@echo Running http://code.google.com/closure/compiler/...
@java -jar res/closure-compiler/compiler.jar --js=src/lib/jquery-1.8.custom.js --js=src/content_scripts/decryptFrame.js --js=src/content_scripts/encryptFrame.js --js=src/content_scripts/main-cs.js --js_output_file=src/content_scripts/build/cs-mailvelope.min.js
@java -jar res/closure-compiler/compiler.jar --js=common/dep/jquery.js --js=common/ui/inline/mvelo.js --js=common/ui/inline/main-cs.js --js=common/ui/inline/decryptFrame.js --js=common/ui/inline/encryptFrame.js --js_output_file=common/ui/inline/build/cs-mailvelope.min.js
@echo Appending //@ sourceURL=cs-mailvelope.min.js...
@echo '//@ sourceURL=cs-mailvelope.min.js' >> src/content_scripts/build/cs-mailvelope.min.js
@echo '//@ sourceURL=cs-mailvelope.min.js' >> common/ui/inline/build/cs-mailvelope.min.js

build-cs: pack minify

copy-common:
@echo Update common folder...
@cp -ur common/* chrome/common
@cp -ur common/* firefox/data/common

copy-dep:
@echo Update openpgp.js files...
@cp -u dep/chrome/openpgpjs/resources/openpgp.js chrome/dep
@cp -u dep/chrome/openpgpjs/resources/openpgp.min.js chrome/dep

test-build: pack copy-common copy-dep

build: build-cs copy-common

dist-ff:
@echo package add-on as an XPI file in dist folder
@cfx xpi --pkgdir=firefox
@mv mailvelope.xpi dist

minify: pack compile
start-ff:
@echo Start Firefox...
@cfx run --pkgdir=firefox --profiledir=$(PROFILEDIR)

test-ff: test-build start-ff
27 changes: 15 additions & 12 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# Mailvelope

Mailvelope is a chrome extension that allows secure email communication with Webmail based on the OpenPGP standard.
Mailvelope is a browser extension for Google Chrome and Firefox that allows secure email communication based on the OpenPGP standard. It can be configured to work with arbitrary Webmail provider.

## OpenPGP backends

Mailvelope uses the following OpenPGP implementations

- [OpenPGP.js](http://openpgpjs.org/) for the Chrome Extension
- [Pidgeon Privacy Guard](https://pidgeonpg.org/) for the Firefox Addon

## Status

- Chrome Extension: _beta_
- Firefox Addon: _alpha_

## Installation

Mailvelope is available in the Chrome Web Store:
https://chrome.google.com/webstore/detail/kajibbejlbohfaggdiogboambcijhkke

Or as an XPI file for Firefox: dist/mailvelope.xpi

## Website

http://www.mailvelope.com
Expand All @@ -15,17 +29,6 @@ http://www.mailvelope.com

Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE that can be found in the LICENSE file.

## Credits

Mailvelope is based on the work of the following open source projects which should be thanked and acknowledged:

- [OpenPGP.js](http://openpgpjs.org/)
- [Bootstrap](http://twitter.github.com/bootstrap/)
- [jQuery](http://jquery.com/)
- [Kendo UI](http://www.kendoui.com/)
- [Closure](https://developers.google.com/closure/)
- [Oxygen Icons](http://www.oxygen-icons.org/)

## About

written by Thomas Oberndörfer <toberndo@yarkon.de>
Expand Down
7 changes: 7 additions & 0 deletions chrome/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script data-main="background" src="require.js"></script>
</head>
</html>
214 changes: 214 additions & 0 deletions chrome/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/**
* Mailvelope - secure email with OpenPGP encryption for Webmail
* Copyright (C) 2012 Thomas Oberndörfer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

requirejs.config({
paths: {
jquery: 'common/dep/jquery.min',
openpgp: 'dep/openpgp'
},
shim: {
'openpgp': {
deps: ['jquery'],
exports: 'openpgp'
}
}
});

define(["common/lib/controller", "lib/pgpViewModel", "openpgp", "jquery"], function(controller, model, openpgp, $) {

// inject content script only once per time slot
var injectTimeSlot = 600;
// injection time slot currently open
var injectOpen = true;
// optimized cs injection variant, bootstrap code injected that loads cs
var injectOptimized = true;
// keep reloaded iframes
var frameHosts = [];
// content script coding as string
var csCode = '';

function init() {
controller.extend({initScriptInjection: initScriptInjection});
openpgp.init();
initDefaults(function() {
migrate();
initConnectionManager();
initContextMenu();
initScriptInjection();
initMessageListener();
});
}

function initDefaults(done) {
// apply defaults if don't exist
if (model.getWatchList() === null) {
$.get(chrome.extension.getURL('common/res/defaults.json'), function(data) {
model.setWatchList(data.watch_list);
done();
}, 'json');
} else {
done();
}
}

function initConnectionManager() {
// store incoming connections by name and id
chrome.extension.onConnect.addListener(function(port) {
//console.log('ConnectionManager: onConnect:', port);
controller.addPort(port);
port.onMessage.addListener(controller.handlePortMessage);
// update active ports on disconnect
port.onDisconnect.addListener(controller.removePort);
});
}

function initMessageListener() {
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
switch (request.event) {
// for content scripts requesting code
case 'get-cs':
sendResponse({code: csCode});
break;
case 'get-tabid':
sendResponse({tabid: sender.tab.id});
break;
default:
controller.handleMessageEvent(request, sender, sendResponse);
}
}
);
}

function initContextMenu() {
chrome.contextMenus.create({
"title": "Encrypt",
"contexts": ["page", "frame", "selection", "link", "editable"],
"onclick": onContextMenuEncrypt
});
}

function onContextMenuEncrypt(info) {
//console.log(info);
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendMessage(tab.id, {event: "context-encrypt"});
});
}

function initScriptInjection() {

if (injectOptimized && csCode === '') {
// load content script
$.get(chrome.extension.getURL('common/ui/inline/build/cs-mailvelope.js'), function(data) {
csCode = data;
});
}

var filterURL = controller.getWatchListFilterURLs();

filterURL = filterURL.map(function(host) {
return '*://' + host + '/*';
});

var filterType = ["main_frame", "sub_frame"];

var requestFilter = {
urls: filterURL,
types: filterType
}
chrome.webRequest.onCompleted.removeListener(watchListRequestHandler);
if (filterURL.length !== 0) {
chrome.webRequest.onCompleted.addListener(watchListRequestHandler, requestFilter);
}
}

function watchListRequestHandler(details) {
// store frame URL
frameHosts.push(model.getHost(details.url));
if (injectOpen || details.type === "main_frame") {
setTimeout(function() {
if (frameHosts.length === 0) {
// no requests since last inject
return;
}
//console.log('cs injected');
var scriptDetails;
if (injectOptimized) {
scriptDetails = {code: csBootstrap(), allFrames: true}
} else {
scriptDetails = {file: "common/ui/inline/build/cs-mailvelope.js", allFrames: true}
}
chrome.tabs.executeScript(details.tabId, scriptDetails, function() {
chrome.tabs.insertCSS(details.tabId, {file: "common/ui/inline/framestyles.css", allFrames: true});
// open injection time slot
injectOpen = true;
});
// reset buffer after injection
frameHosts.length = 0;
}, injectTimeSlot);
// close injection time slot
injectOpen = false;
}
}

function csBootstrap() {
return " \
if (!document.mailvelopeControl) { \
var hosts = " + JSON.stringify(frameHosts) + "; \
var match = hosts.some(function(host) { \
return host === document.location.host; \
}); \
if (match) { \
chrome.extension.sendMessage({event: 'get-cs'}, function(response) { \
eval(response.code); \
}); \
} \
} \
";
}

function migrate() {
// migration
migrateTo0420();
}

function migrateTo0420() {
for (var i = 0; i < openpgp.keyring.privateKeys.length; i++) {
// check if corresponding public key
var found = openpgp.keyring.getPublicKeysForKeyId(openpgp.keyring.privateKeys[i].obj.getKeyId());
if (found.length === 0) {
// create public key from private key
var pubArmored = openpgp.keyring.privateKeys[i].obj.extractPublicKey();
if (pubArmored === null) {
// remove private key
openpgp.keyring.removePrivateKey(i);
i--;
} else {
// import public key
var pubKey = openpgp.read_publicKey(pubArmored);
for (var j = 0; j < pubKey.length; j++) {
openpgp.keyring.publicKeys.push({armored: pubArmored, obj: pubKey[j], keyId: pubKey[j].getKeyId()});
}
openpgp.keyring.store();
}
}
}
}

init();

});
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2039f03

Please sign in to comment.