bitwarden

package
v0.0.0-...-820a931 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 23 Imported by: 4

Documentation

Overview

Package bitwarden is used for managing the ciphers, encrypted on the client side.

Index

Constants

View Source
const (
	LoginType      = 1
	SecureNoteType = 2
	CardType       = 3
	IdentityType   = 4
)

LoginType, SecureNoteType, CardType, and IdentityType are the 4 possible types of ciphers.

View Source
const (
	FieldTypeText    = 0
	FieldTypeHidden  = 1
	FieldTypeBoolean = 2
)

Possible types for ciphers additional fields

View Source
const DocTypeVersion = "1"

DocTypeVersion represents the doctype version. Each time this document structure is modified, update this value

Variables

View Source
var (
	ErrInvalidDomain      = errors.New("Invalid domain")
	ErrUnauthorizedDomain = errors.New("Unauthorized domain")
	ErrUnauthorizedIP     = errors.New("IP address are not authorized")
)

BitwardenScope was the OAuth scope, hard-coded with the doctypes needed by the Bitwarden apps. The new scope is dynamic, taken from the cozy-pass web manifest.

View Source
var GlobalDomains = map[GlobalEquivalentDomainsType][]string{
	Ameritrade:    {"ameritrade.com", "tdameritrade.com"},
	BoA:           {"bankofamerica.com", "bofa.com", "mbna.com", "usecfo.com"},
	Sprint:        {"sprint.com", "sprintpcs.com", "nextel.com"},
	Google:        {"youtube.com", "google.com", "gmail.com"},
	Apple:         {"apple.com", "icloud.com"},
	WellsFargo:    {"wellsfargo.com", "wf.com"},
	Merrill:       {"mymerrill.com", "ml.com", "merrilledge.com"},
	Citi:          {"accountonline.com", "citi.com", "citibank.com", "citicards.com", "citibankonline.com"},
	Cnet:          {"cnet.com", "cnettv.com", "com.com", "download.com", "news.com", "search.com", "upload.com"},
	Gap:           {"bananarepublic.com", "gap.com", "oldnavy.com", "piperlime.com"},
	Microsoft:     {"bing.com", "hotmail.com", "live.com", "microsoft.com", "msn.com", "passport.net", "windows.com", "microsoftonline.com", "office365.com", "microsoftstore.com", "xbox.com"},
	United:        {"ua2go.com", "ual.com", "united.com", "unitedwifi.com"},
	Yahoo:         {"overture.com", "yahoo.com"},
	Zonelabs:      {"zonealarm.com", "zonelabs.com"},
	PayPal:        {"paypal.com", "paypal-search.com"},
	Avon:          {"avon.com", "youravon.com"},
	Diapers:       {"diapers.com", "soap.com", "wag.com", "yoyo.com", "beautybar.com", "casa.com", "afterschool.com", "vine.com", "bookworm.com", "look.com", "vinemarket.com"},
	Contacts:      {"1800contacts.com", "800contacts.com"},
	Amazon:        {"amazon.com", "amazon.co.uk", "amazon.ca", "amazon.de", "amazon.fr", "amazon.es", "amazon.it", "amazon.com.au", "amazon.co.nz", "amazon.in"},
	Cox:           {"cox.com", "cox.net", "coxbusiness.com"},
	Norton:        {"mynortonaccount.com", "norton.com"},
	Verizon:       {"verizon.com", "verizon.net"},
	Buy:           {"rakuten.com", "buy.com"},
	Sirius:        {"siriusxm.com", "sirius.com"},
	Ea:            {"ea.com", "origin.com", "play4free.com", "tiberiumalliance.com"},
	Basecamp:      {"37signals.com", "basecamp.com", "basecamphq.com", "highrisehq.com"},
	Steam:         {"steampowered.com", "steamcommunity.com", "steamgames.com"},
	Chart:         {"chart.io", "chartio.com"},
	Gotomeeting:   {"gotomeeting.com", "citrixonline.com"},
	Gogo:          {"gogoair.com", "gogoinflight.com"},
	Oracle:        {"mysql.com", "oracle.com"},
	Discover:      {"discover.com", "discovercard.com"},
	Dcu:           {"dcu.org", "dcu-online.org"},
	Healthcare:    {"healthcare.gov", "cms.gov"},
	Pepco:         {"pepco.com", "pepcoholdings.com"},
	Century21:     {"century21.com", "21online.com"},
	Comcast:       {"comcast.com", "comcast.net", "xfinity.com"},
	Cricket:       {"cricketwireless.com", "aiowireless.com"},
	Mtb:           {"mandtbank.com", "mtb.com"},
	Dropbox:       {"dropbox.com", "getdropbox.com"},
	Snapfish:      {"snapfish.com", "snapfish.ca"},
	Alibaba:       {"alibaba.com", "aliexpress.com", "aliyun.com", "net.cn", "www.net.cn"},
	Playstation:   {"playstation.com", "sonyentertainmentnetwork.com"},
	Mercado:       {"mercadolivre.com", "mercadolivre.com.br", "mercadolibre.com", "mercadolibre.com.ar", "mercadolibre.com.mx"},
	Zendesk:       {"zendesk.com", "zopim.com"},
	Autodesk:      {"autodesk.com", "tinkercad.com"},
	RailNation:    {"railnation.ru", "railnation.de", "rail-nation.com", "railnation.gr", "railnation.us", "trucknation.de", "traviangames.com"},
	Wpcu:          {"wpcu.coop", "wpcuonline.com"},
	Mathletics:    {"mathletics.com", "mathletics.com.au", "mathletics.co.uk"},
	Discountbank:  {"discountbank.co.il", "telebank.co.il"},
	Mi:            {"mi.com", "xiaomi.com"},
	Postepay:      {"postepay.it", "poste.it"},
	Facebook:      {"facebook.com", "messenger.com"},
	Skysports:     {"skysports.com", "skybet.com", "skyvegas.com"},
	Disney:        {"disneymoviesanywhere.com", "go.com", "disney.com", "dadt.com"},
	Pokemon:       {"pokemon-gl.com", "pokemon.com"},
	Uv:            {"myuv.com", "uvvu.com"},
	Mdsol:         {"mdsol.com", "imedidata.com"},
	Yahavo:        {"bank-yahav.co.il", "bankhapoalim.co.il"},
	Sears:         {"sears.com", "shld.net"},
	Xiami:         {"xiami.com", "alipay.com"},
	Belkin:        {"belkin.com", "seedonk.com"},
	Turbotax:      {"turbotax.com", "intuit.com"},
	Shopify:       {"shopify.com", "myshopify.com"},
	Ebay:          {"ebay.com", "ebay.de", "ebay.ca", "ebay.in", "ebay.co.uk", "ebay.com.au"},
	Techdata:      {"techdata.com", "techdata.ch"},
	Schwab:        {"schwab.com", "schwabplan.com"},
	Tesla:         {"tesla.com", "teslamotors.com"},
	MorganStanley: {"morganstanley.com", "morganstanleyclientserv.com", "stockplanconnect.com", "ms.com"},
	TaxAct:        {"taxact.com", "taxactonline.com"},
	Wikimedia:     {"mediawiki.org", "wikibooks.org", "wikidata.org", "wikimedia.org", "wikinews.org", "wikipedia.org", "wikiquote.org", "wikisource.org", "wikiversity.org", "wikivoyage.org", "wiktionary.org"},
	Airbnb:        {"airbnb.at", "airbnb.be", "airbnb.ca", "airbnb.ch", "airbnb.cl", "airbnb.co.cr", "airbnb.co.id", "airbnb.co.in", "airbnb.co.kr", "airbnb.co.nz", "airbnb.co.uk", "airbnb.co.ve", "airbnb.com", "airbnb.com.ar", "airbnb.com.au", "airbnb.com.bo", "airbnb.com.br", "airbnb.com.bz", "airbnb.com.co", "airbnb.com.ec", "airbnb.com.gt", "airbnb.com.hk", "airbnb.com.hn", "airbnb.com.mt", "airbnb.com.my", "airbnb.com.ni", "airbnb.com.pa", "airbnb.com.pe", "airbnb.com.py", "airbnb.com.sg", "airbnb.com.sv", "airbnb.com.tr", "airbnb.com.tw", "airbnb.cz", "airbnb.de", "airbnb.dk", "airbnb.es", "airbnb.fi", "airbnb.fr", "airbnb.gr", "airbnb.gy", "airbnb.hu", "airbnb.ie", "airbnb.is", "airbnb.it", "airbnb.jp", "airbnb.mx", "airbnb.nl", "airbnb.no", "airbnb.pl", "airbnb.pt", "airbnb.ru", "airbnb.se"},
	Eventbrite:    {"eventbrite.at", "eventbrite.be", "eventbrite.ca", "eventbrite.ch", "eventbrite.cl", "eventbrite.co.id", "eventbrite.co.in", "eventbrite.co.kr", "eventbrite.co.nz", "eventbrite.co.uk", "eventbrite.co.ve", "eventbrite.com", "eventbrite.com.au", "eventbrite.com.bo", "eventbrite.com.br", "eventbrite.com.co", "eventbrite.com.hk", "eventbrite.com.hn", "eventbrite.com.pe", "eventbrite.com.sg", "eventbrite.com.tr", "eventbrite.com.tw", "eventbrite.cz", "eventbrite.de", "eventbrite.dk", "eventbrite.fi", "eventbrite.fr", "eventbrite.gy", "eventbrite.hu", "eventbrite.ie", "eventbrite.is", "eventbrite.it", "eventbrite.jp", "eventbrite.mx", "eventbrite.nl", "eventbrite.no", "eventbrite.pl", "eventbrite.pt", "eventbrite.ru", "eventbrite.se"},
	StackExchange: {"stackexchange.com", "superuser.com", "stackoverflow.com", "serverfault.com", "mathoverflow.net", "askubuntu.com"},
}

GlobalDomains is the list of the global equivalent domains. https://github.com/bitwarden/server/blob/master/src/Core/Utilities/StaticStore.cs

Functions

func CreateAccessJWT

func CreateAccessJWT(i *instance.Instance, c *oauth.Client) (string, error)

CreateAccessJWT returns a new JSON Web Token that can be used with Bitwarden apps. It is an access token, with some additional custom fields. See https://github.com/bitwarden/jslib/blob/master/common/src/services/token.service.ts

func CreateRefreshJWT

func CreateRefreshJWT(i *instance.Instance, c *oauth.Client) (string, error)

CreateRefreshJWT returns a new JSON Web Token that can be used with Bitwarden apps. It is a refresh token, with an additional security stamp.

func DeleteUnrecoverableCiphers

func DeleteUnrecoverableCiphers(inst *instance.Instance) error

DeleteUnrecoverableCiphers will delete all the ciphers that are not shared with the cozy organization. It should be called when the master password is lost, as there are no ways to recover those encrypted ciphers.

func IsBitwardenClient

func IsBitwardenClient(client *oauth.Client, scope string) bool

IsBitwardenClient returns true if the client can use the bitwarden refresh endpoint.

func ParseBitwardenDeviceType

func ParseBitwardenDeviceType(deviceType string) string

ParseBitwardenDeviceType takes a deviceType (Bitwarden) and transforms it into a client_kind (Cozy). See https://github.com/bitwarden/server/blob/f37f33512046707eef69a2cb3944338de819439d/src/Core/Enums/DeviceType.cs

Types

type Cipher

type Cipher struct {
	CouchID        string                 `json:"_id,omitempty"`
	CouchRev       string                 `json:"_rev,omitempty"`
	Type           CipherType             `json:"type"`
	SharedWithCozy bool                   `json:"shared_with_cozy"`
	Favorite       bool                   `json:"favorite,omitempty"`
	Name           string                 `json:"name"`
	Notes          string                 `json:"notes,omitempty"`
	FolderID       string                 `json:"folder_id,omitempty"`
	OrganizationID string                 `json:"organization_id,omitempty"`
	CollectionID   string                 `json:"collection_id,omitempty"`
	Login          *LoginData             `json:"login,omitempty"`
	Data           *MapData               `json:"data,omitempty"`
	Fields         []Field                `json:"fields"`
	Metadata       *metadata.CozyMetadata `json:"cozyMetadata,omitempty"`
	DeletedDate    *time.Time             `json:"deletedDate,omitempty"`
}

Cipher is an encrypted item that can be a login, a secure note, a card or an identity.

func FindCiphersInFolder

func FindCiphersInFolder(inst *instance.Instance, folderID string) ([]*Cipher, error)

FindCiphersInFolder finds the ciphers in the given folder.

func (*Cipher) Clone

func (c *Cipher) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Cipher) DocType

func (c *Cipher) DocType() string

DocType returns the cipher document type

func (*Cipher) Fetch

func (c *Cipher) Fetch(field string) []string

Fetch implements permissions.Fetcher

func (*Cipher) ID

func (c *Cipher) ID() string

ID returns the cipher qualified identifier

func (*Cipher) Rev

func (c *Cipher) Rev() string

Rev returns the cipher revision

func (*Cipher) SetID

func (c *Cipher) SetID(id string)

SetID changes the cipher qualified identifier

func (*Cipher) SetRev

func (c *Cipher) SetRev(rev string)

SetRev changes the cipher revision

type CipherType

type CipherType int

CipherType is used to know what contains the cipher: a login, a secure note, a card or an identity.

type Collection

type Collection struct {
	DocID string `json:"_id"`
	Name  string `json:"name"`
}

Collection is used to regroup ciphers.

func (*Collection) ID

func (c *Collection) ID() string

ID returns the collection identifier

type Contact

type Contact struct {
	UserID    string                `json:"_id,omitempty"`
	CouchRev  string                `json:"_rev,omitempty"`
	Email     string                `json:"email"`
	PublicKey string                `json:"public_key"`
	Confirmed bool                  `json:"confirmed,omitempty"`
	Metadata  metadata.CozyMetadata `json:"cozyMetadata"`
}

Contact is used to add users to an organization.

func (*Contact) Clone

func (c *Contact) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Contact) DocType

func (c *Contact) DocType() string

DocType returns the contact document type

func (*Contact) ID

func (c *Contact) ID() string

ID returns the contact identifier

func (*Contact) Rev

func (c *Contact) Rev() string

Rev returns the contact revision

func (*Contact) SetID

func (c *Contact) SetID(id string)

SetID changes the contact identifier

func (*Contact) SetRev

func (c *Contact) SetRev(rev string)

SetRev changes the contact revision

type Field

type Field struct {
	// See https://github.com/bitwarden/jslib/blob/master/common/src/enums/fieldType.ts
	Type  int    `json:"type"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

Field is used to store some additional fields.

type Folder

type Folder struct {
	CouchID  string                 `json:"_id,omitempty"`
	CouchRev string                 `json:"_rev,omitempty"`
	Name     string                 `json:"name"`
	Metadata *metadata.CozyMetadata `json:"cozyMetadata,omitempty"`
}

Folder is a space to organize ciphers. Its name is encrypted on client-side.

func (*Folder) Clone

func (f *Folder) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Folder) DocType

func (f *Folder) DocType() string

DocType returns the folder document type

func (*Folder) ID

func (f *Folder) ID() string

ID returns the folder qualified identifier

func (*Folder) Rev

func (f *Folder) Rev() string

Rev returns the folder revision

func (*Folder) SetID

func (f *Folder) SetID(id string)

SetID changes the folder qualified identifier

func (*Folder) SetRev

func (f *Folder) SetRev(rev string)

SetRev changes the folder revision

type GlobalEquivalentDomainsType

type GlobalEquivalentDomainsType int

GlobalEquivalentDomainsType is an enum for global domain identifiers.

const (
	Google        GlobalEquivalentDomainsType = 0
	Apple         GlobalEquivalentDomainsType = 1
	Ameritrade    GlobalEquivalentDomainsType = 2
	BoA           GlobalEquivalentDomainsType = 3
	Sprint        GlobalEquivalentDomainsType = 4
	WellsFargo    GlobalEquivalentDomainsType = 5
	Merrill       GlobalEquivalentDomainsType = 6
	Citi          GlobalEquivalentDomainsType = 7
	Cnet          GlobalEquivalentDomainsType = 8
	Gap           GlobalEquivalentDomainsType = 9
	Microsoft     GlobalEquivalentDomainsType = 10
	United        GlobalEquivalentDomainsType = 11
	Yahoo         GlobalEquivalentDomainsType = 12
	Zonelabs      GlobalEquivalentDomainsType = 13
	PayPal        GlobalEquivalentDomainsType = 14
	Avon          GlobalEquivalentDomainsType = 15
	Diapers       GlobalEquivalentDomainsType = 16
	Contacts      GlobalEquivalentDomainsType = 17
	Amazon        GlobalEquivalentDomainsType = 18
	Cox           GlobalEquivalentDomainsType = 19
	Norton        GlobalEquivalentDomainsType = 20
	Verizon       GlobalEquivalentDomainsType = 21
	Buy           GlobalEquivalentDomainsType = 22
	Sirius        GlobalEquivalentDomainsType = 23
	Ea            GlobalEquivalentDomainsType = 24
	Basecamp      GlobalEquivalentDomainsType = 25
	Steam         GlobalEquivalentDomainsType = 26
	Chart         GlobalEquivalentDomainsType = 27
	Gotomeeting   GlobalEquivalentDomainsType = 28
	Gogo          GlobalEquivalentDomainsType = 29
	Oracle        GlobalEquivalentDomainsType = 30
	Discover      GlobalEquivalentDomainsType = 31
	Dcu           GlobalEquivalentDomainsType = 32
	Healthcare    GlobalEquivalentDomainsType = 33
	Pepco         GlobalEquivalentDomainsType = 34
	Century21     GlobalEquivalentDomainsType = 35
	Comcast       GlobalEquivalentDomainsType = 36
	Cricket       GlobalEquivalentDomainsType = 37
	Mtb           GlobalEquivalentDomainsType = 38
	Dropbox       GlobalEquivalentDomainsType = 39
	Snapfish      GlobalEquivalentDomainsType = 40
	Alibaba       GlobalEquivalentDomainsType = 41
	Playstation   GlobalEquivalentDomainsType = 42
	Mercado       GlobalEquivalentDomainsType = 43
	Zendesk       GlobalEquivalentDomainsType = 44
	Autodesk      GlobalEquivalentDomainsType = 45
	RailNation    GlobalEquivalentDomainsType = 46
	Wpcu          GlobalEquivalentDomainsType = 47
	Mathletics    GlobalEquivalentDomainsType = 48
	Discountbank  GlobalEquivalentDomainsType = 49
	Mi            GlobalEquivalentDomainsType = 50
	Facebook      GlobalEquivalentDomainsType = 51
	Postepay      GlobalEquivalentDomainsType = 52
	Skysports     GlobalEquivalentDomainsType = 53
	Disney        GlobalEquivalentDomainsType = 54
	Pokemon       GlobalEquivalentDomainsType = 55
	Uv            GlobalEquivalentDomainsType = 56
	Yahavo        GlobalEquivalentDomainsType = 57
	Mdsol         GlobalEquivalentDomainsType = 58
	Sears         GlobalEquivalentDomainsType = 59
	Xiami         GlobalEquivalentDomainsType = 60
	Belkin        GlobalEquivalentDomainsType = 61
	Turbotax      GlobalEquivalentDomainsType = 62
	Shopify       GlobalEquivalentDomainsType = 63
	Ebay          GlobalEquivalentDomainsType = 64
	Techdata      GlobalEquivalentDomainsType = 65
	Schwab        GlobalEquivalentDomainsType = 66
	Mozilla       GlobalEquivalentDomainsType = 67 // deprecated
	Tesla         GlobalEquivalentDomainsType = 68
	MorganStanley GlobalEquivalentDomainsType = 69
	TaxAct        GlobalEquivalentDomainsType = 70
	Wikimedia     GlobalEquivalentDomainsType = 71
	Airbnb        GlobalEquivalentDomainsType = 72
	Eventbrite    GlobalEquivalentDomainsType = 73
	StackExchange GlobalEquivalentDomainsType = 74
)

The list of all the global domain identifiers https://github.com/bitwarden/server/blob/master/src/Core/Enums/GlobalEquivalentDomainsType.cs

type Icon

type Icon struct {
	Mime string `json:"mime"`
	Body []byte `json:"body"`
}

Icon is a simple struct with a content-type and the content of an icon.

func GetIcon

func GetIcon(domain string) (*Icon, error)

GetIcon returns an icon for the given domain.

type LoginData

type LoginData struct {
	URIs     []LoginURI `json:"uris,omitempty"`
	Username string     `json:"username,omitempty"`
	Password string     `json:"password,omitempty"`
	RevDate  string     `json:"passwordRevisionDate,omitempty"`
	TOTP     string     `json:"totp,omitempty"`
}

LoginData is the encrypted data for a cipher with the login type.

type LoginURI

type LoginURI struct {
	URI   string      `json:"uri"`
	Match interface{} `json:"match,omitempty"`
}

LoginURI is a field for an URI. See https://github.com/bitwarden/jslib/blob/master/common/src/models/api/loginUriApi.ts

type MapData

type MapData map[string]interface{}

MapData is used for the data of secure note, card, and identity.

type OrgMember

type OrgMember struct {
	UserID   string          `json:"user_id"`
	Email    string          `json:"email"`
	Name     string          `json:"name"`
	OrgKey   string          `json:"key,omitempty"` // The organization key encrypted with the public key of the user
	Status   OrgMemberStatus `json:"status"`
	Owner    bool            `json:"owner,omitempty"`
	ReadOnly bool            `json:"read_only,omitempty"`
}

OrgMember is a struct for describing a member of an organization.

type OrgMemberStatus

type OrgMemberStatus int

OrgMemberStatus is a type for the status of an organization member

const (
	// OrgMemberInvited is used when the member is invited but has not yet
	// accepted the invitation.
	OrgMemberInvited OrgMemberStatus = 0
	// OrgMemberAccepted is used when the member is accepted but the owner has
	// not yet confirmed that the fingerprint is OK.
	OrgMemberAccepted OrgMemberStatus = 1
	// OrgMemberConfirmed is used when the member is confirmed, and has access
	// to the organization key to decrypt/encrypt ciphers.
	OrgMemberConfirmed OrgMemberStatus = 2
)

type Organization

type Organization struct {
	CouchID    string                `json:"_id,omitempty"`
	CouchRev   string                `json:"_rev,omitempty"`
	Name       string                `json:"name"`
	Members    map[string]OrgMember  `json:"members"` // the keys are the instances domains
	Collection Collection            `json:"defaultCollection"`
	Metadata   metadata.CozyMetadata `json:"cozyMetadata"`
}

Organization is used to make collections of ciphers and can be used for sharing them with other users with cryptography mechanisms.

func FindAllOrganizations

func FindAllOrganizations(inst *instance.Instance, setting *settings.Settings) ([]*Organization, error)

FindAllOrganizations returns all the organizations, including the Cozy one.

func GetCozyOrganization

func GetCozyOrganization(inst *instance.Instance, setting *settings.Settings) (*Organization, error)

GetCozyOrganization returns the organization used to store the credentials for the konnectors running on the Cozy server.

func (*Organization) Clone

func (o *Organization) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Organization) Delete

func (o *Organization) Delete(inst *instance.Instance) error

Delete will delete the organization and the ciphers inside it.

func (*Organization) DocType

func (o *Organization) DocType() string

DocType returns the organization document type

func (*Organization) FindCiphers

func (o *Organization) FindCiphers(inst *instance.Instance) ([]*Cipher, error)

FindCiphers returns the ciphers for this organization.

func (*Organization) ID

func (o *Organization) ID() string

ID returns the organization identifier

func (*Organization) Rev

func (o *Organization) Rev() string

Rev returns the organization revision

func (*Organization) SetID

func (o *Organization) SetID(id string)

SetID changes the organization identifier

func (*Organization) SetRev

func (o *Organization) SetRev(rev string)

SetRev changes the organization revision

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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