aspnetcookie

package module
v0.0.0-...-b931529 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2017 License: MIT Imports: 13 Imported by: 0

README

Build Status Coverage Status

aspnetcookie

A Go package that can decode and validate an ASP.net FormsAuthentication encrypted and signed cookie.

Limitations

Currently only the following (Web.config) configuration is tested:

<machineKey
    validationKey="2E502E08392C704E2234759EDA7A5940A8CE1C42C7964B8142778764CF0006C2"
    decryptionKey="5226859B3CB262982B574093B29DAD9083030C93604C820F009D5192BDEC31F2"
    validation="SHA1"
    decryption="AES"
    compatibilityMode="Framework20SP2"
/>

Only SHA1 based HMAC and AES encryption are currently supported.

Usage

validationKey, _ := hex.DecodeString("2E502E08392C704E2234759EDA7A5940A8CE1C42C7964B8142778764CF0006C2")
decryptionKey, _ := hex.DecodeString("5226859B3CB262982B574093B29DAD9083030C93604C820F009D5192BDEC31F2")
codec := aspnetcookie.New("SHA1", validationKey, "AES", decryptionKey)
cookie, _ := codec.EncodeNew("maurits.vanderschee", 3600*24*365, true, "\"nothing\"", "/")
ticket, _ := codec.Decode(cookie)

where ticket is:

// FormsAuthenticationTicket holds:
type FormsAuthenticationTicket struct {
	version           byte
	name              string
	issueDateUtc      int64
	expirationDateUtc int64
	isPersistent      bool
	userData          string
	cookiePath        string
}

see: https://referencesource.microsoft.com/#System.Web/Security/FormsAuthentication.cs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomKey

func GenerateRandomKey(length int) ([]byte, error)

GenerateRandomKey creates a random key with the given length in bytes.

Types

type AspNetCookie

type AspNetCookie struct {
	// contains filtered or unexported fields
}

AspNetCookie encodes and decodes authenticated and encrypted cookie values holding a FormsAuthenticationTicket.

func New

func New(hashName string, hashKey []byte, blockName string, blockKey []byte) *AspNetCookie

New returns a new AspNetCookie.

func (*AspNetCookie) Decode

func (s *AspNetCookie) Decode(b []byte) (*FormsAuthenticationTicket, error)

Decode decodes a cookie value.

func (*AspNetCookie) Encode

func (s *AspNetCookie) Encode(value *FormsAuthenticationTicket) ([]byte, error)

Encode encodes a cookie value.

func (*AspNetCookie) EncodeNew

func (s *AspNetCookie) EncodeNew(name string, ttl int64, isPersistent bool, userData, cookiePath string) ([]byte, error)

EncodeNew encodes a cookie value.

type FormsAuthenticationTicket

type FormsAuthenticationTicket struct {
	// contains filtered or unexported fields
}

FormsAuthenticationTicket holds:

func (*FormsAuthenticationTicket) Deserialize

func (t *FormsAuthenticationTicket) Deserialize(buf []byte) (int, error)

Deserialize is

func (*FormsAuthenticationTicket) Serialize

func (t *FormsAuthenticationTicket) Serialize() ([]byte, error)

Serialize is

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL