Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bitmask-vpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
bitmask-vpn
Commits
b4fe45c4
Verified
Commit
b4fe45c4
authored
1 year ago
by
Pea Nut
Browse files
Options
Downloads
Patches
Plain Diff
Rename Bitmask3 back to Bitmask
parent
b22edc65
Branches
Branches containing commit
No related tags found
1 merge request
!198
v5 implementation with a single Bitmask struct
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/bitmask/legacy/main.go
+17
-19
17 additions, 19 deletions
pkg/bitmask/legacy/main.go
pkg/bitmask/legacy/openvpn.go
+23
-23
23 additions, 23 deletions
pkg/bitmask/legacy/openvpn.go
pkg/bitmask/legacy/status.go
+9
-9
9 additions, 9 deletions
pkg/bitmask/legacy/status.go
with
49 additions
and
51 deletions
pkg/bitmask/legacy/main.go
+
17
−
19
View file @
b4fe45c4
...
...
@@ -33,9 +33,7 @@ import (
obfsvpn
"0xacab.org/leap/obfsvpn/client"
)
// Bitmask3 holds the bitmask client data
// Bitmask3 implements Bitmask interface (api version v3)
type
Bitmask3
struct
{
type
Bitmask
struct
{
tempdir
string
onGateway
bonafide
.
Gateway
ptGateway
bonafide
.
Gateway
...
...
@@ -57,7 +55,7 @@ type Bitmask3 struct {
}
// Init the connection to bitmask
func
Init
()
(
*
Bitmask
3
,
error
)
{
func
Init
()
(
*
Bitmask
,
error
)
{
statusCh
:=
make
(
chan
string
,
10
)
tempdir
,
err
:=
ioutil
.
TempDir
(
""
,
"leap-"
)
if
err
!=
nil
{
...
...
@@ -71,7 +69,7 @@ func Init() (*Bitmask3, error) {
return
nil
,
err
}
b
:=
Bitmask
3
{
b
:=
Bitmask
{
tempdir
,
bonafide
.
Gateway
{},
bonafide
.
Gateway
{},
statusCh
,
nil
,
bf
,
launch
,
...
...
@@ -105,11 +103,11 @@ func Init() (*Bitmask3, error) {
return
&
b
,
err
}
func
(
b
*
Bitmask
3
)
SetProvider
(
p
string
)
{
func
(
b
*
Bitmask
)
SetProvider
(
p
string
)
{
b
.
provider
=
p
}
func
(
b
*
Bitmask
3
)
checkForUpgrades
()
{
func
(
b
*
Bitmask
)
checkForUpgrades
()
{
// SNAPS have their own way of upgrading. We probably should also try to detect
// if we've been installed via another package manager.
...
...
@@ -121,21 +119,21 @@ func (b *Bitmask3) checkForUpgrades() {
b
.
canUpgrade
=
version
.
CanUpgrade
()
}
func
(
b
*
Bitmask
3
)
checkForMOTD
()
{
func
(
b
*
Bitmask
)
checkForMOTD
()
{
b
.
motd
=
motd
.
FetchLatest
()
}
// GetStatusCh returns a channel that will recieve VPN status changes
func
(
b
*
Bitmask
3
)
GetStatusCh
()
<-
chan
string
{
func
(
b
*
Bitmask
)
GetStatusCh
()
<-
chan
string
{
return
b
.
statusCh
}
func
(
b
*
Bitmask
3
)
GetSnowflakeCh
()
<-
chan
*
snowflake
.
StatusEvent
{
func
(
b
*
Bitmask
)
GetSnowflakeCh
()
<-
chan
*
snowflake
.
StatusEvent
{
return
b
.
bonafide
.
SnowflakeCh
}
// Close the connection to bitmask, and does cleanup of temporal files
func
(
b
*
Bitmask
3
)
Close
()
{
func
(
b
*
Bitmask
)
Close
()
{
log
.
Info
()
.
Msg
(
"Close: cleanup and vpn shutdown..."
)
err
:=
b
.
StopVPN
()
if
err
!=
nil
{
...
...
@@ -160,32 +158,32 @@ func (b *Bitmask3) Close() {
}
// Version gets the bitmask version string
func
(
b
*
Bitmask
3
)
Version
()
(
string
,
error
)
{
func
(
b
*
Bitmask
)
Version
()
(
string
,
error
)
{
return
""
,
nil
}
func
(
b
*
Bitmask
3
)
NeedsCredentials
()
bool
{
func
(
b
*
Bitmask
)
NeedsCredentials
()
bool
{
return
b
.
bonafide
.
NeedsCredentials
()
}
func
(
b
*
Bitmask
3
)
DoLogin
(
username
,
password
string
)
(
bool
,
error
)
{
func
(
b
*
Bitmask
)
DoLogin
(
username
,
password
string
)
(
bool
,
error
)
{
return
b
.
bonafide
.
DoLogin
(
username
,
password
)
}
func
(
b
*
Bitmask
3
)
UseUDP
(
udp
bool
)
{
func
(
b
*
Bitmask
)
UseUDP
(
udp
bool
)
{
b
.
udp
=
udp
}
func
(
b
*
Bitmask
3
)
UseSnowflake
(
s
bool
)
error
{
func
(
b
*
Bitmask
)
UseSnowflake
(
s
bool
)
error
{
b
.
snowflake
=
s
return
nil
}
func
(
b
*
Bitmask
3
)
OffersUDP
()
bool
{
func
(
b
*
Bitmask
)
OffersUDP
()
bool
{
return
b
.
bonafide
.
IsUDPAvailable
()
}
func
(
b
*
Bitmask
3
)
GetMotd
()
string
{
func
(
b
*
Bitmask
)
GetMotd
()
string
{
bytes
,
err
:=
json
.
Marshal
(
b
.
motd
)
if
err
!=
nil
{
log
.
Warn
()
.
...
...
@@ -195,6 +193,6 @@ func (b *Bitmask3) GetMotd() string {
return
string
(
bytes
)
}
func
(
b
*
Bitmask
3
)
CanUpgrade
()
bool
{
func
(
b
*
Bitmask
)
CanUpgrade
()
bool
{
return
b
.
canUpgrade
}
This diff is collapsed.
Click to expand it.
pkg/bitmask/legacy/openvpn.go
+
23
−
23
View file @
b4fe45c4
...
...
@@ -41,7 +41,7 @@ const (
)
// StartVPN for provider
func
(
b
*
Bitmask
3
)
StartVPN
(
provider
string
)
error
{
func
(
b
*
Bitmask
)
StartVPN
(
provider
string
)
error
{
if
!
b
.
CanStartVPN
()
{
log
.
Warn
()
.
Msg
(
"BUG cannot start"
)
return
errors
.
New
(
"BUG: cannot start vpn"
)
...
...
@@ -61,14 +61,14 @@ func (b *Bitmask3) StartVPN(provider string) error {
return
b
.
startOpenVPN
(
ctx
)
}
func
(
b
*
Bitmask
3
)
CanStartVPN
()
bool
{
func
(
b
*
Bitmask
)
CanStartVPN
()
bool
{
/* FIXME this is not enough. We should check, if provider needs
* credentials, if we have a valid token, otherwise remove it and
make sure that we're asking for the credentials input */
return
!
b
.
bonafide
.
NeedsCredentials
()
}
func
(
b
*
Bitmask
3
)
startTransportForPrivateBridge
(
ctx
context
.
Context
,
gw
bonafide
.
Gateway
)
(
proxy
string
,
err
error
)
{
func
(
b
*
Bitmask
)
startTransportForPrivateBridge
(
ctx
context
.
Context
,
gw
bonafide
.
Gateway
)
(
proxy
string
,
err
error
)
{
proxyAddr
:=
"127.0.0.1:8080"
kcpMode
:=
false
if
os
.
Getenv
(
"LEAP_KCP"
)
==
"1"
{
...
...
@@ -92,7 +92,7 @@ func (b *Bitmask3) startTransportForPrivateBridge(ctx context.Context, gw bonafi
return
proxyAddr
,
nil
}
func
(
b
*
Bitmask
3
)
startTransport
(
ctx
context
.
Context
,
host
string
)
(
proxy
string
,
err
error
)
{
func
(
b
*
Bitmask
)
startTransport
(
ctx
context
.
Context
,
host
string
)
(
proxy
string
,
err
error
)
{
// TODO configure socks port if not available
// TODO get port from UI/config file
proxyAddr
:=
"127.0.0.1:8080"
...
...
@@ -173,7 +173,7 @@ func maybeGetPrivateGateway() (bonafide.Gateway, bool) {
}
// generates a password and returns the path for a temporary file where this password is written
func
(
b
*
Bitmask
3
)
generateManagementPassword
()
string
{
func
(
b
*
Bitmask
)
generateManagementPassword
()
string
{
pass
:=
getRandomPass
(
12
)
tmpFile
,
err
:=
ioutil
.
TempFile
(
b
.
tempdir
,
"leap-vpn-"
)
if
err
!=
nil
{
...
...
@@ -186,7 +186,7 @@ func (b *Bitmask3) generateManagementPassword() string {
return
tmpFile
.
Name
()
}
func
(
b
*
Bitmask
3
)
startOpenVPN
(
ctx
context
.
Context
)
error
{
func
(
b
*
Bitmask
)
startOpenVPN
(
ctx
context
.
Context
)
error
{
arg
:=
b
.
openvpnArgs
/*
XXX has this changed??
...
...
@@ -324,7 +324,7 @@ func (b *Bitmask3) startOpenVPN(ctx context.Context) error {
return
b
.
launch
.
OpenvpnStart
(
arg
...
)
}
func
(
b
*
Bitmask
3
)
getCert
()
(
certPath
string
,
err
error
)
{
func
(
b
*
Bitmask
)
getCert
()
(
certPath
string
,
err
error
)
{
log
.
Info
()
.
Msg
(
"Getting certificate..."
)
persistentCertFile
:=
filepath
.
Join
(
config
.
Path
,
strings
.
ToLower
(
config
.
Provider
)
+
".pem"
)
if
_
,
err
:=
os
.
Stat
(
persistentCertFile
);
!
os
.
IsNotExist
(
err
)
&&
isValidCert
(
persistentCertFile
)
{
...
...
@@ -363,7 +363,7 @@ func (b *Bitmask3) getCert() (certPath string, err error) {
}
// Explicit call to GetGateways, to be able to fetch them all before starting the vpn
func
(
b
*
Bitmask
3
)
fetchGateways
()
{
func
(
b
*
Bitmask
)
fetchGateways
()
{
log
.
Info
()
.
Msg
(
"Fetching gateways..."
)
_
,
err
:=
b
.
bonafide
.
GetAllGateways
(
b
.
transport
)
if
err
!=
nil
{
...
...
@@ -374,7 +374,7 @@ func (b *Bitmask3) fetchGateways() {
}
// StopVPN or cancel
func
(
b
*
Bitmask
3
)
StopVPN
()
error
{
func
(
b
*
Bitmask
)
StopVPN
()
error
{
err
:=
b
.
launch
.
FirewallStop
()
if
err
!=
nil
{
return
err
...
...
@@ -388,14 +388,14 @@ func (b *Bitmask3) StopVPN() error {
return
nil
}
func
(
b
*
Bitmask
3
)
tryStopFromManagement
()
{
func
(
b
*
Bitmask
)
tryStopFromManagement
()
{
if
b
.
managementClient
!=
nil
{
b
.
managementClient
.
SendSignal
(
"SIGTERM"
)
}
}
// Reconnect to the VPN
func
(
b
*
Bitmask
3
)
Reconnect
()
error
{
func
(
b
*
Bitmask
)
Reconnect
()
error
{
if
!
b
.
CanStartVPN
()
{
return
errors
.
New
(
"BUG: cannot start vpn"
)
}
...
...
@@ -427,7 +427,7 @@ func (b *Bitmask3) Reconnect() error {
}
// ReloadFirewall restarts the firewall
func
(
b
*
Bitmask
3
)
ReloadFirewall
()
error
{
func
(
b
*
Bitmask
)
ReloadFirewall
()
error
{
err
:=
b
.
launch
.
FirewallStop
()
if
err
!=
nil
{
return
err
...
...
@@ -449,7 +449,7 @@ func (b *Bitmask3) ReloadFirewall() error {
}
// GetStatus returns the VPN status
func
(
b
*
Bitmask
3
)
GetStatus
()
(
string
,
error
)
{
func
(
b
*
Bitmask
)
GetStatus
()
(
string
,
error
)
{
status
:=
Off
if
b
.
isFailed
()
{
status
=
Failed
...
...
@@ -465,37 +465,37 @@ func (b *Bitmask3) GetStatus() (string, error) {
return
status
,
nil
}
func
(
b
*
Bitmask
3
)
InstallHelpers
()
error
{
func
(
b
*
Bitmask
)
InstallHelpers
()
error
{
// TODO use pickle module from here
return
nil
}
// VPNCheck returns if the helpers are installed and up to date and if polkit is running
func
(
b
*
Bitmask
3
)
VPNCheck
()
(
helpers
bool
,
privilege
bool
,
err
error
)
{
func
(
b
*
Bitmask
)
VPNCheck
()
(
helpers
bool
,
privilege
bool
,
err
error
)
{
return
b
.
launch
.
Check
()
}
func
(
b
*
Bitmask
3
)
ListLocationFullness
(
transport
string
)
map
[
string
]
float64
{
func
(
b
*
Bitmask
)
ListLocationFullness
(
transport
string
)
map
[
string
]
float64
{
return
b
.
bonafide
.
ListLocationFullness
(
transport
)
}
func
(
b
*
Bitmask
3
)
ListLocationLabels
(
transport
string
)
map
[
string
][]
string
{
func
(
b
*
Bitmask
)
ListLocationLabels
(
transport
string
)
map
[
string
][]
string
{
return
b
.
bonafide
.
ListLocationLabels
(
transport
)
}
// UseGateway selects a gateway, by label, as the default gateway
func
(
b
*
Bitmask
3
)
UseGateway
(
label
string
)
{
func
(
b
*
Bitmask
)
UseGateway
(
label
string
)
{
b
.
bonafide
.
SetManualGateway
(
label
)
}
// UseAutomaticGateway sets the gateway to be selected automatically
// best gateway will be used
func
(
b
*
Bitmask
3
)
UseAutomaticGateway
()
{
func
(
b
*
Bitmask
)
UseAutomaticGateway
()
{
b
.
bonafide
.
SetAutomaticGateway
()
}
// SetTransport selects an obfuscation transport to use
func
(
b
*
Bitmask
3
)
SetTransport
(
t
string
)
error
{
func
(
b
*
Bitmask
)
SetTransport
(
t
string
)
error
{
if
t
!=
"openvpn"
&&
t
!=
"obfs4"
{
return
fmt
.
Errorf
(
"Transport %s not implemented"
,
t
)
}
...
...
@@ -515,7 +515,7 @@ func (b *Bitmask3) SetTransport(t string) error {
}
// GetTransport gets the obfuscation transport to use. Only obfs4 available for now.
func
(
b
*
Bitmask
3
)
GetTransport
()
string
{
func
(
b
*
Bitmask
)
GetTransport
()
string
{
if
b
.
transport
==
"obfs4"
{
return
"obfs4"
}
else
{
...
...
@@ -523,11 +523,11 @@ func (b *Bitmask3) GetTransport() string {
}
}
func
(
b
*
Bitmask
3
)
getTempCertPemPath
()
string
{
func
(
b
*
Bitmask
)
getTempCertPemPath
()
string
{
return
filepath
.
Join
(
b
.
tempdir
,
"openvpn.pem"
)
}
func
(
b
*
Bitmask
3
)
getTempCaCertPath
()
string
{
func
(
b
*
Bitmask
)
getTempCaCertPath
()
string
{
return
filepath
.
Join
(
b
.
tempdir
,
"cacert.pem"
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/bitmask/legacy/status.go
+
9
−
9
View file @
b4fe45c4
...
...
@@ -46,7 +46,7 @@ var statusNames = map[string]string{
"FAILED"
:
Off
,
}
func
(
b
*
Bitmask
3
)
openvpnManagement
()
{
func
(
b
*
Bitmask
)
openvpnManagement
()
{
// TODO: we should warn the user on ListenAndServe errors
newConnection
:=
func
(
conn
management
.
IncomingConn
)
{
eventCh
:=
make
(
chan
management
.
Event
,
10
)
...
...
@@ -68,7 +68,7 @@ func (b *Bitmask3) openvpnManagement() {
}
}
func
(
b
*
Bitmask
3
)
eventHandler
(
eventCh
<-
chan
management
.
Event
)
{
func
(
b
*
Bitmask
)
eventHandler
(
eventCh
<-
chan
management
.
Event
)
{
for
event
:=
range
eventCh
{
log
.
Debug
()
.
Str
(
"event"
,
event
.
String
())
.
...
...
@@ -105,27 +105,27 @@ func (b *Bitmask3) eventHandler(eventCh <-chan management.Event) {
b
.
statusCh
<-
Off
}
func
(
b
*
Bitmask
3
)
GetCurrentGateway
()
string
{
func
(
b
*
Bitmask
)
GetCurrentGateway
()
string
{
return
b
.
onGateway
.
Host
}
func
(
b
*
Bitmask
3
)
GetCurrentLocation
()
string
{
func
(
b
*
Bitmask
)
GetCurrentLocation
()
string
{
return
b
.
onGateway
.
LocationName
}
func
(
b
*
Bitmask
3
)
GetCurrentCountry
()
string
{
func
(
b
*
Bitmask
)
GetCurrentCountry
()
string
{
return
b
.
onGateway
.
CountryCode
}
func
(
b
*
Bitmask
3
)
GetBestLocation
(
transport
string
)
string
{
func
(
b
*
Bitmask
)
GetBestLocation
(
transport
string
)
string
{
return
b
.
bonafide
.
GetBestLocation
(
transport
)
}
func
(
b
*
Bitmask
3
)
IsManualLocation
()
bool
{
func
(
b
*
Bitmask
)
IsManualLocation
()
bool
{
return
b
.
bonafide
.
IsManualLocation
()
}
func
(
b
*
Bitmask
3
)
getOpenvpnState
()
(
string
,
error
)
{
func
(
b
*
Bitmask
)
getOpenvpnState
()
(
string
,
error
)
{
if
b
.
managementClient
==
nil
{
return
""
,
fmt
.
Errorf
(
"No management connected"
)
}
...
...
@@ -140,6 +140,6 @@ func (b *Bitmask3) getOpenvpnState() (string, error) {
return
status
,
nil
}
func
(
b
*
Bitmask
3
)
isFailed
()
bool
{
func
(
b
*
Bitmask
)
isFailed
()
bool
{
return
b
.
launch
.
Failed
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment