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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Merlin
bitmask-vpn
Commits
86d30f2a
Unverified
Commit
86d30f2a
authored
3 years ago
by
Kali Kaneko
Browse files
Options
Downloads
Patches
Plain Diff
[feat] retry if dns lookup fails
parent
083f4095
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/vpn/bonafide/bonafide.go
+40
-1
40 additions, 1 deletion
pkg/vpn/bonafide/bonafide.go
pkg/vpn/bonafide/eip_service.go
+7
-0
7 additions, 0 deletions
pkg/vpn/bonafide/eip_service.go
pkg/vpn/openvpn.go
+20
-2
20 additions, 2 deletions
pkg/vpn/openvpn.go
with
67 additions
and
3 deletions
pkg/vpn/bonafide/bonafide.go
+
40
−
1
View file @
86d30f2a
// Copyright (C) 2018-202
0
LEAP
// Copyright (C) 2018-202
1
LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
...
...
@@ -75,6 +75,17 @@ type geoLocation struct {
SortedGateways
[]
geoGateway
`json:"sortedGateways"`
}
func
getAPIAddr
(
provider
string
)
string
{
switch
provider
{
case
"riseup.net"
:
return
"198.252.153.107"
case
"calyx.net"
:
return
"162.247.73.194"
default
:
return
""
}
}
// New Bonafide: Initializes a Bonafide object. By default, no Credentials are passed.
func
New
()
*
Bonafide
{
certs
:=
x509
.
NewCertPool
()
...
...
@@ -179,6 +190,17 @@ func (b *Bonafide) GetPemCertificate() ([]byte, error) {
return
ioutil
.
ReadAll
(
resp
.
Body
)
}
func
(
b
*
Bonafide
)
GetPemCertificateNoDNS
()
([]
byte
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
"POST"
,
b
.
getURLNoDNS
(
"certv3"
),
strings
.
NewReader
(
""
))
resp
,
err
:=
b
.
client
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
return
ioutil
.
ReadAll
(
resp
.
Body
)
}
func
(
b
*
Bonafide
)
getURL
(
object
string
)
string
{
switch
object
{
case
"cert"
:
...
...
@@ -192,6 +214,23 @@ func (b *Bonafide) getURL(object string) string {
return
""
}
func
(
b
*
Bonafide
)
getURLNoDNS
(
object
string
)
string
{
p
:=
strings
.
ToLower
(
config
.
Provider
)
base
:=
"https://"
+
getAPIAddr
(
p
)
+
"/"
switch
object
{
case
"cert"
:
return
base
+
certPathv1
case
"certv3"
:
return
base
+
certPathv3
case
"auth"
:
return
base
+
authPathv3
case
"eip"
:
return
base
+
"3/config/eip-service.json"
}
log
.
Println
(
"BUG: unknown url object"
)
return
""
}
func
(
b
*
Bonafide
)
maybeInitializeEIP
()
error
{
if
b
.
eip
==
nil
{
err
:=
b
.
fetchEipJSON
()
...
...
This diff is collapsed.
Click to expand it.
pkg/vpn/bonafide/eip_service.go
+
7
−
0
View file @
86d30f2a
...
...
@@ -83,6 +83,13 @@ func (b *Bonafide) fetchEipJSON() error {
// TODO why exactly 1 retry? Make it configurable, for tests
time
.
Sleep
(
retryFetchJSONSeconds
*
time
.
Second
)
resp
,
err
=
b
.
client
.
Post
(
eip3API
,
""
,
nil
)
if
err
!=
nil
{
// TODO it might be that it's not an error, but an empty file or whatever done
// by DNS poisoning. Should try to parse the file.
uri
:=
b
.
getURLNoDNS
(
"eip"
)
log
.
Println
(
"Fetching "
,
uri
)
resp
,
err
=
b
.
client
.
Post
(
uri
,
""
,
nil
)
}
}
defer
resp
.
Body
.
Close
()
...
...
This diff is collapsed.
Click to expand it.
pkg/vpn/openvpn.go
+
20
−
2
View file @
86d30f2a
// Copyright (C) 2018-202
0
LEAP
// Copyright (C) 2018-202
1
LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
...
...
@@ -177,6 +177,7 @@ func (b *Bitmask) startOpenVPN() error {
}
func
(
b
*
Bitmask
)
getCert
()
(
certPath
string
,
err
error
)
{
failed
:=
false
persistentCertFile
:=
filepath
.
Join
(
config
.
Path
,
strings
.
ToLower
(
config
.
Provider
)
+
".pem"
)
if
_
,
err
:=
os
.
Stat
(
persistentCertFile
);
!
os
.
IsNotExist
(
err
)
&&
isValidCert
(
persistentCertFile
)
{
// reuse cert. for the moment we're not writing one there, this is
...
...
@@ -191,9 +192,26 @@ func (b *Bitmask) getCert() (certPath string, err error) {
log
.
Println
(
"Fetching certificate to"
,
certPath
)
cert
,
err
:=
b
.
bonafide
.
GetPemCertificate
()
if
err
!=
nil
{
return
""
,
err
log
.
Println
(
err
)
failed
=
true
}
err
=
ioutil
.
WriteFile
(
certPath
,
cert
,
0600
)
if
err
!=
nil
{
failed
=
true
}
}
}
if
failed
||
!
isValidCert
(
certPath
)
{
cert
,
err
:=
b
.
bonafide
.
GetPemCertificateNoDNS
()
if
cert
!=
nil
{
log
.
Println
(
"Successfully did certificate bypass"
)
err
=
nil
}
else
{
err
=
errors
.
New
(
"Cannot get vpn certificate"
)
}
err
=
ioutil
.
WriteFile
(
certPath
,
cert
,
0600
)
if
err
!=
nil
{
failed
=
true
}
}
return
certPath
,
err
...
...
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