Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

# Commands 

 

# License {{{1 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see http://www.gnu.org/licenses/. 

 

 

# Imports {{{1 

from .collection import Collection 

from .config import get_setting, override_setting 

from .editors import GenericEditor 

from .generator import PasswordGenerator 

from .gpg import GnuPG, PythonFile 

from .obscure import Obscure 

from .utilities import two_columns 

from .writer import get_writer 

from inform import ( 

Error, error, codicil, output, conjoin, os_error, 

is_collection, is_str, indent, render, 

) 

from shlib import chmod, mv, rm, to_path 

from docopt import docopt 

from textwrap import dedent, fill 

import re 

import sys 

 

 

# Utilities {{{1 

def title(text): 

return text[0].upper() + text[1:] + '.' 

 

# Command base class {{{1 

class Command(object): 

@classmethod 

def commands(cls): 

for cmd in cls.__subclasses__(): 

yield cmd 

for sub in cmd.commands(): 

yield sub 

 

@classmethod 

def commands_sorted(cls): 

for cmd in sorted(cls.commands(), key=lambda c: c.get_name()): 

yield cmd 

 

@classmethod 

def find(cls, name): 

for command in cls.commands(): 

if name in command.NAMES: 

return command 

 

@classmethod 

def execute(cls, name, args): 

if args is None: 

args = [] 

command = cls.find(name) 

if not command: 

# assume they simply neglected to specify the command explicitly 

args = [name] + args 

name = get_setting('default_command') 

command = cls.find(name) 

if not command: 

error('unknown command.', culprit=name) 

codicil("Use 'avendesora help' for list of available commands."), 

return 

command.run(name, args if args else []) 

 

@classmethod 

def summarize(cls, width=16): 

summaries = [] 

for cmd in Command.commands_sorted(): 

summaries.append(two_columns(', '.join(cmd.NAMES), cmd.DESCRIPTION)) 

return '\n'.join(summaries) 

 

@classmethod 

def get_name(cls): 

return cls.NAMES[0] 

 

 

# Add {{{1 

class Add(Command): 

NAMES = 'add', 'a' 

DESCRIPTION = 'add a new account' 

USAGE = dedent(""" 

Usage: 

avendesora [options] add [<template>] 

avendesora [options] a [<template>] 

 

Options: 

-f <file>, --file <file> 

Add account to specified accounts file. 

 

Creates a new account starting from a template. The template consists of 

boilerplate code and fields. The fields take the from _NAME_. They 

should be replaced by appropriate values or deleted if not needed. If 

you are using the Vim editor, it is preconfigured to jump to the next 

field when you press 'n'. If the field is surrounded by '<<' and '>>', 

as in '<<_ACCOUNT_NUMBER_>>', the value you enter will be concealed. 

 

You can create your own templates by adding them to 'account_templates' 

in the ~/.config/avendesora/config file. 

 

You can change the editor used when adding account by changing the 

'edit_template', also found in the ~/.config/avendesora/config file. 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

The default template is {default}. The available templates are: 

{templates} 

 

The available accounts files are: 

{files} 

""").strip() 

def indented_list(l): 

indent = get_setting('indent') 

return indent + ('\n'+indent).join(sorted(l)) 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE, 

default=get_setting('default_account_template'), 

templates=indented_list(get_setting('account_templates').keys()), 

files=indented_list(get_setting('accounts_files', [])), 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

try: 

# get the specified template 

templates = get_setting('account_templates') 

if cmdline['<template>']: 

template_name = cmdline['<template>'] 

else: 

template_name = get_setting('default_account_template') 

template = dedent(templates[template_name]).strip() + '\n' 

 

# save template to tmp file and open it in the editor 

from tempfile import mktemp 

tmpfile = GnuPG(mktemp(suffix='_avendesora.gpg')) 

tmpfile.save(template, get_setting('gpg_ids')) 

GenericEditor.open_and_search(tmpfile.path) 

 

# read the tmp file and determine if it has changed 

new = tmpfile.read() 

tmpfile.remove() 

if new == template: 

return output('Unchanged, and so ignored.') 

 

# hide the values that should be hidden 

def hide(match): 

return 'Hidden(%r)' % Obscure.hide(match.group(1)) 

new = re.sub("<<(.*?)>>", hide, new) 

 

# determine the accounts file 

prefix = cmdline['--file'] 

if prefix: 

candidates = [ 

p 

for p in get_setting('accounts_files') 

if p.startswith(prefix) 

] 

if not candidates: 

raise Error('not found.', cuplrit=cmdline['--file']) 

if len(candidates) > 1: 

raise Error( 

'ambiguous, matches %s.' % conjoin(candidates), 

cuplrit=prefix 

) 

filename = candidates[0] 

else: 

filename = get_setting('accounts_files')[0] 

path = to_path(get_setting('settings_dir'), filename) 

 

# get original contents of accounts file 

orig_accounts_file = PythonFile(path) 

accounts = orig_accounts_file.run() 

gpg_ids = accounts.get('gpg_ids') 

 

# add new account to the contents 

accounts = orig_accounts_file.code + new + '\n' 

 

# rename the original file and then save the new version 

orig_accounts_file.rename('.saved') 

new_accounts_file = GnuPG(path) 

new_accounts_file.save(accounts, gpg_ids) 

except OSError as err: 

error(os_error(err)) 

except KeyError as err: 

error( 

'unknown account template, choose from %s.' % conjoin( 

sorted(templates.keys()) 

), culprit=template_name 

) 

 

 

# Archive {{{1 

class Archive(Command): 

NAMES = 'archive', 'A' 

DESCRIPTION = 'generates archive of all account information' 

USAGE = dedent(""" 

Usage: 

avendesora archive 

avendesora A 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

This command creates an encrypted archive that contains all the 

information in your accounts files, including the fully generated 

secrets. You should never need this file, but its presence protects 

you in case you lose access to Avendesora. To access your secrets 

without Avendesora, simply decrypt the archive file with GPG. The 

actual secrets will be hidden, but it easy to retrieve them even 

without Avendesora. When hidden, the secrets are encoded in base64. 

You can decode it by running 'base64 -d -' and pasting the encoded 

secret into the terminal. 

 

When you run this command it overwrites the existing archive. If you 

have accidentally deleted an account or changed a secret, then 

replacing the archive could cause the last copy of the original 

information to be lost. To prevent this from occurring it is a good 

practice to run the 'changed' command before regenerating the 

archive. It describes all of the changes that have occurred since 

the last time the archive was generated. You should only regenerate 

the archive once you have convinced yourself all of the changes are 

as expected. 

""").strip() 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE, 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

archive_file = get_setting('archive_file') 

 

# first, save existing archive if it exists 

try: 

previous_archive = get_setting('previous_archive_file') 

if previous_archive and archive_file.is_file(): 

rm(previous_archive) 

mv(archive_file, previous_archive) 

except OSError as err: 

raise Error(os_error(err)) 

 

# run the generator 

generator = PasswordGenerator() 

 

# get dictionary that fully describes the contents of each account 

entries = [] 

for account in generator.all_accounts: 

entry = account.archive() 

if entry: 

entries.append(indent('%r: %s,' % ( 

account.get_name(), render(entry) 

), ' ')) 

 

# build file contents 

from .preferences import ARCHIVE_FILE_CONTENTS 

import arrow 

contents = ARCHIVE_FILE_CONTENTS.format( 

encoding = get_setting('encoding'), 

date=str(arrow.now()), 

accounts = '\n\n'.join(entries) 

) 

 

archive = GnuPG(archive_file) 

if not archive.will_encrypt(): 

warn('archive file is not encrypted.', culprit=archive_file) 

try: 

archive.save(contents) 

chmod(0o600, archive_file) 

except OSError as err: 

raise Error(os_error(err), culprit=archive_file) 

 

 

# Browse {{{1 

class Browse(Command): 

NAMES = 'browse', 'b' 

DESCRIPTION = 'open account URL in web browser' 

USAGE = dedent(""" 

Usage: 

avendesora [options] browse <account> [<key>] 

avendesora [options] b <account> [<key>] 

 

Options: 

-b <browser>, --browser <browser> 

Open account in specified browser. 

""").strip() 

 

@classmethod 

def help(cls): 

default_browser = get_setting('default_browser') 

browsers = get_setting('browsers') 

browsers = '\n'.join([ 

two_columns(k, browsers[k].split()[0], width=1) 

for k in sorted(browsers) 

]) 

text = dedent(""" 

{title} 

 

{usage} 

 

The account is examined for URLS, a URL is chosen, and then that URL 

is opened in the chosen browser. First URLS are gathered from the 

'urls' account attribute, which can be a string containing one or 

more URLS, a list, or a dictionary. If 'urls' is a dictionary, the 

desired URL can be chosen by entering the key as an argument to the 

browse command. If a key is not given, then the 'default_url' 

account attribute is used to specify the key to use by default. If 

'urls' is not a dictionary, then the first URL specified is used. 

URLs are also taken from RecognizeURL objects in the 'discovery' 

account attribute. If the 'name' argument is specified, the 

corresponding URL can be chosen using a key. 

 

The default browser is {default}. You can override the default 

browser on a per-account basis by adding an attribute named 

'browser' to the account. An example of when you would specify the 

browser in an account would be an account associated with Tor hidden 

service, which generally can only be accessed using torbrowser: 

 

class SilkRoad(Account): 

passcode = Passphrase() 

username = 'viscount-placebo' 

url = 'http://silkroad6ownowfk.onion' 

browser = 't' 

 

The available browsers are: 

{browsers} 

""").strip() 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE, 

default=default_browser, browsers=browsers 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# determine the account and open the URL 

account = generator.get_account(cmdline['<account>']) 

account.open_browser(cmdline['--browser'], cmdline['<key>']) 

 

# Changed {{{1 

class Changed(Command): 

NAMES = 'changed', 'C' 

DESCRIPTION = 'identify any changes that have occurred since the archive was created' 

USAGE = dedent(""" 

Usage: 

avendesora changed 

avendesora C 

 

When you run the 'archive' command it overwrites the existing 

archive. If you have accidentally deleted an account or changed a 

secret, then replacing the archive could cause the last copy of the 

original information to be lost. To prevent this from occurring it 

is a good practice to run the 'changed' command before regenerating 

the archive. It describes all of the changes that have occurred 

since the last time the archive was generated. You should only 

regenerate the archive once you have convinced yourself all of the 

changes are as expected. 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE, 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# read archive file 

archive_path = get_setting('archive_file') 

f = PythonFile(archive_path) 

archive = f.run() 

import arrow 

created = archive.get('CREATED') 

if created: 

created = arrow.get(created).format('YYYY-MM-DD hh:mm:ss A ZZ') 

output('archive created: %s' % created) 

archive_accounts = archive.get('ACCOUNTS') 

if not archive_accounts: 

raise Error( 

'corrupt archive, ACCOUNTS missing.', culprit=archive_path 

) 

 

# run the generator 

generator = PasswordGenerator() 

 

# determine the account and open the URL 

current_accounts = {} 

for account in generator.all_accounts: 

entry = account.archive() 

if entry: 

current_accounts[account.get_name()] = entry 

 

# report any new or missing accounts 

new = set(current_accounts.keys()) - set(archive_accounts.keys()) 

missing = set(archive_accounts.keys()) - set(current_accounts.keys()) 

for each in sorted(new): 

output('new account:', each) 

for each in sorted(missing): 

output('missing account:', each) 

 

# for the common accounts, report any differences in the fields 

common = set(archive_accounts.keys()) & set(current_accounts.keys()) 

for account_name in sorted(common): 

archive_account = archive_accounts[account_name] 

current_account = current_accounts[account_name] 

 

# report any new or missing fields 

new = set(current_account.keys()) - set(archive_account.keys()) 

missing = set(archive_account.keys()) - set(current_account.keys()) 

for each in sorted(new): 

output(account_name, 'new field', each, sep=': ') 

for each in sorted(missing): 

output(account_name, 'new field', each, sep=': ') 

 

# for the common fields, report any differences in the values 

shared = set(archive_account.keys()) & set(current_account.keys()) 

for field_name in sorted(shared): 

try: 

archive_value = archive_account[field_name] 

current_value = current_account[field_name] 

if is_collection(current_value) != is_collection(archive_value): 

output(account_name, 'field dimension differs', field_name, sep=': ') 

elif is_collection(current_value): 

archive_items = Collection(archive_account[field_name]).items() 

current_items = Collection(current_account[field_name]).items() 

archive_keys = set(k for k, v in archive_items) 

current_keys = set(k for k, v in current_items) 

new = current_keys - archive_keys 

missing = archive_keys - current_keys 

for each in sorted(new): 

output(account_name, field_name, 'new member', each, sep=': ') 

for each in sorted(missing): 

output(account_name, field_name, 'missing member', each, sep=': ') 

for k in sorted(archive_keys & current_keys): 

if str(archive_value[k]) != str(current_value[k]): 

output(account_name, 'member differs', '%s[%s]' % (field_name, k), sep=': ') 

else: 

if dedent(str(archive_value)) != dedent(str(current_value)): 

output(account_name, 'field differs', field_name, sep=': ') 

except Exception: 

error( 

'unanticipated situation.', 

culprit=(account_name, field_name) 

) 

raise 

 

 

# Conceal {{{1 

class Conceal(Command): 

NAMES = 'conceal', 'c' 

DESCRIPTION = 'conceal text by encoding it' 

USAGE = dedent(""" 

Usage: 

avendesora [options] conceal [<text>] 

avendesora [options] c [<text>] 

 

Options: 

-e <encoding>, --encoding <encoding> 

Encoding used when concealing information. 

-s, --symmetric Encrypt with a passphrase rather than using your 

GPG key (only appropriate for gpg encodings). 

""").strip() 

 

@classmethod 

def help(cls): 

encodings = [] 

for name, desc in Obscure.encodings(): 

encodings.append('%s:\n%s' % (name, indent(desc, ' '))) 

encodings = '\n\n'.join(encodings) 

text = dedent(""" 

{title} 

 

{usage} 

 

Possible encodings include{default_encoding}: 

 

{encodings} 

 

Though available as an option for convenience, you should not pass 

the text to be hidden as an argument as it is possible for others to 

examine the commands you run and their argument list. For any 

sensitive secret, you should simply run 'avendesora conceal' and 

then enter the secret text when prompted. 

""").strip() 

default_encoding = Obscure.default_encoding() 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE, encodings=encodings, 

default_encoding=' (default encoding is %s)' % default_encoding, 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# get the text 

text = cmdline['<text>'] 

symmetric = cmdline['--symmetric'] 

if not text: 

output('Enter text to obscure, type ctrl-d to terminate.') 

text = sys.stdin.read()[:-1] 

 

# transform and output the string 

output(Obscure.hide(text, cmdline['--encoding'], True, symmetric)) 

 

 

# Edit {{{1 

class Edit(Command): 

NAMES = 'edit', 'e' 

DESCRIPTION = 'edit an account' 

USAGE = dedent(""" 

Usage: 

avendesora edit <account> 

avendesora e <account> 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

Opens an existing account in your editor. 

 

You can specify the editor by changing the 'edit_account' setting in 

the config file (~/.config/avendesora/config). 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# determine the account and open the URL 

account = generator.get_account(cmdline['<account>']) 

filepath = account._file_info.path 

account_name = account.__name__ 

GenericEditor.open_and_search(filepath, account_name) 

 

 

# Find {{{1 

class Find(Command): 

NAMES = 'find', 'f' 

DESCRIPTION = 'find an account' 

USAGE = dedent(""" 

Find accounts whose name contains the search text. 

 

Usage: 

avendesora find <text> 

avendesora f <text> 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# find accounts whose name matches the criteria 

to_print = [] 

for acct in generator.find_accounts(cmdline['<text>']): 

aliases = Collection(getattr(acct, 'aliases', [])).values() 

 

aliases = ' (%s)' % (', '.join(aliases)) if aliases else '' 

to_print += [acct.get_name() + aliases] 

output(cmdline['<text>']+ ':') 

output(' ' + ('\n '.join(sorted(to_print)))) 

 

 

# Help {{{1 

class Help(Command): 

NAMES = 'help', 'h' 

DESCRIPTION = 'give information about commands or other topics' 

USAGE = dedent(""" 

Usage: 

avendesora help [<topic>] 

avendesora h [<topic>] 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# in this case we don't need to bother with a possibly encrypted logfile 

override_setting('discard_logfile', True) 

 

from .help import HelpMessage 

HelpMessage.show(cmdline['<topic>']) 

 

 

# Initialize {{{1 

class Initialize(Command): 

NAMES = 'initialize', 'I' 

DESCRIPTION = 'create initial set of Avendesora files' 

USAGE = dedent(""" 

Usage: 

avendesora initialize [--gpg-id <id>]... [options] 

avendesora I [--gpg-id <id>]... [options] 

 

Options: 

-g <id>, --gpg-id <id> Use this ID when creating any missing encrypted files. 

-h <path>, --gpg-home <path> 

GPG home directory (default is ~/.gnupg). 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

Create Avendesora data directory (~/.config/avendesora) and populate 

it with initial versions of all essential files. 

 

It is safe to run this command even after the data directory and 

files have been created. Doing so will simply recreate any missing 

files. Existing files are not modified. 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

if cmdline['--gpg-home']: 

override_setting('gpg_home', cmdline['--gpg-home']) 

 

# save the gpg_ids for the logfile in case it is encrypted. 

gpg_ids = cmdline['--gpg-id'] 

if not get_setting('gpg_ids'): 

override_setting('gpg_ids', gpg_ids) 

 

# run the generator 

generator = PasswordGenerator(init=True, gpg_ids=gpg_ids) 

 

 

# New {{{1 

class New(Command): 

NAMES = 'new', 'N' 

DESCRIPTION = 'create new accounts file' 

USAGE = dedent(""" 

Usage: 

avendesora new [--gpg-id <id>]... <name> 

avendesora N [--gpg-id <id>]... <name> 

 

Options: 

-g <id>, --gpg-id <id> Use this ID when creating any missing encrypted files. 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

Creates a new accounts file. Accounts that share the same file share 

the same master password by default and, if the file is encrypted, 

can be decrypted by the same recipients. 

 

Generally you would create a new accounts file for each person or 

group with which you wish to share accounts. You would also use 

separate files for passwords with different security domains. For 

example, a high-value passwords might be placed in an encrypted file 

that would only be placed highly on protected computers. Conversely, 

low-value passwords might be contained in perhaps an unencrypted 

file that is found on many computers. 

 

Add a '.gpg' extension to <name> to encrypt the file. 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# get the gpg ids of those who will be able to decrypt the file 

gpg_ids = cmdline['--gpg-id'] 

if not gpg_ids: 

gpg_ids = get_setting('gpg_ids', []) 

 

# run the generator 

generator = PasswordGenerator( 

init=cmdline['<name>'], gpg_ids=sorted(set(gpg_ids)) 

# docopt sometimes duplicates the gpg_ids 

) 

 

 

# Reveal {{{1 

class Reveal(Command): 

NAMES = 'reveal', 'r' 

DESCRIPTION = 'reveal concealed text' 

USAGE = dedent(""" 

Transform concealed text to reveal its original form. 

 

Usage: 

avendesora reveal [<text>] 

avendesora r [<text>] 

 

Options: 

-e <encoding>, --encoding <encoding> 

Encoding used when revealing information. 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

 

Though available as an option for convenience, you should not pass 

the text to be revealed as an argument as it is possible for others 

to examine the commands you run and their argument list. For any 

sensitive secret, you should simply run 'avendesora reveal' and then 

enter the encoded text when prompted. 

""").strip() 

return text.format( 

title=title(cls.DESCRIPTION), usage=cls.USAGE 

) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# get the text 

text = cmdline['<text>'] 

if not text: 

output('Enter the obscured text, type ctrl-d to terminate.') 

text = sys.stdin.read() 

 

# transform and output the string 

output(Obscure.show(text)) 

 

 

# Search {{{1 

class Search(Command): 

NAMES = 'search', 's' 

DESCRIPTION = 'search accounts' 

USAGE = dedent(""" 

Search for accounts whose values contain the search text. 

 

Usage: 

avendesora search <text> 

avendesora s <text> 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# search for accounts that match search criteria 

to_print = [] 

for acct in generator.search_accounts(cmdline['<text>']): 

aliases = ', '.join(Collection(getattr(acct, 'aliases', [])).values()) 

aliases = ' (%s)' % (aliases) if aliases else '' 

to_print += [acct.get_name() + aliases] 

output(cmdline['<text>']+ ':') 

output(' ' + ('\n '.join(sorted(to_print)))) 

 

 

# Value {{{1 

class Value(Command): 

NAMES = 'value', 'val', 'v' 

DESCRIPTION = 'show an account value' 

USAGE = dedent(""" 

Produce an account value. If the value is secret, it is produced only 

temporarily unless --stdout is specified. 

 

Usage: 

avendesora value [options] [--stdout | --clipboard] [<account> [<field>]] 

avendesora val [options] [--stdout | --clipboard] [<account> [<field>]] 

avendesora v [options] [--stdout | --clipboard] [<account> [<field>]] 

 

Options: 

-c, --clipboard Write output to clipboard rather than stdout. 

-s, --stdout Write output to the standard output without 

any annotation or protections. 

-S, --seed Interactively request additional seed for 

generated secrets. 

-v, --verbose Add additional information to log file to 

help identify issues in account discovery. 

-t <title>, --title <title> 

Use account discovery on this title. 

 

You would request a scalar value by specifying its name after the 

account. For example: 

 

avendesora value pin 

 

If is a composite value, you should also specify a key that indicates 

which of the composite values you want. For example, if the 'accounts' 

field is a dictionary, you would specify accounts.checking or 

accounts[checking] to get information on your checking account. If the 

value is an array, you would give the index of the desired value. For 

example, questions.0 or questions[0]. If you only specify a number, then 

the name is assumed to be 'questions', as in the list of security 

questions (this can be changed by specifying the desired name as the 

'default_vector_field' in the account or the config file). 

 

If no value is requested the result produced is determined by the value 

of the 'default' attribute. If no value is given for 'default', then the 

'passcode' attribute is produced (this can be changed by specifying 

'default_field' in the config file). If 'default' is a script (see 

'avendesora help scripts') then the script is executed. A typical script 

might be 'username: {username}, password: {passcode}'. It is best if the 

script produces a one line output if it contains secrets. If not a 

script, the value of 'default' should be the name of another attribute, 

and the value of that attribute is shown. 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# determine the account and output specified information 

account_name = cmdline['<account>'] 

writer = get_writer( 

bool(account_name), cmdline['--clipboard'], cmdline['--stdout'] 

) 

if account_name: 

account = generator.get_account(account_name, cmdline['--seed']) 

writer.display_field(account, cmdline['<field>']) 

else: 

# use discovery to determine account 

account_name, script = generator.discover_account( 

title=cmdline['--title'], verbose=cmdline['--verbose'] 

) 

account = generator.get_account(account_name) 

writer.run_script(account, script) 

 

 

# Values {{{1 

class Values(Command): 

NAMES = 'values', 'vals', 'V' 

DESCRIPTION = 'display all account values' 

USAGE = dedent(""" 

Show all account values. 

 

Usage: 

avendesora values <account> 

avendesora vals <account> 

avendesora V <account> 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# run the generator 

generator = PasswordGenerator() 

 

# determine the account 

account = generator.get_account(cmdline['<account>']) 

account.write_summary() 

 

# Version {{{1 

class Version(Command): 

NAMES = 'version', 

DESCRIPTION = 'display Avendesora version' 

USAGE = dedent(""" 

Usage: 

avendesora version 

""").strip() 

 

@classmethod 

def help(cls): 

text = dedent(""" 

{title} 

 

{usage} 

""").strip() 

return text.format(title=title(cls.DESCRIPTION), usage=cls.USAGE) 

 

@classmethod 

def run(cls, command, args): 

# read command line 

cmdline = docopt(cls.USAGE, argv=[command] + args) 

 

# output the version 

from .__init__ import __version__, __released__ 

output('Avendesora version: %s (%s).' % (__version__, __released__))