forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_psiphon.go
52 lines (43 loc) · 1.42 KB
/
session_psiphon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build ooni_psiphon_config
package engine
import (
"bytes"
"context"
_ "embed"
"filippo.io/age"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
//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 netxlite.ReadAllContext(ctx, 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)
}
// CheckEmbeddedPsiphonConfig checks whether we can load psiphon's config
func CheckEmbeddedPsiphonConfig() error {
child := &sessionTunnelEarlySession{}
_, err := child.FetchPsiphonConfig(context.Background())
return err
}