Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardcode openvpn endpoints under ooni infra #1638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/experiment/openvpn/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func (e *endpoint) AsInputURI() string {
return url.String()
}

// APIEnabledProviders is the list of providers that the stable API Endpoint knows about.
// This array will be a subset of the keys in defaultOptionsByProvider, but it might make sense
// to still register info about more providers that the API officially knows about.
// APIEnabledProviders is the list of providers that the stable API Endpoint and/or this
// experiment knows about.
var APIEnabledProviders = []string{
"riseupvpn",
"oonivpn",
}

// isValidProvider returns true if the provider is found as key in the array of [APIEnabledProviders].
Expand All @@ -178,9 +178,10 @@ func newOpenVPNConfig(
vpnconfig.WithOpenVPNOptions(
&vpnconfig.OpenVPNOptions{
// endpoint-specific options.
Remote: endpoint.IPAddr,
Port: endpoint.Port,
Proto: vpnconfig.Proto(endpoint.Transport),
Remote: endpoint.IPAddr,
Port: endpoint.Port,
Proto: vpnconfig.Proto(endpoint.Transport),
Compress: vpnconfig.Compression(config.Compress),

// options and credentials come from the experiment
// richer input targets.
Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/openvpn/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

const (
testName = "openvpn"
testVersion = "0.1.4"
testVersion = "0.1.5"
openVPNProtocol = "openvpn"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/experiment/openvpn/openvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
if m.ExperimentName() != "openvpn" {
t.Fatal("invalid ExperimentName")
}
if m.ExperimentVersion() != "0.1.4" {
if m.ExperimentVersion() != "0.1.5" {
t.Fatal("invalid ExperimentVersion")
}
}
Expand Down
36 changes: 32 additions & 4 deletions internal/experiment/openvpn/richerinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ func (tl *targetLoader) Load(ctx context.Context) ([]model.ExperimentTarget, err
// If inputs and files are all empty and there are no options, let's use the backend
if len(tl.loader.StaticInputs) <= 0 && len(tl.loader.SourceFiles) <= 0 &&
reflectx.StructOrStructPtrIsZero(tl.options) {
return tl.loadFromBackend(ctx)
targets, err := tl.loadFromBackend(ctx)
if err == nil {
return targets, nil
}
}

tl.loader.Logger.Warnf("Error fetching OpenVPN targets from backend")

// Otherwise, attempt to load the static inputs from CLI and files
inputs, err := targetloading.LoadStatic(tl.loader)

// Handle the case where we couldn't load from CLI or files
// Handle the case where we couldn't load from CLI or files:
if err != nil {
return nil, err
}
Expand All @@ -106,11 +111,34 @@ func (tl *targetLoader) Load(ctx context.Context) ([]model.ExperimentTarget, err
URL: input,
})
}
if len(targets) > 0 {
return targets, nil
}

// Return the hardcoded endpoints.
return tl.loadFromDefaultEndpoints()
}

func (tl *targetLoader) loadFromDefaultEndpoints() ([]model.ExperimentTarget, error) {
tl.loader.Logger.Warnf("Using default OpenVPN endpoints")
targets := []model.ExperimentTarget{}
if udp, err := defaultOONIOpenVPNTargetUDP(); err == nil {
targets = append(targets,
&Target{
Config: pickFromDefaultOONIOpenVPNConfig(),
URL: udp,
})
}
if tcp, err := defaultOONIOpenVPNTargetTCP(); err == nil {
targets = append(targets,
&Target{
Config: pickFromDefaultOONIOpenVPNConfig(),
URL: tcp,
})
}
return targets, nil
}

// TODO(https://github.com/ooni/probe/issues/2755): make the code that fetches experiment private
// and let the common code export just the bare minimum to make this possible.
func (tl *targetLoader) loadFromBackend(ctx context.Context) ([]model.ExperimentTarget, error) {
if tl.options.Provider == "" {
tl.options.Provider = defaultProvider
Expand Down
16 changes: 0 additions & 16 deletions internal/experiment/openvpn/richerinput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,6 @@ func TestTargetLoaderLoad(t *testing.T) {
},
},
},
{
name: "with just options",
options: &Config{
Provider: "riseupvpn",
},
loader: &targetloading.Loader{
ExperimentName: "openvpn",
InputPolicy: model.InputOrQueryBackend,
Logger: model.DiscardLogger,
Session: &mocks.Session{},
StaticInputs: []string{},
SourceFiles: []string{},
},
expectErr: nil,
expectTargets: nil,
},
}

for _, tc := range cases {
Expand Down
78 changes: 78 additions & 0 deletions internal/experiment/openvpn/targets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package openvpn

import (
"fmt"
"math/rand"
"net"
)

const defaultOpenVPNEndpoint = "openvpn-server1.ooni.io"

// this is a safety toggle: it's on purpose that the experiment will receive no
// input if the resolution fails. This also implies that we have no way of knowing if this
// target has been blocked at the level of DNS.
// TODO(ain,mehul): we might want to try resolving with other techniques (DoT etc),
// and perhaps also transform DNS failure into a specific failure of the experiment, not
// a skip.
// TODO(ain): update the openvpn spec to reflect the CURRENT state of delivering the targets.
func resolveTarget(domain string) (string, error) {
ips, err := net.LookupIP(domain)
if err != nil {
return "", err
}
if len(ips) > 0 {
return ips[0].String(), nil
}
return "", fmt.Errorf("cannot resolve %v", defaultOpenVPNEndpoint)
}

func defaultOONITargetURL(ip string) string {
return "openvpn://oonivpn.corp/?address=" + ip + ":1194"
}

func defaultOONIOpenVPNTargetUDP() (string, error) {
ip, err := resolveTarget(defaultOpenVPNEndpoint)
if err != nil {
return "", err
}
return defaultOONITargetURL(ip) + "&transport=udp", nil
}

func defaultOONIOpenVPNTargetTCP() (string, error) {
ip, err := resolveTarget(defaultOpenVPNEndpoint)
if err != nil {
return "", err
}
return defaultOONITargetURL(ip) + "&transport=tcp", nil
}

func pickFromDefaultOONIOpenVPNConfig() *Config {
idx := rand.Intn(len(defaultOONIOpenVPNConfig))
return defaultOONIOpenVPNConfig[idx]
}

var defaultCA = "-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dXbrDj94bwmkQa8s\nl8Mp/PFaFeLNXXuGGVEbIlFuw9RY32vbJ1CrS9rrWlVq9Q17NrAmSYSBi9T19mDh\nMFslRMPBN4Jfd/45V26iW2XMpWCONY5aqAfx+2Oz2g==\n-----END CERTIFICATE-----"
var defaultOONIOpenVPNConfig = []*Config{
{
Cipher: "AES-256-GCM",
Auth: "SHA512",
Compress: "stub",
Provider: "oonivpn",
Obfuscation: "none",
// yes, github, I know this looks like a leaked certificate. That is exactly what it is.
SafeCA: defaultCA,
SafeCert: "-----BEGIN CERTIFICATE-----\nMIIDXjCCAkagAwIBAgIRALM/5njrVcneGXfmqnIX278wDQYJKoZIhvcNAQELBQAw\nFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMjQwNzMxMTc1MjAxWhcNMjYxMTAz\nMTc1MjAxWjAaMRgwFgYDVQQDDA9jbGllbnQtY2VydC0wMDIwggEiMA0GCSqGSIb3\nDQEBAQUAA4IBDwAwggEKAoIBAQDfVfY+RK1Wl4Dw+KPJMOu7UT4g8VoWS0r5B3z8\nqzL/RAL9xEMaeJbeJPCkOCMaPiS5Xyuj2X/idSlejINmC+XhAx0+ANbxD7oilhBt\nLO43u8QRE5N2HBt045dJdFiN/lt2OwQOrYAL4p7hEn91zObT35wzK6jfNFMON9HQ\n3JZzEqcs/5SfnCvyAtAnV+Qfr4TolX2lRhu74Yl88OzjNFiGADniK/jJGJWfPEzn\nhqfzbcpXCVKUD38kFje3wBN+DrWQabuXTlJhOfhHANMgUnqoS91ea/TbfdiQ4kni\n1sE9RG/X+v8/Xm1BmJO2db1t1K/Px4wqE5Ku7XvdyVU4U4YHAgMBAAGjgaIwgZ8w\nCQYDVR0TBAIwADAdBgNVHQ4EFgQUAT/5mtUeUGCeFKrgBb/6i0B+2ycwUQYDVR0j\nBEowSIAUcr4ZIMrPHSCM73B+/k5XAE0+mxmhGqQYMBYxFDASBgNVBAMMC0Vhc3kt\nUlNBIENBghQ4+XCGnaz3qqoYXnOAs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ATE KEY-----",
},
{
Cipher: "AES-256-GCM",
Auth: "SHA512",
Compress: "stub",
Provider: "oonivpn",
Obfuscation: "none",
// yes, github, I know this looks like a leaked certificate. That is exactly what it is.
SafeCA: defaultCA,
SafeCert: "-----BEGIN CERTIFICATE-----\nMIIDXTCCAkWgAwIBAgIQFiJOrUbahl4vlYa6xv7SmzANBgkqhkiG9w0BAQsFADAW\nMRQwEgYDVQQDDAtFYXN5LVJTQSBDQTAeFw0yNDA3MzExNzUyMDBaFw0yNjExMDMx\nNzUyMDBaMBoxGDAWBgNVBAMMD2NsaWVudC1jZXJ0LTAwMTCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBANXyxnIb9tLqe6di6xIJaCDm0Ue4D8Cy0XYQKnbB\n8Ko9xJiglUm4BXAkjkOHLfSB38hOx9exXTW4whMuYOEJoo26JcdbmLJhaxiVAwTQ\nzMROgCbpJi1lu5cQ8F0U4Sq1/+IZKIGfmiWtxa2YP4Kc4qgEESk+AZ6rtxuKUvQU\nY0rLO1J1FuH8CgYnPG/dkwekVn47v7VnLzIM6XgPdezFNqwGYDAINrxutvnh8dI1\n9hoUZ5sTS9+747kXBy8049xfZqd7rUst9aC47Bt2BOXPUaKCeu1S4v6yEwQcQuSm\nHHoKHJsmlI1DQRS9ZRMq4e0ugFxwIMWz2Wwf2uC1VTOFbCUCAwEAAaOBojCBnzAJ\nBgNVHRMEAjAAMB0GA1UdDgQWBBR4NMh/CIuWF1L7MGM81Hg54ChATzBRBgNVHSME\nSjBIgBRyvhkgys8dIIzvcH7+TlcATT6bGaEapBgwFjEUMBIGA1UEAwwLRWFzeS1S\nU0EgQ0GCFDj5cIadrPeqqhhec4CzqdJ6DdrsMBMGA1UdJQQMMAoGCCsGAQUFBwMC\nMAsGA1UdDwQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEARhgY3kmrJ5QP2cz9OcFB\nTjFQaQlnEts7Z4xcl/DNz3WNmqP2HVe1jzcHvZgkkcFNoP3BR/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MgWayB1MQKBgQDxtSFf1vfq+jCjhMMg\nmE2asnS/rnyH4pog1k8TiJZncubKdZU5QuaozDJhsGkSL16EAa7X2pvi17BhDJhe\ns0fprsziWqjp9isTQjMFMdrZhnL5uEVkK/JiSUGQdvlXxUpd0quhlVWkh8ZmZ8ce\nOQArEUJHWWgtvu5gS78izPnEUQKBgQDimW/7CE7zfdczUlj6Sp4v1+Tbdz/Iket3\nIQDj4f3DD6f1v5Hd9k43oPFPP6jbOwSW9dFMuHzsQW4G7WNSJmA+x0fe6qeKRLoV\nDe89WVMcCVlNX0kvwF68ojyFQ+/V+NjF2A6yeOAiM8tQf4YDHuNokzjSP7TVZIAc\nbeRERwZZlQKBgCqCVppKblOvKLq5cK/c2VkppYrInzIu0jiQOFwRG5KaDKjywQnP\nEE4Di6DOq8v89Lx2p09jLSNaF7UZx/pvwWgBzBrLIwXyu2SpsdtqBzlWggYVOG8D\no59RjuxfYD7lfcy+blz+rI9BKc181vIjyDnK0UNHICFbgQUCjV0Le6nhAoGBAM4M\nKehBuNDuZ+YSBjip60ej8EWkHMq77TnpN87/62kY7minJvOHib5JycN/JoMbGmRO\n6F/0DhwirvL7n2nO3YuYWAEarPgs4GxOvHGzrL/8vEh/0aPrL/olKBUiHo8Z9buJ\naGvfQCe5ozHyk6B40N6BqJR+O2gjN98iCgQP9XU1AoGBAJF9+aKNz5eirXnCT60n\nDjZ+o4jJ1c0C/dpuGBU9Sm0Q0qqLsZKIBLSrfMccmgpxhnsQ8a/9yXAkFkL+E0yX\nSOlGzbO1VhnsreBQg7oIe5PMsie+zulHwZ9gqvwH5T3xYGJJc6AzB1V3CS00jPsf\ncAnOQHux3yai6ZZkdXAAWJ8w\n-----END PRIVATE KEY-----",
},
}
81 changes: 81 additions & 0 deletions internal/experiment/openvpn/targets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package openvpn

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func Test_resolveTarget(t *testing.T) {
// TODO: mustHaveExternalNetwork() equivalent.
if testing.Short() {
t.Skip("skip test in short mode")
}

_, err := resolveTarget("google.com")

if err != nil {
if err.Error() == "connection_refused" {
// connection_refused is raised when running this test
// on the restricted network for coverage tests.
// so we bail out
return
}
t.Fatal("should be able to resolve the target")
}

_, err = resolveTarget("nothing.corp")
if err == nil {
t.Fatal("should not be able to resolve the target")
}

_, err = resolveTarget("asfasfasfasfasfafs.ooni.io")
if err == nil {
t.Fatal("should not be able to resolve the target")
}
}

func Test_defaultOONIOpenVPNTargetUDP(t *testing.T) {
url, err := defaultOONIOpenVPNTargetUDP()
if err != nil {
if err.Error() == "connection_refused" {
// connection_refused is raised when running this test
// on the restricted network for coverage tests.
// so we bail out
return
}
t.Fatal("unexpected error")
}
expected := "openvpn://oonivpn.corp/?address=37.218.243.98:1194&transport=udp"
if diff := cmp.Diff(url, expected); diff != "" {
t.Fatal(diff)
}
}

func Test_defaultOONIOpenVPNTargetTCP(t *testing.T) {
url, err := defaultOONIOpenVPNTargetTCP()
if err != nil {
if err.Error() == "connection_refused" {
// connection_refused is raised when running this test
// on the restricted network for coverage tests.
// so we bail out
return
}
t.Fatal("unexpected error")
}
expected := "openvpn://oonivpn.corp/?address=37.218.243.98:1194&transport=tcp"
if diff := cmp.Diff(url, expected); diff != "" {
t.Fatal(diff)
}
}

func Test_pickFromDefaultOONIOpenVPNConfig(t *testing.T) {
pick := pickFromDefaultOONIOpenVPNConfig()

if pick.Cipher != "AES-256-GCM" {
t.Fatal("cipher unexpected")
}
if pick.SafeCA != defaultCA {
t.Fatal("ca unexpected")
}
}
Loading