func (sd *SessionData) AddCookies(cookies *cookiejar.Jar) {
	cookies.SetCookies(cookiePath, []*http.Cookie{
		&http.Cookie{
			Name:   "mobileClientVersion",
			Value:  "0 (2.1.3)",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "mobileClient",
			Value:  "android",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "Steam_Language",
			Value:  "english",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "steamid",
			Value:  strconv.FormatUint(sd.SteamID, 10),
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:     "steamLogin",
			Value:    sd.SteamLogin,
			Path:     "/",
			Domain:   ".steamcommunity.com",
			HttpOnly: true,
		},
		&http.Cookie{
			Name:     "steamLoginSecure",
			Value:    sd.SteamLoginSecure,
			Path:     "/",
			Domain:   ".steamcommunity.com",
			Secure:   true,
			HttpOnly: true,
		},
		&http.Cookie{
			Name:   "dob",
			Value:  "",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "sessionid",
			Value:  sd.SessionID,
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
	})
}
Exemple #2
0
func login(privKey box.PrivateKey) error {
	var err error
	var challenge []byte
	var ok bool
	var jar *cookiejar.Jar
	c := make(map[string]string)
	// Step1: request challenge
	resp, err := http.Get(fmt.Sprintf("%s/%s", api["auth"].String(), username))
	if err != nil {
		return err
	}
	d := json.NewDecoder(resp.Body)
	defer resp.Body.Close()
	d.Decode(&c)
	data := decodeBase64(c["challenge"])
	if box.BoxIsSigned(data) {
		log.Println("opening signed box...")
		challenge, ok = box.OpenAndVerify(data, privKey, srvKey)
	} else {
		log.Println("opening box...")
		challenge, ok = box.Open(data, privKey)
	}
	if !ok {
		log.Println("unboxing returned not ok")
		return &internalError{E_AUTH}
	}

	// Step2: validate challenge
	step2, err := json.Marshal(&map[string]string{"id": c["id"], "challenge": base64.StdEncoding.EncodeToString(challenge)})
	if err != nil {
		return err
	}
	resp, err = http.Post(api["auth"].String(), jsonMime, strings.NewReader(string(step2)))
	if err != nil {
		return err
	}
	if resp.StatusCode == http.StatusUnauthorized {
		return &internalError{E_AUTH}
	}
	if resp.StatusCode != http.StatusOK {
		return &internalError{E_SERVER}
	}

	jar, err = cookiejar.New(nil)
	if err != nil {
		log.Fatalf("Failed opening cookiejar: %v\n", err)
	}
	jar.SetCookies(api["/"], resp.Cookies())
	myId, _ = strconv.ParseInt(c["id"], 10, 64)
	client = &http.Client{Jar: jar}

	return nil
}
Exemple #3
0
func getFinalURL(jar *cookiejar.Jar, addr *url.URL, level int) (*url.URL, error) {
	if flDebug {
		log.Printf("new request (level %d): %s", level, addr.String())
	}
	if level == 0 {
		return nil, fmt.Errorf("too many redirects")
	}
	if addr.Scheme != "http" && addr.Scheme != "https" {
		return nil, fmt.Errorf("unsupported url scheme: %s", addr.Scheme)
	}
	req, err := http.NewRequest("GET", addr.String(), nil)
	if err != nil {
		return nil, fmt.Errorf("request create err: %s", err)
	}
	cookies := jar.Cookies(addr)
	for _, cookie := range cookies {
		if flDebug {
			log.Printf("add cookie: %s", cookie.String())
		}
		req.AddCookie(cookie)
	}
	req.Header.Set("User-Agent", userAgent)
	resp, err := http.DefaultTransport.RoundTrip(req)
	if err != nil {
		if uErr, ok := err.(*url.Error); !ok || uErr.Err != errStopRedirect {
			return nil, fmt.Errorf("request err: %s", err)
		}
	}
	defer resp.Body.Close()
	ct := strings.ToLower(resp.Header.Get("Content-Type"))
	if flDebug {
		log.Printf("response code: %d, content-type %s", resp.StatusCode, ct)
	}
	jar.SetCookies(resp.Request.URL, resp.Cookies())
	if resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 303 || resp.StatusCode == 307 {
		location := resp.Header.Get("Location")
		addr, err = url.Parse(location)
		if err != nil {
			return nil, err
		}
		return getFinalURL(jar, addr, level-1)
	}
	if !strings.HasPrefix(ct, "text/html") {
		if flDebug {
			log.Printf("not html content-type: %s", ct)
		}
		return resp.Request.URL, err
	}
	buf := &bytes.Buffer{}
	_, err = io.CopyN(buf, resp.Body, 1024*1024*10)
	if err != nil && err != io.EOF {
		return nil, err
	}
	data := bytes.ToLower(buf.Bytes())
	if flDebug {
		log.Printf("html: %s", string(data))
	}
	metaRedirect, err := findMetaRedirect(data)
	if err != nil {
		return nil, fmt.Errorf("meta redirect err: %s", err)
	}
	if metaRedirect == nil {
		return addr, nil
	}
	if flDebug {
		log.Printf("html meta redirect: %s", metaRedirect)
	}
	return getFinalURL(jar, metaRedirect, level-1)
}