/
backend.py
857 lines (719 loc) · 27.2 KB
/
backend.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
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
"""
backend.py
Created by Kang Zhang on 2009-07-09
"""
import getpass
import os
import sys
import ConfigParser
import base64
from keyring.util.escape import escape as escape_for_ini
from keyring.util import properties
import keyring.util.platform
import keyring.util.loc_compat
try:
from abc import ABCMeta, abstractmethod, abstractproperty
except ImportError:
# to keep compatible with older Python versions.
class ABCMeta(type):
pass
def abstractmethod(funcobj):
return funcobj
def abstractproperty(funcobj):
return property(funcobj)
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
_KEYRING_SETTING = 'keyring-setting'
_CRYPTED_PASSWORD = 'crypted-password'
_BLOCK_SIZE = 32
_PADDING = '0'
class PasswordSetError(Exception):
"""Raised when the password can't be set.
"""
class KeyringBackend(object):
"""The abstract base class of the keyring, every backend must implement
this interface.
"""
__metaclass__ = ABCMeta
@abstractmethod
def supported(self):
"""Return if this keyring supports current environment:
-1: not applicable
0: suitable
1: recommended
"""
return -1
@abstractmethod
def get_password(self, service, username):
"""Get password of the username for the service
"""
return None
@abstractmethod
def set_password(self, service, username, password):
"""Set password for the username of the service
"""
raise PasswordSetError("reason")
class _ExtensionKeyring(KeyringBackend):
"""_ExtensionKeyring is a adaptor class for the platform related keyring
backends.
"""
def __init__(self):
try:
self.keyring_impl = self._init_backend()
except ImportError:
# keyring is not installed properly
self.keyring_impl = None
def _init_backend(self):
"""Return the keyring implementation handler
"""
return None
def _recommend(self):
"""If this keyring is recommended on current environment.
"""
return False
def supported(self):
"""Override the supported() in KeyringBackend.
"""
if self.keyring_impl is None:
return -1
elif self._recommend():
return 1
return 0
def get_password(self, service, username):
"""Override the get_password() in KeyringBackend.
"""
try:
password = self.keyring_impl.password_get(service, username)
except OSError:
password = None
return password
def set_password(self, service, username, password):
"""Override the set_password() in KeyringBackend.
"""
try:
self.keyring_impl.password_set(service, username, password)
except OSError, e:
raise PasswordSetError(e.message)
class OSXKeychain(_ExtensionKeyring):
"""Mac OS X Keychain"""
def _init_backend(self):
"""Return the handler: osx_keychain
"""
from backends import osx_keychain
return osx_keychain
def _recommend(self):
"""Recommended for all OSX environment.
"""
return sys.platform == 'darwin'
class GnomeKeyring(KeyringBackend):
"""Gnome Keyring"""
# Name of the keyring to store the passwords in.
# Use None for the default keyring.
KEYRING_NAME = None
def supported(self):
try:
import gnomekeyring
except ImportError:
return -1
else:
if ("GNOME_KEYRING_CONTROL" in os.environ and
"DISPLAY" in os.environ and
"DBUS_SESSION_BUS_ADDRESS" in os.environ):
return 1
else:
return 0
def get_password(self, service, username):
"""Get password of the username for the service
"""
import gnomekeyring
try:
items = gnomekeyring.find_network_password_sync(username, service)
except gnomekeyring.NoMatchError:
return None
except gnomekeyring.CancelledError:
# The user pressed "Cancel" when prompted to unlock their keyring.
return None
assert len(items) == 1, 'no more than one entry should ever match'
return items[0]['password']
def set_password(self, service, username, password):
"""Set password for the username of the service
"""
import gnomekeyring
try:
gnomekeyring.item_create_sync(
self.KEYRING_NAME, gnomekeyring.ITEM_NETWORK_PASSWORD,
"Password for '%s' on '%s'" % (username, service),
{'user': username, 'domain': service},
password, True)
except gnomekeyring.CancelledError:
# The user pressed "Cancel" when prompted to unlock their keyring.
raise PasswordSetError("cancelled by user")
class SecretServiceKeyring(KeyringBackend):
"""Secret Service Keyring"""
def supported(self):
try:
import dbus
except ImportError:
return -1
try:
bus = dbus.SessionBus()
bus.get_object('org.freedesktop.secrets',
'/org/freedesktop/secrets')
except dbus.exceptions.DBusException:
return -1
else:
return 1
def get_password(self, service, username):
"""Get password of the username for the service
"""
import dbus
bus = dbus.SessionBus()
service_obj = bus.get_object('org.freedesktop.secrets',
'/org/freedesktop/secrets')
service_iface = dbus.Interface(service_obj,
'org.freedesktop.Secret.Service')
unlocked, locked = service_iface.SearchItems(
{"username": username, "service": service})
_, session = service_iface.OpenSession("plain", "")
no_longer_locked, prompt = service_iface.Unlock(locked)
assert prompt == "/"
secrets = service_iface.GetSecrets(unlocked + locked, session)
for item_path, secret in secrets.iteritems():
return "".join([str(x) for x in secret[2]])
return None
def set_password(self, service, username, password):
"""Set password for the username of the service
"""
import dbus
bus = dbus.SessionBus()
service_obj = bus.get_object('org.freedesktop.secrets',
'/org/freedesktop/secrets')
service_iface = dbus.Interface(service_obj,
'org.freedesktop.Secret.Service')
collection_obj = bus.get_object(
'org.freedesktop.secrets',
'/org/freedesktop/secrets/aliases/default')
collection = dbus.Interface(collection_obj,
'org.freedesktop.Secret.Collection')
attributes = {
"service": service,
"username": username
}
_, session = service_iface.OpenSession("plain", "")
if isinstance(password, unicode):
password = password.encode('utf-8')
secret = dbus.Struct(
(session, "", dbus.ByteArray(password), "text/plain"))
properties = {
"org.freedesktop.Secret.Item.Label": "%s @ %s" % (
username, service),
"org.freedesktop.Secret.Item.Attributes": attributes}
(item, prompt) = collection.CreateItem(properties, secret,
True)
assert prompt == "/"
kwallet = None
def open_kwallet(kwallet_module=None, qt_module=None):
# If we specified the kwallet_module and/or qt_module, surely we won't need
# the cached kwallet object...
if kwallet_module is None and qt_module is None:
global kwallet
if not kwallet is None:
return kwallet
# Allow for the injection of module-like objects for testing purposes.
if kwallet_module is None:
kwallet_module = KWallet.Wallet
if qt_module is None:
qt_module = QtGui
# KDE wants us to instantiate an application object.
app = None
if qt_module.qApp.instance() == None:
app = qt_module.QApplication([])
try:
window = qt_module.QWidget()
kwallet = kwallet_module.openWallet(
kwallet_module.NetworkWallet(),
window.winId(),
kwallet_module.Synchronous)
if kwallet is not None:
if not kwallet.hasFolder('Python'):
kwallet.createFolder('Python')
kwallet.setFolder('Python')
return kwallet
finally:
if app:
app.exit()
try:
from PyKDE4.kdeui import KWallet
from PyQt4 import QtGui
except ImportError:
kwallet_support = False
else:
kwallet_support = True
class KDEKWallet(KeyringBackend):
"""KDE KWallet"""
def supported(self):
if kwallet_support and os.environ.has_key('KDE_SESSION_UID'):
return 1
elif kwallet_support:
return 0
else:
return -1
def get_password(self, service, username):
"""Get password of the username for the service
"""
key = username + '@' + service
network = KWallet.Wallet.NetworkWallet()
wallet = open_kwallet()
if wallet.keyDoesNotExist(network, 'Python', key):
return None
result = wallet.readPassword(key)[1]
# The string will be a PyQt4.QtCore.QString, so turn it into a unicode
# object.
return unicode(result)
def set_password(self, service, username, password):
"""Set password for the username of the service
"""
wallet = open_kwallet()
wallet.writePassword(username+'@'+service, password)
class BasicFileKeyring(KeyringBackend):
"""BasicFileKeyring is a file-based implementation of keyring.
It stores the password directly in the file, and supports the
encryption and decryption. The encrypted password is stored in base64
format.
"""
@properties.NonDataProperty
def file_path(self):
"""
The path to the file where passwords are stored. This property
may be overridden by the subclass or at the instance level.
"""
return os.path.join(keyring.util.platform.data_root(), self.filename)
@abstractproperty
def filename(self):
"""The filename used to store the passwords.
"""
pass
@abstractmethod
def encrypt(self, password):
"""Encrypt the password.
"""
pass
@abstractmethod
def decrypt(self, password_encrypted):
"""Decrypt the password.
"""
pass
def _relocate_file(self):
old_location = os.path.join(os.path.expanduser('~'), self.filename)
new_location = self.file_path
keyring.util.loc_compat.relocate_file(old_location, new_location)
# disable this function - it only needs to be run once
self._relocate_file = lambda: None
def get_password(self, service, username):
"""Read the password from the file.
"""
self._relocate_file()
service = escape_for_ini(service)
username = escape_for_ini(username)
# load the passwords from the file
config = ConfigParser.RawConfigParser()
if os.path.exists(self.file_path):
config.read(self.file_path)
# fetch the password
try:
password_base64 = config.get(service, username).encode()
# decode with base64
password_encrypted = base64.decodestring(password_base64)
# decrypted the password
password = self.decrypt(password_encrypted).decode('utf-8')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
password = None
return password
def set_password(self, service, username, password):
"""Write the password in the file.
"""
self._relocate_file()
service = escape_for_ini(service)
username = escape_for_ini(username)
# encrypt the password
password_encrypted = self.encrypt(password.encode('utf-8'))
# load the password from the disk
config = ConfigParser.RawConfigParser()
if os.path.exists(self.file_path):
config.read(self.file_path)
# encode with base64
password_base64 = base64.encodestring(password_encrypted).decode()
# write the modification
if not config.has_section(service):
config.add_section(service)
config.set(service, username, password_base64)
# ensure the storage path exists
if not os.path.isdir(os.path.dirname(self.file_path)):
os.makedirs(os.path.dirname(self.file_path))
config_file = open(self.file_path,'w')
config.write(config_file)
class UncryptedFileKeyring(BasicFileKeyring):
"""Uncrypted File Keyring"""
filename = 'keyring_pass.cfg'
def encrypt(self, password):
"""Directly return the password itself.
"""
return password
def decrypt(self, password_encrypted):
"""Directly return encrypted password.
"""
return password_encrypted
def supported(self):
"""Applicable for all platforms, but do not recommend.
"""
return 0
class CryptedFileKeyring(BasicFileKeyring):
"""PyCrypto File Keyring"""
filename = 'crypted_pass.cfg'
def supported(self):
"""Applicable for all platforms, but not recommend"
"""
try:
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Random import get_random_bytes
status = 0
except ImportError:
status = -1
return status
def _getpass(self, *args, **kwargs):
"""Wrap getpass.getpass(), so that we can override it when testing.
"""
return getpass.getpass(*args, **kwargs)
def _init_file(self):
"""Init the password file, set the password for it.
"""
password = None
while password is None:
password = self._getpass("Please set a password for your new keyring")
password2 = self._getpass('Password (again): ')
if password != password2:
sys.stderr.write("Error: Your passwords didn't match\n")
password = None
continue
if '' == password.strip():
# forbid the blank password
sys.stderr.write("Error: blank passwords aren't allowed.\n")
password = None
# write down the initialization
config = ConfigParser.RawConfigParser()
self._write_config(config, password)
def _create_cipher(self, password, salt, IV):
"""Create the cipher object to encrypt or decrypt the keyring.
"""
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Cipher import AES
pw = PBKDF2(password, salt, dkLen=_BLOCK_SIZE)
return AES.new(pw[:_BLOCK_SIZE], AES.MODE_CFB, IV)
def _write_config(self, config, keyring_password):
"""Write the keyring with the given password.
"""
config_file = StringIO()
config.write(config_file)
config_file.seek(0)
from Crypto.Random import get_random_bytes
salt = get_random_bytes(_BLOCK_SIZE)
from Crypto.Cipher import AES
IV = get_random_bytes(AES.block_size)
cipher = self._create_cipher(keyring_password, salt, IV)
if not os.path.isdir(os.path.dirname(self.file_path)):
os.makeidrs(os.path.dirname(self.file_path))
encrypted_config_file = open(self.file_path, 'w')
encrypted_config_file.write((salt + IV).encode('base64'))
encrypted_config_file.write(cipher.encrypt(config_file.read()).encode('base64'))
encrypted_config_file.close()
def _convert_old_keyring(self, keyring_password=None):
"""Convert keyring to new format.
"""
config_file = open(self.file_path, 'r')
config = ConfigParser.RawConfigParser()
config.readfp(config_file)
config_file.close()
if keyring_password is None:
keyring_password = self._getpass("Please input your password for the keyring: ")
import crypt
hashed = crypt.crypt(keyring_password, keyring_password)
if config.get(_KEYRING_SETTING, _CRYPTED_PASSWORD) != hashed:
sys.stderr.write("Wrong password for the keyring.\n")
raise ValueError("Wrong password")
from Crypto.Cipher import AES
password = keyring_password + (_BLOCK_SIZE - len(keyring_password) % _BLOCK_SIZE) * _PADDING
config.remove_option(_KEYRING_SETTING, _CRYPTED_PASSWORD)
for section in config.sections():
for opt in config.options(section):
cipher = AES.new(password, AES.MODE_CFB, '\0' * AES.block_size)
p = config.get(section, opt).decode()
p = cipher.decrypt(p.decode('base64'))
config.set(section, opt, p)
self._write_config(config, keyring_password)
return (config, keyring_password)
def _read_config(self, keyring_password=None):
"""Read the keyring.
"""
# load the passwords from the file
if not os.path.exists(self.file_path):
self._init_file()
encrypted_config_file = open(self.file_path, 'r')
salt = encrypted_config_file.readline()
if salt[0] == '[':
encrypted_config_file.close()
return self._convert_old_keyring(keyring_password)
data = salt.decode('base64')
salt = data[:_BLOCK_SIZE]
IV = data[_BLOCK_SIZE:]
data = encrypted_config_file.read().decode('base64')
encrypted_config_file.close()
if keyring_password is None:
keyring_password = self._getpass("Please input your password for the keyring: ")
cipher = self._create_cipher(keyring_password, salt, IV)
config_file = StringIO(cipher.decrypt(data))
config = ConfigParser.RawConfigParser()
try:
config.readfp(config_file)
except ConfigParser.Error:
sys.stderr.write("Wrong password for the keyring.\n")
raise ValueError("Wrong password")
return (config, keyring_password)
def get_password(self, service, username):
"""Read the password from the file.
"""
self._relocate_file()
service = escape_for_ini(service)
username = escape_for_ini(username)
# load the passwords from the file
if not os.path.exists(self.file_path):
self._init_file()
config, keyring_password = self._read_config()
# fetch the password
try:
password = config.get(service, username)
password = password.decode('utf-8')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
password = None
return password
def set_password(self, service, username, password):
"""Save the password in the file.
"""
self._relocate_file()
service = escape_for_ini(service)
username = escape_for_ini(username)
config, keyring_password = self._read_config()
password = password.encode('utf-8')
# write the modification
if not config.has_section(service):
config.add_section(service)
config.set(service, username, password)
self._write_config(config, keyring_password)
def encrypt(self, password):
raise NotImplementedError()
def decrypt(self, password_encrypted):
raise NotImplementedError()
class Win32CryptoKeyring(BasicFileKeyring):
"""Win32 Cryptography Keyring"""
filename = 'wincrypto_pass.cfg'
def __init__(self):
super(Win32CryptoKeyring, self).__init__()
try:
from backends import win32_crypto
self.crypt_handler = win32_crypto
except ImportError:
self.crypt_handler = None
def supported(self):
"""Recommended when other Windows backends are unavailable
"""
recommended = select_windows_backend()
if recommended == None:
return -1
elif recommended == 'file':
return 1
else:
return 0
def encrypt(self, password):
"""Encrypt the password using the CryptAPI.
"""
return self.crypt_handler.encrypt(password)
def decrypt(self, password_encrypted):
"""Decrypt the password using the CryptAPI.
"""
return self.crypt_handler.decrypt(password_encrypted)
class WinVaultKeyring(KeyringBackend):
"""
WinVaultKeyring stores encrypted passwords using the Windows Credential
Manager.
Requires pywin32
This backend does some gymnastics to simulate multi-user support,
which WinVault doesn't support natively. See
https://bitbucket.org/kang/python-keyring-lib/issue/47/winvaultkeyring-only-ever-returns-last#comment-731977
for details on the implementation, but here's the gist:
Passwords are stored under the service name unless there is a collision
(another password with the same service name but different user name),
in which case the previous password is moved into a compound name:
{username}@{service}
"""
def __init__(self):
super(WinVaultKeyring, self).__init__()
try:
import pywintypes
import win32cred
self.win32cred = win32cred
self.pywintypes = pywintypes
except ImportError:
self.win32cred = None
def supported(self):
'''Default Windows backend, when it is available
'''
recommended = select_windows_backend()
if recommended == None:
return -1
elif recommended == 'cred':
return 1
else:
return 0
@staticmethod
def _compound_name(username, service):
return u'%(username)s@%(service)s' % vars()
def get_password(self, service, username):
# first attempt to get the password under the service name
res = self._get_password(service)
if not res or res['UserName'] != username:
# It wasn't found so attempt to get it with the compound name
res = self._get_password(self._compound_name(username, service))
if not res:
return None
blob = res['CredentialBlob']
return blob.decode('utf-16')
def _get_password(self, target):
try:
res = self.win32cred.CredRead(
Type=self.win32cred.CRED_TYPE_GENERIC,
TargetName=target,
)
except self.pywintypes.error, e:
if e.winerror == 1168 and e.funcname == 'CredRead': # not found
return None
raise
return res
def set_password(self, service, username, password):
existing_pw = self._get_password(service)
if existing_pw:
# resave the existing password using a compound target
existing_username = existing_pw['UserName']
target = self._compound_name(existing_username, service)
self._set_password(target, existing_username,
existing_pw['CredentialBlob'].decode('utf-16'))
self._set_password(service, username, unicode(password))
def _set_password(self, target, username, password):
credential = dict(Type=self.win32cred.CRED_TYPE_GENERIC,
TargetName=target,
UserName=username,
CredentialBlob=password,
Comment="Stored using python-keyring",
Persist=self.win32cred.CRED_PERSIST_ENTERPRISE)
self.win32cred.CredWrite(credential, 0)
def delete_password(self, service, username):
compound = self._compound_name(username, service)
for target in service, compound:
existing_pw = self._get_password(target)
if existing_pw and existing_pw['UserName'] == username:
self._delete_password(target)
def _delete_password(self, target):
self.win32cred.CredDelete(
Type=self.win32cred.CRED_TYPE_GENERIC,
TargetName=target,
)
class Win32CryptoRegistry(KeyringBackend):
"""Win32CryptoRegistry is a keyring which use Windows CryptAPI to encrypt
the user's passwords and store them under registry keys
"""
def __init__(self):
super(Win32CryptoRegistry, self).__init__()
try:
from backends import win32_crypto
import _winreg
self.crypt_handler = win32_crypto
except ImportError:
self.crypt_handler = None
def supported(self):
"""Return if this keyring supports current enviroment.
-1: not applicable
0: suitable
1: recommended
"""
recommended = select_windows_backend()
if recommended == None:
return -1
elif recommended == 'reg':
return 1
else:
return 0
def get_password(self, service, username):
"""Get password of the username for the service
"""
from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx
try:
# fetch the password
key = r'Software\%s\Keyring' % service
hkey = OpenKey(HKEY_CURRENT_USER, key)
password_base64 = QueryValueEx(hkey, username)[0]
# decode with base64
password_encrypted = base64.decodestring(password_base64)
# decrypted the password
password = self.crypt_handler.decrypt(password_encrypted)
except EnvironmentError:
password = None
return password
def set_password(self, service, username, password):
"""Write the password to the registry
"""
# encrypt the password
password_encrypted = self.crypt_handler.encrypt(password)
# encode with base64
password_base64 = base64.encodestring(password_encrypted)
# store the password
from _winreg import HKEY_CURRENT_USER, CreateKey, SetValueEx, REG_SZ
hkey = CreateKey(HKEY_CURRENT_USER, r'Software\%s\Keyring' % service)
SetValueEx(hkey, username, 0, REG_SZ, password_base64)
def select_windows_backend():
if os.name != 'nt':
return None
major, minor, build, platform, text = sys.getwindowsversion()
try:
import pywintypes
import win32cred
if (major, minor) >= (5, 1):
# recommend for windows xp+
return 'cred'
except ImportError:
pass
try:
from backends import win32_crypto
import _winreg
if (major, minor) >= (5, 0):
# recommend for windows 2k+
return 'reg'
except ImportError:
pass
try:
from backends import win32_crypto
return 'file'
except ImportError:
pass
return None
_all_keyring = None
def get_all_keyring():
"""Return the list of all keyrings in the lib
"""
global _all_keyring
if _all_keyring is None:
_all_keyring = [OSXKeychain(), GnomeKeyring(), KDEKWallet(),
CryptedFileKeyring(), UncryptedFileKeyring(),
Win32CryptoKeyring(), Win32CryptoRegistry(),
WinVaultKeyring(), SecretServiceKeyring()]
return _all_keyring