1 function jappixmini_addon_xor(str1, str2) {
2 if (str1.length != str2.length) throw "not same length";
6 for (i=0; i<str1.length;i++) {
7 var a = str1.charCodeAt(i);
8 var b = str2.charCodeAt(i);
11 encoded += String.fromCharCode(c);
17 function jappixmini_addon_set_client_secret(password) {
18 client_secret = str_sha1("client_secret:"+password);
19 setDB('jappix-mini', 'client_secret', client_secret);
22 function jappixmini_addon_get_client_secret() {
23 client_secret = getDB('jappix-mini', 'client_secret');
24 if (client_secret===null) {
25 div = $('<div style="position:fixed;padding:1em;background-color:#F00;color:#fff;top:50px;left:50px;" id="x123">Reintroduce your Friendica password for chatting:</div>');
26 div.append($("<br>"));
27 input = $('<input type="password">')
29 button = $('<input type="button" value="OK">');
30 button.click(function(){
31 password = input.val();
32 jappixmini_addon_set_client_secret(password);
36 $("body").append(div);
42 function jappixmini_addon_encrypt_password(password) {
43 client_secret = jappixmini_addon_get_client_secret();
45 // add \0 to password until it has the same length as secret
46 if (client_secret.length<password.length) throw "password too long";
47 while (password.length<client_secret.length) {
51 // xor password with secret
52 encrypted_password = jappixmini_addon_xor(client_secret, password);
54 encrypted_password = encodeURI(encrypted_password)
55 return encrypted_password;
58 function jappixmini_addon_decrypt_password(encrypted_password) {
59 encrypted_password = decodeURI(encrypted_password);
61 client_secret = jappixmini_addon_get_client_secret();
63 // xor encrypted password with secret
64 password = jappixmini_addon_xor(client_secret, encrypted_password);
67 first_null = password.indexOf("\0")
68 password = password.substr(0, first_null);
73 function jappixmini_manage_roster(contacts, autoapprove, autosubscribe) {
74 // listen for subscriptions
75 con.registerHandler('presence',function(presence){
76 var type = presence.getType();
77 if (type != "subscribe") return;
79 var from = fullXID(getStanzaFrom(presence));
80 var xid = bareXID(from);
83 if ((!autoapprove) || ($.inArray(xid, contacts) == -1))
84 approve = confirm("Accept "+xid+" for chat?");
88 //alert("Accepted "+xid+" for chat.");
94 for (i=0; i<contacts.length; i++) {
96 sendSubscribe(xid, "subscribe");
101 function jappixmini_addon_start(server, username, bosh, encrypted_password) {
102 // check if settings have changed, reinitialize jappix mini if this is the case
103 settings_identifier = str_sha1(server);
104 settings_identifier += str_sha1(username);
105 settings_identifier += str_sha1(bosh);
106 settings_identifier += str_sha1(encrypted_password);
108 saved_identifier = getDB("jappix-mini", "settings_identifier");
109 if (saved_identifier != settings_identifier) removeDB('jappix-mini', 'dom');
110 setDB("jappix-mini", "settings_identifier", settings_identifier);
113 HOST_BOSH = HOST_BOSH+"?host_bosh="+encodeURI(bosh);
116 password = jappixmini_addon_decrypt_password(encrypted_password);
119 launchMini(true, false, server, username, password);