Erik Grinaker is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

erikg / Revelation

Revelation is a password manager for the GNOME desktop, released under the GNU GPL license. It stores all your accounts and passwords in a single, secure place, and gives you access to it through a user-friendly graphical interface.

Clone this repository (size: 2.1 MB): HTTPS / SSH
hg clone https://bitbucket.org/erikg/revelation
hg clone ssh://hg@bitbucket.org/erikg/revelation

Revelation / src / lib / entry.py

  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
#
# Revelation 0.4.0 - a password manager for GNOME 2
# http://oss.codepoet.no/revelation/
# $Id$
#
# Module containing entry information
#
#
# Copyright (c) 2003-2005 Erik Grinaker
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

from revelation import ui

import copy, time


DATATYPE_FILE           = "file"
DATATYPE_EMAIL          = "email"
DATATYPE_PASSWORD       = "password"
DATATYPE_STRING         = "string"
DATATYPE_URL            = "url"



class EntryFieldError(Exception):
        "Exception for invalid entry fields"
        pass


class EntryTypeError(Exception):
        "Exception for invalid entry types"
        pass



class Entry(object):
        "An entry object"

        id              = None
        typename        = ""
        icon            = None

        def __init__(self):
                self.name               = ""
                self.description        = ""
                self.updated            = int(time.time())
                self.fields             = []


        def __getitem__(self, key):
                return self.get_field(key).value


        def __setitem__(self, key, value):
                self.get_field(key).value = value


        def copy(self):
                "Create a copy of the entry"

                return copy.deepcopy(self)


        def get_field(self, fieldtype):
                "Get one of the entrys fields"

                for field in self.fields:
                        if type(field) == fieldtype:
                                return field

                else:
                        raise EntryFieldError


        def has_field(self, fieldtype):
                "Check if the entry has a field"

                try:
                        self.get_field(fieldtype)
                        return True

                except EntryFieldError:
                        return False


        def mirror(self, entry):
                "Makes this entry mirror a different entry (same data)"

                if type(self) != type(entry):
                        raise EntryTypeError

                self.name               = entry.name
                self.description        = entry.description
                self.updated            = entry.updated

                for field in entry.fields:
                        self[type(field)] = field.value



class FolderEntry(Entry):

        id              = "folder"
        typename        = "Folder"
        icon            = ui.STOCK_ENTRY_FOLDER

        def __init__(self):
                Entry.__init__(self)



class CreditcardEntry(Entry):

        id              = "creditcard"
        typename        = "Creditcard"
        icon            = ui.STOCK_ENTRY_CREDITCARD

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        CardtypeField(),
                        CardnumberField(),
                        ExpirydateField(),
                        CCVField(),
                        PINField()
                ]



class CryptoKeyEntry(Entry):

        id              = "cryptokey"
        typename        = "Crypto Key"
        icon            = ui.STOCK_ENTRY_CRYPTOKEY

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        HostnameField(),
                        CertificateField(),
                        KeyfileField(),
                        PasswordField()
                ]



class DatabaseEntry(Entry):

        id              = "database"
        typename        = "Database"
        icon            = ui.STOCK_ENTRY_DATABASE

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        HostnameField(),
                        UsernameField(),
                        PasswordField(),
                        DatabaseField()
                ]



class DoorEntry(Entry):

        id              = "door"
        typename        = "Door lock"
        icon            = ui.STOCK_ENTRY_DOOR

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        LocationField(),
                        CodeField()
                ]



class EmailEntry(Entry):

        id              = "email"
        typename        = "Email"
        icon            = ui.STOCK_ENTRY_EMAIL

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        EmailField(),
                        HostnameField(),
                        UsernameField(),
                        PasswordField()
                ]



class FTPEntry(Entry):

        id              = "ftp"
        typename        = "FTP"
        icon            = ui.STOCK_ENTRY_FTP

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        HostnameField(),
                        PortField(),
                        UsernameField(),
                        PasswordField()
                ]



class GenericEntry(Entry):

        id              = "generic"
        typename        = "Generic"
        icon            = ui.STOCK_ENTRY_GENERIC

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        HostnameField(),
                        UsernameField(),
                        PasswordField()
                ]



class PhoneEntry(Entry):

        id              = "phone"
        typename        = "Phone"
        icon            = ui.STOCK_ENTRY_PHONE

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        PhonenumberField(),
                        PINField()
                ]



class ShellEntry(Entry):

        id              = "shell"
        typename        = "Shell"
        icon            = ui.STOCK_ENTRY_SHELL

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        HostnameField(),
                        DomainField(),
                        UsernameField(),
                        PasswordField()
                ]



class WebEntry(Entry):

        id              = "website"
        typename        = "Website"
        icon            = ui.STOCK_ENTRY_WEBSITE

        def __init__(self):
                Entry.__init__(self)

                self.fields = [
                        URLField(),
                        UsernameField(),
                        PasswordField()
                ]



ENTRYLIST = [
        FolderEntry,
        CreditcardEntry,
        CryptoKeyEntry,
        DatabaseEntry,
        DoorEntry,
        EmailEntry,
        FTPEntry,
        GenericEntry,
        PhoneEntry,
        ShellEntry,
        WebEntry
]



class Field(object):
        "An entry field object"

        id              = None
        name            = ""
        description     = ""
        symbol          = None

        datatype        = None
        value           = None

        def __init__(self, value = ""):
                self.value = value


        def __str__(self):
                return self.value is not None and self.value or ""



class CardnumberField(Field):

        id              = "creditcard-cardnumber"
        name            = "Card number"
        description     = "The number of a creditcard, usually a 16-digit number"
        symbol          = "N"
        datatype        = DATATYPE_STRING



class CardtypeField(Field):

        id              = "creditcard-cardtype"
        name            = "Card type"
        description     = "The type of creditcard, like MasterCard or VISA"
        symbol          = "C"
        datatype        = DATATYPE_STRING



class CCVField(Field):

        id              = "creditcard-ccv"
        name            = "CCV number"
        description     = "A Credit Card Verification number, normally a 3-digit code found on the back of a card"
        symbol          = "V"
        datatype        = DATATYPE_STRING



class CertificateField(Field):

        id              = "generic-certificate"
        name            = "Certificate"
        description     = "A certificate, such as an X.509 SSL Certificate"
        symbol          = "x"
        datatype        = DATATYPE_FILE



class CodeField(Field):

        id              = "generic-code"
        name            = "Code"
        description     = "A code used to provide access to something"
        symbol          = "c"
        datatype        = DATATYPE_PASSWORD



class DatabaseField(Field):

        id              = "generic-database"
        name            = "Database"
        description     = "A database name"
        symbol          = "D"
        datatype        = DATATYPE_STRING



class DomainField(Field):

        id              = "generic-domain"
        name            = "Domain"
        description     = "An Internet or logon domain, like amazon.com or a Windows logon domain"
        symbol          = "d"
        datatype        = DATATYPE_STRING



class EmailField(Field):

        id              = "generic-email"
        name            = "Email"
        description     = "An email address"
        symbol          = "e"
        datatype        = DATATYPE_EMAIL



class ExpirydateField(Field):

        id              = "creditcard-expirydate"
        name            = "Expiry date"
        description     = "The month that the credit card validity expires"
        symbol          = "E"
        datatype        = DATATYPE_STRING



class HostnameField(Field):

        id              = "generic-hostname"
        name            = "Hostname"
        description     = "The name of a computer, like computer.domain.com or MYCOMPUTER"
        symbol          = "h"
        datatype        = DATATYPE_STRING



class KeyfileField(Field):

        id              = "generic-keyfile"
        name            = "Key File"
        description     = "A key file, used for authentication for example via ssh or to encrypt X.509 certificates"
        symbol          = "f"
        datatype        = DATATYPE_FILE



class LocationField(Field):

        id              = "generic-location"
        name            = "Location"
        description     = "A physical location, like office entrance"
        symbol          = "L"
        datatype        = DATATYPE_STRING



class PasswordField(Field):

        id              = "generic-password"
        name            = "Password"
        description     = "A secret word or character combination used for proving you have access"
        symbol          = "p"
        datatype        = DATATYPE_PASSWORD



class PhonenumberField(Field):

        id              = "phone-phonenumber"
        name            = "Phone number"
        description     = "A telephone number"
        symbol          = "n"
        datatype        = DATATYPE_STRING



class PINField(Field):

        id              = "generic-pin"
        name            = "PIN"
        description     = "A Personal Identification Number, a numeric code used for credit cards, phones etc"
        symbol          = "P"
        datatype        = DATATYPE_PASSWORD



class PortField(Field):

        id              = "generic-port"
        name            = "Port number"
        description     = "A network port number, used to access network services directly"
        symbol          = "o"
        datatype        = DATATYPE_STRING



class URLField(Field):

        id              = "generic-url"
        name            = "URL"
        description     = "A Uniform Resource Locator, such as a web-site address"
        symbol          = "U"
        datatype        = DATATYPE_URL



class UsernameField(Field):

        id              = "generic-username"
        name            = "Username"
        description     = "A name or other identification used to identify yourself"
        symbol          = "u"
        datatype        = DATATYPE_STRING



FIELDLIST = [
        CardnumberField,
        CardtypeField,
        CCVField,
        CertificateField,
        CodeField,
        DatabaseField,
        DomainField,
        EmailField,
        ExpirydateField,
        HostnameField,
        KeyfileField,
        LocationField,
        PasswordField,
        PhonenumberField,
        PINField,
        PortField,
        URLField,
        UsernameField
]



def convert_entry_generic(entry):
        "Converts an entry to GenericEntry, tries to keep as much data as possible"

        generic = GenericEntry()
        generic.name = entry.name
        generic.description = entry.description
        generic.updated = entry.updated

        # do direct field copies
        for field in generic.fields:
                if entry.has_field(type(field)):
                        field.value = entry[type(field)]

        # handle special conversions
        if type(entry) == CreditcardEntry:
                generic[UsernameField] = entry[CardnumberField]
                generic[PasswordField] = entry[PINField]

        elif type(entry) == CryptoKeyEntry:
                generic[UsernameField] = entry[KeyfileField]

        elif type(entry) == DatabaseEntry:
                if entry[DatabaseField] != "":
                        generic[HostnameField] = entry[DatabaseField] + "@" + entry[HostnameField]

        elif type(entry) == DoorEntry:
                generic[PasswordField] = entry[CodeField]
                generic[HostnameField] = entry[LocationField]

        elif type(entry) == FTPEntry:
                if entry[PortField] not in ( "", "21" ):
                        generic[HostnameField] += ":" + entry[PortField]

        elif type(entry) == PhoneEntry:
                generic[UsernameField] = entry[PhonenumberField]
                generic[PasswordField] = entry[PINField]

        elif type(entry) == WebEntry:
                generic[HostnameField] = entry[URLField]


        return generic