Exemplo n.º 1
0
    def test_read_simple(self):
        username = "******"
        password = "******"
        comment = u"Created by MiniPyWin32Cred test suite"

        target = u"{0}@{1}".format(username, password)

        r_credentials = {
            u"Type": CRED_TYPE_GENERIC,
            u"TargetName": target,
            u"UserName": username,
            u"CredentialBlob": password,
            u"Comment": comment,
            u"Persist": CRED_PERSIST_ENTERPRISE}
        win32cred.CredWrite(r_credentials)

        credentials = CredRead(target, CRED_TYPE_GENERIC)

        # XXX: the fact that we have to decode the password when reading, but
        # not encode when writing is a bit insane, but that's what pywin32
        # seems to do as well, and we try to be backward compatible here.
        self.assertEqual(credentials["UserName"], username)
        self.assertEqual(credentials["TargetName"], target)
        self.assertEqual(credentials["Comment"], comment)
        self.assertEqual(
            credentials["CredentialBlob"].decode("utf-16"), password)
Exemplo n.º 2
0
 def _set_password(self, target, username, password):
     credential = dict(Type=win32cred.CRED_TYPE_GENERIC,
                       TargetName=target,
                       UserName=username,
                       CredentialBlob=password,
                       Comment="Stored using python-keyring",
                       Persist=win32cred.CRED_PERSIST_ENTERPRISE)
     win32cred.CredWrite(credential, 0)
Exemplo n.º 3
0
 def _vault_store(service, ident, secret):
     target = '%(ident)s@%(service)s' % vars()
     credential = dict(Type=win32cred.CRED_TYPE_GENERIC,
                       TargetName=target,
                       UserName=ident,
                       CredentialBlob=secret,
                       Comment='Stored using tea-crypt',
                       Persist=win32cred.CRED_PERSIST_ENTERPRISE)
     win32cred.CredWrite(credential, 0)
Exemplo n.º 4
0
    'Keyword': 'attr2',
    'Flags': 0,
    'Value': 'character data'
}]
cred = {
    'Comment': 'Created by win32cred_demo.py',
    'UserName': target,
    'TargetAlias': None,
    'TargetName': target,
    'CredentialBlob': pwd,
    'Flags': win32cred.CRED_FLAGS_USERNAME_TARGET,
    'Persist': win32cred.CRED_PERSIST_ENTERPRISE,
    'Type': win32cred.CRED_TYPE_DOMAIN_PASSWORD,
    'Attributes': attrs
}
win32cred.CredWrite(cred)
pwd = None
print win32cred.CredRead(target, win32cred.CRED_TYPE_DOMAIN_PASSWORD)

## Marshal saved credential and use it to log on
mc = win32cred.CredMarshalCredential(win32cred.UsernameTargetCredential,
                                     target)
th = win32security.LogonUser(mc, None, '', win32con.LOGON32_LOGON_INTERACTIVE,
                             win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(th)
print 'GetUserName:'******'s profile.  (first check if user has a roaming profile)
username, domain = win32cred.CredUIParseUserName(target)
user_info_4 = win32net.NetUserGetInfo(None, username, 4)