2021-02-26 10:16:34 +01:00
|
|
|
// Package signal contains the Signal network experiment.
|
|
|
|
//
|
|
|
|
// See https://github.com/ooni/spec/blob/master/nettests/ts-029-signal.md.
|
|
|
|
package signal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-06-25 12:39:45 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-02-26 10:16:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
testName = "signal"
|
2022-10-26 12:59:31 +02:00
|
|
|
testVersion = "0.2.1"
|
2021-02-26 10:16:34 +01:00
|
|
|
|
|
|
|
signalCA = `-----BEGIN CERTIFICATE-----
|
|
|
|
MIID7zCCAtegAwIBAgIJAIm6LatK5PNiMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD
|
|
|
|
VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5j
|
|
|
|
aXNjbzEdMBsGA1UECgwUT3BlbiBXaGlzcGVyIFN5c3RlbXMxHTAbBgNVBAsMFE9w
|
|
|
|
ZW4gV2hpc3BlciBTeXN0ZW1zMRMwEQYDVQQDDApUZXh0U2VjdXJlMB4XDTEzMDMy
|
|
|
|
NTIyMTgzNVoXDTIzMDMyMzIyMTgzNVowgY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQI
|
|
|
|
DApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMR0wGwYDVQQKDBRP
|
|
|
|
cGVuIFdoaXNwZXIgU3lzdGVtczEdMBsGA1UECwwUT3BlbiBXaGlzcGVyIFN5c3Rl
|
|
|
|
bXMxEzARBgNVBAMMClRleHRTZWN1cmUwggEiMA0GCS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4k2LMarkxf2TQX
|
|
|
|
aelPHRa5xNPVfkrN8xw4fv/8TLE9GSjKlrNJm1EoTZL5CYWQU+qe4CuKfAJU6h8l
|
|
|
|
xIkcik61aCeNLQoaI1L3V8tPXmmqMWpsnZmFg6YLGeMTLs4skdFqgLOnx9EF2jgO
|
|
|
|
7EAJ9HcrgSPirQeuDJKhamaLtQiqIQR8L3H4YG1FDiuOeto6f1LRCIqjH1Mye1BM
|
|
|
|
33Qg/VilLQIWp8+C4GJZ0+LO1cfatNh8tkDbrwMzUeA1nLEZHMlgXE05z00euNlQ
|
|
|
|
0+evTmJzWRKJHugPnA3vvdzy4lbYvYWaXs8pACrVpESui8I+v6jdH814lOxpDwNH
|
|
|
|
bPrxfOxhIxfFiVttCl3AQZBLJM6M0ty6/Q7bYsdNT23jKMl0AmDhj9qn/7dzYcVi
|
|
|
|
vI0XKaaJl4ov3IDbuMe0oZWhoLwzPuWxxkWDjTb8ngDnWZT1o5dAR9fltr38m42N
|
|
|
|
uA/SkxghiAMmvkC8nhEJ7yT2hme+rozPZSp1SSEDViDkA4KnnQpMcNiotCQpNOe7
|
|
|
|
YfA9uSnjHjZloRTPUgtkKQ3u8ZZprFQlS2jDE18BRGdh24V5OsCbMvFPtrEsjG4H
|
|
|
|
5xvkiIV0FpbMk4Gj8I4Hbw==
|
2021-02-26 10:16:34 +01:00
|
|
|
-----END CERTIFICATE-----`
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains the signal experiment config.
|
|
|
|
type Config struct {
|
|
|
|
// SignalCA is used to pass in a custom CA in testing
|
|
|
|
SignalCA string
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestKeys contains signal test keys.
|
|
|
|
type TestKeys struct {
|
|
|
|
urlgetter.TestKeys
|
|
|
|
SignalBackendStatus string `json:"signal_backend_status"`
|
|
|
|
SignalBackendFailure *string `json:"signal_backend_failure"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTestKeys creates new signal TestKeys.
|
|
|
|
func NewTestKeys() *TestKeys {
|
|
|
|
return &TestKeys{
|
|
|
|
SignalBackendStatus: "ok",
|
|
|
|
SignalBackendFailure: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update updates the TestKeys using the given MultiOutput result.
|
|
|
|
func (tk *TestKeys) Update(v urlgetter.MultiOutput) {
|
|
|
|
// update the easy to update entries first
|
|
|
|
tk.NetworkEvents = append(tk.NetworkEvents, v.TestKeys.NetworkEvents...)
|
|
|
|
tk.Queries = append(tk.Queries, v.TestKeys.Queries...)
|
|
|
|
tk.Requests = append(tk.Requests, v.TestKeys.Requests...)
|
|
|
|
tk.TCPConnect = append(tk.TCPConnect, v.TestKeys.TCPConnect...)
|
|
|
|
tk.TLSHandshakes = append(tk.TLSHandshakes, v.TestKeys.TLSHandshakes...)
|
|
|
|
// Ignore the result of the uptime DNS lookup
|
|
|
|
if v.Input.Target == "dnslookup://uptime.signal.org" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if v.TestKeys.Failure != nil {
|
|
|
|
tk.SignalBackendStatus = "blocked"
|
|
|
|
tk.SignalBackendFailure = v.TestKeys.Failure
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurer performs the measurement
|
|
|
|
type Measurer struct {
|
|
|
|
// Config contains the experiment settings. If empty we
|
|
|
|
// will be using default settings.
|
|
|
|
Config Config
|
|
|
|
|
|
|
|
// Getter is an optional getter to be used for testing.
|
|
|
|
Getter urlgetter.MultiGetter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExperimentName implements ExperimentMeasurer.ExperimentName
|
|
|
|
func (m Measurer) ExperimentName() string {
|
|
|
|
return testName
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExperimentVersion implements ExperimentMeasurer.ExperimentVersion
|
|
|
|
func (m Measurer) ExperimentVersion() string {
|
|
|
|
return testVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements ExperimentMeasurer.Run
|
|
|
|
func (m Measurer) Run(ctx context.Context, sess model.ExperimentSession,
|
|
|
|
measurement *model.Measurement, callbacks model.ExperimentCallbacks) error {
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
urlgetter.RegisterExtensions(measurement)
|
|
|
|
|
2021-06-25 12:39:45 +02:00
|
|
|
certPool := netxlite.NewDefaultCertPool()
|
2022-10-26 12:59:31 +02:00
|
|
|
signalCAByteSlice := [][]byte{
|
|
|
|
[]byte(signalCA),
|
|
|
|
[]byte(signalCANew),
|
|
|
|
}
|
2021-02-26 10:16:34 +01:00
|
|
|
if m.Config.SignalCA != "" {
|
2022-10-26 12:59:31 +02:00
|
|
|
signalCAByteSlice = [][]byte{[]byte(m.Config.SignalCA)}
|
2021-02-26 10:16:34 +01:00
|
|
|
}
|
2022-10-26 12:59:31 +02:00
|
|
|
for _, caBytes := range signalCAByteSlice {
|
|
|
|
if !certPool.AppendCertsFromPEM(caBytes) {
|
|
|
|
return errors.New("AppendCertsFromPEM failed")
|
|
|
|
}
|
2021-02-26 10:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inputs := []urlgetter.MultiInput{
|
|
|
|
// Here we need to provide the method explicitly. See
|
|
|
|
// https://github.com/ooni/probe-engine/issues/827.
|
|
|
|
{Target: "https://textsecure-service.whispersystems.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "https://storage.signal.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "https://api.directory.signal.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "https://cdn.signal.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "https://cdn2.signal.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "https://sfu.voip.signal.org/", Config: urlgetter.Config{
|
|
|
|
Method: "GET",
|
|
|
|
FailOnHTTPError: false,
|
|
|
|
CertPool: certPool,
|
|
|
|
}},
|
|
|
|
{Target: "dnslookup://uptime.signal.org"},
|
|
|
|
}
|
|
|
|
multi := urlgetter.Multi{Begin: time.Now(), Getter: m.Getter, Session: sess}
|
|
|
|
testkeys := NewTestKeys()
|
|
|
|
testkeys.Agent = "redirect"
|
|
|
|
measurement.TestKeys = testkeys
|
|
|
|
for entry := range multi.Collect(ctx, inputs, "signal", callbacks) {
|
|
|
|
testkeys.Update(entry)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewExperimentMeasurer creates a new ExperimentMeasurer.
|
|
|
|
func NewExperimentMeasurer(config Config) model.ExperimentMeasurer {
|
|
|
|
return Measurer{Config: config}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SummaryKeys contains summary keys for this experiment.
|
|
|
|
//
|
2022-05-09 09:33:18 +02:00
|
|
|
// Note that this structure is part of the ABI contract with ooniprobe
|
2021-02-26 10:16:34 +01:00
|
|
|
// therefore we should be careful when changing it.
|
|
|
|
type SummaryKeys struct {
|
|
|
|
SignalBackendStatus string `json:"signal_backend_status"`
|
|
|
|
SignalBackendFailure *string `json:"signal_backend_failure"`
|
|
|
|
IsAnomaly bool `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSummaryKeys implements model.ExperimentMeasurer.GetSummaryKeys.
|
|
|
|
func (m Measurer) GetSummaryKeys(measurement *model.Measurement) (interface{}, error) {
|
|
|
|
sk := SummaryKeys{IsAnomaly: false}
|
|
|
|
tk, ok := measurement.TestKeys.(*TestKeys)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("invalid test keys type")
|
|
|
|
}
|
|
|
|
sk.SignalBackendStatus = tk.SignalBackendStatus
|
|
|
|
sk.SignalBackendFailure = tk.SignalBackendFailure
|
2021-11-16 15:57:16 +01:00
|
|
|
sk.IsAnomaly = tk.SignalBackendStatus == "blocked"
|
2021-02-26 10:16:34 +01:00
|
|
|
return sk, nil
|
|
|
|
}
|