This repository was archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperimental.py
138 lines (105 loc) · 4.4 KB
/
experimental.py
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
from zeep import Client
import hashlib
import datetime
import base64
# Usage Examples
# Connect to the two main webservices, system and share
ADM_USER = "admin"
ADM_PASSWORD = "secret"
def createUser(uid, pw, creds):
DATA = creds.copy()
DATA.update(dict(action='CREATE', memberId='',
newAccountName=uid, newCredential=pw))
result = syscli.service.processMember(DATA)
if result.returnCode == "SUCCESS":
return result.memberId
elif result.returnCode == "CONSTRAINT_ERROR":
return None
else:
return None # XXX
syscli = Client('http://localhost:8080/cws/system?wsdl')
sharecli = Client('http://localhost:8080/cws/share?wsdl')
print "Set an initial password for your administrator"
# We do this by sending an arbitrary initial authenticated request which
# will set the so far unset password
# We fetch all existing circles, which should be an empty list now.
CRED = dict(accountName=ADM_USER, credential=ADM_PASSWORD,
credentialType="PASSPHRASE")
result = syscli.service.fetchCircles(CRED)
assert result.returnCode == "SUCCESS"
print "Connection successful"
# assert result.circles == []
assert result.trustees == []
# By now the password is set, we can use it.
print "Next is creation of a normal users account"
member_id = createUser(uid='pilz', pw='secret', creds=CRED)
print "Member ID: %s" % member_id
print "Now we need to create a circle"
DATA = CRED.copy()
DATA.update(dict(action="CREATE", circleId="",
circleName="MyNewCircle", memberId=member_id,
trustLevel="ADMIN"))
# Trustlevel is irrelevant here, the first one is always admin
result = syscli.service.processCircle(DATA)
if result.returnCode == "SUCCESS":
circle_id = result.circleId
print "Circle ID: %s" % circle_id
print "Now we need a second user and add it to the same circle"
jensen_id = createUser(uid='jensen', pw='secret', creds=CRED)
print "Jensen ID: %s" % jensen_id
print "Now we add jensen to the circle"
# This time, we do it as the circle admin user, not the sysadmin
DATA = dict(accountName="pilz", credential="secret",
credentialType="PASSPHRASE", action="ADD", circleId=circle_id,
circleName="", memberId=jensen_id, trustLevel="WRITE")
result = syscli.service.processCircle(DATA)
print result
print "Check the circle"
DATA = CRED.copy()
DATA.update(dict(circleId=circle_id))
result = syscli.service.fetchCircles(CRED)
print result
print "Let's put a file in / Note that we use sharecli now"
print "Upload file"
BLOB = open('test/plone.pdf', 'rb').read() # Add a real blob here
BLOB = base64.b64encode(BLOB)
UUID = hashlib.md5(BLOB).hexdigest()
DATA = dict(accountName="pilz", credential="secret",
credentialType="PASSPHRASE", action="ADD", circleId=circle_id,
dataId='', typeName='data', folderId=None,
dataName=UUID, data=BLOB
)
result = sharecli.service.processData(DATA)
data_id = result.dataId
print result
print "Read the file again"
DATA = dict(accountName="jensen", credential="secret",
credentialType="PASSPHRASE", circleId=circle_id,
dataId=data_id, folderId=None, pageSize=1, pageNumber=1
)
result = sharecli.service.fetchData(DATA)
data_out = base64.b64decode(result.data)
open('out.pdf', 'wb').write(data_out)
print result
print "Sign a document"
DATA = dict(accountName="pilz", credential="secret",
credentialType="PASSPHRASE", data=BLOB,
expires=datetime.date(datetime.MAXYEAR, 12, 31)
)
result = sharecli.service.sign(DATA)
print result
signature = result.signature
# signature = 'B0AEfotILqPDLS6TTjiRvaWH68H4rqbpeajv3nPxE8exknKSQbFPsT+juqIWS29JYZb+3V/zdV5zFcr7/0FFsdsmBJkOBLGr1VN4a9xiPabL6XoVgmyQzKrFy6FMnh7U4k9Rv7UfVv4lMoNQzGy0ZfgtOvqpQ/sVoUVySQXnsxddqvgtzGjmT1wOsgYVtbUb/93BDdEBtJWSQqJlXQC20WTmd8KnzDm/0fi5xq1a51gOh6Lhb9+WiWFK4oLGUcSq3AGTnDx0R1xxxvKIw3KS07i9SbE99OF5ePSzSzdgjVC+kQ7o1Zqvo5PKmqcYtfYgFndk3bJRTyvT6q7UjTu1Mw=='
DATA = dict(accountName="jensen", credential="secret",
credentialType="PASSPHRASE", data=BLOB, signature=signature
)
result = sharecli.service.verify(DATA)
print result
assert result.verified == True
print "Verify the signature"
DATA = dict(accountName="jensen", credential="secret",
credentialType="PASSPHRASE", data=BLOB+'x', signature=signature
)
result = sharecli.service.verify(DATA)
print result
assert result.verified == False