~bzr/ubuntu/intrepid/bzr-svn/bzr-ppa

« back to all changes in this revision

Viewing changes to auth.py

  • Committer: Gary van der Merwe
  • Date: 2010-02-11 01:38:09 UTC
  • mfrom: (309.2.49 unstable)
  • Revision ID: garyvdm@gmail.com-20100211013809-19kwah9hz03o3ujl
  * Merge debian unstable (1.0.2-2)
      [ Jelmer Vernooij ]
      * New upstream release.
      * Mark as compatible with Bazaar 2.1.
      * Bump standards version to 3.8.4.
      * Remove Reinhard from uploaders. Closes: #565128
      * Allow python-sqlite to not be installed if python-tdb is installed.: 1.0.2-2~bazaar2~intrepid1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005-2009 Jelmer Vernooij <jelmer@samba.org>
2
 
 
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
28
28
    AuthenticationConfig,
29
29
    CredentialStore,
30
30
    )
31
 
from bzrlib.errors import (
32
 
    BzrError,
33
 
    )
34
31
from bzrlib.trace import (
35
32
    mutter,
36
33
    )
40
37
 
41
38
AUTH_PARAM_DEFAULT_USERNAME = getattr(subvertpy, "AUTH_PARAM_DEFAULT_USERNAME",
42
39
                                      'svn:auth:username')
43
 
AUTH_PARAM_DEFAULT_PASSWORD = getattr(subvertpy, "AUTH_PARAM_DEFAULT_PASSWORD", 
 
40
AUTH_PARAM_DEFAULT_PASSWORD = getattr(subvertpy, "AUTH_PARAM_DEFAULT_PASSWORD",
44
41
                                      'svn:auth:password')
45
42
 
46
43
SSL_NOTYETVALID = getattr(subvertpy, "SSL_NOTYETVALID", 0x00000001)
51
48
 
52
49
 
53
50
class SubversionAuthenticationConfig(AuthenticationConfig):
54
 
    """Simple extended version of AuthenticationConfig that can provide 
 
51
    """Simple extended version of AuthenticationConfig that can provide
55
52
    the information Subversion requires.
56
53
    """
57
54
    def __init__(self, scheme, host, port, path, file=None):
63
60
        self.host = host
64
61
        self.port = port
65
62
        self.path = path
66
 
       
 
63
 
67
64
    def get_svn_username(self, realm, may_save):
68
65
        """Look up a Subversion user name in the Bazaar authentication cache.
69
66
 
71
68
        :param may_save: Whether or not the username should be saved.
72
69
        """
73
70
        mutter("Obtaining username for SVN connection")
74
 
        username = self.get_user(self.scheme, host=self.host, path=self.path, 
 
71
        username = self.get_user(self.scheme, host=self.host, path=self.path,
75
72
                                 realm=realm, ask=True)
76
73
        return (username.encode('utf-8'), False)
77
74
 
78
75
    def get_svn_simple(self, realm, username, may_save):
79
 
        """Look up a Subversion user name+password combination in the Bazaar 
 
76
        """Look up a Subversion user name+password combination in the Bazaar
80
77
        authentication cache.
81
78
 
82
79
        :param realm: Authentication realm (optional)
85
82
        """
86
83
        mutter("Obtaining username and password for SVN connection %r"
87
84
               "(username: %r)", realm, username)
88
 
        username = self.get_user(self.scheme, 
 
85
        username = self.get_user(self.scheme,
89
86
                host=self.host, path=self.path, realm=realm, ask=True)
90
 
        password = self.get_password(self.scheme, host=self.host, 
91
 
            path=self.path, user=username, 
 
87
        password = self.get_password(self.scheme, host=self.host,
 
88
            path=self.path, user=username,
92
89
            realm=realm, prompt="%s %s password" % (realm, username))
 
90
        assert type(password) == str
93
91
        return (username.encode("utf-8"), password, False)
94
92
 
95
93
    def get_svn_ssl_server_trust(self, realm, failures, cert_info, may_save):
102
100
        """
103
101
        mutter("Verifying SSL server: %s", realm)
104
102
        credentials = self.get_credentials(self.scheme, host=self.host)
105
 
        if (credentials is not None and 
106
 
            credentials.has_key("verify_certificates") and 
 
103
        if (credentials is not None and
 
104
            credentials.has_key("verify_certificates") and
107
105
            credentials["verify_certificates"] == False):
108
106
            accepted_failures = (
109
 
                    SSL_NOTYETVALID + 
 
107
                    SSL_NOTYETVALID +
110
108
                    SSL_EXPIRED +
111
109
                    SSL_CNMISMATCH +
112
110
                    SSL_UNKNOWNCA +
116
114
        return (accepted_failures, False)
117
115
 
118
116
    def get_svn_username_prompt_provider(self, retries):
119
 
        """Return a Subversion auth provider for retrieving the username, as 
 
117
        """Return a Subversion auth provider for retrieving the username, as
120
118
        accepted by svn_auth_open().
121
 
        
 
119
 
122
120
        :param retries: Number of allowed retries.
123
121
        """
124
 
        return ra.get_username_prompt_provider(self.get_svn_username, 
 
122
        return ra.get_username_prompt_provider(self.get_svn_username,
125
123
                                                     retries)
126
124
 
127
125
    def get_svn_simple_prompt_provider(self, retries):
128
 
        """Return a Subversion auth provider for retrieving a 
 
126
        """Return a Subversion auth provider for retrieving a
129
127
        username+password combination, as accepted by svn_auth_open().
130
 
        
 
128
 
131
129
        :param retries: Number of allowed retries.
132
130
        """
133
131
        return ra.get_simple_prompt_provider(self.get_svn_simple, retries)
134
132
 
135
133
    def get_svn_ssl_server_trust_prompt_provider(self):
136
 
        """Return a Subversion auth provider for checking 
 
134
        """Return a Subversion auth provider for checking
137
135
        whether a SSL server is trusted."""
138
136
        return ra.get_ssl_server_trust_prompt_provider(
139
137
            self.get_svn_ssl_server_trust)
184
182
 
185
183
def create_auth_baton(url):
186
184
    """Create an authentication baton for the specified URL.
187
 
    
 
185
 
188
186
    :param url: URL to create auth baton for.
189
187
    """
190
188
    assert isinstance(url, str)
224
222
            try:
225
223
                credentials['port'] = socket.getservbyname(credentials['scheme'])
226
224
            except socket.error:
227
 
                mutter("Unable to look up default port for %(scheme)s" % 
 
225
                mutter("Unable to look up default port for %(scheme)s" %
228
226
                       credentials)
229
227
                return None
230
228
        return "<%(scheme)s://%(host)s:%(port)s> %(realm)s" % credentials
238
236
            (username, password, may_save) = creds.next()
239
237
        except StopIteration:
240
238
            return None
 
239
        assert type(password) == str
241
240
        if credentials.get("user") not in (username, None):
242
241
            # Subversion changed the username
243
242
            return None
244
243
        return password
245
244
 
246
 
    def get_credentials(self, scheme, host, port=None, user=None, path=None, 
 
245
    def get_credentials(self, scheme, host, port=None, user=None, path=None,
247
246
                        realm=None):
248
247
        assert isinstance(realm, str) or realm is None
249
 
        credentials = { "scheme": scheme, "host": host, "port": port, 
 
248
        credentials = { "scheme": scheme, "host": host, "port": port,
250
249
            "realm": realm, "user": user}
251
250
        svn_realm = self._get_realm(credentials)
252
251
        if svn_realm is None: