2 # -*- coding: utf-8 -*-
3 # Debian-Depends: python-soaplib
4 # Debian-Suggests: python-wsgiref
5 from soaplib
.wsgi_soap
import SimpleWSGISoapApp
6 from soaplib
.service
import soapmethod
7 from soaplib
.serializers
.primitive
import String
, Integer
, Array
8 from random
import choice
9 from crypt
import crypt
11 class CryptService(SimpleWSGISoapApp
):
13 def make_salt(self
, count
=16):
14 choices
= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./'
15 return ''.join([choice(choices
) for x
in range(count
)])
17 def crypt(self
, username
, password
, method
):
18 return crypt(password
, '$%s$%s$' % (method
, self
.make_salt()) )
20 @soapmethod(String
, String
, _returns
=String
)
21 def crypt1(self
, username
, password
):
23 GNU libc's crypt function, method 1 (SHA-160).
24 @param username the username
25 @param password the password
26 @return the encrypted password
28 return self
.crypt(username
, password
, '1')
30 @soapmethod(String
, String
, _returns
=String
)
31 def crypt5(self
, username
, password
):
33 GNU libc's crypt function, method 5 (SHA-256).
34 @param username the username
35 @param password the password
36 @return the encrypted password
38 return self
.crypt(username
, password
, '5')
40 @soapmethod(String
, String
, _returns
=String
)
41 def crypt6(self
, username
, password
):
43 GNU libc's crypt function, method 6 (SHA-512).
44 @param username the username
45 @param password the password
46 @return the encrypted password
48 return self
.crypt(username
, password
, '6')
50 application
= CryptService()
52 if __name__
=='__main__':
53 from wsgiref
.simple_server
import make_server
54 server
= make_server('', 8000, application
)
55 server
.serve_forever()