Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
added WG
Browse files Browse the repository at this point in the history
  • Loading branch information
pertinentstark committed Apr 15, 2019
1 parent 8e63ffc commit 7de7207
Show file tree
Hide file tree
Showing 35 changed files with 1,206 additions and 369 deletions.
30 changes: 1 addition & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wallet 2.0/debian.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": ["openvpn", "libgconf2-4", "gksu","shadowsocks-libev"]
"depends": ["openvpn", "libgconf2-4", "gksu","shadowsocks-libev", "wireguard"]
}
17 changes: 17 additions & 0 deletions wallet 2.0/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function windowManager() {
protocol: 'file:',
slashes: true
}));
// this.window.loadURL('http://localhost:3000');

this.window.on('close', async (e) => {
let self = this;
Expand All @@ -49,6 +50,18 @@ function windowManager() {
}
showTmPrompt = true;
if (isTM === 'true') {
if (process.platform === 'linux'){
exec(`wg-quick down wg0`, async function (error, stdout, stderr) {
console.log("disconnecting local Wireguard...")
if (error) throw error;
else {
// removeItemsLocal();
// clearConfig();
cb(null);
}
});
}

isTMVPNConnected(function (isConnected) {
if (showTmPrompt && isConnected) {
// e.preventDefault();
Expand Down Expand Up @@ -88,6 +101,10 @@ function windowManager() {
app.quit();
}
})




} else {
isVPNConnected((isConnected) => {
if (process.platform === 'win32')
Expand Down
1 change: 1 addition & 0 deletions wallet 2.0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"material-ui-rating": "^2.0.0",
"moment": "^2.22.2",
"net-stat": "^2.0.1",
"node-notifier": "^5.3.0",
"path": "^0.12.7",
"sudo-prompt": "^8.1.0",
"url": "^0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion wallet 2.0/platform_utils/debian.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": ["openvpn", "libgconf2-4", "shadowsocks-libev"]
"depends": ["openvpn", "libgconf2-4", "shadowsocks-libev", "wireguard"]
}
Binary file modified wallet 2.0/public/gaiacli
Binary file not shown.
55 changes: 5 additions & 50 deletions wallet 2.0/src/Actions/connectOVPN.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { CONNECT_VPN } from '../Constants/action.names';
import { checkDependencies, getOVPNAndSave, getUserHome, getOVPNTM } from '../Utils/utils';
import { checkDependencies, getOVPNAndSave, getUserHome, getOVPNTM, getWireguardTM } from '../Utils/utils';
import { getVPNPIDs } from '../Utils/VpnConfig';
import { getConfig } from '../Utils/UserConfig';
import { disconnectVPN } from '../Utils/DisconnectVpn';
Expand All @@ -11,6 +11,7 @@ const sudo = remote.require('sudo-prompt');
const SENT_DIR = getUserHome() + '/.sentinel';
const CONFIG_FILE = SENT_DIR + '/config';
const OVPN_FILE = SENT_DIR + '/client.ovpn';
const WIREGUARD_CONFIG_FILE = SENT_DIR + '/wg0.conf';
const fs = window.require('fs');
let async = window.require('async');
const { exec, execSync } = window.require('child_process');
Expand All @@ -23,6 +24,7 @@ let outputCount = 0;
let count = 0;

export async function connectVPN(account_addr, vpn_addr, os, data, cb) {
console.log("tryin to connect VPN also..")
checkVPNDependencies(os, (otherErr, winErr) => {
if (otherErr) cb(otherErr, false, null);
else if (winErr) cb(null, winErr, null);
Expand All @@ -40,56 +42,9 @@ export async function connectVPN(account_addr, vpn_addr, os, data, cb) {
}
}
})
// switch (os) {
// case 'win32':
// checkOpenvpn((error) => {
// if (error) cb(null, error, null);
// else {
}

// }
// })
// break;

// case 'darwin':
// checkMacDependencies((err) => {
// if (err) cb(err, false, null);
// else {
// if (localStorage.getItem('isTM') === 'true') {
// tmConnect(account_addr, vpn_addr, data, (err, res) => {
// cb(err, false, res)
// });
// }
// else {
// testConnect(account_addr, vpn_addr, (err, res) => {
// cb(err, false, res)
// });
// }
// }
// })
// case 'linux': {
// checkDependencies(['openvpn'], (e, o, se) => {
// if (o) {
// if (localStorage.getItem('isTM') === 'true') {
// tmConnect(account_addr, vpn_addr, data, (err, res) => {
// cb(err, false, res)
// });
// }
// else {
// testConnect(account_addr, vpn_addr, (err, res) => {
// cb(err, false, res)
// });
// }
// } else {
// console.log("dependecy error")
// }
// });
// break;
// }
// default: {
// break;
// }
// }
}

export async function checkVPNDependencies(os, cb) {
switch (os) {
Expand Down Expand Up @@ -164,6 +119,7 @@ export async function testConnect(account_addr, vpn_addr, cb) {

}


export async function tmConnect(account_addr, vpn_data, session_data, cb) {
getOVPNTM(account_addr, vpn_data, session_data, (err) => {
if (err) cb(err, null);
Expand All @@ -178,7 +134,6 @@ export async function tmConnect(account_addr, vpn_data, session_data, cb) {
}
})
}

export async function connectwithOVPN(resp, cb) {
let command;
let initialIP = '';
Expand Down
133 changes: 133 additions & 0 deletions wallet 2.0/src/Actions/connectWG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { checkDependencies, getUserHome, getWireguardTM } from '../Utils/utils';
const SENT_DIR = getUserHome() + '/.sentinel';
const WIREGUARD_CONFIG_FILE = SENT_DIR + '/wg0.conf';
const fs = window.require('fs');
const { exec } = window.require('child_process');


export async function connectWireguard(account_addr, vpn_addr, os, data, cb) {
// console.log("in connectWireguard");
checkWireguardDependencies(os, (otherErr, winErr) => {
if (otherErr) cb(otherErr, false, null);
else if (winErr) cb(null, winErr, null);
else {
if (localStorage.getItem('isTM') === 'true') {
tmWireguardConnect(account_addr, vpn_addr, data, (err, res) => {
cb(err, false, res)
});
}
}
})

}

export async function checkWireguardDependencies(os, cb) {
switch (os) {
case 'linux': {
checkDependencies(['wireguard'], (e, o, se) => {
if (o) cb(null, null);
else cb({ message: "Wireguard Not Installed." }, null);
})
break;
}
default: {
cb({ message: "Can't detect current os platform." }, null)
break;
}
}
}

export async function tmWireguardConnect(account_addr, vpn_data, session_data, cb) {
// console.log("in TMWGConnect")
getWireguardTM(account_addr, vpn_data, session_data, (err) => {

if (err) {
// console.log("getting err in tmwg connect", err)
cb(err, null);
}
else {
// console.log("no err in conecting tmwg")
let resp = {
success: true,
message: 'Connected To Wireguard'
}
connectwithWireguard(resp, (error, response) => {
cb(error, response);
});
}
})
}

export async function connectwithWireguard(resp, cb) {
// console.log("trying to connect WG in WG")
let pk = '', pubg = '';
exec('cat privateKeyFile', function (err, stdout, stderr) {
if (err) {
// console.log("private key err")
}
if (stdout) {
pk = stdout
// console.log("client private fetched ", pk)
fs.readFile(WIREGUARD_CONFIG_FILE, 'utf8', function (err, data) {
if (err) {
console.log("in if")
err.toString().includes('ENOENT') ?
fs.writeFile(WIREGUARD_CONFIG_FILE, (

`[Interface] \n Address = ${localStorage.getItem('WG_IP')} \n PrivateKey = ${pk} \n [Peer] \n Publickey = ${localStorage.getItem('WG_PUBKEY')}\n Endpoint = ${localStorage.getItem('WG_ENDPOINT')} \n AllowedIPs = ${localStorage.getItem('WG_ALLOWEDIPS')} \n PersistentKeepalive = ${localStorage.getItem('WG_PERSISTENT')}`

// `[Interface] \n Address = 10.0.0.3/32 \n PrivateKey = ${pk} \n [Peer] \n Publickey = l59DUgGPWA05eUEGoPZtX14ZKTdsNom/G5QfSri12Cc= \n Endpoint = 35.200.183.162:5253 \n AllowedIPs = 0.0.0.0/0 \n PersistentKeepalive = 21`
), function (e) {
if (e) throw e;
else {
// console.log("copying...");
exec(`cp "${WIREGUARD_CONFIG_FILE}" /etc/wireguard && wg-quick up wg0`, function (err, stdout, stderr) {
// console.log("step3")
// if (err) { console.log("normal err") }
// if (stdout) { console.log("wg outpt", stdout) }
// if (stderr) { console.log("stderr", stderr) }
})
}

})
: null
cb(err, null)
}
else {
// console.log("in else")
fs.writeFile(WIREGUARD_CONFIG_FILE, (
`[Interface] \n Address = ${localStorage.getItem('WG_IP')} \n PrivateKey = ${pk} \n [Peer] \n Publickey = ${localStorage.getItem('WG_PUBKEY')}\n Endpoint = ${localStorage.getItem('WG_ENDPOINT')} \n AllowedIPs = ${localStorage.getItem('WG_ALLOWEDIPS')} \n PersistentKeepalive = ${localStorage.getItem('WG_PERSISTENT')}`
),
function (e) {
if (e) throw e;

else {
// console.log("copying...");
exec(`cp "${WIREGUARD_CONFIG_FILE}" /etc/wireguard && wg-quick up wg0`, function (err, stdout, stderr) {
// console.log("step3")
// if (err) { console.log("normal err") }
// if (stdout) { console.log("wg outpt", stdout) }
// if (stderr) { console.log("stderr", stderr) }
})
}

})

cb(null, "local WG Node is up")
}
})

}
if (stderr) {
// console.log("stderr1", stderr)
}
})
// exec(` cat privateKeyFile`, function (a, b, c) {
// if (b) { console.log("logging..", b); }

// })

}



24 changes: 19 additions & 5 deletions wallet 2.0/src/Actions/tendermint.action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as types from './../Constants/action.names';
import { TM_URL, TM_FREE_TOKEN_URL, TMain_URL } from '../Constants/constants';
import { getTMConfig } from './../Utils/UserConfig';
import { getTMConfig, getWireguardConfig, getWireguardKeys} from './../Utils/UserConfig';
import axios from 'axios';

// Fetch TxHash from MN API
Expand Down Expand Up @@ -80,6 +80,16 @@ export function getTendermintAccount(cb) {
cb(null)
})
}
export function generateWireguardKeys(cb) {
console.log("getting wireguard keys ");
getWireguardKeys( (err, data) => {

if (data )
return('Hello Im generated keys')
else
cb(null)
})
}

export function setTMAccount(data) {
return {
Expand Down Expand Up @@ -182,14 +192,18 @@ export async function getTxInfo(hash, time) {
return ({
hash: response.data.hash,
amount: response.data.tx.value.msg[0].type === 'sentinel/getvpnpayment' ?
(response.data.result.tags[3] ? parseFloat(new Buffer(response.data.result.tags[3].value, 'base64').toString()) * (10 ** 8) : 100 * (10 ** 8))
(response.data.result.tags[3] ? parseFloat(new Buffer(response.data.result.tags[3].value, 'base64').toString()) : 100 * (10 ** 8))
- parseInt(response.data.tx.value.msg[0].value.Coins[0].amount) :
response.data.tx.value.msg[0].value.Coins[0].amount,
(response.data.tx.value.msg[0].type === 'sentinel/clientrefund' ?
(response.data.result.tags[1] ? parseFloat(new Buffer(response.data.result.tags[1].value, 'base64').toString()) : 0)
: response.data.tx.value.msg[0].value.Coins[0].amount),
from: response.data.tx.value.msg[0].type === 'sentinel/getvpnpayment' ?
`Released`
: response.data.tx.value.msg[0].value.From,
: (response.data.tx.value.msg[0].type === 'sentinel/clientrefund' ?
`Refunded` : response.data.tx.value.msg[0].value.From),
to: response.data.tx.value.msg[0].value.To ? response.data.tx.value.msg[0].value.To : 'ClaimedBy',
sessionId: response.data.tx.value.msg[0].type === 'sentinel/getvpnpayment' ?
sessionId: response.data.tx.value.msg[0].type === 'sentinel/getvpnpayment' ||
response.data.tx.value.msg[0].type === 'sentinel/clientrefund' ?
new Buffer(response.data.tx.value.msg[0].value.Sessionid, 'base64').toString() :
(response.data.tx.value.msg[0].type === 'sentinel/payvpnservice' ?
new Buffer(response.data.result.tags[1].value, 'base64').toString() : null),
Expand Down
4 changes: 3 additions & 1 deletion wallet 2.0/src/Actions/tmvpn.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getSessionInfo(hash) {
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
}
}, timeout: 12000
})
return {
type: types.GET_SESSION_INFO,
Expand All @@ -46,6 +46,8 @@ export async function getSessionInfo(hash) {
}
}



export async function getSignHash(amount, counter, isfinal) {
// let sessionBuffer = new Buffer(localStorage.getItem('SESSION_NAME'), 'base64');
// let session_name = sessionBuffer.toString();
Expand Down
Loading

0 comments on commit 7de7207

Please sign in to comment.