Esempio n. 1
0
func New() *Cookie {
	cookies.Lock()
	defer cookies.Unlock()
	now := time.Now().UnixNano()
	buf := make([]byte, CookieSize)
	for i, v := 0, now; i < 8; i, v = i+1, v>>8 {
		buf[i] = uint8(v)
	}
	rnd := xio.NewRandomReader(now)
	for i := 0; i < 4; i++ {
		rnd.ReadBytes(buf[8:])
		value := string(buf)
		if c := cookies.values[value]; c != nil {
			continue
		}
		c := &Cookie{}
		c.value = value
		c.alloctime = now
		cookies.values[value] = c
		counts.Count("cookie.new", 1)
		return c
	}
	counts.Count("cookie.null", 1)
	return nil
}
Esempio n. 2
0
func init() {
	prefix := []byte{0x01, 0x0a, 0x41, 0x0e}
	suffix := []byte{0x02, 0x15, 0x02, 0x02, 0x15, 0x05, 0x02, 0x15, 0x0e}
	middle := make([]byte, 64)
	xio.NewRandomReader(time.Now().UnixNano()).ReadBytes(middle)
	magic := make([]byte, len(prefix)+len(middle)+len(suffix))
	copy(magic, prefix)
	copy(magic[len(prefix):], middle)
	copy(magic[len(prefix)+len(middle):], suffix)
	certificate = magic
	log.Printf("[certificate]: \n%s\n", utils.Formatted(certificate))
}