a849213b59
This diff breaks the circular dependency between session and tunnel, by introducing the concept of early session. An early session is a session that is able to fetch the psiphon configuration file _only_ if it's embedded in the binary. This breaks `miniooni --tunnel=psiphon` for users who have access to the OONI backend. They are not the users we are writing this feature for, though, so I think this is reasonable. At the same time, this opens up the possibility of creating a psiphon tunnel when constructing a session, which is the approach I was following in https://github.com/ooni/probe-cli/pull/286. This work is part of https://github.com/ooni/probe/issues/985. Once this diff is in, I can land https://github.com/ooni/probe-cli/pull/286.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// +build ooni_psiphon_config
|
|
|
|
package engine
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
_ "embed"
|
|
"io/ioutil"
|
|
|
|
"filippo.io/age"
|
|
)
|
|
|
|
//go:embed psiphon-config.json.age
|
|
var psiphonConfigJSONAge []byte
|
|
|
|
//go:embed psiphon-config.key
|
|
var psiphonConfigSecretKey string
|
|
|
|
// sessionTunnelEarlySession is the early session that we pass
|
|
// to tunnel.Start to fetch the Psiphon configuration.
|
|
type sessionTunnelEarlySession struct{}
|
|
|
|
// FetchPsiphonConfig decrypts psiphonConfigJSONAge using
|
|
// filippo.io/age _and_ psiphonConfigSecretKey.
|
|
func (s *sessionTunnelEarlySession) FetchPsiphonConfig(ctx context.Context) ([]byte, error) {
|
|
key := "AGE-SECRET-KEY-1" + psiphonConfigSecretKey
|
|
identity, err := age.ParseX25519Identity(key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
input := bytes.NewReader(psiphonConfigJSONAge)
|
|
output, err := age.Decrypt(input, identity)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ioutil.ReadAll(output)
|
|
}
|
|
|
|
// FetchPsiphonConfig decrypts psiphonConfigJSONAge using
|
|
// filippo.io/age _and_ psiphonConfigSecretKey.
|
|
func (s *Session) FetchPsiphonConfig(ctx context.Context) ([]byte, error) {
|
|
child := &sessionTunnelEarlySession{}
|
|
return child.FetchPsiphonConfig(ctx)
|
|
}
|