func makeCookie(info *RequestInfo) (*http.Cookie, error) { var clientPublicKey, dummyKey [32]byte keydata, err := base64.StdEncoding.DecodeString(info.ClientPublicKeyBase64) if err != nil { return nil, fmt.Errorf("error decoding info.ClientPublicKeyBase64: %s", err) } copy(clientPublicKey[:], keydata) cr := crypto.New(clientPublicKey, dummyKey) cookie := &Cookie{ PsiphonServerAddr: info.PsiphonServerAddr, SshSessionID: info.SshSessionID, MeekProtocolVersion: info.MeekProtocolVersion, } j, err := json.Marshal(cookie) if err != nil { return nil, err } encrypted, err := cr.Encrypt(j) if err != nil { return nil, err } obfuscated, err := cr.Obfuscate(encrypted, info.ObfuscatedKeyword) if err != nil { return nil, err } cookieValue := base64.StdEncoding.EncodeToString(obfuscated) cookieName := string(byte(randInt(65, 90))) return &http.Cookie{Name: cookieName, Value: cookieValue}, nil }
func NewDispatcher(config *Config) (*Dispatcher, error) { var cookiePrivateKey, dummyKey [32]byte keydata, err := base64.StdEncoding.DecodeString(config.CookiePrivateKeyBase64) if err != nil { return nil, fmt.Errorf("error decoding config.CookiePrivateKeyBase64: %s", err) } copy(cookiePrivateKey[:], keydata) crypto := crypto.New(dummyKey, cookiePrivateKey) dispatcher := &Dispatcher{ config: config, crypto: crypto, sessionMap: make(map[string]*Session), } return dispatcher, nil }