bitw

package
v0.0.0-...-ed45667 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0, BSD-3-Clause Imports: 29 Imported by: 0

README

bitw

This module contains code from https://github.com/mvdan/bitw the primary use in this package is to save requiring reimplementation of the cryptographic functions however new code is added to make this more flexible and allow it to be used as a package.

A simple BitWarden client. Requires Go 1.16 or later.

go install mvdan.cc/bitw@latest

The goal is a static and portable client which integrates well with one's system. For example, on Linux it implements the org.freedesktop.secrets D-Bus service.

Note that this tool is still a work in progress.

Quickstart

Log in and sync, providing a password when asked:

export EMAIL=you@domain.com
bitw sync

You can then view your secrets:

bitw dump

You can also start the D-Bus service, and use it:

bitw serve
secret-tool lookup name mysecret
Non-goals

These features are not planned at the moment:

  • A graphical interface - use vault.bitwarden.com
  • Querying secrets directly - use D-Bus clients like secret-tool
  • Integration with gnome-keyring - they both implement the same D-Bus service
Further reading

Talking to BitWarden:

Integrating with the OS:

Documentation

Overview

Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc> This file is covered by the license at https://github.com/mvdan/bitw/blob/master/LICENSE

Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc> This file is covered by the license at https://github.com/mvdan/bitw/blob/master/LICENSE

Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc> This file is covered by the license at https://github.com/mvdan/bitw/blob/master/LICENSE

  • Copyright 2022 Martin Proffitt <mproffitt@choclab.net> *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc> This file is covered by the license at https://github.com/mvdan/bitw/blob/master/LICENSE

  • Copyright 2022 Martin Proffitt <mproffitt@choclab.net> *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc> This file is covered by the license at https://github.com/mvdan/bitw/blob/master/LICENSE

Index

Constants

View Source
const CHUNKSIZE int = 5
View Source
const MAX_RETRIES = 5

Variables

View Source
var (
	ApiServer string
	IdtServer string
	EmailAddr string
)

Functions

func DeriveHttpGetAPIKey

func DeriveHttpGetAPIKey(partial string) string

func GetFolder

func GetFolder(path string) uuid.UUID

func Prelogin

func Prelogin(email string) (*preLoginResponse, error)

func ReadLine

func ReadLine(prompt string) (string, error)

func ReadPassword

func ReadPassword(prompt string) (string, error)

func SetMasterPassword

func SetMasterPassword(password, email string, plr *preLoginResponse) string

func Sync

func Sync(ctx context.Context) error

Types

type AuthToken

type AuthToken struct{}

type Card

type Card struct {
	CardholderName CipherString
	Brand          CipherString
	Number         CipherString
	ExpMonth       CipherString
	ExpYear        CipherString
	Code           CipherString
}

type Cipher

type Cipher struct {
	Type         CipherType
	ID           uuid.UUID
	Name         CipherString
	Edit         bool
	RevisionDate time.Time

	FolderID            *uuid.UUID  `json:",omitempty"`
	OrganizationID      *uuid.UUID  `json:",omitempty"`
	Favorite            bool        `json:",omitempty"`
	Attachments         interface{} `json:",omitempty"`
	OrganizationUseTotp bool        `json:",omitempty"`
	CollectionIDs       []string    `json:",omitempty"`
	Fields              []Field     `json:",omitempty"`

	Card       *Card         `json:",omitempty"`
	Identity   *Identity     `json:",omitempty"`
	Login      *Login        `json:",omitempty"`
	Notes      *CipherString `json:",omitempty"`
	SecureNote *SecureNote   `json:",omitempty"`
}

func (*Cipher) Match

func (c *Cipher) Match(attr, value string) bool

type CipherString

type CipherString struct {
	Type CipherStringType

	IV, CT, MAC []byte
}

func (CipherString) IsZero

func (s CipherString) IsZero() bool

func (CipherString) MarshalText

func (s CipherString) MarshalText() ([]byte, error)

func (CipherString) String

func (s CipherString) String() string

func (*CipherString) UnmarshalText

func (s *CipherString) UnmarshalText(data []byte) error

type CipherStringType

type CipherStringType int
const (
	AesCbc256_B64                     CipherStringType = 0
	AesCbc128_HmacSha256_B64          CipherStringType = 1
	AesCbc256_HmacSha256_B64          CipherStringType = 2
	Rsa2048_OaepSha256_B64            CipherStringType = 3
	Rsa2048_OaepSha1_B64              CipherStringType = 4
	Rsa2048_OaepSha256_HmacSha256_B64 CipherStringType = 5
	Rsa2048_OaepSha1_HmacSha256_B64   CipherStringType = 6
)

Taken from https://github.com/bitwarden/jslib/blob/f30d6f8027055507abfdefd1eeb5d9aab25cc601/src/enums/encryptionType.ts

func (CipherStringType) HasMAC

func (t CipherStringType) HasMAC() bool

type CipherType

type CipherType int
const (
	CipherLogin CipherType
	CipherCard
	CipherIdentity
	CipherNote
)

type DataFile

type DataFile struct {
	DeviceID      string
	AccessToken   string
	RefreshToken  string
	TokenExpiry   time.Time
	KDF           int
	KDFIterations int

	LastSync time.Time
	Sync     SyncData
	// contains filtered or unexported fields
}

type DecryptedCipher

type DecryptedCipher struct {
	Type           int               `json:"type"`
	ID             uuid.UUID         `json:"id"`
	RevisionDate   time.Time         `json:"revision_date"`
	Name           string            `json:"name"`
	Fields         map[string]string `json:"fields"`
	FolderID       *uuid.UUID        `json:"folder_id,omitempty"`
	OrganizationID *uuid.UUID        `json:"org_id,omitempty"`

	Username string `json:"username"`
	Password string `json:"password"`
}

func Get

func Get(path string) ([]DecryptedCipher, bool)

func (*DecryptedCipher) Get

func (d *DecryptedCipher) Get(what string) (value interface{})

type Field

type Field struct {
	Type  FieldType
	Name  CipherString
	Value CipherString
}

type FieldType

type FieldType int

type Folder

type Folder struct {
	ID           uuid.UUID
	Name         CipherString
	RevisionDate time.Time
}

type Identity

type Identity struct {
	Title      CipherString
	FirstName  CipherString
	MiddleName CipherString
	LastName   CipherString

	Username       CipherString
	Company        CipherString
	SSN            CipherString
	PassportNumber CipherString
	LicenseNumber  CipherString

	Email      CipherString
	Phone      CipherString
	Address1   CipherString
	Address2   CipherString
	Address3   CipherString
	City       CipherString
	State      CipherString
	PostalCode CipherString
	Country    CipherString
}

type Login

type Login struct {
	Password CipherString
	URI      CipherString
	URIs     []URI
	Username CipherString `json:",omitempty"`
	Totp     string       `json:",omitempty"`
}

type LoginResponse

type LoginResponse struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token"`
	Key          string `json:"key"`
}

func ApiLogin

func ApiLogin(clientId, clientSecret string) (*LoginResponse, error)

func UserLogin

func UserLogin(hashedPassword, email string) (*LoginResponse, error)

type Organization

type Organization struct {
	Object          string
	Id              uuid.UUID
	Name            string
	UseGroups       bool
	UseDirectory    bool
	UseEvents       bool
	UseTotp         bool
	Use2fa          bool
	UseApi          bool
	UsersGetPremium bool
	SelfHost        bool
	Seats           int
	MaxCollections  int
	MaxStorageGb    int
	Key             string
	Status          int
	Type            int
	Enabled         bool
}

type Profile

type Profile struct {
	ID                 uuid.UUID
	Name               string
	Email              string
	EmailVerified      bool
	Premium            bool
	MasterPasswordHint string
	Culture            string
	TwoFactorEnabled   bool
	Key                CipherString
	PrivateKey         CipherString
	SecurityStamp      string
	Organizations      []Organization
}

type SecureNote

type SecureNote struct {
	Type SecureNoteType
}

type SecureNoteType

type SecureNoteType int

type SyncData

type SyncData struct {
	Profile Profile
	Folders []Folder
	Ciphers []Cipher
}

type TwoFactorProvider

type TwoFactorProvider int
const (
	Authenticator   TwoFactorProvider = 0
	Email           TwoFactorProvider = 1
	Duo             TwoFactorProvider = 2
	YubiKey         TwoFactorProvider = 3
	U2f             TwoFactorProvider = 4
	Remember        TwoFactorProvider = 5
	OrganizationDuo TwoFactorProvider = 6
)

Enum values copied from https://github.com/bitwarden/server/blob/f311f40d9333442a727eb8b77f3859597de199da/src/Core/Enums/TwoFactorProviderType.cs. Do not use iota, to clarify that these integer values are defined elsewhere.

func (TwoFactorProvider) Line

func (t TwoFactorProvider) Line(extra map[string]interface{}) string

func (*TwoFactorProvider) UnmarshalText

func (t *TwoFactorProvider) UnmarshalText(text []byte) error

type URI

type URI struct {
	URI   string
	Match URIMatch
}

type URIMatch

type URIMatch int

Jump to

Keyboard shortcuts

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