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
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# $Id$
#
# PyLasso - Python bindings for Lasso Library
#
# Copyright (C) 2003-2004 Easter-eggs, Valery Febvre
# http://lasso.labs.libre-entreprise.org
#
# Author: Valery Febvre <vfebvre@easter-eggs.com>
#
# 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
__docformat__ = "plaintext en"
import lassomod
from lasso_strings import *
class Error(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return repr(self.msg)
def init():
"""
"""
return lassomod.init()
def shutdown():
"""
Shutdown Lasso Library
"""
return lassomod.shutdown()
################################################################################
# xml : low level classes
################################################################################
class Node:
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
## #self._o = lassomod.(size)
## if self._o is None: raise Error('lasso_node_new() failed')
def dump(self, encoding="utf8", format=1):
return lassomod.node_dump(self, encoding, format)
def destroy(self):
lassomod.node_unref(self)
def get_attr_value(self, name):
return lassomod.node_get_attr_value(self, name)
def get_child(self, name):
return Node(_obj=lassomod.node_get_child(self, name))
def url_encode(self, sign_method, private_key_file):
return lassomod.node_url_encode(self, sign_method, private_key_file)
def verify_signature(self, certificate_file):
return lassomod.node_verify_signature(self, certificate_file)
class LibAuthnRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_authn_request_new()
if _obj is None: raise Error('lasso_lib_authn_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_forceAuthn(self, forceAuthn):
lassomod.lib_authn_request_set_forceAuthn(self, forceAuthn)
def set_isPassive(self, isPassive):
lassomod.lib_authn_request_set_isPassive(self, isPassive)
def set_nameIDPolicy(self, nameIDPolicy):
lassomod.lib_authn_request_set_nameIDPolicy(self, nameIDPolicy)
def set_protocolProfile(self, protocolProfile):
lassomod.lib_authn_request_set_protocolProfile(self, protocolProfile)
def set_relayState(self, relayState):
lassomod.lib_authn_request_set_relayState(self, relayState)
class LibFederationTerminationNotification(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_federation_termination_notification_new()
if _obj is None:
raise Error('lasso_lib_federation_termination_notification_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_federation_termination_notification_set_consent(self, consent)
class LibLogoutRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_logout_request_new()
if _obj is None: raise Error('lasso_lib_logout_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_logout_request_set_consent(self, consent)
def set_nameIdentifier(self, nameIdentifier):
lassomod.lib_logout_request_set_nameIdentifier(self, nameIdentifier)
def set_providerID(self, providerID):
lassomod.lib_logout_request_set_providerID(self, providerID)
def set_relayState(self, relayState):
lassomod.lib_logout_request_set_relayState(self, relayState)
def set_sessionIndex(self, sessionIndex):
lassomod.lib_logout_request_set_sessionIndex(self, sessionIndex)
class LibNameIdentifierMappingRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_name_identifier_mapping_request_new()
if _obj is None:
raise Error('lasso_lib_name_identifier_mapping_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_name_identifier_mapping_request_set_consent(self, consent)
class SamlAssertion(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_assertion_new()
if _obj is None: raise Error('lasso_saml_assertion_new() failed')
Node.__init__(self, _obj=_obj)
def add_authenticationStatement(self, authenticationStatement):
lassomod.saml_assertion_add_authenticationStatement(self,
authenticationStatement)
class SamlAuthenticationStatement(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_authentication_statement_new()
if _obj is None: raise Error('lasso_saml_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
class SamlNameIdentifier(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_name_identifier_new()
if _obj is None: raise Error('lasso_saml_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
def set_format(self, format):
lassomod.saml_name_identifier_set_format(self, format)
def set_nameQualifier(self, nameQualifier):
lassomod.saml_name_identifier_set_nameQualifier(self, nameQualifier)
################################################################################
# protocols : high level classes
################################################################################
def authn_request_get_protocolProfile(query):
return lassomod.authn_request_get_protocolProfile(query)
class AuthnRequest(LibAuthnRequest):
def __init__(self, providerID, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.authn_request_new(providerID)
if _obj is None: raise Error('lasso_authn_request_new() failed')
LibAuthnRequest.__init__(self, _obj=_obj)
def set_requestAuthnContext(self, authnContextClassRefs=None,
authnContextStatementRefs=None,
authnContextComparison=None):
lassomod.authn_request_set_requestAuthnContext(self,
authnContextClassRefs,
authnContextStatementRefs,
authnContextComparison)
def set_scoping(self, proxyCount):
lassomod.authn_request_set_scoping(self, proxyCount)
class AuthnResponse(Node):
def __init__(self, query, providerID, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.authn_response_new(query, providerID)
if _obj is None: raise Error('lasso_authn_response_new() failed')
Node.__init__(self, _obj=_obj)
def __isprivate(self, name):
return name == '_o'
def __getattr__(self, name):
if self.__isprivate(name):
return self.__dict__[name]
if name[:2] == "__" and name[-2:] == "__" and name != "__members__":
raise AttributeError, name
ret = lassomod.authn_response_getattr(self, name)
if ret is None:
raise AttributeError, name
return ret
def add_assertion(self, assertion, private_key_file, certificate_file):
lassomod.authn_response_add_assertion(self, assertion,
private_key_file,
certificate_file)
def must_authenticate(self, is_authenticated):
return lassomod.authn_response_must_authenticate(self,
is_authenticated)
def process_authentication_result(self, authentication_result):
lassomod.authn_response_process_authentication_result(self,
authentication_result)
def verify_signature(self, public_key_file, private_key_file):
return lassomod.authn_response_verify_signature(self, public_key_file,
private_key_file)
class FederationTerminationNotification(LibFederationTerminationNotification):
def __init__(self, providerID, nameIdentifier,
nameQualifier=None, format=None, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
self._o = lassomod.federation_termination_notification_new(providerID,
nameIdentifier,
nameQualifier,
format)
if self._o is None:
raise Error('lasso_federation_termination_notification_new() failed')
LibFederationTerminationNotification.__init__(self, _obj=_obj)
class LogoutRequest(LibLogoutRequest):
def __init__(self, providerID, nameIdentifier,
nameQualifier=None, format=None, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.logout_request_new(providerID,
nameIdentifier,
nameQualifier,
format)
if _obj is None: raise Error('lasso_logout_request_new() failed')
LibLogoutRequest.__init__(self, _obj=_obj)
class LogoutResponse(Node):
def __init__(self, providerID, statusCodeValue, request, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.logout_response_new(providerID, statusCodeValue,
request)
if _obj is None: raise Error('lasso_logout_response_new() failed')
Node.__init__(self, _obj=_obj)
class NameIdentifierMappingRequest(LibNameIdentifierMappingRequest):
def __init__(self, providerID, nameIdentifier,
nameQualifier=None, format=None, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.name_identifier_mapping_request_new(providerID,
nameIdentifier,
nameQualifier,
format)
if _obj is None:
raise Error('lasso_name_identifier_mapping_request_new() failed')
LibNameIdentifierMappingRequest.__init__(self, _obj=_obj)
class NameIdentifierMappingResponse(Node):
def __init__(self, providerID, statusCodeValue, request, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.name_identifier_mapping_response_new(providerID,
statusCodeValue,
request)
if _obj is None:
raise Error('lasso_name_identifier_mapping_response_new() failed')
Node.__init__(self, _obj=_obj)
class RegisterNameIdentifierRequest(Node):
def __init__(self,
providerID,
idpNameIdentifier, idpNameQualifier, idpFormat,
spNameIdentifier, spNameQualifier, spFormat,
oldNameIdentifier, oldNameQualifier, oldFormat,
_obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.register_name_identifier_request_new(providerID,
idpNameIdentifier, idpNameQualifier, idpFormat,
spNameIdentifier, spNameQualifier, spFormat,
oldNameIdentifier, oldNameQualifier, oldFormat)
if _obj is None:
raise Error('lasso_register_name_identifier_request_new() failed')
Node.__init__(self, _obj=_obj)
def changeAttributeNamesIdentifiers(self):
lassomod.register_name_identifier_request_change_attribute_names_identifiers(self);
class RegisterNameIdentifierResponse(Node):
def __init__(self,
providerID,
statusCodeValue,
request,
_obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.register_name_identifier_response_new(providerID,
statusCodeValue,
request)
if _obj is None:
raise Error('lasso_register_name_identifier_response_new() failed')
Node.__init__(self, _obj=_obj)
################################################################################
# elements
################################################################################
class Assertion(SamlAssertion):
def __init__(self, issuer, requestID, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.assertion_new(issuer, requestID)
if _obj is None: raise Error('lasso_assertion_new() failed')
SamlAssertion.__init__(self, _obj=_obj)
class AuthenticationStatement(Node):
def __init__(self,
authenticationMethod,
sessionIndex,
reauthenticateOnOrAfter,
nameIdentifier,
nameQualifier,
format,
idp_nameIdentifier,
idp_nameQualifier,
idp_format,
confirmationMethod,
_obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.authentication_statement_new(authenticationMethod,
sessionIndex,
reauthenticateOnOrAfter,
nameIdentifier,
nameQualifier,
format,
idp_nameIdentifier,
idp_nameQualifier,
idp_format,
confirmationMethod)
if _obj is None:
raise Error('lasso_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
|