summaryrefslogtreecommitdiff
path: root/src/leap/eip/exceptions.py
blob: b7d398c3ed33532b9b704e01bb688dfff668db2a (plain)
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
"""
Generic error hierarchy
Leap/EIP exceptions used for exception handling,
logging, and notifying user of errors
during leap operation.

Exception hierarchy
-------------------
All EIP Errors must inherit from EIPClientError (note: move that to
a more generic LEAPClientBaseError).

Exception attributes and their meaning/uses
-------------------------------------------

* critical:    if True, will abort execution prematurely,
               after attempting any cleaning
               action.

* failfirst:   breaks any error_check loop that is examining
               the error queue.

* message:     the message that will be used in the __repr__ of the exception.

* usermessage: the message that will be passed to user in ErrorDialogs
               in Qt-land.

TODO:

* EIPClientError:
  Should inherit from LeapException

* gettext / i18n for user messages.

"""
from leap.base.exceptions import LeapException
from leap.util.translations import translate


# This should inherit from LeapException
class EIPClientError(Exception):
    """
    base EIPClient exception
    """
    critical = False
    failfirst = False
    warning = False


class CriticalError(EIPClientError):
    """
    we cannot do anything about it, sorry
    """
    critical = True
    failfirst = True


class Warning(EIPClientError):
    """
    just that, warnings
    """
    warning = True


class EIPNoPolkitAuthAgentAvailable(CriticalError):
    message = "No polkit authentication agent could be found"
    usermessage = translate(
        "EIPErrors",
        "We could not find any authentication "
        "agent in your system.<br/>"
        "Make sure you have "
        "<b>polkit-gnome-authentication-agent-1</b> "
        "running and try again.")


class EIPNoPkexecAvailable(Warning):
    message = "No pkexec binary found"
    usermessage = translate(
        "EIPErrors",
        "We could not find <b>pkexec</b> in your "
        "system.<br/> Do you want to try "
        "<b>setuid workaround</b>? "
        "(<i>DOES NOTHING YET</i>)")
    failfirst = True


class EIPNoCommandError(EIPClientError):
    message = "no suitable openvpn command found"
    usermessage = translate(
        "EIPErrors",
        "No suitable openvpn command found. "
        "<br/>(Might be a permissions problem)")


class EIPBadCertError(Warning):
    # XXX this should be critical and fail close
    message = "cert verification failed"
    usermessage = translate(
        "EIPErrors",
        "there is a problem with provider certificate")


class LeapBadConfigFetchedError(Warning):
    message = "provider sent a malformed json file"
    usermessage = translate(
        "EIPErrors",
        "an error occurred during configuratio of leap services")


class OpenVPNAlreadyRunning(CriticalError):
    message = "Another OpenVPN Process is already running."
    usermessage = translate(
        "EIPErrors",
        "Another OpenVPN Process has been detected. "
        "Please close it before starting leap-client")


class HttpsNotSupported(LeapException):
    message = "connection refused while accessing via https"
    usermessage = translate(
        "EIPErrors",
        "Server does not allow secure connections")


class HttpsBadCertError(LeapException):
    message = "verification error on cert"
    usermessage = translate(
        "EIPErrors",
        "Server certificate could not be verified")

#
# errors still needing some love
#


class EIPInitNoKeyFileError(CriticalError):
    message = "No vpn keys found in the expected path"
    usermessage = translate(
        "EIPErrors",
        "We could not find your eip certs in the expected path")


class EIPInitBadKeyFilePermError(Warning):
    # I don't know if we should be telling user or not,
    # we try to fix permissions and should only re-raise
    # if permission check failed.
    pass


class EIPInitNoProviderError(EIPClientError):
    pass


class EIPInitBadProviderError(EIPClientError):
    pass


class EIPConfigurationError(EIPClientError):
    pass

#
# Errors that probably we don't need anymore
# chase down for them and check.
#


class MissingSocketError(Exception):
    pass


class ConnectionRefusedError(Exception):
    pass


class EIPMissingDefaultProvider(Exception):
    pass