mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-04 06:11:39 +00:00
Compare commits
2392 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3d560a8a2 | ||
|
|
ed20fe252e | ||
|
|
375e36ff96 | ||
|
|
e7108b108e | ||
|
|
6d59daad19 | ||
|
|
21c693921b | ||
|
|
7bcd5fbed7 | ||
|
|
7104970e17 | ||
|
|
1a2950b580 | ||
|
|
085b24e1c5 | ||
|
|
8688ce6328 | ||
|
|
fbdfed81e7 | ||
|
|
94fe20607e | ||
|
|
6c62483e8e | ||
|
|
54689129c6 | ||
|
|
e9e8dd5a82 | ||
|
|
00e764b118 | ||
|
|
cee7eb970a | ||
|
|
daed17fac8 | ||
|
|
8708f4f93f | ||
|
|
c7c1bfbeba | ||
|
|
0418438b6f | ||
|
|
a2ea4d036e | ||
|
|
dc7a29908f | ||
|
|
794db5d2a4 | ||
|
|
e5f9db129b | ||
|
|
a6aecf4e9d | ||
|
|
b59bc4ec90 | ||
|
|
41920f7865 | ||
|
|
4630bf5681 | ||
|
|
1c78ebd20e | ||
|
|
80d17cfda3 | ||
|
|
a154007927 | ||
|
|
bd8274cc27 | ||
|
|
fb08991c05 | ||
|
|
7c1f06fdf7 | ||
|
|
93b38b9f95 | ||
|
|
7ffc97d301 | ||
|
|
280301f258 | ||
|
|
40daf38f80 | ||
|
|
d24925cd5f | ||
|
|
cd42d54b43 | ||
|
|
53d8ecb6bc | ||
|
|
98e87d0297 | ||
|
|
400b4af769 | ||
|
|
368701afb1 | ||
|
|
a501b89ecd | ||
|
|
91cddd72e5 | ||
|
|
8a1f0c9dbf | ||
|
|
e3e5318b4f | ||
|
|
b060664c9f | ||
|
|
83fbf0e8ac | ||
|
|
537a926618 | ||
|
|
f791a59b1d | ||
|
|
0b8e41f993 | ||
|
|
f540fa2a38 | ||
|
|
2d7bc2f34a | ||
|
|
c2dea0a4d7 | ||
|
|
42cbfbf8ed | ||
|
|
137e79b012 | ||
|
|
5849ed3ecc | ||
|
|
d3dc1e1197 | ||
|
|
c20f0bef44 | ||
|
|
c572b6b182 | ||
|
|
a1392dbf86 | ||
|
|
4e719bab5e | ||
|
|
34b51ea64a | ||
|
|
5a2a72f530 | ||
|
|
2ea80c41ab | ||
|
|
6f987958e8 | ||
|
|
ae4007aad5 | ||
|
|
c4401f8bd4 | ||
|
|
0e7472de50 | ||
|
|
e998c78609 | ||
|
|
c30b92cd38 | ||
|
|
2bf2d2aef7 | ||
|
|
cdc04b0803 | ||
|
|
5f5875acc1 | ||
|
|
d306c5e0a3 | ||
|
|
19a815cffe | ||
|
|
da0c559293 | ||
|
|
a2c91ef7b3 | ||
|
|
722b94ca32 | ||
|
|
299742fe03 | ||
|
|
3964cbf911 | ||
|
|
63e4947ad5 | ||
|
|
e3cb13a414 | ||
|
|
01fec79d78 | ||
|
|
a7043a1359 | ||
|
|
91a93ecd62 | ||
|
|
c52fdf6395 | ||
|
|
1d1dad4b30 | ||
|
|
f07a57e478 | ||
|
|
ebacd9b4b4 | ||
|
|
f010e59597 | ||
|
|
a184d7a8e0 | ||
|
|
807f54c549 | ||
|
|
24684abc1d | ||
|
|
1f1a49976c | ||
|
|
562fda3079 | ||
|
|
05642f3c14 | ||
|
|
251e2774aa | ||
|
|
2089589d34 | ||
|
|
c48b135c43 | ||
|
|
70121a6ebf | ||
|
|
c23e53585a | ||
|
|
89e964163e | ||
|
|
0357774ba6 | ||
|
|
93cf750249 | ||
|
|
b712f7a344 | ||
|
|
4159a5cbb8 | ||
|
|
2e78a291d4 | ||
|
|
3f1705c2a5 | ||
|
|
bb1f5f7059 | ||
|
|
75b7d0c419 | ||
|
|
41a6c11c55 | ||
|
|
57d908e369 | ||
|
|
64274fdb33 | ||
|
|
da919fd189 | ||
|
|
cfa25f12d3 | ||
|
|
05bc1c1263 | ||
|
|
939c79c37f | ||
|
|
d352ddeea1 | ||
|
|
72a683f2b1 | ||
|
|
784399f345 | ||
|
|
710be4371b | ||
|
|
eece358aec | ||
|
|
b43ada4f83 | ||
|
|
9030af4faf | ||
|
|
38b424b62e | ||
|
|
1d9bf0b1aa | ||
|
|
d3b7700c07 | ||
|
|
d9513e159f | ||
|
|
6ddfdf2514 | ||
|
|
478804bd5c | ||
|
|
b61165a753 | ||
|
|
b3814ae7be | ||
|
|
019c363a74 | ||
|
|
da5f80e704 | ||
|
|
b37b10e669 | ||
|
|
8ca92eda39 | ||
|
|
81dbbc36db | ||
|
|
7065101b87 | ||
|
|
00c302e545 | ||
|
|
703530ce7f | ||
|
|
7ac15042d8 | ||
|
|
a80ec52027 | ||
|
|
4da4132220 | ||
|
|
8682e66eb0 | ||
|
|
34bf205d37 | ||
|
|
d6c2c6a2c3 | ||
|
|
f45639e6e2 | ||
|
|
82968e29bf | ||
|
|
5d3d571545 | ||
|
|
6999c13877 | ||
|
|
82a551e88f | ||
|
|
1b1a0c876c | ||
|
|
b262c4a898 | ||
|
|
22d1055d82 | ||
|
|
fe38565a9a | ||
|
|
a25d14e83f | ||
|
|
15b21dd8d7 | ||
|
|
caedcde49b | ||
|
|
8091e23e00 | ||
|
|
08e1090b15 | ||
|
|
f76b5cb2eb | ||
|
|
edc4311dcb | ||
|
|
a613bff664 | ||
|
|
8f875d2a9c | ||
|
|
fb60e0b389 | ||
|
|
2199fb2828 | ||
|
|
b7d052a6b3 | ||
|
|
b333816dc8 | ||
|
|
90160da042 | ||
|
|
6f2ebf8d2d | ||
|
|
a65635365e | ||
|
|
0eee6979b0 | ||
|
|
ec796e9f84 | ||
|
|
aaed2a6d86 | ||
|
|
0ea7c500e1 | ||
|
|
d90c884cf2 | ||
|
|
93700c01a8 | ||
|
|
1df5662d4f | ||
|
|
338eeba944 | ||
|
|
9651e4abb1 | ||
|
|
ed1f3400ac | ||
|
|
e9d9353fbb | ||
|
|
00adf4ca46 | ||
|
|
870fc27c72 | ||
|
|
bd38b7479f | ||
|
|
a567599eae | ||
|
|
5e6f9353c2 | ||
|
|
7de1179b7e | ||
|
|
ea7c80c3a1 | ||
|
|
f252f757f1 | ||
|
|
b27c63d0d7 | ||
|
|
bcce1a4472 | ||
|
|
9d9655512d | ||
|
|
7af75f31e4 | ||
|
|
83f02c377f | ||
|
|
ce4f74bc61 | ||
|
|
66651d0eed | ||
|
|
ec0e143361 | ||
|
|
250e0188f7 | ||
|
|
3123e472fc | ||
|
|
c12f7f1123 | ||
|
|
7e706518c5 | ||
|
|
d8ca573983 | ||
|
|
2225625cd8 | ||
|
|
89f0f01fd2 | ||
|
|
a36282d114 | ||
|
|
a8c92b7f9a | ||
|
|
f505dac8f3 | ||
|
|
8e4730a3bd | ||
|
|
b094bb344b | ||
|
|
2685aa049d | ||
|
|
b738d57433 | ||
|
|
539b870754 | ||
|
|
abeb0998ea | ||
|
|
82faddd985 | ||
|
|
b8084c270e | ||
|
|
22c7da420c | ||
|
|
45a3c89b0b | ||
|
|
8fc9e6d1ee | ||
|
|
7f0b286d8e | ||
|
|
4f664df087 | ||
|
|
dff48e3146 | ||
|
|
0fefa19f80 | ||
|
|
88e07ddbaa | ||
|
|
44a3ef0d70 | ||
|
|
5e793f171f | ||
|
|
e9bc63bee8 | ||
|
|
5636876e42 | ||
|
|
f2f7f549b0 | ||
|
|
1fc6e4f781 | ||
|
|
d641458fb4 | ||
|
|
517d44fa3c | ||
|
|
80ee0bf9a8 | ||
|
|
0934b70414 | ||
|
|
f74168e2c7 | ||
|
|
bf4a6e6cde | ||
|
|
0e09675779 | ||
|
|
40e92ca3d2 | ||
|
|
e776919bfd | ||
|
|
84bfeffe46 | ||
|
|
1360abbecb | ||
|
|
2a13accfe4 | ||
|
|
e26dac3993 | ||
|
|
1b7a43e82b | ||
|
|
141aca9e25 | ||
|
|
4f99eb6f07 | ||
|
|
81075bb000 | ||
|
|
33057faaab | ||
|
|
28b831c6a2 | ||
|
|
ef4d3d2659 | ||
|
|
09c0c18fce | ||
|
|
ff80150216 | ||
|
|
a8203baa50 | ||
|
|
aa33dc83d4 | ||
|
|
4155e2bb64 | ||
|
|
9660cafa99 | ||
|
|
c55b9cfe96 | ||
|
|
78ea96767e | ||
|
|
d11d7a8ffc | ||
|
|
bec789d2fb | ||
|
|
0cda3fca31 | ||
|
|
4f8980184f | ||
|
|
ffa096d988 | ||
|
|
6e1b1ed9d5 | ||
|
|
48526b815e | ||
|
|
1ded893e7b | ||
|
|
c61bd01c0f | ||
|
|
f0adcc90c7 | ||
|
|
2abb13bb4c | ||
|
|
8f69c4c820 | ||
|
|
5652c52d96 | ||
|
|
ff29cc192e | ||
|
|
7428d0e734 | ||
|
|
caad9e999c | ||
|
|
24cb225381 | ||
|
|
2e3195c5ee | ||
|
|
bfa039a612 | ||
|
|
49f8988912 | ||
|
|
7e214dbe3b | ||
|
|
42ad12d8d8 | ||
|
|
842e6ef788 | ||
|
|
56b87039c2 | ||
|
|
1767a0889d | ||
|
|
3036366de5 | ||
|
|
a8f1031e0f | ||
|
|
054107c3b9 | ||
|
|
c478b22ab9 | ||
|
|
2f712499ea | ||
|
|
39b9622cdb | ||
|
|
59a3a68357 | ||
|
|
d920dbd79e | ||
|
|
49dd390c6b | ||
|
|
d20b4bc334 | ||
|
|
a973807e3e | ||
|
|
431b5f4f30 | ||
|
|
636799e567 | ||
|
|
d003e3fa1b | ||
|
|
07edbe6619 | ||
|
|
dc4a5a05fe | ||
|
|
a8c86eb53d | ||
|
|
8ef9a62dc9 | ||
|
|
29c9ed4135 | ||
|
|
0426a4ca0d | ||
|
|
af7bbe3cca | ||
|
|
3c55153752 | ||
|
|
a82ff4bb4e | ||
|
|
73759e9611 | ||
|
|
71d6d08f5a | ||
|
|
2f2be201a7 | ||
|
|
49aaca7172 | ||
|
|
f29c64984b | ||
|
|
a50329edf3 | ||
|
|
15d163abf4 | ||
|
|
852a116c9d | ||
|
|
e9c18d0c01 | ||
|
|
5e6d4ecb1c | ||
|
|
97635311db | ||
|
|
3c7ddfd236 | ||
|
|
e0aa0eb4a3 | ||
|
|
8eba9d252f | ||
|
|
5966680a31 | ||
|
|
eb1563b1e7 | ||
|
|
84f52668b7 | ||
|
|
cc60095344 | ||
|
|
5a1f237b30 | ||
|
|
934a671344 | ||
|
|
b81ea8e8c7 | ||
|
|
817920940e | ||
|
|
e0f7ebbcba | ||
|
|
8ce18960fe | ||
|
|
6a879927a7 | ||
|
|
9c22114aa5 | ||
|
|
add9bef046 | ||
|
|
64b6cfea93 | ||
|
|
c8e76d5727 | ||
|
|
4fda0b6aaa | ||
|
|
4634237879 | ||
|
|
5cc91fef53 | ||
|
|
4a3c408ec5 | ||
|
|
23f0c55053 | ||
|
|
e1cf21328a | ||
|
|
7ce5f982b3 | ||
|
|
8fb9439eff | ||
|
|
700e348dbd | ||
|
|
91a86a8663 | ||
|
|
293270c03d | ||
|
|
af13113161 | ||
|
|
59b9dca5ec | ||
|
|
bc5d4e8efb | ||
|
|
91111a62f6 | ||
|
|
5525324620 | ||
|
|
29bd632e45 | ||
|
|
369e3c7269 | ||
|
|
383fed7b3d | ||
|
|
849dd8d436 | ||
|
|
6340a35cf2 | ||
|
|
1b2ea1d4bd | ||
|
|
9087872bc2 | ||
|
|
d914e06f42 | ||
|
|
e12af0c870 | ||
|
|
b0b9e2a7de | ||
|
|
5b88d8b9ca | ||
|
|
b7010b099f | ||
|
|
5484d39d90 | ||
|
|
181a2f8949 | ||
|
|
cee0f97850 | ||
|
|
fd91388b7a | ||
|
|
beae08a99d | ||
|
|
aef614aeae | ||
|
|
c87bc39ad8 | ||
|
|
d0b78f8e81 | ||
|
|
f126cc1d6c | ||
|
|
2d8c3427c4 | ||
|
|
c2acd926af | ||
|
|
b904d77497 | ||
|
|
c093b92c0b | ||
|
|
734b8bfd40 | ||
|
|
e337d1f116 | ||
|
|
8434ac1e2f | ||
|
|
349cdbf582 | ||
|
|
693aeae9e5 | ||
|
|
e4ea8e156d | ||
|
|
ca2b7dd674 | ||
|
|
8a744aa7fc | ||
|
|
7f2beb4d80 | ||
|
|
103c421b31 | ||
|
|
0f4238e9a7 | ||
|
|
c9508d2dac | ||
|
|
5d293b4318 | ||
|
|
3f4b814c0b | ||
|
|
aca71d8db1 | ||
|
|
87dbe3c945 | ||
|
|
c254fc946f | ||
|
|
5a4718eae8 | ||
|
|
935c52f291 | ||
|
|
04fe93d3b8 | ||
|
|
22f279e309 | ||
|
|
a0cff87e5f | ||
|
|
943d327975 | ||
|
|
6c4aced95e | ||
|
|
ad80fd2a91 | ||
|
|
43d50734a4 | ||
|
|
52d6057365 | ||
|
|
8dd5a5dd8a | ||
|
|
4799b33e0e | ||
|
|
d25ae7de81 | ||
|
|
83cbbbf0b7 | ||
|
|
4794578688 | ||
|
|
446da392d9 | ||
|
|
07cbd4cdbb | ||
|
|
f17cbdc111 | ||
|
|
28c5d277a0 | ||
|
|
939840b702 | ||
|
|
78485ae4e9 | ||
|
|
cc47a93872 | ||
|
|
af122eeb5c | ||
|
|
ec118968ed | ||
|
|
2de416fe81 | ||
|
|
d10a3b91e3 | ||
|
|
cdadf68f30 | ||
|
|
900a123141 | ||
|
|
4b2f9488ce | ||
|
|
02d7f45988 | ||
|
|
cc34dbb88e | ||
|
|
5e9d99083c | ||
|
|
295bf74a1b | ||
|
|
7928437dc6 | ||
|
|
83283b7b6b | ||
|
|
09a289b4c4 | ||
|
|
6b940b9d01 | ||
|
|
cb492e0183 | ||
|
|
92799d57ae | ||
|
|
066100f218 | ||
|
|
cd4dd44004 | ||
|
|
40a2fdb7fd | ||
|
|
b60cf11668 | ||
|
|
0fa617c580 | ||
|
|
1cfa08612e | ||
|
|
2cebef9d4b | ||
|
|
c75313cdf4 | ||
|
|
ae1eaac037 | ||
|
|
01465a898a | ||
|
|
d6a7917ffd | ||
|
|
d9946088ab | ||
|
|
a2ad6a1037 | ||
|
|
34e240b40a | ||
|
|
ca1f33ade6 | ||
|
|
d8bddb1c21 | ||
|
|
64bab14483 | ||
|
|
2d1830f4fc | ||
|
|
ab00f2bd42 | ||
|
|
6d9505a4c0 | ||
|
|
40e3cb8ce5 | ||
|
|
4783ec6696 | ||
|
|
3bd746fe91 | ||
|
|
a91a82eecc | ||
|
|
a9564583cb | ||
|
|
f988c8879e | ||
|
|
825cad81a2 | ||
|
|
b9c0ea065a | ||
|
|
50ef633573 | ||
|
|
10202df7d7 | ||
|
|
a7815b41db | ||
|
|
cf467eb868 | ||
|
|
a3be19154f | ||
|
|
a7c19c689c | ||
|
|
1c78e3aac0 | ||
|
|
b9cc3d77b3 | ||
|
|
1feb81adf3 | ||
|
|
fd937758e6 | ||
|
|
fcc3d674c2 | ||
|
|
ce74264a01 | ||
|
|
aaf6448563 | ||
|
|
4a696635f5 | ||
|
|
beb14befca | ||
|
|
c91703364d | ||
|
|
597cea17cd | ||
|
|
9585f6c598 | ||
|
|
e356fe3e85 | ||
|
|
55e5b86ec4 | ||
|
|
bf29a56aeb | ||
|
|
07c57d4197 | ||
|
|
146db31cb5 | ||
|
|
14239fcd47 | ||
|
|
8dc6a17295 | ||
|
|
76f9a6c746 | ||
|
|
eb155a5690 | ||
|
|
b78575aa8f | ||
|
|
91a5cd5c69 | ||
|
|
dd3e6420b6 | ||
|
|
d6a65861e0 | ||
|
|
fe77ff3f60 | ||
|
|
326cccd525 | ||
|
|
b41ca0f0be | ||
|
|
02fa092775 | ||
|
|
57860dc5a6 | ||
|
|
e28f2fb8cd | ||
|
|
0423dd4069 | ||
|
|
5e38137916 | ||
|
|
dc90fb9c94 | ||
|
|
2e2575c360 | ||
|
|
2732abbc93 | ||
|
|
e9d5d676a5 | ||
|
|
18bab4044e | ||
|
|
2ccc4a6932 | ||
|
|
d01d02e700 | ||
|
|
56c6f6cabe | ||
|
|
adb1e58937 | ||
|
|
a59c893652 | ||
|
|
93bcd5f43b | ||
|
|
d7453a7841 | ||
|
|
4fe3dc052a | ||
|
|
c88c755785 | ||
|
|
31f83d33f5 | ||
|
|
597256d048 | ||
|
|
62594a2898 | ||
|
|
00582d486c | ||
|
|
cda626b01c | ||
|
|
7d84da1520 | ||
|
|
11b96b488f | ||
|
|
1853c0ca32 | ||
|
|
0b8fb177c4 | ||
|
|
4e80434956 | ||
|
|
c2f53577ab | ||
|
|
4974150357 | ||
|
|
1586d97295 | ||
|
|
5f65898c33 | ||
|
|
88e7941db3 | ||
|
|
6c715263e0 | ||
|
|
7088962d44 | ||
|
|
429bb0957d | ||
|
|
424fda55dd | ||
|
|
1b26a11281 | ||
|
|
56f52c8623 | ||
|
|
908edff878 | ||
|
|
487e1dc4c1 | ||
|
|
244398e096 | ||
|
|
fafd9e2bd8 | ||
|
|
367ea4df39 | ||
|
|
630abbd0fc | ||
|
|
fe20428a14 | ||
|
|
0e36681ec1 | ||
|
|
884cbc52a3 | ||
|
|
88c17af8ef | ||
|
|
549670e45f | ||
|
|
4fa0e58e80 | ||
|
|
d60b9b2b47 | ||
|
|
3368bd3879 | ||
|
|
dbc47c5420 | ||
|
|
f86b5a2bf3 | ||
|
|
0e0c126726 | ||
|
|
45e0e57668 | ||
|
|
7ee1edbab8 | ||
|
|
747ad9f29a | ||
|
|
7e128dc6c3 | ||
|
|
5e1352077a | ||
|
|
22fc54b2fa | ||
|
|
b67e068991 | ||
|
|
40f5bb07d8 | ||
|
|
c1063d1967 | ||
|
|
964cd19949 | ||
|
|
f55305a800 | ||
|
|
8392856ec5 | ||
|
|
01e1551838 | ||
|
|
d3f042433d | ||
|
|
0e5635cc2a | ||
|
|
73677544a3 | ||
|
|
7c46d8548e | ||
|
|
186381426a | ||
|
|
af1e695661 | ||
|
|
4ccd51269a | ||
|
|
560cfe225f | ||
|
|
e9e4c3d333 | ||
|
|
dbca6e3b88 | ||
|
|
ad465ed20c | ||
|
|
9370f7ce15 | ||
|
|
d9151a866b | ||
|
|
7937fd00d4 | ||
|
|
d2199a5b9c | ||
|
|
6e765325c1 | ||
|
|
18119b3d64 | ||
|
|
378a7c2d6c | ||
|
|
1270a315b2 | ||
|
|
931b2cc700 | ||
|
|
e145ac0ad1 | ||
|
|
ab8e882e94 | ||
|
|
b66d671b74 | ||
|
|
f662a13778 | ||
|
|
845aa122e1 | ||
|
|
bb19336d06 | ||
|
|
774948cf9d | ||
|
|
e26e077c83 | ||
|
|
f264ffd040 | ||
|
|
7e16e4880b | ||
|
|
dd1ee6ff44 | ||
|
|
90d628cc75 | ||
|
|
d5a0b33f04 | ||
|
|
470e7826f1 | ||
|
|
54e9ae568f | ||
|
|
d2ae5173fc | ||
|
|
e9b5133151 | ||
|
|
7959d35f3f | ||
|
|
b42dfb2021 | ||
|
|
b68b773b95 | ||
|
|
e89a926d53 | ||
|
|
6132c03893 | ||
|
|
2db54fc67a | ||
|
|
96095453d5 | ||
|
|
32c02c36c9 | ||
|
|
1eb7ce3896 | ||
|
|
da4f29049b | ||
|
|
d46dd46732 | ||
|
|
8eb72ae6e7 | ||
|
|
6a421d3b78 | ||
|
|
f71a14126e | ||
|
|
35c2024eec | ||
|
|
e570341f93 | ||
|
|
45a9f97fc8 | ||
|
|
6238a4c127 | ||
|
|
e38ec13dac | ||
|
|
0268858784 | ||
|
|
0bd4eefeca | ||
|
|
216f2920b9 | ||
|
|
1fe3e69c56 | ||
|
|
f301dac442 | ||
|
|
dae5cff728 | ||
|
|
f605afb647 | ||
|
|
ed832956ea | ||
|
|
402ff9e8d0 | ||
|
|
2fc51dba17 | ||
|
|
fd8358af90 | ||
|
|
4cd835577a | ||
|
|
bc1c11e650 | ||
|
|
765f432ef2 | ||
|
|
4cd92a1372 | ||
|
|
a2b3975c12 | ||
|
|
4b6cca8dd8 | ||
|
|
55b43b6bc0 | ||
|
|
c987861f02 | ||
|
|
f92c4d18db | ||
|
|
eeebf56a78 | ||
|
|
a04f231c9e | ||
|
|
7df2293f1b | ||
|
|
7dfdf4cdbd | ||
|
|
62fa5fef79 | ||
|
|
ce9fe17994 | ||
|
|
ff54449d1d | ||
|
|
43a8900c24 | ||
|
|
e1660aa909 | ||
|
|
5f6306911f | ||
|
|
268d07938a | ||
|
|
42a4ce5006 | ||
|
|
251b0a0a93 | ||
|
|
153aca30dc | ||
|
|
d9b9aa7de4 | ||
|
|
003d41a496 | ||
|
|
18bc459850 | ||
|
|
97f6781d8a | ||
|
|
7a33c5e18c | ||
|
|
971e2ff76a | ||
|
|
007a378f2b | ||
|
|
2f02148e36 | ||
|
|
475fb4fa2e | ||
|
|
f3d2ef86f8 | ||
|
|
35d2fd4cbc | ||
|
|
c4f1a7eb70 | ||
|
|
c83430a537 | ||
|
|
c398d30f37 | ||
|
|
f60246846f | ||
|
|
3184de1392 | ||
|
|
921324d968 | ||
|
|
c74cdeb773 | ||
|
|
64ecf51ad9 | ||
|
|
518ad04815 | ||
|
|
12ca54f6ba | ||
|
|
0a0ca9ef03 | ||
|
|
9ef7b2f80a | ||
|
|
86b0ed0a04 | ||
|
|
65e77e07a8 | ||
|
|
309308ed59 | ||
|
|
bb82ca0557 | ||
|
|
e5e5db335d | ||
|
|
490d0a7815 | ||
|
|
7ff7c71b4e | ||
|
|
13fa01c4e2 | ||
|
|
d3dfcc3248 | ||
|
|
69d57b7a13 | ||
|
|
b4959547a3 | ||
|
|
3c7085f073 | ||
|
|
0ffb2ab7a7 | ||
|
|
fa4f18b59e | ||
|
|
bdbe034c13 | ||
|
|
b677e8b4b2 | ||
|
|
68745703f8 | ||
|
|
615d571aef | ||
|
|
d23003ab0c | ||
|
|
c29fc410ad | ||
|
|
cbdaa143ea | ||
|
|
ff92cb53cc | ||
|
|
3890af9e1a | ||
|
|
21d70bbcb2 | ||
|
|
1f80e029b8 | ||
|
|
9372b87d5b | ||
|
|
be3f886a57 | ||
|
|
896d7a045a | ||
|
|
545c9ea8dd | ||
|
|
ae1c658065 | ||
|
|
ebea409db6 | ||
|
|
f406fa2445 | ||
|
|
97784c92cf | ||
|
|
8c59241abb | ||
|
|
73bfd6abaa | ||
|
|
b4ccc83696 | ||
|
|
1b557d9769 | ||
|
|
1f69f55437 | ||
|
|
2c049dc38e | ||
|
|
276c14f507 | ||
|
|
117538754e | ||
|
|
f0c22e32df | ||
|
|
30d480debc | ||
|
|
d8bbf71c19 | ||
|
|
574a29363c | ||
|
|
c3382d1501 | ||
|
|
d5058d153e | ||
|
|
9b64bf422d | ||
|
|
da90239e2b | ||
|
|
e15a93ebcb | ||
|
|
286f512f40 | ||
|
|
ff10649a21 | ||
|
|
923c74b8f0 | ||
|
|
95a92aec8f | ||
|
|
9894f5c7fb | ||
|
|
b54a3959d9 | ||
|
|
ee92a56ba9 | ||
|
|
65bbe9ffe4 | ||
|
|
d144ce3135 | ||
|
|
a54a29a3ac | ||
|
|
8a18df0e7f | ||
|
|
0d0e867ef6 | ||
|
|
15a16135e3 | ||
|
|
4444974a9e | ||
|
|
1a32f2a6f8 | ||
|
|
ff43f8474e | ||
|
|
7577e4385c | ||
|
|
0feee6e007 | ||
|
|
d78d68b4da | ||
|
|
e7eea5b9d2 | ||
|
|
0256a3f267 | ||
|
|
a13fef6237 | ||
|
|
357c295fec | ||
|
|
a7a7bc3ebe | ||
|
|
5d02d73737 | ||
|
|
4213b4739e | ||
|
|
b41a6b1d60 | ||
|
|
587fbadd7c | ||
|
|
9e2e0d9bb8 | ||
|
|
24282e4289 | ||
|
|
8659df3c4c | ||
|
|
9913014c4c | ||
|
|
04daf6f0bb | ||
|
|
a9917432d4 | ||
|
|
c23cfd121e | ||
|
|
11efa4fc9e | ||
|
|
1d0c463e3b | ||
|
|
87f9d8f8c3 | ||
|
|
3904177d16 | ||
|
|
9910bb5dc7 | ||
|
|
e1d76a93c9 | ||
|
|
6a5807e94b | ||
|
|
6e9cbdd898 | ||
|
|
ed5f743422 | ||
|
|
e3abe13def | ||
|
|
e8325c13de | ||
|
|
ff55b452eb | ||
|
|
62a0a064aa | ||
|
|
8d5c8f33f2 | ||
|
|
c1e7af620f | ||
|
|
9e0641d8e1 | ||
|
|
b5d07cf5dc | ||
|
|
e8d333a46b | ||
|
|
85f8a012c7 | ||
|
|
aeaa421de6 | ||
|
|
0f8bf26746 | ||
|
|
ee89aa649a | ||
|
|
8cc401a5bf | ||
|
|
c69934e10c | ||
|
|
152d856b24 | ||
|
|
0541d21364 | ||
|
|
47bdad65c2 | ||
|
|
8fdc7839fb | ||
|
|
69905abb9f | ||
|
|
dfa80244ce | ||
|
|
601b5fd57d | ||
|
|
822ba6051c | ||
|
|
c827f193f2 | ||
|
|
dfd755c0da | ||
|
|
72b63c4339 | ||
|
|
52e3b0ee8e | ||
|
|
41521f4c04 | ||
|
|
f35067c9ba | ||
|
|
4cd538e8c1 | ||
|
|
9d0de5df22 | ||
|
|
19e9e9e287 | ||
|
|
cd450a48e6 | ||
|
|
cd1ca91b7f | ||
|
|
9fd0562f98 | ||
|
|
89a4711a77 | ||
|
|
6a7c3a60ec | ||
|
|
0ee3f11345 | ||
|
|
773311439f | ||
|
|
6d2ee67536 | ||
|
|
b90f291998 | ||
|
|
d34034065f | ||
|
|
ae425d25ec | ||
|
|
3c98fc460a | ||
|
|
7725d32788 | ||
|
|
bbd4dd736e | ||
|
|
a1967bc706 | ||
|
|
d06a38d09e | ||
|
|
5d8b06b239 | ||
|
|
2caa782b83 | ||
|
|
f085dac4a0 | ||
|
|
5092e3fc65 | ||
|
|
0f0cb0f28d | ||
|
|
47cfdedd1f | ||
|
|
6347e1f779 | ||
|
|
0afffb4ee2 | ||
|
|
ccc5b2ac44 | ||
|
|
b52ea80ab8 | ||
|
|
86d478f25c | ||
|
|
07e5cfef93 | ||
|
|
f644727e1c | ||
|
|
a00c20296e | ||
|
|
8968833003 | ||
|
|
239fcba631 | ||
|
|
bc555b75dc | ||
|
|
30f72975f7 | ||
|
|
3acf6e50a7 | ||
|
|
34567480a2 | ||
|
|
4323140799 | ||
|
|
df04318366 | ||
|
|
6a27e4388c | ||
|
|
71da849ba9 | ||
|
|
4fb73e6073 | ||
|
|
1f3f23a4f8 | ||
|
|
64554f51a6 | ||
|
|
12c0b33cf1 | ||
|
|
bb5eab886d | ||
|
|
af48f5de3f | ||
|
|
6c002bb135 | ||
|
|
ca77243f4f | ||
|
|
7cbe37033d | ||
|
|
08e790ebbb | ||
|
|
75eec07207 | ||
|
|
22d841144c | ||
|
|
8a9a08a2d2 | ||
|
|
497251186d | ||
|
|
2c0a005d3e | ||
|
|
bea7981bdb | ||
|
|
0be104fd02 | ||
|
|
ea1cdd553c | ||
|
|
6a14964f8f | ||
|
|
cb9f5eab14 | ||
|
|
4ad972f7fe | ||
|
|
3925d6a467 | ||
|
|
6fcc59169c | ||
|
|
02eebf186c | ||
|
|
5b7d0fd3b8 | ||
|
|
aa4e72844b | ||
|
|
f9617a101b | ||
|
|
c641596d42 | ||
|
|
d389b8ad14 | ||
|
|
6248958c94 | ||
|
|
e0e4c46329 | ||
|
|
fdca4c2822 | ||
|
|
cbc6eeabda | ||
|
|
dea2958d9d | ||
|
|
a0c410be0e | ||
|
|
4cc1a97a0a | ||
|
|
ae6ac851c7 | ||
|
|
0f39b991df | ||
|
|
6e9068c952 | ||
|
|
891e5967db | ||
|
|
542f21d58d | ||
|
|
1af3f9f196 | ||
|
|
f0ca2e2601 | ||
|
|
84f0296917 | ||
|
|
96ad8c15c6 | ||
|
|
d77d45b5bc | ||
|
|
dc788a68f8 | ||
|
|
d3af49972c | ||
|
|
c7a732a61e | ||
|
|
d28a412204 | ||
|
|
2722d97a7d | ||
|
|
79c62d86cc | ||
|
|
9f1dcc4c9f | ||
|
|
4230f49bd9 | ||
|
|
9fe9171798 | ||
|
|
dac3b79f4d | ||
|
|
083c2f4e9b | ||
|
|
17f88eb4e7 | ||
|
|
2798e89925 | ||
|
|
79db8f2df3 | ||
|
|
089aadd729 | ||
|
|
201e37d185 | ||
|
|
9d6b569ddb | ||
|
|
c7b026fd1d | ||
|
|
66b95abb96 | ||
|
|
e2ef8a293d | ||
|
|
b25f6e041c | ||
|
|
4607580e6f | ||
|
|
f2d48c0e8f | ||
|
|
c9d12e21d8 | ||
|
|
2f4764a3f2 | ||
|
|
8b67039fa6 | ||
|
|
8cf8d51c79 | ||
|
|
90226c6981 | ||
|
|
91a248bdbe | ||
|
|
0d3bfacc84 | ||
|
|
ac3c156a0b | ||
|
|
f24d403705 | ||
|
|
da3b16c0d4 | ||
|
|
2b2cb03784 | ||
|
|
19d0ff3d46 | ||
|
|
04b6b0ad76 | ||
|
|
6a5fb33306 | ||
|
|
d0262ea6ae | ||
|
|
512c2ee000 | ||
|
|
e708e885f6 | ||
|
|
cc3b7b8124 | ||
|
|
39c9deb456 | ||
|
|
7991790f94 | ||
|
|
5f418d3f1a | ||
|
|
5047bf5466 | ||
|
|
dca7c26b9d | ||
|
|
c6173e2957 | ||
|
|
b646023c41 | ||
|
|
45e3b01b15 | ||
|
|
97515ab758 | ||
|
|
d85328e729 | ||
|
|
0aa7082391 | ||
|
|
946431b83f | ||
|
|
a101e3e7a6 | ||
|
|
f73120dbaa | ||
|
|
a55879c93a | ||
|
|
fe02af151d | ||
|
|
f1a963fa9c | ||
|
|
8c6dee4213 | ||
|
|
9208b4c4dd | ||
|
|
0e04b34852 | ||
|
|
796e35e8a4 | ||
|
|
72f0ae906f | ||
|
|
464482d197 | ||
|
|
48ce39a645 | ||
|
|
f993240d2b | ||
|
|
83fd9babef | ||
|
|
66fb0cf8fc | ||
|
|
459ac84d29 | ||
|
|
736b833d52 | ||
|
|
dc37020d73 | ||
|
|
93916d4ed1 | ||
|
|
1d1e48acb7 | ||
|
|
1884e1a111 | ||
|
|
2d0396da21 | ||
|
|
cce47ba723 | ||
|
|
2831680d14 | ||
|
|
5e3374acbc | ||
|
|
13d7de9501 | ||
|
|
d78abc92f2 | ||
|
|
07672eb874 | ||
|
|
e7225ce487 | ||
|
|
cb24d3bf78 | ||
|
|
8360019080 | ||
|
|
f3b34bea26 | ||
|
|
edf09a2d7b | ||
|
|
1de445c5b8 | ||
|
|
8d7f307173 | ||
|
|
0a23a6d084 | ||
|
|
87fa70be2c | ||
|
|
b57c62fe1b | ||
|
|
a8c1051e0f | ||
|
|
d7ba12e729 | ||
|
|
1d3c47f3fd | ||
|
|
4ae81bae99 | ||
|
|
2fc301d061 | ||
|
|
fc6e6d1ab6 | ||
|
|
9cb4ee9d6f | ||
|
|
0e1da6982b | ||
|
|
28573b47a8 | ||
|
|
851bd1ef14 | ||
|
|
0c7d64563d | ||
|
|
b984f62bbf | ||
|
|
a89e0936c2 | ||
|
|
677146d905 | ||
|
|
00b7ead8bb | ||
|
|
dce5016261 | ||
|
|
2bc759778c | ||
|
|
3aa6869a4b | ||
|
|
209fdfd5b9 | ||
|
|
eec0df14b5 | ||
|
|
7e2810d33d | ||
|
|
78404c8cd3 | ||
|
|
f05ceecf8e | ||
|
|
bcef526213 | ||
|
|
00d5767246 | ||
|
|
6655301bfe | ||
|
|
5beff97f95 | ||
|
|
cfa6b49bab | ||
|
|
a659d5fada | ||
|
|
c1521bfa3f | ||
|
|
096e6c911a | ||
|
|
26f7cd38e5 | ||
|
|
802541c09f | ||
|
|
cfd36c2836 | ||
|
|
7689ac7bed | ||
|
|
7a5ba99b36 | ||
|
|
8f4a40bc9a | ||
|
|
e3ab846d70 | ||
|
|
29db574bc5 | ||
|
|
4851d5b62f | ||
|
|
caef16bdee | ||
|
|
1a0f9ab66a | ||
|
|
021c3bfb13 | ||
|
|
b3dfa41df6 | ||
|
|
5f94263db2 | ||
|
|
68d8e46b4c | ||
|
|
ed221b0d7b | ||
|
|
1243563cd4 | ||
|
|
1170457a39 | ||
|
|
435ed9f568 | ||
|
|
81884e48d0 | ||
|
|
a7be6d233b | ||
|
|
584ddba1a5 | ||
|
|
2bc6c8bca0 | ||
|
|
fc1e81a01d | ||
|
|
eebfaaf373 | ||
|
|
652223d9bc | ||
|
|
e75664fd2e | ||
|
|
556278b216 | ||
|
|
f9bfaa98bb | ||
|
|
b6bd2da6ce | ||
|
|
7c36a6b601 | ||
|
|
413924b11a | ||
|
|
251883dae5 | ||
|
|
7e4d0da8fb | ||
|
|
3fc2aeed4d | ||
|
|
7f4f785f0b | ||
|
|
9f5920989d | ||
|
|
62bceb30c5 | ||
|
|
8c736e52ac | ||
|
|
2669079a31 | ||
|
|
cbfd93e440 | ||
|
|
ffd1c297e5 | ||
|
|
1a11cb04f9 | ||
|
|
438fd5b59a | ||
|
|
2fef5e2cfa | ||
|
|
db8ad38fd3 | ||
|
|
cbb2722291 | ||
|
|
be1c7f2167 | ||
|
|
61f4a137b0 | ||
|
|
dac9e91428 | ||
|
|
83c64f1f71 | ||
|
|
443f4e707b | ||
|
|
70bf2a05f3 | ||
|
|
33a4747677 | ||
|
|
a4cce17767 | ||
|
|
67cd03d3f1 | ||
|
|
1f88c18f94 | ||
|
|
d2fc706b17 | ||
|
|
b5e5786813 | ||
|
|
38e741c788 | ||
|
|
e9a0b85682 | ||
|
|
5ab3602c2a | ||
|
|
dd4bf7b144 | ||
|
|
922326c5ce | ||
|
|
c69be414ca | ||
|
|
10bc47402c | ||
|
|
193e42cf22 | ||
|
|
e0f58e5264 | ||
|
|
f14e48320c | ||
|
|
474fcd33a6 | ||
|
|
a2a9ffc895 | ||
|
|
b02416b32c | ||
|
|
fa52d9e89e | ||
|
|
6383aa594a | ||
|
|
54eb59c27b | ||
|
|
3877f8309b | ||
|
|
d8b0681831 | ||
|
|
cd8303dbea | ||
|
|
ab51d6e931 | ||
|
|
b7e402dca2 | ||
|
|
842040a8b3 | ||
|
|
1205da5d34 | ||
|
|
f40824fedd | ||
|
|
67fa0cbc61 | ||
|
|
e029c77f76 | ||
|
|
2b23ae4e67 | ||
|
|
c8ecc23c9c | ||
|
|
94f8959879 | ||
|
|
2cdb8eb44d | ||
|
|
ebc1d1ecb3 | ||
|
|
d9e99334d2 | ||
|
|
a06776bbbd | ||
|
|
aecd725a71 | ||
|
|
ad8e9364e1 | ||
|
|
b812fef1c3 | ||
|
|
56371214b0 | ||
|
|
3669a86f41 | ||
|
|
4095bf63ef | ||
|
|
d75321ca8a | ||
|
|
c931e1cdd7 | ||
|
|
ea8cda72c7 | ||
|
|
f0bcd7888a | ||
|
|
6a08a66221 | ||
|
|
5e58edf598 | ||
|
|
1e79772ec1 | ||
|
|
3461ce053f | ||
|
|
9c84ce30e8 | ||
|
|
93ca63e133 | ||
|
|
e367c86fce | ||
|
|
34dc12994a | ||
|
|
df4de5ce4b | ||
|
|
ea630480b2 | ||
|
|
db1159cd0d | ||
|
|
ccf1dc0585 | ||
|
|
1cb96cf057 | ||
|
|
2bc8a114c1 | ||
|
|
7f183b9edc | ||
|
|
f86be17834 | ||
|
|
6854e3729a | ||
|
|
5f48b1e16f | ||
|
|
aea92be8d3 | ||
|
|
b4c5d6c626 | ||
|
|
0e2845082b | ||
|
|
705a40d035 | ||
|
|
f85a072708 | ||
|
|
e990387660 | ||
|
|
feb76f504c | ||
|
|
6a33173a49 | ||
|
|
5e8e9765fa | ||
|
|
2a6cdb9b14 | ||
|
|
642c0fa216 | ||
|
|
9d5e79725c | ||
|
|
db301d2635 | ||
|
|
d7283d17e2 | ||
|
|
bd7b58ad43 | ||
|
|
27c0e5f8a6 | ||
|
|
7a439a3e07 | ||
|
|
fff6e6717f | ||
|
|
2671764e99 | ||
|
|
4f12e2affb | ||
|
|
e1faab524b | ||
|
|
6c5585d059 | ||
|
|
dc678dd510 | ||
|
|
7b70c5a745 | ||
|
|
2e8190ce29 | ||
|
|
14b09b91df | ||
|
|
b77d7eaadc | ||
|
|
c68e0bfbc4 | ||
|
|
8a26e99dfc | ||
|
|
9e2dd11617 | ||
|
|
19f01007f4 | ||
|
|
2c4bbbbbfb | ||
|
|
71536c50a2 | ||
|
|
1d118a9ca3 | ||
|
|
94f6c45291 | ||
|
|
fd4a64f6a7 | ||
|
|
d8ba15ab98 | ||
|
|
a0a2e1359e | ||
|
|
34b32da1e6 | ||
|
|
f9af688bea | ||
|
|
8829bc3a65 | ||
|
|
59d8e5a853 | ||
|
|
fddd77e87c | ||
|
|
eed3fb1ed9 | ||
|
|
fbaf9272a8 | ||
|
|
97df7c75b1 | ||
|
|
358892869b | ||
|
|
7cca371c22 | ||
|
|
8b1c8b36ce | ||
|
|
86154adc92 | ||
|
|
bfc0b57f62 | ||
|
|
d67110e771 | ||
|
|
2d7c382c2f | ||
|
|
4536cd13ef | ||
|
|
627db97b30 | ||
|
|
bbdce9536b | ||
|
|
5f0644d924 | ||
|
|
0b5dffc5a5 | ||
|
|
33c85e9ed6 | ||
|
|
c04164e47a | ||
|
|
06e7545f33 | ||
|
|
0399d96fd4 | ||
|
|
347688ac8c | ||
|
|
37ce64acb7 | ||
|
|
4b8bc4e7ea | ||
|
|
d9ba83217f | ||
|
|
1d658ca1ac | ||
|
|
65f94ff465 | ||
|
|
1b010fbd07 | ||
|
|
a1bce42387 | ||
|
|
4808f18ca0 | ||
|
|
b41baf19b4 | ||
|
|
9d78fa8825 | ||
|
|
2a6a424ce0 | ||
|
|
c05c040241 | ||
|
|
3d3f2b535b | ||
|
|
49bf1f675a | ||
|
|
50f3ac493c | ||
|
|
690302f2b3 | ||
|
|
af7b387f94 | ||
|
|
1c38c47e4a | ||
|
|
74525efc37 | ||
|
|
985db74216 | ||
|
|
6d4a34d971 | ||
|
|
43b17cce0e | ||
|
|
0fc11de8bf | ||
|
|
39f5b1dbc2 | ||
|
|
f3596856ba | ||
|
|
fc7e8b4deb | ||
|
|
4178b4a61e | ||
|
|
05d5fdde53 | ||
|
|
3be1e97863 | ||
|
|
0cffb8202d | ||
|
|
657ce1cbbf | ||
|
|
f8ee80be19 | ||
|
|
70de8b8719 | ||
|
|
f972f0b8e4 | ||
|
|
8c025758c9 | ||
|
|
2713bd9bfc | ||
|
|
cdc067c4b7 | ||
|
|
a18ab16d9d | ||
|
|
7bdde3ec68 | ||
|
|
2c89f988a1 | ||
|
|
ead7c7403a | ||
|
|
5ce67e5f5c | ||
|
|
b34b2d8e2a | ||
|
|
64d1dec3d8 | ||
|
|
7f14bbcc22 | ||
|
|
9396cdef4a | ||
|
|
b49f759ef9 | ||
|
|
3087e0cbdb | ||
|
|
9992eaad2b | ||
|
|
33f5e74e45 | ||
|
|
9a068f02da | ||
|
|
b71a4f1d0b | ||
|
|
42950550cc | ||
|
|
86842bbb02 | ||
|
|
4ca0277e63 | ||
|
|
671ac52201 | ||
|
|
78c71babda | ||
|
|
19196a2ee4 | ||
|
|
843c5f0687 | ||
|
|
260160ade1 | ||
|
|
06525ff690 | ||
|
|
ac2ccc2d03 | ||
|
|
41eba0c873 | ||
|
|
f6672496d1 | ||
|
|
004b51f3cd | ||
|
|
1046716304 | ||
|
|
187b7a8c39 | ||
|
|
27177e3ef4 | ||
|
|
367eaae47f | ||
|
|
dcee433547 | ||
|
|
ea74e24024 | ||
|
|
6353ddf58a | ||
|
|
911d83cfd8 | ||
|
|
49fc1c4f7e | ||
|
|
097eb07fcc | ||
|
|
00f992259b | ||
|
|
ce655173f8 | ||
|
|
ec1c146362 | ||
|
|
4098a9b70f | ||
|
|
b617d5cab0 | ||
|
|
4b29fda924 | ||
|
|
37d07c9bd8 | ||
|
|
0cf964073d | ||
|
|
298e161658 | ||
|
|
997b2e84da | ||
|
|
c135866f0d | ||
|
|
509f125e3a | ||
|
|
90c51a2d51 | ||
|
|
2b58539588 | ||
|
|
8b3bf26edf | ||
|
|
d4190496fb | ||
|
|
a8ceb40953 | ||
|
|
e47b6a32de | ||
|
|
77ed31d975 | ||
|
|
2d4a24554f | ||
|
|
4fcade37c2 | ||
|
|
71978841b1 | ||
|
|
6aab88abce | ||
|
|
7bc5ad35cb | ||
|
|
751020a589 | ||
|
|
fdfd6e80fb | ||
|
|
ee3b6e471b | ||
|
|
b818d6a1c1 | ||
|
|
221cd9826d | ||
|
|
5afda1dc2f | ||
|
|
108ca38f10 | ||
|
|
f104c7acdc | ||
|
|
a62a7d4da4 | ||
|
|
2f0fa38f3d | ||
|
|
2243a4e8eb | ||
|
|
4e15cb6618 | ||
|
|
2e103a2d69 | ||
|
|
22c7609e0d | ||
|
|
04504cdb2e | ||
|
|
294211bf84 | ||
|
|
0f7e0a4c87 | ||
|
|
351e9ab929 | ||
|
|
6d16eae210 | ||
|
|
f0d0345fcd | ||
|
|
1c8cb1a617 | ||
|
|
bc065d4b31 | ||
|
|
71c9d90b39 | ||
|
|
dd7d4923be | ||
|
|
f348405d46 | ||
|
|
7e37e7298e | ||
|
|
ed56599260 | ||
|
|
457ce15a4c | ||
|
|
892d200cd2 | ||
|
|
0b763b70f4 | ||
|
|
9310771832 | ||
|
|
a590c0487e | ||
|
|
46fcd84ecb | ||
|
|
f8f492efb2 | ||
|
|
ebe29d3a5a | ||
|
|
92b8ea6dcd | ||
|
|
1654dee62e | ||
|
|
2316b9e76a | ||
|
|
b095b361cb | ||
|
|
fe7c72beac | ||
|
|
9930209980 | ||
|
|
48553f4ad9 | ||
|
|
a7bb600bf5 | ||
|
|
57938b19a8 | ||
|
|
8d485f4f74 | ||
|
|
8db6d1f4f7 | ||
|
|
6198f7ace3 | ||
|
|
9472fb2a4c | ||
|
|
8fdc49a0af | ||
|
|
639cede6c4 | ||
|
|
65fd49e377 | ||
|
|
4e141bf764 | ||
|
|
2db40e841b | ||
|
|
1f728ff4da | ||
|
|
4c43b28820 | ||
|
|
e6610357e3 | ||
|
|
8ad2f8d633 | ||
|
|
127d354972 | ||
|
|
a099981b3c | ||
|
|
857230def3 | ||
|
|
693c23e562 | ||
|
|
5c6e31200e | ||
|
|
074318d797 | ||
|
|
838b377d4b | ||
|
|
f1061d7190 | ||
|
|
948e40f51a | ||
|
|
fb6746e694 | ||
|
|
e68632e840 | ||
|
|
049319c499 | ||
|
|
958c2ee356 | ||
|
|
6b569df751 | ||
|
|
7587a58dc3 | ||
|
|
7ea3930975 | ||
|
|
cccaf5fe54 | ||
|
|
932dbd74ee | ||
|
|
4cbb2300df | ||
|
|
ecb4efa352 | ||
|
|
03d7fe0407 | ||
|
|
3f6dff1543 | ||
|
|
9857869799 | ||
|
|
8879c5d8c7 | ||
|
|
7d1edd41c7 | ||
|
|
970542eb7f | ||
|
|
5270929b57 | ||
|
|
6543ead625 | ||
|
|
817d618d08 | ||
|
|
a0833393a8 | ||
|
|
811a2db58b | ||
|
|
8b9af97012 | ||
|
|
36b874d8a0 | ||
|
|
5680bc05b5 | ||
|
|
90b8751874 | ||
|
|
51712af78d | ||
|
|
f5681cb746 | ||
|
|
85d52a4d68 | ||
|
|
cec7f88d2b | ||
|
|
4043bcab61 | ||
|
|
1efa50aeab | ||
|
|
400fa08ebc | ||
|
|
eda1a1de24 | ||
|
|
31d8cd09dd | ||
|
|
91b3ddb489 | ||
|
|
2392d575c2 | ||
|
|
8b47748df9 | ||
|
|
7a9899f747 | ||
|
|
2e5e784f4c | ||
|
|
5b9d14e966 | ||
|
|
5fb0b1b5ff | ||
|
|
a08d95a742 | ||
|
|
64380cbd4d | ||
|
|
837d98deaf | ||
|
|
a63ac294db | ||
|
|
d20a0d8455 | ||
|
|
cd710e99c0 | ||
|
|
1cedbc9423 | ||
|
|
2ce5915e70 | ||
|
|
e602d3fef0 | ||
|
|
c6e1e5c1cf | ||
|
|
837bff58e7 | ||
|
|
01d50adce7 | ||
|
|
05cbe1c6f3 | ||
|
|
939bd8d9ab | ||
|
|
204a689848 | ||
|
|
a852c7e5ca | ||
|
|
b3ad45f2cc | ||
|
|
9f988bb464 | ||
|
|
ce0ad0a3ea | ||
|
|
c5daf892c6 | ||
|
|
bd484cbe41 | ||
|
|
cbfb0a7310 | ||
|
|
45027da057 | ||
|
|
fb53f2ed0e | ||
|
|
37e0e8942e | ||
|
|
ef86508bbb | ||
|
|
f6459e20f9 | ||
|
|
aeff5edaeb | ||
|
|
d274d05336 | ||
|
|
207eb0990c | ||
|
|
1cbe8297aa | ||
|
|
5b8fcebabd | ||
|
|
820f17ce74 | ||
|
|
753ecd7244 | ||
|
|
df3ea385ee | ||
|
|
eb041e9e65 | ||
|
|
96eb2496e4 | ||
|
|
cbe89c8c40 | ||
|
|
4d893c4da1 | ||
|
|
9dd0b135b9 | ||
|
|
5b0439ddb5 | ||
|
|
c3cb82a2de | ||
|
|
516f13bf48 | ||
|
|
c3bf18cf5a | ||
|
|
ece2d2943e | ||
|
|
610dbd4dcf | ||
|
|
fe3c043d61 | ||
|
|
83d8135722 | ||
|
|
6caf3f2252 | ||
|
|
b8331a3a4a | ||
|
|
c271349c30 | ||
|
|
329a6e0768 | ||
|
|
fae2dca9dc | ||
|
|
7112a42c96 | ||
|
|
d76618cbad | ||
|
|
d8db37786c | ||
|
|
79bc1065f3 | ||
|
|
b107afc13c | ||
|
|
fcfbf0a733 | ||
|
|
8460a7a87d | ||
|
|
2940dd71ab | ||
|
|
135ebaa251 | ||
|
|
f94b3eb383 | ||
|
|
a3db496f31 | ||
|
|
dd78c05d59 | ||
|
|
d9c4326a6b | ||
|
|
4ec90dbcfe | ||
|
|
b8c6800b37 | ||
|
|
a82a33996c | ||
|
|
9a27f19e2e | ||
|
|
c56c6e3e05 | ||
|
|
0c0fb37b33 | ||
|
|
e865d81dad | ||
|
|
cc86d67c26 | ||
|
|
3287a18cac | ||
|
|
135ea0f120 | ||
|
|
468928a2e6 | ||
|
|
57cafe78f8 | ||
|
|
8d27ef7a37 | ||
|
|
5acad994b6 | ||
|
|
6ebdf9ba4e | ||
|
|
f8067f11e1 | ||
|
|
4a0d23d652 | ||
|
|
42be930dfc | ||
|
|
47bc500f40 | ||
|
|
d536b6e43a | ||
|
|
5ef91076f9 | ||
|
|
5966e39406 | ||
|
|
044686b564 | ||
|
|
19018e4854 | ||
|
|
518e506df4 | ||
|
|
26ebf30da7 | ||
|
|
587fed282d | ||
|
|
98cabddcdc | ||
|
|
419bd01818 | ||
|
|
5a1ab0c168 | ||
|
|
74514b487d | ||
|
|
8e7bd453f4 | ||
|
|
348450b9d9 | ||
|
|
a50a481bb5 | ||
|
|
342e08e8fe | ||
|
|
65da6f39dc | ||
|
|
5774b99891 | ||
|
|
02ce970aea | ||
|
|
f8c24bf86a | ||
|
|
bbb486f7b2 | ||
|
|
bdbc7cf713 | ||
|
|
a44d4f0872 | ||
|
|
16636c34b5 | ||
|
|
ce2e379f30 | ||
|
|
4c4f5eef3e | ||
|
|
6a70a1412b | ||
|
|
a9025e2aba | ||
|
|
b1e26e3a48 | ||
|
|
7fc88f2641 | ||
|
|
68388a6011 | ||
|
|
481b060caf | ||
|
|
3cb8dae374 | ||
|
|
55999b5b65 | ||
|
|
1e126cd633 | ||
|
|
b6f7ff7038 | ||
|
|
8885bdd5f0 | ||
|
|
35b986e2be | ||
|
|
a80625d5f7 | ||
|
|
d2bb1a83a1 | ||
|
|
9f829c6990 | ||
|
|
6d52e06f66 | ||
|
|
1c8fcdbe6e | ||
|
|
b207814ffd | ||
|
|
f700e178a1 | ||
|
|
e75c7078ce | ||
|
|
74f7549b7f | ||
|
|
d9dc4ac68c | ||
|
|
134f170726 | ||
|
|
14fab0293e | ||
|
|
5318a7a9da | ||
|
|
46d655b328 | ||
|
|
099d0176d6 | ||
|
|
9aaee86120 | ||
|
|
e3d3927cfd | ||
|
|
c6d0f3da92 | ||
|
|
156fd4ee6f | ||
|
|
f192758f25 | ||
|
|
62f3507a32 | ||
|
|
25800a7883 | ||
|
|
15855bf6bf | ||
|
|
8dd683029b | ||
|
|
d10302ad9d | ||
|
|
06e74cf44f | ||
|
|
1b46b4b13b | ||
|
|
39d8c93444 | ||
|
|
6629f5578c | ||
|
|
5d4502e971 | ||
|
|
d070372117 | ||
|
|
330871cfbf | ||
|
|
d6dce1f0fe | ||
|
|
947c816591 | ||
|
|
c525d893d3 | ||
|
|
9ebdfc96a4 | ||
|
|
1ed0895803 | ||
|
|
eb4b8479f3 | ||
|
|
48fa6b755e | ||
|
|
4cef7c4c2d | ||
|
|
d072172ff5 | ||
|
|
6a90a76fb1 | ||
|
|
0ca083f5e9 | ||
|
|
f8e7ff86ab | ||
|
|
690832b7d7 | ||
|
|
78a42f29b1 | ||
|
|
d8be1dbb86 | ||
|
|
2995327a15 | ||
|
|
2cc48a0f25 | ||
|
|
511d436947 | ||
|
|
78a3a5f762 | ||
|
|
c98473d118 | ||
|
|
5b2e6591bc | ||
|
|
63ca5f8054 | ||
|
|
b1a2eb4de5 | ||
|
|
a1ca3523a3 | ||
|
|
ce5eb39f37 | ||
|
|
98438644c5 | ||
|
|
18d98a6384 | ||
|
|
ea49c9ef15 | ||
|
|
ddebd0c974 | ||
|
|
6e9c1dc08e | ||
|
|
7b433940bf | ||
|
|
dd2fffcfd5 | ||
|
|
679b5f144d | ||
|
|
f45601435c | ||
|
|
301cf2f1ba | ||
|
|
ba9a3a7980 | ||
|
|
80a002dadc | ||
|
|
206ba319af | ||
|
|
bdb217bed7 | ||
|
|
0805725a6f | ||
|
|
df177ac43f | ||
|
|
4ff76bab5c | ||
|
|
86c4c552db | ||
|
|
bc9582bcc1 | ||
|
|
f383c45e6b | ||
|
|
3bf5ffeb99 | ||
|
|
875879caed | ||
|
|
5f28bc82e0 | ||
|
|
0327f5c30f | ||
|
|
774c084708 | ||
|
|
325a06162e | ||
|
|
e3dbf56ef5 | ||
|
|
919f54d0d2 | ||
|
|
4563441a3a | ||
|
|
323c7da201 | ||
|
|
d667da4851 | ||
|
|
6be6b2ebde | ||
|
|
8f03a3aabb | ||
|
|
5f1489438c | ||
|
|
695843d7ec | ||
|
|
b9e4787b1c | ||
|
|
f2e0b436c6 | ||
|
|
e78dbeb056 | ||
|
|
cdbf740d38 | ||
|
|
bbbf7c5391 | ||
|
|
ad535b2e3f | ||
|
|
4f30ed6537 | ||
|
|
c6567d7830 | ||
|
|
a72ef287e3 | ||
|
|
86297a08bd | ||
|
|
0a81e51072 | ||
|
|
d33eb3b455 | ||
|
|
c6b1a163af | ||
|
|
8cca8f642c | ||
|
|
e8f49b8ecc | ||
|
|
4f1680810b | ||
|
|
7710578a3c | ||
|
|
02aae0d351 | ||
|
|
16512f3507 | ||
|
|
91976b2a2b | ||
|
|
fc44143587 | ||
|
|
70b160373d | ||
|
|
bafc648c9d | ||
|
|
e8e9e599f8 | ||
|
|
9051635bf5 | ||
|
|
dfb582ecc5 | ||
|
|
6ea1d6a237 | ||
|
|
a758a235dc | ||
|
|
5c20087f19 | ||
|
|
9b942ba05a | ||
|
|
96b6c89da9 | ||
|
|
3585d15353 | ||
|
|
d89d99da78 | ||
|
|
8a7468ef67 | ||
|
|
a76d4a79d1 | ||
|
|
882e75b7a3 | ||
|
|
222e00619e | ||
|
|
1f7edc5bb9 | ||
|
|
6a4712ec37 | ||
|
|
96376669ef | ||
|
|
a94cdbc633 | ||
|
|
3cd25f3c10 | ||
|
|
7281a813e0 | ||
|
|
3c1f141339 | ||
|
|
aa51d5be1d | ||
|
|
bb60488bf3 | ||
|
|
4fbabd9f35 | ||
|
|
f8750fe0b6 | ||
|
|
420fb1c393 | ||
|
|
7628b5a08d | ||
|
|
9038587f67 | ||
|
|
824dad6fab | ||
|
|
dbd2960841 | ||
|
|
b02fa6c358 | ||
|
|
bc1c51894c | ||
|
|
6136ece5dd | ||
|
|
bb204fa868 | ||
|
|
ce84ad8774 | ||
|
|
597a236e05 | ||
|
|
180606f721 | ||
|
|
dcfa718a9b | ||
|
|
6858f87926 | ||
|
|
743e808404 | ||
|
|
0ffb257f08 | ||
|
|
d670d5feab | ||
|
|
f34859f51b | ||
|
|
42ae43e81e | ||
|
|
41cad79a21 | ||
|
|
92c7525d0a | ||
|
|
86e496040c | ||
|
|
21c2ecfd1d | ||
|
|
720bd46683 | ||
|
|
b83967809d | ||
|
|
385d4e8ab2 | ||
|
|
96d52f47d1 | ||
|
|
e4353189dc | ||
|
|
dbe8dc67f2 | ||
|
|
4998c30d20 | ||
|
|
20e84b9c9a | ||
|
|
efdaa6a64e | ||
|
|
1a96622366 | ||
|
|
d5af189125 | ||
|
|
5ebaf8264a | ||
|
|
40bfde9697 | ||
|
|
a52805b35e | ||
|
|
0312258db7 | ||
|
|
2ddd9e2477 | ||
|
|
be44d2c601 | ||
|
|
ee44ba67cf | ||
|
|
c462216be7 | ||
|
|
e43ebd4d40 | ||
|
|
0ea0c416ec | ||
|
|
3f42eb86d2 | ||
|
|
b003e5065a | ||
|
|
cc25c40406 | ||
|
|
8e3c632a7c | ||
|
|
ab94208bb5 | ||
|
|
0562ed3eb9 | ||
|
|
3ceef052a3 | ||
|
|
d5b5251587 | ||
|
|
0ae73fa6b3 | ||
|
|
38b6fd213f | ||
|
|
39193ae92f | ||
|
|
c8c18497cc | ||
|
|
bdb0b3d6dc | ||
|
|
7312c8f396 | ||
|
|
831272a137 | ||
|
|
d50231b888 | ||
|
|
6160bb0953 | ||
|
|
1e013e6cd7 | ||
|
|
96955d9305 | ||
|
|
fdfa38a209 | ||
|
|
daa4b57af1 | ||
|
|
de3be6ba52 | ||
|
|
81c2e425ef | ||
|
|
4bf6b6fb96 | ||
|
|
4ed8497bd7 | ||
|
|
738280bbe5 | ||
|
|
ad9384aeac | ||
|
|
67f5416858 | ||
|
|
51567ff5c4 | ||
|
|
6f6a94c9b0 | ||
|
|
08bd3ecc91 | ||
|
|
6ebc0f4e81 | ||
|
|
bf39798263 | ||
|
|
92521acfa3 | ||
|
|
f8d43a19c1 | ||
|
|
842ddc2a26 | ||
|
|
bafed078e5 | ||
|
|
8999fb84de | ||
|
|
3b162924c5 | ||
|
|
242c61205d | ||
|
|
139727dd33 | ||
|
|
a52341e29e | ||
|
|
c2358f60fb | ||
|
|
c8ea108be3 | ||
|
|
8fdd0abc53 | ||
|
|
f396b2f476 | ||
|
|
6e9413eada | ||
|
|
30a5467b82 | ||
|
|
3ffa3ca5e5 | ||
|
|
f0351b8bec | ||
|
|
d8093fa1f0 | ||
|
|
2080f33fdb | ||
|
|
6a2925c546 | ||
|
|
26960c96d9 | ||
|
|
58a080fe6b | ||
|
|
3c3b7527a1 | ||
|
|
0d7028416a | ||
|
|
aa6dca4b4c | ||
|
|
3d7a7bd609 | ||
|
|
35854af1e9 | ||
|
|
4450652c32 | ||
|
|
d34e09f8d5 | ||
|
|
610ba5bf6a | ||
|
|
65debc6a27 | ||
|
|
61868d5fde | ||
|
|
998f4c6dff | ||
|
|
a2a8393775 | ||
|
|
d9ec9d3af9 | ||
|
|
7104b24633 | ||
|
|
9cd81c9148 | ||
|
|
56a60d1651 | ||
|
|
1cdf02bc31 | ||
|
|
5b469496d6 | ||
|
|
2a1d3a1ce1 | ||
|
|
9b89492d83 | ||
|
|
45b1eee8f3 | ||
|
|
e9dda2079a | ||
|
|
c279acbab8 | ||
|
|
082cd9b087 | ||
|
|
7d2e5d674a | ||
|
|
b2d95c545d | ||
|
|
127c3125ad | ||
|
|
63f1e0d504 | ||
|
|
1ad10b6954 | ||
|
|
820cf98087 | ||
|
|
15bd6beebd | ||
|
|
31871f192c | ||
|
|
7acfa4a2ac | ||
|
|
e212d68d60 | ||
|
|
6aeee89ee4 | ||
|
|
623572a652 | ||
|
|
f7c587c08b | ||
|
|
da1f346b1a | ||
|
|
056b56ed78 | ||
|
|
791581b850 | ||
|
|
08f426ba09 | ||
|
|
54371cffff | ||
|
|
c7946c0edf | ||
|
|
ae578c64a0 | ||
|
|
08bc1898cc | ||
|
|
dc626b1b3e | ||
|
|
7283e06750 | ||
|
|
c76368509e | ||
|
|
b54eb97f6b | ||
|
|
2d997fb046 | ||
|
|
e2cf769b20 | ||
|
|
281786b3b9 | ||
|
|
b06b8608d0 | ||
|
|
22dc39eb85 | ||
|
|
4a894958f0 | ||
|
|
38273a786a | ||
|
|
6ba0a5d942 | ||
|
|
2ad731f4e0 | ||
|
|
a491fb5471 | ||
|
|
33cfb940b4 | ||
|
|
46b79334e4 | ||
|
|
a7e841bcba | ||
|
|
f2400b35b0 | ||
|
|
31058336ce | ||
|
|
ac2cbef7f8 | ||
|
|
d7187ff998 | ||
|
|
2cc79f44ea | ||
|
|
067a67c14e | ||
|
|
054addfa9b | ||
|
|
6b7cf875de | ||
|
|
581e31499b | ||
|
|
a5883a8429 | ||
|
|
95c2d91a5b | ||
|
|
9f487d57fb | ||
|
|
e0d278e7ea | ||
|
|
36725c3574 | ||
|
|
8c911215b1 | ||
|
|
2b57a976c2 | ||
|
|
4817ce282a | ||
|
|
2da6666587 | ||
|
|
07f1bc050a | ||
|
|
9135e15b12 | ||
|
|
5c32a86257 | ||
|
|
d5bcac4d14 | ||
|
|
73bcadbbfe | ||
|
|
d3091d3dd8 | ||
|
|
f9ab78e393 | ||
|
|
7a94077906 | ||
|
|
6b438c3a46 | ||
|
|
5383ed22ea | ||
|
|
dbd09daa33 | ||
|
|
25ace13a3d | ||
|
|
8fc6112e32 | ||
|
|
ac2eb99d63 | ||
|
|
43707d8074 | ||
|
|
b0b3c18e99 | ||
|
|
349f2801c5 | ||
|
|
658e7beb2b | ||
|
|
e777eb6c99 | ||
|
|
8a6ce43ad3 | ||
|
|
72d182032b | ||
|
|
9b8189a3e4 | ||
|
|
14eb9ca3f8 | ||
|
|
cc2cba8c70 | ||
|
|
17660220fe | ||
|
|
d5538a79da | ||
|
|
fc5cd1c219 | ||
|
|
e10e63a87f | ||
|
|
93b05de15e | ||
|
|
a6a94060c6 | ||
|
|
a12ec0ffdc | ||
|
|
ae5d484309 | ||
|
|
2cdcc6f5ad | ||
|
|
3699e0199b | ||
|
|
5ec417d50c | ||
|
|
240edd6812 | ||
|
|
faa1b87926 | ||
|
|
08a9764465 | ||
|
|
e3a73ce7d1 | ||
|
|
d75a5e78a5 | ||
|
|
6a179215d6 | ||
|
|
c2dc2f0712 | ||
|
|
b6b6824ee1 | ||
|
|
2902fc8931 | ||
|
|
1a6ec398b2 | ||
|
|
7d849e0cc0 | ||
|
|
2958bd9f86 | ||
|
|
15d93c9e5d | ||
|
|
082c34b453 | ||
|
|
32e7932050 | ||
|
|
6becd08f3c | ||
|
|
26fbf9c524 | ||
|
|
d9124f3ffa | ||
|
|
aa1db89bd3 | ||
|
|
ff3a8644ec | ||
|
|
4721469b1d | ||
|
|
c4a3d29964 | ||
|
|
1454526e65 | ||
|
|
2c0026512d | ||
|
|
3c85da292e | ||
|
|
c7b5251b03 | ||
|
|
5307a560bd | ||
|
|
059e6a1813 | ||
|
|
395a561b8c | ||
|
|
6c3a744ed3 | ||
|
|
907126d642 | ||
|
|
9e4506141e | ||
|
|
5deac72484 | ||
|
|
9def6e6d73 | ||
|
|
fefe9de384 | ||
|
|
f8341be9ea | ||
|
|
3c50f464cc | ||
|
|
6961a0e1b3 | ||
|
|
3fa6cde6b0 | ||
|
|
4129e05f5e | ||
|
|
42137297a1 | ||
|
|
bc64e9a67c | ||
|
|
e1ec8b8649 | ||
|
|
b9ec06807b | ||
|
|
e3d826cdb3 | ||
|
|
4306dba9f1 | ||
|
|
cf397c228c | ||
|
|
a2a6719333 | ||
|
|
7cef626a6f | ||
|
|
be44ae4322 | ||
|
|
4c00b54ad4 | ||
|
|
8508ee4afa | ||
|
|
17b2c4091d | ||
|
|
925f4532bc | ||
|
|
786bbe5609 | ||
|
|
6be52c8b3c | ||
|
|
2c2046a784 | ||
|
|
20de452685 | ||
|
|
df603937ee | ||
|
|
315a1db144 | ||
|
|
968c096a99 | ||
|
|
6703519d36 | ||
|
|
9dd8696c1e | ||
|
|
df7c12b737 | ||
|
|
7cfba0ada1 | ||
|
|
2ee5109424 | ||
|
|
721f787f0f | ||
|
|
bc62f7a9f6 | ||
|
|
4eee744321 | ||
|
|
0dbd460b71 | ||
|
|
5c27695613 | ||
|
|
e52e939afa | ||
|
|
60a97b3e26 | ||
|
|
fb41698e5f | ||
|
|
9397c1c07c | ||
|
|
071231310c | ||
|
|
1c92ad3d6d | ||
|
|
facd10d882 | ||
|
|
e634a04dc7 | ||
|
|
f291e9c4d3 | ||
|
|
ed48e5ecd9 | ||
|
|
34e55a492e | ||
|
|
abf3d8fa1c | ||
|
|
6143d00476 | ||
|
|
a2fe11fd70 | ||
|
|
78ce646eee | ||
|
|
3115c578a0 | ||
|
|
5eb029baf1 | ||
|
|
cf0af20d89 | ||
|
|
ce067c3e2d | ||
|
|
801078e618 | ||
|
|
dabb3362c8 | ||
|
|
8d2af5ca66 | ||
|
|
31cdf55af8 | ||
|
|
c4dffd7584 | ||
|
|
14c86e3780 | ||
|
|
cc1126ff2f | ||
|
|
6b0fb9e54d | ||
|
|
8435d41d44 | ||
|
|
e92b9690d4 | ||
|
|
953ea36177 | ||
|
|
36d0d7da7b | ||
|
|
e101231f9b | ||
|
|
3090c59582 | ||
|
|
1de7e32f25 | ||
|
|
2bf058b089 | ||
|
|
c507714ab6 | ||
|
|
cdc72d2f23 | ||
|
|
2368adfebd | ||
|
|
46c000f6d1 | ||
|
|
4254ed4d86 | ||
|
|
3233807c17 | ||
|
|
b3501a2d4a | ||
|
|
3d5ac7c448 | ||
|
|
11e2a3845d | ||
|
|
9812c23513 | ||
|
|
5c02c1b50c | ||
|
|
f3f3f91fcb | ||
|
|
f8be56efdc | ||
|
|
dcae0155b2 | ||
|
|
7c21c670dc | ||
|
|
44c0d4bf15 | ||
|
|
39159d3ce7 | ||
|
|
62565d7c97 | ||
|
|
b8b268f0ad | ||
|
|
4182b3cd1e | ||
|
|
24c0390174 | ||
|
|
2b336d8c9f | ||
|
|
5b02a22d77 | ||
|
|
b680a6bf12 | ||
|
|
2b65d87bfa | ||
|
|
e214ad8154 | ||
|
|
3bf2ecc6e3 | ||
|
|
594e10d0a4 | ||
|
|
656f87f89c | ||
|
|
a5dd9b69e3 | ||
|
|
ae8949c6d6 | ||
|
|
eeb29355f1 | ||
|
|
4dea7cb650 | ||
|
|
da4177f0e4 | ||
|
|
c7b44ae8d9 | ||
|
|
37726c493d | ||
|
|
83af5ee757 | ||
|
|
c35df829b0 | ||
|
|
1539c37576 | ||
|
|
34b9029e90 | ||
|
|
50abefd5f9 | ||
|
|
0508554e2c | ||
|
|
67ab67c81b | ||
|
|
7bf263fd35 | ||
|
|
88067e64e6 | ||
|
|
8254b1040c | ||
|
|
fdaf6508b1 | ||
|
|
bbc9b8fb2b | ||
|
|
f229ab7de2 | ||
|
|
3b5b5be881 | ||
|
|
b9155f42d6 | ||
|
|
aa48edc0ff | ||
|
|
2f306d1181 | ||
|
|
0e01a32c64 | ||
|
|
a1b2e3b63b | ||
|
|
219509853f | ||
|
|
f66aa71ec1 | ||
|
|
e1e49f8edf | ||
|
|
bbb70421ed | ||
|
|
7a2785ba5c | ||
|
|
2c15230756 | ||
|
|
232755590d | ||
|
|
ddd040e395 | ||
|
|
a9dc255979 | ||
|
|
785073eb87 | ||
|
|
368a6d1217 | ||
|
|
13d2f9dd96 | ||
|
|
e85e54b86a | ||
|
|
e39d441d01 | ||
|
|
f6f15c8801 | ||
|
|
0dc8accb64 | ||
|
|
79964892f6 | ||
|
|
b648ddbfdf | ||
|
|
cab068357a | ||
|
|
acb4b39953 | ||
|
|
74481b1c31 | ||
|
|
aa9cd3f1ca | ||
|
|
7f67a3043a | ||
|
|
734413266b | ||
|
|
159d4cf085 | ||
|
|
4b380be637 | ||
|
|
0f84ee1e07 | ||
|
|
38df869afc | ||
|
|
c05c2ffaa2 | ||
|
|
bb86db3cd3 | ||
|
|
9e2e9632c2 | ||
|
|
2b686ebe74 | ||
|
|
15043d1de8 | ||
|
|
e00151ef39 | ||
|
|
160ea6aa5b | ||
|
|
7e3297e8c7 | ||
|
|
880a9c8939 | ||
|
|
64f9cbd54f | ||
|
|
6b97662f8a | ||
|
|
71f37acdf4 | ||
|
|
a58c300e84 | ||
|
|
b1ce6544f5 | ||
|
|
d5daf24c15 | ||
|
|
9b9aea9841 | ||
|
|
1145faef56 | ||
|
|
e42ca916fe | ||
|
|
24611614d6 | ||
|
|
6df45551e5 | ||
|
|
7c211c664f | ||
|
|
f07a2ef2be | ||
|
|
3df6d1f833 | ||
|
|
f6396d5e4a | ||
|
|
8db8c48fd9 | ||
|
|
8cc4710874 | ||
|
|
d42f4d764a | ||
|
|
21715f079b | ||
|
|
b345cb063f | ||
|
|
d6fdaa2874 | ||
|
|
daf2735eb3 | ||
|
|
68ad322f41 | ||
|
|
f688404ac6 | ||
|
|
13a9024dd1 | ||
|
|
2fdfc3750d | ||
|
|
9246aed660 | ||
|
|
0efb736b42 | ||
|
|
ef7fcb2114 | ||
|
|
52f4c049e1 | ||
|
|
ee00a41ff9 | ||
|
|
289fda94df | ||
|
|
49d1845129 | ||
|
|
d850f5575b | ||
|
|
1f2ffcf97a | ||
|
|
4ea63c3167 | ||
|
|
f2887abb49 | ||
|
|
3ada129e7f | ||
|
|
6c3a0e2b71 | ||
|
|
457feac4ac | ||
|
|
45728fbbda | ||
|
|
0d507855bd | ||
|
|
5fa2f3d955 | ||
|
|
bfc734138d | ||
|
|
fdfa830aa0 | ||
|
|
d78ea8efeb | ||
|
|
d47f5967e9 | ||
|
|
2debf9507a | ||
|
|
e527cd42a1 | ||
|
|
38399c0e1e | ||
|
|
43782ca3f8 | ||
|
|
b5f911e259 | ||
|
|
4596accf5a | ||
|
|
d4cad7a242 | ||
|
|
9ba732e0bf | ||
|
|
0034704b3f | ||
|
|
b6caa8a5ba | ||
|
|
cca9684ffb | ||
|
|
c00259a5b6 | ||
|
|
455730dad8 | ||
|
|
b17b80ee12 | ||
|
|
4fadf68da4 | ||
|
|
fb9aebf123 | ||
|
|
087c6775e3 | ||
|
|
a3c509ce61 | ||
|
|
6b0fce21a5 | ||
|
|
7b8b4674e7 | ||
|
|
4956873357 | ||
|
|
4dd1d6a244 | ||
|
|
65367947e0 | ||
|
|
a83414f831 | ||
|
|
bba894bdc3 | ||
|
|
190c4f212d | ||
|
|
d8a78d96ae | ||
|
|
1d30eb7d91 | ||
|
|
ac86758e79 | ||
|
|
afee6c32a3 | ||
|
|
7412236679 | ||
|
|
3ef433687a | ||
|
|
82d43d0b62 | ||
|
|
bf31e72384 | ||
|
|
2a37589a9f | ||
|
|
a334645910 | ||
|
|
6519a5b007 | ||
|
|
cafa01248a | ||
|
|
5ab14fef05 | ||
|
|
6b6ada5b2c | ||
|
|
18420275af | ||
|
|
8f283acf66 | ||
|
|
f27df74339 | ||
|
|
ca059a62a6 | ||
|
|
6dae2302c0 | ||
|
|
bae5f20ec4 | ||
|
|
51a4d92a90 | ||
|
|
d527f4104f | ||
|
|
2d74916ca5 | ||
|
|
0aabe4ae9b | ||
|
|
0a41b4ec68 | ||
|
|
9cf4a151aa | ||
|
|
10fcf566b8 | ||
|
|
2704a8b695 | ||
|
|
09814b7dcd | ||
|
|
4f2ce2625d | ||
|
|
9c368b7d10 | ||
|
|
f9bd5506c7 | ||
|
|
4a168d16a3 | ||
|
|
b817bd04ec | ||
|
|
43adae4e70 | ||
|
|
77ebba9c62 | ||
|
|
ee517c1800 | ||
|
|
154099c3f4 | ||
|
|
1746845651 | ||
|
|
d07ab2d7e1 | ||
|
|
f3b970ae14 | ||
|
|
16d8cddf12 | ||
|
|
671f7d810c | ||
|
|
0d94dd3fa5 | ||
|
|
eb5cfde630 | ||
|
|
aa04e3ec1d | ||
|
|
0333e29eef | ||
|
|
8929ee534f | ||
|
|
8eb347488f | ||
|
|
f8642a18df | ||
|
|
12ccd58eae | ||
|
|
95bb288e38 | ||
|
|
5c64f0825f | ||
|
|
25e97b97d4 | ||
|
|
d258d4da63 | ||
|
|
cb79688a73 | ||
|
|
dae75f6234 | ||
|
|
0209b51c4d | ||
|
|
f35c188496 | ||
|
|
c00d820c75 | ||
|
|
69689e286b | ||
|
|
5697580bd0 | ||
|
|
2288e99e56 | ||
|
|
c8fd6e76af | ||
|
|
23cb9afec7 | ||
|
|
20e8175ae1 | ||
|
|
3a38dceb5f | ||
|
|
c885cdefbb | ||
|
|
b7d5374718 | ||
|
|
59a0aadd72 | ||
|
|
a3f218a98d | ||
|
|
0424ced649 | ||
|
|
9f75968684 | ||
|
|
90fd503838 | ||
|
|
a7a3f2eef6 | ||
|
|
008a65329e | ||
|
|
2390c4284e | ||
|
|
75483185d6 | ||
|
|
acb21cb926 | ||
|
|
c0ee674060 | ||
|
|
7d69c8e3bd | ||
|
|
38a37c49de | ||
|
|
a36478b1f5 | ||
|
|
bcb17cd0a5 | ||
|
|
1ec164a25a | ||
|
|
571a9dcb3e | ||
|
|
a0ac6265e9 | ||
|
|
ea6f49f7be | ||
|
|
0470680a4d | ||
|
|
e0c52c8660 | ||
|
|
3182ce031c | ||
|
|
f6dd0ccd12 | ||
|
|
775b0c8c60 | ||
|
|
1c4424dd0b | ||
|
|
8501aec7bc | ||
|
|
05a36d3245 | ||
|
|
2bf8f9164e | ||
|
|
56732ea3e8 | ||
|
|
7a4b32aadb | ||
|
|
16add1bf24 | ||
|
|
433cdfe87d | ||
|
|
a3d0a0250a | ||
|
|
b037333d2b | ||
|
|
bf6c2ef266 | ||
|
|
abde922b49 | ||
|
|
eca89ca5e9 | ||
|
|
a91c987107 | ||
|
|
12166e2245 | ||
|
|
e612c20141 | ||
|
|
d2039e5566 | ||
|
|
20bba75e41 | ||
|
|
2d26b647c8 | ||
|
|
ab0bec7a7b | ||
|
|
b6c5f1b1e7 | ||
|
|
881cc4d255 | ||
|
|
3d61973071 | ||
|
|
5ae1f3c441 | ||
|
|
6ae4cf495d | ||
|
|
900fc9c4e3 | ||
|
|
0207e84551 | ||
|
|
3a2d663c86 | ||
|
|
7aaaaf9125 | ||
|
|
e051b9bffa | ||
|
|
df0bcda952 | ||
|
|
d871378336 | ||
|
|
f99add7a3f | ||
|
|
7515700b1a | ||
|
|
99db4d50d3 | ||
|
|
0cd8246bdb | ||
|
|
29ee81ef18 | ||
|
|
9e09c06770 | ||
|
|
65603ca314 | ||
|
|
a983d23f91 | ||
|
|
3545306559 | ||
|
|
08163cc5cd | ||
|
|
c629c3424c | ||
|
|
ef403119d9 | ||
|
|
798c126881 | ||
|
|
813d503bb8 | ||
|
|
7e71a06c5f | ||
|
|
68475a00c1 | ||
|
|
4d71b6943c | ||
|
|
42caddb8a3 | ||
|
|
52d8604099 | ||
|
|
2df3aef52d | ||
|
|
9773e25932 | ||
|
|
cd766d90e4 | ||
|
|
8f69fc84a8 | ||
|
|
a8f0882220 | ||
|
|
d79c28d2d3 | ||
|
|
ba756d12b2 | ||
|
|
48e6872233 | ||
|
|
5037a9bbfd | ||
|
|
3fcde95fe8 | ||
|
|
a58e5e4276 | ||
|
|
2235c10df7 | ||
|
|
327e09291b | ||
|
|
1dd36424be | ||
|
|
ade2d0ae54 | ||
|
|
ac3dbd25f3 | ||
|
|
2e6811d2d4 | ||
|
|
61a9d0c0a6 | ||
|
|
4cc775bcae | ||
|
|
96dfa52dba | ||
|
|
1f1329c536 | ||
|
|
3bb54f875d | ||
|
|
84b6c1cb87 | ||
|
|
4f4bb316d0 | ||
|
|
fe6430edc6 | ||
|
|
6c421de8c4 | ||
|
|
c04ae91dc5 | ||
|
|
14bc340e56 | ||
|
|
6fd107c230 | ||
|
|
5f2c2103a5 | ||
|
|
a06828dbcf | ||
|
|
b260cb8f50 | ||
|
|
2fc3355388 | ||
|
|
24d5a169f6 | ||
|
|
2bc0dd5fbe | ||
|
|
d76e5008a7 | ||
|
|
21f01757a3 | ||
|
|
4da936344f | ||
|
|
05920cc7d7 | ||
|
|
edb17ad06e | ||
|
|
ab6f8fa7bf | ||
|
|
b822608b15 | ||
|
|
7a9bda9b1b | ||
|
|
3edfce202f | ||
|
|
c5b4a822d9 | ||
|
|
e3ae862732 | ||
|
|
74b1127f6e | ||
|
|
2c3f12b38c | ||
|
|
94ee718aa9 | ||
|
|
f34620aa73 | ||
|
|
a43bb56a43 | ||
|
|
a4ed95b81b | ||
|
|
ddd8348bdd | ||
|
|
d32095f3fe | ||
|
|
a958bf8be7 | ||
|
|
2d643a551c | ||
|
|
b16d75ec43 | ||
|
|
f40af555c3 | ||
|
|
c82672d77b | ||
|
|
867488bf77 | ||
|
|
9c485334f1 | ||
|
|
04ff83fc2d | ||
|
|
d61e2751ef | ||
|
|
87b64572db | ||
|
|
50a33a5083 | ||
|
|
2dc72ab262 | ||
|
|
6dec0ea0f1 | ||
|
|
fdc4e867c2 | ||
|
|
525731fe33 | ||
|
|
66d86b8d4d | ||
|
|
2443d5d1cf | ||
|
|
8863e7337e | ||
|
|
27b31ff1fb | ||
|
|
58335025c4 | ||
|
|
c1225178d6 | ||
|
|
8b19040e45 | ||
|
|
6ba62b66b4 | ||
|
|
e1bd7d7ae9 | ||
|
|
c9b2c1d8d6 | ||
|
|
1ae2b960c7 | ||
|
|
0c2d4ab5cb | ||
|
|
b9460cbcea | ||
|
|
886a26cc5d | ||
|
|
94dcd98e8d | ||
|
|
c3038807b9 | ||
|
|
7acb8a9e85 | ||
|
|
2d47622a0e | ||
|
|
bbfe5d36e8 | ||
|
|
0ecb732d60 | ||
|
|
8b5ac30030 | ||
|
|
0c7bf10355 | ||
|
|
319273eb03 | ||
|
|
199c49ff5e | ||
|
|
8d967b1125 |
14
.github/ISSUE_TEMPLATE.txt
vendored
Normal file
14
.github/ISSUE_TEMPLATE.txt
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
The issue tracker is for reporting product deficiencies. "How do I?" questions should be posted to the discussion forum at https://groups.google.com/group/google-apps-manager. When in doubt, start at the discussion forum and return here only when instructed to do so.
|
||||
|
||||
Please confirm the following:
|
||||
* I have upgraded to the latest GAM release from https://git.io/gamreleases and I still have this issue.
|
||||
* I am typing the command as described in the GAM Wiki at https://github.com/jay0lee/gam/wiki
|
||||
|
||||
Full steps to reproduce the issue:
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
Expected outcome (what are you trying to do?):
|
||||
|
||||
Actual outcome (what errors or bad behavior do you see instead?):
|
||||
14
.github/ISSUE_TEMPLATE/aa-question.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/aa-question.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Question about using GAM
|
||||
about: Help with using GAM or running it for the first time
|
||||
title: Please use the GAM discussion group
|
||||
labels: invalid
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
If you need help with GAM, please do not file an issue here, it will be closed and ignored.
|
||||
|
||||
Please post your question to the GAM discussion group where other admins are ready and willing to help:
|
||||
|
||||
https://groups.google.com/g/google-apps-manager
|
||||
23
.github/ISSUE_TEMPLATE/za-bug-report.md
vendored
Normal file
23
.github/ISSUE_TEMPLATE/za-bug-report.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: jay0lee
|
||||
|
||||
---
|
||||
|
||||
The issue tracker is for reporting product deficiencies. "How do I?" questions should be posted to the discussion forum at https://groups.google.com/group/google-apps-manager. When in doubt, start at the discussion forum and return here only when instructed to do so.
|
||||
|
||||
Please confirm the following:
|
||||
* I have upgraded to the latest GAM release from https://git.io/gamreleases and I still have this issue.
|
||||
* I am typing the command as described in the GAM Wiki at https://github.com/jay0lee/gam/wiki
|
||||
|
||||
Full steps to reproduce the issue:
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
Expected outcome (what are you trying to do?):
|
||||
|
||||
Actual outcome (what errors or bad behavior do you see instead?):
|
||||
20
.github/ISSUE_TEMPLATE/zz-feature-request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/zz-feature-request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for GAM
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: jay0lee
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
BIN
.github/actions/creds.tar.gpg
vendored
Normal file
BIN
.github/actions/creds.tar.gpg
vendored
Normal file
Binary file not shown.
17
.github/actions/decrypt.sh
vendored
Normal file
17
.github/actions/decrypt.sh
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
gpgfile="$1"
|
||||
echo "source file is ${gpgfile}"
|
||||
credsfile="$2"
|
||||
echo "target file is ${credsfile}"
|
||||
if [ -z ${PASSCODE+x} ]; then
|
||||
echo "PASSCODE is unset";
|
||||
else
|
||||
echo "PASSCODE is set";
|
||||
fi
|
||||
|
||||
gpg --quiet --batch --yes --decrypt --passphrase="${PASSCODE}" \
|
||||
--output "${credsfile}" "${gpgfile}"
|
||||
|
||||
tar xvvf "${credsfile}" --directory "${gampath}"
|
||||
ls -l "${gampath}"
|
||||
113
.github/actions/linux-before-install.sh
vendored
Executable file
113
.github/actions/linux-before-install.sh
vendored
Executable file
@@ -0,0 +1,113 @@
|
||||
echo "RUNNING: apt update..."
|
||||
sudo apt-get -qq --yes update > /dev/null
|
||||
sudo apt-get -qq --yes install swig libpcsclite-dev
|
||||
if [[ "$TRAVIS_JOB_NAME" == *"Testing" ]]; then
|
||||
export python="python"
|
||||
export pip="pip"
|
||||
echo "Travis setup Python $TRAVIS_PYTHON_VERSION"
|
||||
echo "running tests with this version"
|
||||
else
|
||||
export whereibelong=$(pwd)
|
||||
echo "We are running on $ImageOS $ImageVersion"
|
||||
export LD_LIBRARY_PATH=~/ssl/lib:~/python/lib
|
||||
cpucount=$(nproc --all)
|
||||
echo "This device has $cpucount CPUs for compiling..."
|
||||
SSLVER=$(~/ssl/bin/openssl version)
|
||||
SSLRESULT=$?
|
||||
PYVER=$(~/python/bin/python3 -V)
|
||||
PYRESULT=$?
|
||||
if [ $SSLRESULT -ne 0 ] || [[ "$SSLVER" != "OpenSSL $BUILD_OPENSSL_VERSION "* ]] || [ $PYRESULT -ne 0 ] || [[ "$PYVER" != "Python $BUILD_PYTHON_VERSION"* ]]; then
|
||||
echo "SSL Result: $SSLRESULT - SSL Ver: $SSLVER - Py Result: $PYRESULT - Py Ver: $PYVER"
|
||||
if [ $SSLRESULT -ne 0 ]; then
|
||||
echo "sslresult -ne 0"
|
||||
fi
|
||||
if [[ "$SSLVER" != "OpenSSL $BUILD_OPENSSL_VERSION "* ]]; then
|
||||
echo "sslver not equal to..."
|
||||
fi
|
||||
if [ $PYRESULT -ne 0 ]; then
|
||||
echo "pyresult -ne 0"
|
||||
fi
|
||||
if [[ "$PYVER" != "Python $BUILD_PYTHON_VERSION" ]]; then
|
||||
echo "pyver not equal to..."
|
||||
fi
|
||||
cd ~
|
||||
rm -rf ssl
|
||||
rm -rf python
|
||||
mkdir ssl
|
||||
mkdir python
|
||||
echo "RUNNING: apt upgrade..."
|
||||
sudo apt-mark hold openssh-server
|
||||
sudo apt-get --yes upgrade
|
||||
sudo apt-get --yes --with-new-pkgs upgrade
|
||||
echo "Installing build tools..."
|
||||
sudo apt-get -qq --yes install build-essential
|
||||
echo "Installing deps for python3"
|
||||
sudo cp -v /etc/apt/sources.list /tmp
|
||||
sudo chmod a+rwx /tmp/sources.list
|
||||
echo "deb-src http://archive.ubuntu.com/ubuntu/ $TRAVIS_DIST main" >> /tmp/sources.list
|
||||
sudo cp -v /tmp/sources.list /etc/apt
|
||||
sudo apt-get -qq --yes update > /dev/null
|
||||
sudo apt-get -qq --yes build-dep python3 > /dev/null
|
||||
|
||||
# Compile latest OpenSSL
|
||||
wget --quiet https://www.openssl.org/source/openssl-$BUILD_OPENSSL_VERSION.tar.gz
|
||||
echo "Extracting OpenSSL..."
|
||||
tar xf openssl-$BUILD_OPENSSL_VERSION.tar.gz
|
||||
cd openssl-$BUILD_OPENSSL_VERSION
|
||||
echo "Compiling OpenSSL $BUILD_OPENSSL_VERSION..."
|
||||
./config shared --prefix=$HOME/ssl
|
||||
echo "Running make for OpenSSL..."
|
||||
make -j$cpucount -s
|
||||
echo "Running make install for OpenSSL..."
|
||||
make install > /dev/null
|
||||
cd ~
|
||||
|
||||
# Compile latest Python
|
||||
echo "Downloading Python $BUILD_PYTHON_VERSION..."
|
||||
curl -O https://www.python.org/ftp/python/$BUILD_PYTHON_VERSION/Python-$BUILD_PYTHON_VERSION.tar.xz
|
||||
echo "Extracting Python..."
|
||||
tar xf Python-$BUILD_PYTHON_VERSION.tar.xz
|
||||
cd Python-$BUILD_PYTHON_VERSION
|
||||
echo "Compiling Python $BUILD_PYTHON_VERSION..."
|
||||
safe_flags="--with-openssl=$HOME/ssl --enable-shared --prefix=$HOME/python --with-ensurepip=upgrade"
|
||||
unsafe_flags="--enable-optimizations --with-lto"
|
||||
if [ ! -e Makefile ]; then
|
||||
echo "running configure with safe and unsafe"
|
||||
./configure $safe_flags $unsafe_flags > /dev/null
|
||||
fi
|
||||
#make -j$cpucount PROFILE_TASK="-m test.regrtest --pgo -j$(( $cpucount * 2 ))" -s
|
||||
make -j$cpucount -s
|
||||
RESULT=$?
|
||||
echo "First make exited with $RESULT"
|
||||
if [ $RESULT != 0 ]; then
|
||||
echo "Trying Python compile again without unsafe flags..."
|
||||
make clean
|
||||
./configure $safe_flags > /dev/null
|
||||
make -j$cpucount -s
|
||||
echo "Sticking with safe Python for now..."
|
||||
fi
|
||||
echo "Installing Python..."
|
||||
make install > /dev/null
|
||||
cd ~
|
||||
fi
|
||||
|
||||
python=~/python/bin/python3
|
||||
pip=~/python/bin/pip3
|
||||
|
||||
if ([ "${ImageOS}" == "ubuntu16" ]) && [ "${HOSTTYPE}" == "x86_64" ]; then
|
||||
echo "Installing deps for StaticX..."
|
||||
if [ ! -d patchelf-$PATCHELF_VERSION ]; then
|
||||
echo "Downloading PatchELF $PATCHELF_VERSION"
|
||||
wget https://github.com/NixOS/patchelf/archive/$PATCHELF_VERSION.tar.gz
|
||||
tar xf $PATCHELF_VERSION.tar.gz
|
||||
cd patchelf-$PATCHELF_VERSION/
|
||||
./bootstrap.sh
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
fi
|
||||
$pip install staticx
|
||||
fi
|
||||
|
||||
cd $whereibelong
|
||||
fi
|
||||
34
.github/actions/linux-install.sh
vendored
Executable file
34
.github/actions/linux-install.sh
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
export distpath="dist/"
|
||||
export gampath="${distpath}gam"
|
||||
rm -rf $gampath
|
||||
#mkdir -p $gampath
|
||||
#export gampath=$(readlink -e $gampath)
|
||||
$pip install wheel
|
||||
$python -OO -m PyInstaller --clean --noupx --strip --distpath $gampath gam.spec
|
||||
export gam="${gampath}/gam"
|
||||
export GAMVERSION=`$gam version simple`
|
||||
cp LICENSE $gampath
|
||||
cp GamCommands.txt $gampath
|
||||
this_glibc_ver=$(ldd --version | awk '/ldd/{print $NF}')
|
||||
GAM_ARCHIVE="gam-${GAMVERSION}-${GAMOS}-${PLATFORM}-glibc${this_glibc_ver}.tar.xz"
|
||||
rm $gampath/lastupdatecheck.txt
|
||||
# tar will cd to dist and tar up gam/
|
||||
tar -C ${distpath} --create --file $GAM_ARCHIVE --xz gam
|
||||
echo "PyInstaller GAM info:"
|
||||
du -h $gam
|
||||
time $gam version extended
|
||||
if ([ "${ImageOS}" == "ubuntu16" ]) && [ "${HOSTTYPE}" == "x86_64" ]; then
|
||||
GAM_LEGACY_ARCHIVE=gam-${GAMVERSION}-${GAMOS}-${PLATFORM}-legacy.tar.xz
|
||||
$python -OO -m staticx -l /lib/x86_64-linux-gnu/libresolv.so.2 -l /lib/x86_64-linux-gnu/libnss_dns.so.2 $gam $gam-staticx
|
||||
strip $gam-staticx
|
||||
rm $gampath/gam
|
||||
mv $gam-staticx $gam
|
||||
chmod 755 $gam
|
||||
rm $gampath/lastupdatecheck.txt
|
||||
tar -C dist/ --create --file $GAM_LEGACY_ARCHIVE --xz gam
|
||||
echo "Legacy StaticX GAM info:"
|
||||
du -h $gam
|
||||
time $gam version extended
|
||||
fi
|
||||
echo "GAM packages:"
|
||||
ls -l gam-*.tar.xz
|
||||
132
.github/actions/macos-before-install.sh
vendored
Executable file
132
.github/actions/macos-before-install.sh
vendored
Executable file
@@ -0,0 +1,132 @@
|
||||
mypath=$HOME
|
||||
whereibelong=$(pwd)
|
||||
cpucount=$(sysctl -n hw.ncpu)
|
||||
echo "This device has $cpucount CPUs for compiling..."
|
||||
|
||||
#echo "Brew installing xz..."
|
||||
#brew install xz > /dev/null
|
||||
|
||||
#brew upgrade
|
||||
|
||||
brew install coreutils
|
||||
brew install bash
|
||||
|
||||
# prefer standard GNU tools like date over MacOS defaults
|
||||
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$(brew --prefix)/opt/gnu-tar/libexec/gnubin:$PATH"
|
||||
|
||||
date --version
|
||||
gdate --version
|
||||
bash --version
|
||||
|
||||
cd ~
|
||||
|
||||
# Use official Python.org version of Python which is backwards compatible
|
||||
# with older MacOS versions
|
||||
export pyfile=python-$BUILD_PYTHON_VERSION-macos11.pkg
|
||||
|
||||
wget https://www.python.org/ftp/python/$BUILD_PYTHON_VERSION/$pyfile
|
||||
echo "installing Python $BUILD_PYTHON_VERSION..."
|
||||
sudo installer -pkg ./$pyfile -target /
|
||||
|
||||
# This fixes https://github.com/pyinstaller/pyinstaller/issues/5062
|
||||
codesign --remove-signature /Library/Frameworks/Python.framework/Versions/3.9/Python
|
||||
|
||||
#if [ ! -f python-$MIN_PYTHON_VERSION-macosx10.9.pkg ]; then
|
||||
# wget --quiet https://www.python.org/ftp/python/$MIN_PYTHON_VERSION/python-$MIN_PYTHON_VERSION-macosx10.9.pkg
|
||||
#fi
|
||||
#sudo installer -pkg python-$MIN_PYTHON_VERSION-macosx10.9.pkg -target /
|
||||
|
||||
#brew install openssl@1.1
|
||||
#brew upgrade python
|
||||
|
||||
#export python=python3
|
||||
#export pip=pip3
|
||||
|
||||
#echo "Python location:"
|
||||
#which $python
|
||||
|
||||
cd ~
|
||||
|
||||
#export LD_LIBRARY_PATH=~/ssl/lib:~/python/lib
|
||||
#export openssl=~/ssl/bin/openssl
|
||||
#export python=~/python/bin/python3
|
||||
#export pip=~/python/bin/pip3
|
||||
|
||||
export python=/usr/local/bin/python3
|
||||
export pip=/usr/local/bin/pip3
|
||||
SSLVER=$($openssl version)
|
||||
SSLRESULT=$?
|
||||
PYVER=$($python -V)
|
||||
PYRESULT=$?
|
||||
|
||||
brew install swig
|
||||
$pip install pyscard
|
||||
|
||||
#wget --quiet https://www.python.org/ftp/python/$BUILD_PYTHON_VERSION/python-$BUILD_PYTHON_VERSION-macosx10.9.pkg
|
||||
|
||||
#if [ $SSLRESULT -ne 0 ] || [[ "$SSLVER" != "OpenSSL $BUILD_OPENSSL_VERSION "* ]] || [ $PYRESULT -ne 0 ] || [[ "$PYVER" != "Python $BUILD_PYTHON_VERSION"* ]]; then
|
||||
# echo "SSL Result: $SSLRESULT - SSL Ver: $SSLVER - Py Result: $PYRESULT - Py Ver: $PYVER"
|
||||
# if [ $SSLRESULT -ne 0 ]; then
|
||||
# echo "sslresult -ne 0"
|
||||
# fi
|
||||
# if [[ "$SSLVER" != "OpenSSL $BUILD_OPENSSL_VERSION "* ]]; then
|
||||
# echo "sslver not equal to..."
|
||||
# fi
|
||||
# if [ $PYRESULT -ne 0 ]; then
|
||||
# echo "pyresult -ne 0"
|
||||
# fi
|
||||
# if [[ "$PYVER" != "Python $BUILD_PYTHON_VERSION" ]]; then
|
||||
# echo "pyver not equal to..."
|
||||
# fi
|
||||
|
||||
# Start clean
|
||||
# rm -rf python
|
||||
# rm -rf ssl
|
||||
# mkdir python
|
||||
# mkdir ssl
|
||||
|
||||
# Compile latest OpenSSL
|
||||
# wget --quiet https://www.openssl.org/source/openssl-$BUILD_OPENSSL_VERSION.tar.gz
|
||||
# echo "Extracting OpenSSL..."
|
||||
# tar xf openssl-$BUILD_OPENSSL_VERSION.tar.gz
|
||||
# cd openssl-$BUILD_OPENSSL_VERSION
|
||||
# echo "Compiling OpenSSL $BUILD_OPENSSL_VERSION..."
|
||||
# ./config shared --prefix=$HOME/ssl
|
||||
# echo "Running make for OpenSSL..."
|
||||
# make -j$cpucount -s
|
||||
# echo "Running make install for OpenSSL..."
|
||||
# make install > /dev/null
|
||||
# cd ~
|
||||
|
||||
# Compile latest Python
|
||||
# echo "Downloading Python $BUILD_PYTHON_VERSION..."
|
||||
# curl -O https://www.python.org/ftp/python/$BUILD_PYTHON_VERSION/Python-$BUILD_PYTHON_VERSION.tar.xz
|
||||
# echo "Extracting Python..."
|
||||
# tar xf Python-$BUILD_PYTHON_VERSION.tar.xz
|
||||
# cd Python-$BUILD_PYTHON_VERSION
|
||||
# echo "Compiling Python $BUILD_PYTHON_VERSION..."
|
||||
# safe_flags="--with-openssl=$HOME/ssl --enable-shared --prefix=$HOME/python --with-ensurepip=upgrade"
|
||||
# unsafe_flags="--enable-optimizations --with-lto"
|
||||
# if [ ! -e Makefile ]; then
|
||||
# echo "running configure with safe and unsafe"
|
||||
# ./configure $safe_flags $unsafe_flags > /dev/null
|
||||
# fi
|
||||
# make -j$cpucount PROFILE_TASK="-m test.regrtest --pgo -j$(( $cpucount * 2 ))" -s
|
||||
# RESULT=$?
|
||||
# echo "First make exited with $RESULT"
|
||||
# if [ $RESULT != 0 ]; then
|
||||
# echo "Trying Python compile again without unsafe flags..."
|
||||
# make clean
|
||||
# ./configure $safe_flags > /dev/null
|
||||
# make -j$cpucount -s
|
||||
# echo "Sticking with safe Python for now..."
|
||||
# fi
|
||||
# echo "Installing Python..."
|
||||
# make install > /dev/null
|
||||
# cd ~
|
||||
#fi
|
||||
|
||||
$python -V
|
||||
|
||||
cd $whereibelong
|
||||
|
||||
19
.github/actions/macos-install.sh
vendored
Executable file
19
.github/actions/macos-install.sh
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
echo "MacOS Version Info According to Python:"
|
||||
macver=$(python -c "import platform; print(platform.mac_ver()[0])")
|
||||
echo $macver
|
||||
echo "Xcode version:"
|
||||
xcodebuild -version
|
||||
export distpath="dist/"
|
||||
export gampath="${distpath}gam"
|
||||
rm -rf $gampath
|
||||
export specfile="gam.spec"
|
||||
$python -OO -m PyInstaller --clean --noupx --strip --distpath "${gampath}" --target-architecture $PLATFORM "${specfile}"
|
||||
export gam="${gampath}/gam"
|
||||
$gam version extended
|
||||
export GAMVERSION=`$gam version simple`
|
||||
cp LICENSE "${gampath}"
|
||||
cp GamCommands.txt "${gampath}"
|
||||
GAM_ARCHIVE="gam-${GAMVERSION}-${GAMOS}-${PLATFORM}.tar.xz"
|
||||
rm "${gampath}/lastupdatecheck.txt"
|
||||
# tar will cd to dist/ and tar up gam/
|
||||
tar -C dist/ --create --file $GAM_ARCHIVE --xz gam
|
||||
57
.github/actions/windows-before-install.sh
vendored
Executable file
57
.github/actions/windows-before-install.sh
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
if [[ "$PLATFORM" == "x86_64" ]]; then
|
||||
export BITS="64"
|
||||
export PYTHONFILE_BITS="-amd64"
|
||||
export OPENSSL_BITS="-x64"
|
||||
elif [[ "$PLATFORM" == "x86" ]]; then
|
||||
export BITS="32"
|
||||
export PYTHONFILE_BITS=""
|
||||
export OPENSSL_BITS=""
|
||||
export CHOCOPTIONS="--forcex86"
|
||||
fi
|
||||
echo "This is a ${BITS}-bit build for ${PLATFORM}"
|
||||
|
||||
export mypath=$(pwd)
|
||||
cd ~
|
||||
|
||||
export python="c:\python\python.exe"
|
||||
export pip="c:\python\scripts\pip.exe"
|
||||
|
||||
# pyscard needs swig, keep these two together
|
||||
choco install $CHOCOPTIONS swig
|
||||
$pip install pyscard
|
||||
|
||||
# Python
|
||||
#echo "Installing Python..."
|
||||
#export python_file=python-${BUILD_PYTHON_VERSION}${PYTHONFILE_BITS}.exe
|
||||
#if [ ! -e $python_file ]; then
|
||||
# echo "Downloading $python_file..."
|
||||
# curl -O https://www.python.org/ftp/python/$BUILD_PYTHON_VERSION/$python_file
|
||||
#fi
|
||||
#until ./${python_file} /quiet InstallAllUsers=1 TargetDir=c:\\python; do echo "trying python again..."; done
|
||||
#export python=/c/python/python.exe
|
||||
#export pip=/c/python/scripts/pip.exe
|
||||
#until [ -f $python ]; do sleep 1; done
|
||||
#export PATH=$PATH:/c/python/scripts
|
||||
|
||||
# OpenSSL
|
||||
#echo "Installing OpenSSL..."
|
||||
#export exefile=Win${BITS}OpenSSL_Light-${BUILD_OPENSSL_VERSION//./_}.exe
|
||||
#if [ ! -e $exefile ]; then
|
||||
# echo "Downloading $exefile..."
|
||||
# curl -O https://slproweb.com/download/$exefile
|
||||
#fi
|
||||
#until ./${exefile} /silent /sp- /suppressmsgboxes /DIR=C:\\ssl; do echo "trying openssl again..."; done
|
||||
#until cp -v /c/ssl/libcrypto-1_1${OPENSSL_BITS}.dll /c/python/DLLs/; do echo "trying libcrypto copy again..."; sleep 3; done
|
||||
#until cp -v /c/ssl/libssl-1_1${OPENSSL_BITS}.dll /c/python/DLLs/; do echo "trying libssl copy again..."; done
|
||||
#if [[ "$PLATFORM" == "x86_64" ]]; then
|
||||
# cp -v /c/python/DLLs/libssl-1_1-x64.dll /c/python/DLLs/libssl-1_1.dll
|
||||
# cp -v /c/python/DLLs/libcrypto-1_1-x64.dll /c/python/DLLs/libcrypto-1_1.dll
|
||||
#fi
|
||||
|
||||
cd $mypath
|
||||
|
||||
echo "PATH: $PATH"
|
||||
cd ..
|
||||
$python setup.py install
|
||||
echo "cd to $mypath"
|
||||
cd $mypath
|
||||
31
.github/actions/windows-install.sh
vendored
Executable file
31
.github/actions/windows-install.sh
vendored
Executable file
@@ -0,0 +1,31 @@
|
||||
if [[ "$PLATFORM" == "x86_64" ]]; then
|
||||
export WIX_BITS="x64"
|
||||
elif [[ "$PLATFORM" == "x86" ]]; then
|
||||
export WIX_BITS="x86"
|
||||
fi
|
||||
echo "compiling GAM with pyinstaller..."
|
||||
export distpath="dist/"
|
||||
export gampath="${distpath}gam"
|
||||
rm -rf $gampath
|
||||
/c/python/scripts/pyinstaller --clean --noupx --distpath $gampath gam.spec
|
||||
export gam="${gampath}/gam"
|
||||
echo "running compiled GAM..."
|
||||
$gam version
|
||||
export GAMVERSION=$($gam version simple)
|
||||
rm $gampath/lastupdatecheck.txt
|
||||
cp LICENSE $gampath
|
||||
cp GamCommands.txt $gampath
|
||||
cp gam-setup.bat $gampath
|
||||
GAM_ARCHIVE=gam-$GAMVERSION-$GAMOS-$PLATFORM.zip
|
||||
cwd=$(pwd)
|
||||
cd "${distpath}"
|
||||
/c/Program\ Files/7-Zip/7z.exe a -tzip $GAM_ARCHIVE gam -xr!.svn
|
||||
mv "${GAM_ARCHIVE}" "${cwd}"
|
||||
cd "${cwd}"
|
||||
echo "Running WIX candle $WIX_BITS..."
|
||||
/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/candle.exe -arch $WIX_BITS gam.wxs
|
||||
echo "Done with WIX candle..."
|
||||
echo "Running WIX light..."
|
||||
/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/light.exe -ext /c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/WixUIExtension.dll gam.wixobj -o gam-$GAMVERSION-$GAMOS-$PLATFORM.msi || true;
|
||||
echo "Done with WIX light..."
|
||||
rm *.wixpdb
|
||||
61
.github/stale.yml
vendored
Normal file
61
.github/stale.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||
daysUntilStale: 90
|
||||
|
||||
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
||||
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||
daysUntilClose: 7
|
||||
|
||||
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
|
||||
onlyLabels: []
|
||||
|
||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- enhancement
|
||||
- help wanted
|
||||
- security
|
||||
|
||||
# Set to true to ignore issues in a project (defaults to false)
|
||||
exemptProjects: false
|
||||
|
||||
# Set to true to ignore issues in a milestone (defaults to false)
|
||||
exemptMilestones: false
|
||||
|
||||
# Set to true to ignore issues with an assignee (defaults to false)
|
||||
exemptAssignees: false
|
||||
|
||||
# Label to use when marking as stale
|
||||
staleLabel: wontfix
|
||||
|
||||
# Comment to post when marking as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs.
|
||||
|
||||
# Comment to post when removing the stale label.
|
||||
# unmarkComment: >
|
||||
# Your comment here.
|
||||
|
||||
# Comment to post when closing a stale Issue or Pull Request.
|
||||
# closeComment: >
|
||||
# Your comment here.
|
||||
|
||||
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||
limitPerRun: 30
|
||||
|
||||
# Limit to only `issues` or `pulls`
|
||||
# only: issues
|
||||
|
||||
# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
|
||||
# pulls:
|
||||
# daysUntilStale: 30
|
||||
# markComment: >
|
||||
# This pull request has been automatically marked as stale because it has not had
|
||||
# recent activity. It will be closed if no further activity occurs. Thank you
|
||||
# for your contributions.
|
||||
|
||||
# issues:
|
||||
# exemptLabels:
|
||||
# - confirmed
|
||||
373
.github/workflows/build.yml
vendored
Normal file
373
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,373 @@
|
||||
name: Build and test GAM
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '37 22 * * *'
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: src
|
||||
|
||||
env:
|
||||
BUILD_PYTHON_VERSION: "3.9.6"
|
||||
MIN_PYTHON_VERSION: "3.9.6"
|
||||
BUILD_OPENSSL_VERSION: "1.1.1k"
|
||||
MIN_OPENSSL_VERSION: "1.1.1k"
|
||||
PATCHELF_VERSION: "0.12"
|
||||
# PYINSTALLER_VERSION can be full commit hash or version like v4.20
|
||||
PYINSTALLER_VERSION: "0f2b2e921433ab5a510c7efdb21d9c1d7cfbc645"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-16.04
|
||||
jid: 1
|
||||
goal: "build"
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: ubuntu-18.04
|
||||
jid: 2
|
||||
goal: "build"
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: ubuntu-20.04
|
||||
jid: 3
|
||||
goal: "build"
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: macos-11.0
|
||||
jid: 12
|
||||
goal: "build"
|
||||
gamos: "macos"
|
||||
platform: "universal2"
|
||||
- os: windows-2019
|
||||
jid: 5
|
||||
goal: "build"
|
||||
gamos: "windows"
|
||||
pyarch: "x64"
|
||||
platform: "x86_64"
|
||||
- os: windows-2019
|
||||
jid: 6
|
||||
goal: "build"
|
||||
gamos: "windows"
|
||||
platform: "x86"
|
||||
pyarch: "x86"
|
||||
- os: ubuntu-20.04
|
||||
goal: "test"
|
||||
python: "3.6"
|
||||
jid: 7
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: ubuntu-20.04
|
||||
goal: "test"
|
||||
python: "3.7"
|
||||
jid: 8
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: ubuntu-20.04
|
||||
goal: "test"
|
||||
python: "3.8"
|
||||
jid: 9
|
||||
gamos: "linux"
|
||||
platform: "x86_64"
|
||||
- os: ubuntu-20.04
|
||||
goal: test
|
||||
python: "3.10.0-beta.1"
|
||||
jid: 10
|
||||
gamos: linux
|
||||
platform: x86_64
|
||||
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache multiple paths
|
||||
uses: actions/cache@v2
|
||||
if: matrix.goal != 'test'
|
||||
with:
|
||||
path: |
|
||||
~/python
|
||||
~/ssl
|
||||
key: ${{ matrix.os }}-${{ matrix.jid }}-20210628
|
||||
|
||||
- name: Set env variables
|
||||
env:
|
||||
GAMOS: ${{ matrix.gamos }}
|
||||
GOAL: ${{ matrix.goal }}
|
||||
JID: ${{ matrix.jid }}
|
||||
PLATFORM: ${{ matrix.platform }}
|
||||
run: |
|
||||
echo "GAMOS=${GAMOS}" >> $GITHUB_ENV
|
||||
echo "GOAL=${GOAL}" >> $GITHUB_ENV
|
||||
echo "JID=${JID}" >> $GITHUB_ENV
|
||||
echo "PLATFORM=${PLATFORM}" >> $GITHUB_ENV
|
||||
uname -a
|
||||
|
||||
- name: Use pre-compiled Python for testing
|
||||
if: matrix.python != ''
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python }}
|
||||
architecture: ${{ matrix.pyarch }}
|
||||
|
||||
- name: Install Python on Windows
|
||||
if: matrix.os == 'windows-2019'
|
||||
run: |
|
||||
if ( ${Env:PLATFORM} -eq "x86_64" )
|
||||
{
|
||||
Set-Variable -name py_arch -value "-amd64"
|
||||
}
|
||||
else
|
||||
{
|
||||
Set-Variable -name py_arch -value ""
|
||||
}
|
||||
Write-Output "py_arch: $py_arch"
|
||||
Set-Variable -name python_file -value "python-${Env:BUILD_PYTHON_VERSION}${py_arch}.exe"
|
||||
Write-Output "python_file: $python_file"
|
||||
Set-Variable -name python_url -value "https://www.python.org/ftp/python/${Env:BUILD_PYTHON_VERSION}/${python_file}"
|
||||
Write-Output "python_url: $python_url"
|
||||
Invoke-WebRequest -Uri $python_url -OutFile $python_file
|
||||
Start-Process -wait -FilePath $python_file -ArgumentList "/quiet","InstallAllUsers=0","TargetDir=c:\\python","AssociateFiles=1","PrependPath=1"
|
||||
shell: pwsh
|
||||
|
||||
- name: Set env variables for pre-compiled Python
|
||||
if: matrix.goal == 'test'
|
||||
run: |
|
||||
export python=$(which python3)
|
||||
export pip=$(which pip3)
|
||||
export gam="${python} -m gam"
|
||||
export gampath="$(readlink -e .)"
|
||||
echo -e "python: $python\npip: $pip\ngam: $gam\ngampath: $gampath"
|
||||
echo "python=${python}" >> $GITHUB_ENV
|
||||
echo "pip=${pip}" >> $GITHUB_ENV
|
||||
echo "gam=${gam}" >> $GITHUB_ENV
|
||||
echo "gampath=${gampath}" >> $GITHUB_ENV
|
||||
echo "RUNNING: apt update..."
|
||||
sudo apt-get -qq --yes update > /dev/null
|
||||
sudo apt-get -qq --yes install swig libpcsclite-dev
|
||||
$pip install --upgrade pip
|
||||
|
||||
- name: Build and install Python, OpenSSL and PyInstaller
|
||||
if: matrix.goal != 'test' && steps.cache-primes.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
set +e
|
||||
source ../.github/actions/${GAMOS}-before-install.sh
|
||||
echo "PATH=$PATH" >> $GITHUB_ENV # keep gnutools for MacOS
|
||||
echo "python=$python" >> $GITHUB_ENV
|
||||
echo "pip=$pip" >> $GITHUB_ENV
|
||||
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV
|
||||
echo -e "Python: $python\nPip: $pip\nLD_LIB...: $LD_LIBRARY_PATH"
|
||||
$pip install wheel
|
||||
export url="https://codeload.github.com/pyinstaller/pyinstaller/tar.gz/${PYINSTALLER_VERSION}"
|
||||
echo "Downloading ${url}"
|
||||
curl -o pyinstaller.tar.gz --compressed "${url}"
|
||||
tar xf pyinstaller.tar.gz
|
||||
cd "pyinstaller-${PYINSTALLER_VERSION}/"
|
||||
if [ $GAMOS == "windows" ]; then
|
||||
# remove pre-compiled bootloaders so we fail if bootloader compile fails
|
||||
rm -rf PyInstaller/bootloader/*bit
|
||||
cd bootloader
|
||||
if [ "${PLATFORM}" == "x86" ]; then
|
||||
TARGETARCH="--target-arch=32bit"
|
||||
else
|
||||
TARGETARCH=""
|
||||
fi
|
||||
$python ./waf all $TARGETARCH
|
||||
cd ..
|
||||
fi
|
||||
$python setup.py install
|
||||
#$pip install pyinstaller
|
||||
|
||||
- name: Install pip requirements
|
||||
if: matrix.os != 'self-hosted'
|
||||
run: |
|
||||
set +e
|
||||
$pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 $pip install -U --force-reinstall
|
||||
|
||||
$pip install --upgrade -r requirements.txt
|
||||
|
||||
- name: Build GAM with PyInstaller
|
||||
if: matrix.goal != 'test'
|
||||
run: |
|
||||
set +e
|
||||
source ../.github/actions/${GAMOS}-install.sh
|
||||
ls -alRF $gampath
|
||||
echo "gampath=$gampath" >> $GITHUB_ENV
|
||||
echo "gam=$gam" >> $GITHUB_ENV
|
||||
echo -e "GAM: ${gam}\nGAMPATH: ${gampath}\nGAMVERSION: ${GAMVERSION}"
|
||||
|
||||
- name: Basic Tests all jobs
|
||||
run: |
|
||||
echo -e "python: $python\npip: $pip\ngam: $gam\ngampath: $gampath\n"
|
||||
$python -m unittest discover --start-directory ./ --pattern "*_test.py" --buffer
|
||||
touch "${gampath}/nobrowser.txt"
|
||||
$gam version extended
|
||||
export GAMVERSION=$($gam version simple)
|
||||
echo "GAM Version ${GAMVERSION}"
|
||||
echo "GAMVERSION=${GAMVERSION}" >> $GITHUB_ENV
|
||||
|
||||
- name: Basic Tests build jobs only
|
||||
if: matrix.goal != 'test'
|
||||
run: |
|
||||
export vline=$($gam version | grep "Python ")
|
||||
export python_line=($vline)
|
||||
export this_python=${python_line[1]}
|
||||
$python tools/a_atleast_b.py "${this_python}" "${MIN_PYTHON_VERSION}"
|
||||
export vline=$($gam version extended | grep "OpenSSL ")
|
||||
export openssl_line=($vline)
|
||||
export this_openssl="${openssl_line[1]}"
|
||||
$python tools/a_atleast_b.py "${this_openssl}" "${MIN_OPENSSL_VERSION}"
|
||||
|
||||
|
||||
- name: Live API tests push only
|
||||
if: github.event_name == 'push' || github.event_name == 'schedule'
|
||||
env: # Or as an environment variable
|
||||
PASSCODE: ${{ secrets.PASSCODE }}
|
||||
run: |
|
||||
source ../.github/actions/decrypt.sh ../.github/actions/creds.tar.gpg creds.tar
|
||||
export OAUTHFILE="oauth2.txt-gam-gha-${JID}"
|
||||
echo "OAUTHFILE=${OAUTHFILE}" >> $GITHUB_ENV
|
||||
export gam_user="gam-gha-${JID}@pdl.jaylee.us"
|
||||
echo "gam_user=${gam_user}" >> $GITHUB_ENV
|
||||
$gam oauth info
|
||||
$gam info domain
|
||||
$gam oauth refresh
|
||||
$gam info user
|
||||
#$gam info user $gam_user grouptree
|
||||
export tstamp=$(date +%s%3N)
|
||||
export newbase=gha-test-$JID-$tstamp
|
||||
export newuser=$newbase@pdl.jaylee.us
|
||||
export newgroup=$newbase-group@pdl.jaylee.us
|
||||
export newalias=$newbase-alias@pdl.jaylee.us
|
||||
export newbuilding=$newbase-building
|
||||
export newresource=$newbase-resource
|
||||
export GAM_THREADS=5
|
||||
echo email > sample.csv;
|
||||
for i in {01..10}; do
|
||||
echo "${newbase}-bulkuser-$i" >> sample.csv;
|
||||
done
|
||||
$gam create user $newuser firstname GHA lastname $JID password random recoveryphone 12125121110 recoveryemail jay0lee@gmail.com gha.jid $JID
|
||||
$gam user $gam_user sendemail recipient $newuser subject "test message $newbase" message "GHA test message"
|
||||
$gam user $gam_user sendemail recipient exchange@pdl.jaylee.us subject "test ${tstamp}" message "test message"
|
||||
$gam create group $newgroup name "GHA $JID group" description "This is a description" isarchived true
|
||||
$gam user $newuser add license gsuitebusiness
|
||||
$gam update group $newgroup add owner $gam_user
|
||||
$gam update group $newgroup add member $newuser
|
||||
$gam csv sample.csv gam create user ~~email~~ firstname "GHA Bulk" lastname ~~email~~ gha.jid $JID
|
||||
$gam csv sample.csv gam update user ~~email~~ recoveryphone 12125121110 recoveryemail jay0lee@gmail.com password random
|
||||
$gam csv sample.csv gam update user ~~email~~ recoveryphone "" recoveryemail ""
|
||||
$gam csv sample.csv gam user ~email add license gsuitebusiness
|
||||
$gam csv sample.csv gam user $gam_user sendemail recipient ~~email~~@pdl.jaylee.us subject "test message $newbase" message "GHA test message"
|
||||
$gam csv sample.csv gam update group $newgroup add member ~email
|
||||
$gam info group $newgroup
|
||||
$gam info cigroup $newgroup membertree
|
||||
$gam user $gam_user check serviceaccount
|
||||
# confirm mailbox is provisoned before continuing
|
||||
$gam user $newuser waitformailbox
|
||||
$gam user $newuser imap on
|
||||
$gam user $newuser show imap
|
||||
$gam user $newuser show delegates
|
||||
#$gam user $newuser add contactdelegate "${newbase}-bulkuser-01"
|
||||
#$gam user $newuser print contactdelegates
|
||||
export biohazard=$(echo -e '\xe2\x98\xa3')
|
||||
$gam user $newuser label "$biohazard unicode biohazard $biohazard"
|
||||
$gam user $newuser show labels
|
||||
$gam user $newuser show labels > labels.txt
|
||||
$gam user $gam_user importemail subject "GHA import $newbase" message "This is a test import" labels IMPORTANT,UNREAD,INBOX,STARRED
|
||||
$gam user $gam_user insertemail subject "GHA insert $newbase" file gam.py labels INBOX,UNREAD # yep body is gam code
|
||||
$gam user $gam_user sendemail subject "GHA send $gam_user $newbase" file gam.py recipient admin@pdl.jaylee.us
|
||||
$gam user $gam_user draftemail subject "GHA draft $newbase" message "Draft message test"
|
||||
$gam csvfile sample.csv:email waitformailbox
|
||||
$gam user $newuser delegate to "${newbase}-bulkuser-01"
|
||||
$gam users "$gam_user $newbase-bulkuser-01 $newbase-bulkuser-02 $newbase-bulkuser-03" delete messages query in:anywhere maxtodelete 99999 doit
|
||||
$gam users "$newbase-bulkuser-04 $newbase-bulkuser-05 $newbase-bulkuser-06" trash messages query in:anywhere maxtotrash 99999 doit
|
||||
$gam users "$newbase-bulkuser-07 $newbase-bulkuser-08 $newbase-bulkuser-09" modify messages query in:anywhere maxtomodify 99999 addlabel IMPORTANT addlabel STARRED doit
|
||||
$gam user $newuser delete label --ALL_LABELS--
|
||||
$gam create feature name Whiteboard-$newbase
|
||||
$gam create feature name VC-$newbase
|
||||
$gam create building "My Building - $newbase" id $newbuilding floors 1,2,3,4,5,6,7,8,9,10,11,12,14,15 description "No 13th floor here..."
|
||||
$gam create resource $newresource "Resource Calendar $tstamp" capacity 25 features Whiteboard-$newbase,VC-$newbase building $newbuilding floor 15 type Room
|
||||
$gam info resource $newresource
|
||||
$gam user $newuser show filelist
|
||||
$gam calendar $gam_user printacl | $gam csv - gam calendar $gam_user delete id ~id # clear ACLs
|
||||
$gam calendar $gam_user update read domain
|
||||
$gam calendar $gam_user update freebusy default
|
||||
$gam calendar $gam_user add editor $newuser
|
||||
$gam calendar $gam_user showacl
|
||||
$gam calendar $gam_user printacl | $gam csv - gam calendar $gam_user delete id ~id
|
||||
$gam calendar $gam_user addevent summary "GHA test event" start $(date '+%FT%T.%N%:z' -d "now + 1 hour") end $(date '+%FT%T.%N%:z' -d "now + 2 hours") attendee $newgroup hangoutsmeet guestscanmodify true sendupdates all
|
||||
$gam calendar $gam_user printevents after -0d
|
||||
matterid=uid:$($gam create vaultmatter name "GHA matter $newbase" description "test matter" collaborators $newuser | head -1 | cut -d ' ' -f 3)
|
||||
$gam create vaulthold matter $matterid name "GHA hold $newbase" corpus mail accounts $newuser
|
||||
$gam print vaultmatters matterstate open
|
||||
$gam print vaultholds matter $matterid
|
||||
$gam print vaultcount matter $matterid corpus mail everyone todrive
|
||||
$gam create vaultexport matter $matterid name "GHA export $newbase" corpus mail accounts $newuser
|
||||
$gam print exports matter $matterid | $gam csv - gam info export $matterid id:~~id~~
|
||||
$gam csv sample.csv gam user ~email add calendar id:$newresource
|
||||
$gam delete resource $newresource
|
||||
$gam delete feature Whiteboard-$newbase
|
||||
$gam delete feature VC-$newbase
|
||||
$gam delete building $newbuilding
|
||||
$gam delete group $newgroup
|
||||
$gam create alias $newalias user $newuser
|
||||
$gam whatis $newuser
|
||||
$gam user $gam_user show tokens
|
||||
$gam print exports matter $matterid | $gam csv - gam download export $matterid id:~~id~~
|
||||
$gam delete hold "GHA hold $newbase" matter $matterid
|
||||
$gam update matter $matterid action close
|
||||
$gam update matter $matterid action delete
|
||||
$gam delete user $newuser
|
||||
$gam print users query "gha.jid=$JID" | $gam csv - gam delete user ~primaryEmail
|
||||
$gam print mobile
|
||||
$gam print devices
|
||||
$gam print browsers
|
||||
export sn="$JID$JID$JID$JID-$(openssl rand -base64 32 | sed 's/[^a-zA-Z0-9]//g')"
|
||||
$gam create device serialnumber $sn devicetype android
|
||||
$gam print cros allfields nolists
|
||||
$gam report usageparameters customer
|
||||
$gam report usage customer parameters gmail:num_emails_sent,accounts:num_1day_logins
|
||||
$gam report customer todrive
|
||||
$gam report users fields accounts:is_less_secure_apps_access_allowed,gmail:last_imap_time,gmail:last_pop_time filters "accounts:last_login_time>2019-01-01T00:00:00.000Z" todrive
|
||||
$gam report admin start -3d todrive
|
||||
$gam print devices nopersonaldevices nodeviceusers filter "serial:$JID$JID$JID$JID-" | $gam csv - gam delete device id ~name
|
||||
$gam print userinvitations
|
||||
$gam print userinvitations | $gam csv - gam send userinvitation ~name
|
||||
export CUSTOMER_ID="C01wfv983"
|
||||
export GA_DOMAIN="pdl.jaylee.us"
|
||||
touch $gampath/enabledasa.txt
|
||||
echo "printer model count:"
|
||||
$gam print printermodels | wc -l
|
||||
#$gam print printers
|
||||
#$gam create printer displayname "${newbase}" uri ipp://localhost:631 driverless description "made by $(date)"
|
||||
rm $gampath/enabledasa.txt
|
||||
|
||||
- name: Upload to Google Drive, build only.
|
||||
if: github.event_name == 'push' && matrix.goal != 'test'
|
||||
run: |
|
||||
ls gam-$GAMVERSION-*
|
||||
for gamfile in gam-$GAMVERSION-*; do
|
||||
echo "Uploading file ${gamfile} to Google Drive..."
|
||||
fileid=$($gam user $gam_user add drivefile localfile $gamfile drivefilename $GAMVERSION-${GITHUB_SHA:0:7}-$gamfile parentid 1N2zbO33qzUQFsGM49-m9AQC1ijzd_ru1 returnidonly)
|
||||
echo "file uploaded as ${fileid}, setting ACL..."
|
||||
$gam user $gam_user add drivefileacl $fileid anyone role reader withlink
|
||||
done
|
||||
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
if: github.event_name == 'push' && matrix.goal != 'test'
|
||||
with:
|
||||
name: gam-binaries
|
||||
path: |
|
||||
src/*.tar.xz
|
||||
src/*.zip
|
||||
src/*.msi
|
||||
29
.pre-commit-config.yaml
Normal file
29
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,29 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
default_language_version:
|
||||
python: python3.7
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.5.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: double-quote-string-fixer
|
||||
- id: check-yaml
|
||||
- id: check-docstring-first
|
||||
- id: name-tests-test
|
||||
- id: requirements-txt-fixer
|
||||
- id: check-merge-conflict
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-yapf
|
||||
rev: v0.30.0
|
||||
hooks:
|
||||
- id: yapf
|
||||
args: [--style=google, --in-place]
|
||||
|
||||
- repo: https://github.com/PyCQA/pylint
|
||||
rev: pylint-2.5.0
|
||||
hooks:
|
||||
- id: pylint
|
||||
args: [--output-format=colorized]
|
||||
82
README.md
82
README.md
@@ -1,66 +1,26 @@
|
||||
Dito GAM
|
||||
============================
|
||||
GAM is a free, open source command line tool for
|
||||
Google Apps Administrators to efficiently manage
|
||||
domain and user settings quickly and easily. GAM has support
|
||||
for many features, such as
|
||||
GAM is a command line tool for Google Workspace (fka G Suite) Administrators to manage domain and user settings quickly and easily.
|
||||
|
||||
* creating, deleting, and updating users, aliases, groups,
|
||||
organizations, and resource calendars
|
||||
* modifying user email settings such as IMAP, signatures,
|
||||
vacation messages, profile sharing, email forwarding,
|
||||
send as address, labels, and features.
|
||||
* delegating mailboxes and calendars to other users
|
||||
* modifying calendar access rights for users and resource calendars.
|
||||
* auditing user accounts and mailboes
|
||||
* monitoring incoming and outgoing email
|
||||
* generating detailed reports for users, groups, resources,
|
||||
account activity, email clients, and quotas.
|
||||
|
||||
Downloads
|
||||
---------
|
||||
You can download current GAM from
|
||||
the [GitHub Releases] page.
|
||||
|
||||
Documentation
|
||||
------------------
|
||||
The GAM documentation is currently hosted in the [GitHub Wiki]
|
||||
|
||||
Mailing List / Discussion group
|
||||
-------------------------------
|
||||
The GAM mailing list / discussion group is hosted
|
||||
on [Google Groups]. You can join the list and interact
|
||||
via email, or just post from the web itself.
|
||||
|
||||
Source Repository
|
||||
-----------------
|
||||
|
||||
The official GAM source repository is on [GitHub].
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
GAM is maintained by <a href="mailto:jay0lee@gmail.com">Jay Lee</a>.
|
||||
|
||||
Thanks To
|
||||
---------
|
||||
|
||||
GAM is made possible and maintained by the work of Dito.
|
||||
Who is Dito?
|
||||
|
||||
*Dito is solely focused on moving organizations to Google's
|
||||
cloud. After hundreds of successful deployments over the
|
||||
last 5 years, we have gained notoriety for our complete
|
||||
understanding of the platform, our change management &
|
||||
training ability, and our rock-star deployment engineers.
|
||||
We are known worldwide as the Google Apps Experts.*
|
||||
|
||||
Need a Google Apps Expert?
|
||||
[Contact Dito](http://ditoweb.com/contact), which offers
|
||||
[free premium GAM support](http://www.ditoweb.com/dito-gam)
|
||||
for domains that sign up through Dito.
|
||||

|
||||
# Quick Start
|
||||
## Linux / MacOS
|
||||
Open a terminal and run:
|
||||
```
|
||||
bash <(curl -s -S -L https://git.io/install-gam)
|
||||
```
|
||||
this will download GAM, install it and start setup.
|
||||
## Windows
|
||||
Download the MSI Installer from the [GitHub Releases] page. Install the MSI and you'll be prompted to setup GAM.
|
||||
# Documentation
|
||||
The GAM documentation is hosted in the [GitHub Wiki]
|
||||
# Mailing List / Discussion group
|
||||
The GAM mailing list / discussion group is hosted on [Google Groups]. You can join the list and interact via email, or just post from the web itself.
|
||||
# Chat Room
|
||||
There is a public chat room hosted in Google Chat. [Instructions to join](https://git.io/gam-chat).
|
||||
# Author
|
||||
GAM is maintained by <a href="mailto:jay0lee@gmail.com">Jay Lee</a>. Please direct "how do I?" questions to [Google Groups].
|
||||
|
||||
[GAM release]: https://git.io/gamreleases
|
||||
[GitHub Releases]: https://github.com/jay0lee/GAM/releases
|
||||
[GitHub]: https://github.com/jay0lee/GAM/
|
||||
[GitHub]: https://github.com/jay0lee/GAM/tree/master
|
||||
[GitHub Wiki]: https://github.com/jay0lee/GAM/wiki/
|
||||
[Google Groups]: http://groups.google.com/group/google-apps-manager
|
||||
|
||||
@@ -1,642 +0,0 @@
|
||||
{
|
||||
"kind": "discovery#restDescription",
|
||||
"discoveryVersion": "v1",
|
||||
"id": "admin-settings:v1",
|
||||
"name": "admin-settings",
|
||||
"version": "v1",
|
||||
"revision": "20130823",
|
||||
"title": "Admin Settings API (read-only calls)",
|
||||
"description": "Lets you access Google Apps Admin Settings",
|
||||
"ownerDomain": "google.com",
|
||||
"ownerName": "Google",
|
||||
"icons": {
|
||||
"x16": "http://www.google.com/images/icons/product/search-16.gif",
|
||||
"x32": "http://www.google.com/images/icons/product/search-32.gif"
|
||||
},
|
||||
"documentationLink": "https://developers.google.com/admin-sdk/admin-settings",
|
||||
"protocol": "rest",
|
||||
"baseUrl": "https://apps-apis.google.com/",
|
||||
"basePath": "/a/feeds/domain/2.0/",
|
||||
"rootUrl": "https://apps-apis.google.com/",
|
||||
"servicePath": "/a/feeds/domain/2.0/",
|
||||
"parameters": {
|
||||
"v": {
|
||||
"type": "string",
|
||||
"description": "GData Version",
|
||||
"default": "2.0",
|
||||
"enum": [
|
||||
"2.0"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"GData 2.0"
|
||||
],
|
||||
"location": "query"
|
||||
},
|
||||
"alt": {
|
||||
"type": "string",
|
||||
"description": "Data format for the response.",
|
||||
"default": "json",
|
||||
"enum": [
|
||||
"json"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"Responses with Content-Type of application/json"
|
||||
],
|
||||
"location": "query"
|
||||
},
|
||||
"quotaUser": {
|
||||
"type": "string",
|
||||
"description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.",
|
||||
"location": "query"
|
||||
},
|
||||
"prettyPrint": {
|
||||
"type": "boolean",
|
||||
"description": "Returns response with indentations and line breaks.",
|
||||
"default": "true",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"oauth2": {
|
||||
"scopes": {
|
||||
"https://apps-apis.google.com/a/feeds/domain/": {
|
||||
"description": "Manage domain settings"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"DefaultLanguage": {
|
||||
"id": "DefaultLanguage",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "default language value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"OrganizationName": {
|
||||
"id": "OrganizationName",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "organization name value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"MaximumNumberOfUsers": {
|
||||
"id": "MaximumNumberOfUsers",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "maximum number of users value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CurrentNumberOfUsers": {
|
||||
"id": "CurrentNumbersOfUsers",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "current number of users value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"IsVerified": {
|
||||
"id": "IsVerified",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "boolean",
|
||||
"description": "current verification status value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Edition": {
|
||||
"id": "Edition",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain edition value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CustomerPIN": {
|
||||
"id": "CustomerPIN",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "customer pin value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CreationTime": {
|
||||
"id": "CreationTime",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain creation time value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CountryCode": {
|
||||
"id": "CountryCode",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain country code value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"AdminSecondaryEmail": {
|
||||
"id": "AdminSecondaryEmail",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "admin secondary email value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"MXVerification": {
|
||||
"id": "MXVerification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain mx verification value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"SSOGeneral": {
|
||||
"id": "SSOGeneral",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain sso general value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"SSOSigningKey": {
|
||||
"id": "SSOSigningKey",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain sso signing key value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserEmailMigrationEnabled": {
|
||||
"id": "UserEmailMigrationEnabled",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "user email migration enabled value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"OutboundGateway": {
|
||||
"id": "OutboundGateway",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"apps$property": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "property name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "domain outbound gateway value"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"defaultLanguage": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.defaultLanguage.get",
|
||||
"path": "{domainName}/general/defaultLanguage",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "DefaultLanguage"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"organizationName": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.organizationName.get",
|
||||
"path": "{domainName}/general/organizationName",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "OrganizationName"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"maximumNumberOfUsers": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.maximumNumberOfUsers.get",
|
||||
"path": "{domainName}/general/maximumNumberOfUsers",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "MaximumNumberOfUsers"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"currentNumberOfUsers": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.currentNumberOfUsers.get",
|
||||
"path": "{domainName}/general/currentNumberOfUsers",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "CurrentNumberOfUsers"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"isVerified": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.isVerified.get",
|
||||
"path": "{domainName}/accountInformation/isVerified",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "IsVerified"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"edition": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.edition.get",
|
||||
"path": "{domainName}/accountInformation/edition",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Edition"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"customerPIN": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.customerPIN.get",
|
||||
"path": "{domainName}/accountInformation/customerPIN",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "CustomerPIN"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"creationTime": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.creationTime.get",
|
||||
"path": "{domainName}/accountInformation/creationTime",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "CreationTime"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"countryCode": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.countryCode.get",
|
||||
"path": "{domainName}/accountInformation/countryCode",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "CountryCode"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminSecondaryEmail": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.adminSecondaryEmail.get",
|
||||
"path": "{domainName}/accountInformation/adminSecondaryEmail",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "AdminSecondaryEmail"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mxVerification": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.mxVerification.get",
|
||||
"path": "{domainName}/verification/mx",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "MXVerification"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssoGeneral": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.ssoGeneral.get",
|
||||
"path": "{domainName}/sso/general",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "SSOGeneral"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssoSigningKey": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.ssoSigningKey.get",
|
||||
"path": "{domainName}/sso/signingkey",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "SSOSigningKey"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"userEmailMigrationEnabled": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.userEmailMigrationEnabled.get",
|
||||
"path": "{domainName}/email/migration",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "UserEmailMigrationEnabled"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"outboundGateway": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "admin-settings.outboundGateway.get",
|
||||
"path": "{domainName}/email/gateway",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"domainName": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "path"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "OutboundGateway"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1484
atom/__init__.py
1484
atom/__init__.py
File diff suppressed because it is too large
Load Diff
43
atom/auth.py
43
atom/auth.py
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This module is used for version 2 of the Google Data APIs.
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import base64
|
||||
|
||||
|
||||
class BasicAuth(object):
|
||||
"""Sets the Authorization header as defined in RFC1945"""
|
||||
|
||||
def __init__(self, user_id, password):
|
||||
self.basic_cookie = base64.encodestring(
|
||||
'%s:%s' % (user_id, password)).strip()
|
||||
|
||||
def modify_request(self, http_request):
|
||||
http_request.headers['Authorization'] = 'Basic %s' % self.basic_cookie
|
||||
|
||||
ModifyRequest = modify_request
|
||||
|
||||
|
||||
class NoAuth(object):
|
||||
|
||||
def modify_request(self, http_request):
|
||||
pass
|
||||
221
atom/client.py
221
atom/client.py
@@ -1,221 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""AtomPubClient provides CRUD ops. in line with the Atom Publishing Protocol.
|
||||
|
||||
"""
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import atom.http_core
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MissingHost(Error):
|
||||
pass
|
||||
|
||||
|
||||
class AtomPubClient(object):
|
||||
host = None
|
||||
auth_token = None
|
||||
ssl = False # Whether to force all requests over https
|
||||
xoauth_requestor_id = None
|
||||
|
||||
def __init__(self, http_client=None, host=None, auth_token=None, source=None,
|
||||
xoauth_requestor_id=None, **kwargs):
|
||||
"""Creates a new AtomPubClient instance.
|
||||
|
||||
Args:
|
||||
source: The name of your application.
|
||||
http_client: An object capable of performing HTTP requests through a
|
||||
request method. This object is used to perform the request
|
||||
when the AtomPubClient's request method is called. Used to
|
||||
allow HTTP requests to be directed to a mock server, or use
|
||||
an alternate library instead of the default of httplib to
|
||||
make HTTP requests.
|
||||
host: str The default host name to use if a host is not specified in the
|
||||
requested URI.
|
||||
auth_token: An object which sets the HTTP Authorization header when its
|
||||
modify_request method is called.
|
||||
"""
|
||||
self.http_client = http_client or atom.http_core.ProxiedHttpClient()
|
||||
if host is not None:
|
||||
self.host = host
|
||||
if auth_token is not None:
|
||||
self.auth_token = auth_token
|
||||
self.xoauth_requestor_id = xoauth_requestor_id
|
||||
self.source = source
|
||||
|
||||
def request(self, method=None, uri=None, auth_token=None,
|
||||
http_request=None, **kwargs):
|
||||
"""Performs an HTTP request to the server indicated.
|
||||
|
||||
Uses the http_client instance to make the request.
|
||||
|
||||
Args:
|
||||
method: The HTTP method as a string, usually one of 'GET', 'POST',
|
||||
'PUT', or 'DELETE'
|
||||
uri: The URI desired as a string or atom.http_core.Uri.
|
||||
http_request:
|
||||
auth_token: An authorization token object whose modify_request method
|
||||
sets the HTTP Authorization header.
|
||||
|
||||
Returns:
|
||||
The results of calling self.http_client.request. With the default
|
||||
http_client, this is an HTTP response object.
|
||||
"""
|
||||
# Modify the request based on the AtomPubClient settings and parameters
|
||||
# passed in to the request.
|
||||
http_request = self.modify_request(http_request)
|
||||
if isinstance(uri, (str, unicode)):
|
||||
uri = atom.http_core.Uri.parse_uri(uri)
|
||||
if uri is not None:
|
||||
uri.modify_request(http_request)
|
||||
if isinstance(method, (str, unicode)):
|
||||
http_request.method = method
|
||||
# Any unrecognized arguments are assumed to be capable of modifying the
|
||||
# HTTP request.
|
||||
for name, value in kwargs.iteritems():
|
||||
if value is not None:
|
||||
value.modify_request(http_request)
|
||||
# Default to an http request if the protocol scheme is not set.
|
||||
if http_request.uri.scheme is None:
|
||||
http_request.uri.scheme = 'http'
|
||||
# Override scheme. Force requests over https.
|
||||
if self.ssl:
|
||||
http_request.uri.scheme = 'https'
|
||||
if http_request.uri.path is None:
|
||||
http_request.uri.path = '/'
|
||||
# Add the Authorization header at the very end. The Authorization header
|
||||
# value may need to be calculated using information in the request.
|
||||
if auth_token:
|
||||
auth_token.modify_request(http_request)
|
||||
elif self.auth_token:
|
||||
self.auth_token.modify_request(http_request)
|
||||
# Check to make sure there is a host in the http_request.
|
||||
if http_request.uri.host is None:
|
||||
raise MissingHost('No host provided in request %s %s' % (
|
||||
http_request.method, str(http_request.uri)))
|
||||
# Perform the fully specified request using the http_client instance.
|
||||
# Sends the request to the server and returns the server's response.
|
||||
return self.http_client.request(http_request)
|
||||
|
||||
Request = request
|
||||
|
||||
def get(self, uri=None, auth_token=None, http_request=None, **kwargs):
|
||||
"""Performs a request using the GET method, returns an HTTP response."""
|
||||
return self.request(method='GET', uri=uri, auth_token=auth_token,
|
||||
http_request=http_request, **kwargs)
|
||||
|
||||
Get = get
|
||||
|
||||
def post(self, uri=None, data=None, auth_token=None, http_request=None,
|
||||
**kwargs):
|
||||
"""Sends data using the POST method, returns an HTTP response."""
|
||||
return self.request(method='POST', uri=uri, auth_token=auth_token,
|
||||
http_request=http_request, data=data, **kwargs)
|
||||
|
||||
Post = post
|
||||
|
||||
def put(self, uri=None, data=None, auth_token=None, http_request=None,
|
||||
**kwargs):
|
||||
"""Sends data using the PUT method, returns an HTTP response."""
|
||||
return self.request(method='PUT', uri=uri, auth_token=auth_token,
|
||||
http_request=http_request, data=data, **kwargs)
|
||||
|
||||
Put = put
|
||||
|
||||
def delete(self, uri=None, auth_token=None, http_request=None, **kwargs):
|
||||
"""Performs a request using the DELETE method, returns an HTTP response."""
|
||||
return self.request(method='DELETE', uri=uri, auth_token=auth_token,
|
||||
http_request=http_request, **kwargs)
|
||||
|
||||
Delete = delete
|
||||
|
||||
def modify_request(self, http_request):
|
||||
"""Changes the HTTP request before sending it to the server.
|
||||
|
||||
Sets the User-Agent HTTP header and fills in the HTTP host portion
|
||||
of the URL if one was not included in the request (for this it uses
|
||||
the self.host member if one is set). This method is called in
|
||||
self.request.
|
||||
|
||||
Args:
|
||||
http_request: An atom.http_core.HttpRequest() (optional) If one is
|
||||
not provided, a new HttpRequest is instantiated.
|
||||
|
||||
Returns:
|
||||
An atom.http_core.HttpRequest() with the User-Agent header set and
|
||||
if this client has a value in its host member, the host in the request
|
||||
URL is set.
|
||||
"""
|
||||
if http_request is None:
|
||||
http_request = atom.http_core.HttpRequest()
|
||||
|
||||
if self.host is not None and http_request.uri.host is None:
|
||||
http_request.uri.host = self.host
|
||||
|
||||
if self.xoauth_requestor_id is not None:
|
||||
http_request.uri.query['xoauth_requestor_id'] = self.xoauth_requestor_id
|
||||
|
||||
# Set the user agent header for logging purposes.
|
||||
if self.source:
|
||||
http_request.headers['User-Agent'] = '%s gdata-py/2.0.14' % self.source
|
||||
else:
|
||||
http_request.headers['User-Agent'] = 'gdata-py/2.0.14'
|
||||
|
||||
return http_request
|
||||
|
||||
ModifyRequest = modify_request
|
||||
|
||||
|
||||
class CustomHeaders(object):
|
||||
"""Add custom headers to an http_request.
|
||||
|
||||
Usage:
|
||||
>>> custom_headers = atom.client.CustomHeaders(header1='value1',
|
||||
header2='value2')
|
||||
>>> client.get(uri, custom_headers=custom_headers)
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Creates a CustomHeaders instance.
|
||||
|
||||
Initialize the headers dictionary with the arguments list.
|
||||
"""
|
||||
self.headers = kwargs
|
||||
|
||||
def modify_request(self, http_request):
|
||||
"""Changes the HTTP request before sending it to the server.
|
||||
|
||||
Adds the custom headers to the HTTP request.
|
||||
|
||||
Args:
|
||||
http_request: An atom.http_core.HttpRequest().
|
||||
|
||||
Returns:
|
||||
An atom.http_core.HttpRequest() with the added custom headers.
|
||||
"""
|
||||
|
||||
for name, value in self.headers.iteritems():
|
||||
if value is not None:
|
||||
http_request.headers[name] = value
|
||||
return http_request
|
||||
550
atom/core.py
550
atom/core.py
@@ -1,550 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This module is used for version 2 of the Google Data APIs.
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import inspect
|
||||
try:
|
||||
from xml.etree import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
from xml.etree import ElementTree
|
||||
except ImportError:
|
||||
from elementtree import ElementTree
|
||||
|
||||
|
||||
try:
|
||||
from xml.dom.minidom import parseString as xmlString
|
||||
except ImportError:
|
||||
xmlString = None
|
||||
|
||||
STRING_ENCODING = 'utf-8'
|
||||
|
||||
|
||||
class XmlElement(object):
|
||||
"""Represents an element node in an XML document.
|
||||
|
||||
The text member is a UTF-8 encoded str or unicode.
|
||||
"""
|
||||
_qname = None
|
||||
_other_elements = None
|
||||
_other_attributes = None
|
||||
# The rule set contains mappings for XML qnames to child members and the
|
||||
# appropriate member classes.
|
||||
_rule_set = None
|
||||
_members = None
|
||||
text = None
|
||||
|
||||
def __init__(self, text=None, *args, **kwargs):
|
||||
if ('_members' not in self.__class__.__dict__
|
||||
or self.__class__._members is None):
|
||||
self.__class__._members = tuple(self.__class__._list_xml_members())
|
||||
for member_name, member_type in self.__class__._members:
|
||||
if member_name in kwargs:
|
||||
setattr(self, member_name, kwargs[member_name])
|
||||
else:
|
||||
if isinstance(member_type, list):
|
||||
setattr(self, member_name, [])
|
||||
else:
|
||||
setattr(self, member_name, None)
|
||||
self._other_elements = []
|
||||
self._other_attributes = {}
|
||||
if text is not None:
|
||||
self.text = text
|
||||
|
||||
def _list_xml_members(cls):
|
||||
"""Generator listing all members which are XML elements or attributes.
|
||||
|
||||
The following members would be considered XML members:
|
||||
foo = 'abc' - indicates an XML attribute with the qname abc
|
||||
foo = SomeElement - indicates an XML child element
|
||||
foo = [AnElement] - indicates a repeating XML child element, each instance
|
||||
will be stored in a list in this member
|
||||
foo = ('att1', '{http://example.com/namespace}att2') - indicates an XML
|
||||
attribute which has different parsing rules in different versions of
|
||||
the protocol. Version 1 of the XML parsing rules will look for an
|
||||
attribute with the qname 'att1' but verion 2 of the parsing rules will
|
||||
look for a namespaced attribute with the local name of 'att2' and an
|
||||
XML namespace of 'http://example.com/namespace'.
|
||||
"""
|
||||
members = []
|
||||
for pair in inspect.getmembers(cls):
|
||||
if not pair[0].startswith('_') and pair[0] != 'text':
|
||||
member_type = pair[1]
|
||||
if (isinstance(member_type, tuple) or isinstance(member_type, list)
|
||||
or isinstance(member_type, (str, unicode))
|
||||
or (inspect.isclass(member_type)
|
||||
and issubclass(member_type, XmlElement))):
|
||||
members.append(pair)
|
||||
return members
|
||||
|
||||
_list_xml_members = classmethod(_list_xml_members)
|
||||
|
||||
def _get_rules(cls, version):
|
||||
"""Initializes the _rule_set for the class which is used when parsing XML.
|
||||
|
||||
This method is used internally for parsing and generating XML for an
|
||||
XmlElement. It is not recommended that you call this method directly.
|
||||
|
||||
Returns:
|
||||
A tuple containing the XML parsing rules for the appropriate version.
|
||||
|
||||
The tuple looks like:
|
||||
(qname, {sub_element_qname: (member_name, member_class, repeating), ..},
|
||||
{attribute_qname: member_name})
|
||||
|
||||
To give a couple of concrete example, the atom.data.Control _get_rules
|
||||
with version of 2 will return:
|
||||
('{http://www.w3.org/2007/app}control',
|
||||
{'{http://www.w3.org/2007/app}draft': ('draft',
|
||||
<class 'atom.data.Draft'>,
|
||||
False)},
|
||||
{})
|
||||
Calling _get_rules with version 1 on gdata.data.FeedLink will produce:
|
||||
('{http://schemas.google.com/g/2005}feedLink',
|
||||
{'{http://www.w3.org/2005/Atom}feed': ('feed',
|
||||
<class 'gdata.data.GDFeed'>,
|
||||
False)},
|
||||
{'href': 'href', 'readOnly': 'read_only', 'countHint': 'count_hint',
|
||||
'rel': 'rel'})
|
||||
"""
|
||||
# Initialize the _rule_set to make sure there is a slot available to store
|
||||
# the parsing rules for this version of the XML schema.
|
||||
# Look for rule set in the class __dict__ proxy so that only the
|
||||
# _rule_set for this class will be found. By using the dict proxy
|
||||
# we avoid finding rule_sets defined in superclasses.
|
||||
# The four lines below provide support for any number of versions, but it
|
||||
# runs a bit slower then hard coding slots for two versions, so I'm using
|
||||
# the below two lines.
|
||||
#if '_rule_set' not in cls.__dict__ or cls._rule_set is None:
|
||||
# cls._rule_set = []
|
||||
#while len(cls.__dict__['_rule_set']) < version:
|
||||
# cls._rule_set.append(None)
|
||||
# If there is no rule set cache in the class, provide slots for two XML
|
||||
# versions. If and when there is a version 3, this list will need to be
|
||||
# expanded.
|
||||
if '_rule_set' not in cls.__dict__ or cls._rule_set is None:
|
||||
cls._rule_set = [None, None]
|
||||
# If a version higher than 2 is requested, fall back to version 2 because
|
||||
# 2 is currently the highest supported version.
|
||||
if version > 2:
|
||||
return cls._get_rules(2)
|
||||
# Check the dict proxy for the rule set to avoid finding any rule sets
|
||||
# which belong to the superclass. We only want rule sets for this class.
|
||||
if cls._rule_set[version-1] is None:
|
||||
# The rule set for each version consists of the qname for this element
|
||||
# ('{namespace}tag'), a dictionary (elements) for looking up the
|
||||
# corresponding class member when given a child element's qname, and a
|
||||
# dictionary (attributes) for looking up the corresponding class member
|
||||
# when given an XML attribute's qname.
|
||||
elements = {}
|
||||
attributes = {}
|
||||
if ('_members' not in cls.__dict__ or cls._members is None):
|
||||
cls._members = tuple(cls._list_xml_members())
|
||||
for member_name, target in cls._members:
|
||||
if isinstance(target, list):
|
||||
# This member points to a repeating element.
|
||||
elements[_get_qname(target[0], version)] = (member_name, target[0],
|
||||
True)
|
||||
elif isinstance(target, tuple):
|
||||
# This member points to a versioned XML attribute.
|
||||
if version <= len(target):
|
||||
attributes[target[version-1]] = member_name
|
||||
else:
|
||||
attributes[target[-1]] = member_name
|
||||
elif isinstance(target, (str, unicode)):
|
||||
# This member points to an XML attribute.
|
||||
attributes[target] = member_name
|
||||
elif issubclass(target, XmlElement):
|
||||
# This member points to a single occurance element.
|
||||
elements[_get_qname(target, version)] = (member_name, target, False)
|
||||
version_rules = (_get_qname(cls, version), elements, attributes)
|
||||
cls._rule_set[version-1] = version_rules
|
||||
return version_rules
|
||||
else:
|
||||
return cls._rule_set[version-1]
|
||||
|
||||
_get_rules = classmethod(_get_rules)
|
||||
|
||||
def get_elements(self, tag=None, namespace=None, version=1):
|
||||
"""Find all sub elements which match the tag and namespace.
|
||||
|
||||
To find all elements in this object, call get_elements with the tag and
|
||||
namespace both set to None (the default). This method searches through
|
||||
the object's members and the elements stored in _other_elements which
|
||||
did not match any of the XML parsing rules for this class.
|
||||
|
||||
Args:
|
||||
tag: str
|
||||
namespace: str
|
||||
version: int Specifies the version of the XML rules to be used when
|
||||
searching for matching elements.
|
||||
|
||||
Returns:
|
||||
A list of the matching XmlElements.
|
||||
"""
|
||||
matches = []
|
||||
ignored1, elements, ignored2 = self.__class__._get_rules(version)
|
||||
if elements:
|
||||
for qname, element_def in elements.iteritems():
|
||||
member = getattr(self, element_def[0])
|
||||
if member:
|
||||
if _qname_matches(tag, namespace, qname):
|
||||
if element_def[2]:
|
||||
# If this is a repeating element, copy all instances into the
|
||||
# result list.
|
||||
matches.extend(member)
|
||||
else:
|
||||
matches.append(member)
|
||||
for element in self._other_elements:
|
||||
if _qname_matches(tag, namespace, element._qname):
|
||||
matches.append(element)
|
||||
return matches
|
||||
|
||||
GetElements = get_elements
|
||||
# FindExtensions and FindChildren are provided for backwards compatibility
|
||||
# to the atom.AtomBase class.
|
||||
# However, FindExtensions may return more results than the v1 atom.AtomBase
|
||||
# method does, because get_elements searches both the expected children
|
||||
# and the unexpected "other elements". The old AtomBase.FindExtensions
|
||||
# method searched only "other elements" AKA extension_elements.
|
||||
FindExtensions = get_elements
|
||||
FindChildren = get_elements
|
||||
|
||||
def get_attributes(self, tag=None, namespace=None, version=1):
|
||||
"""Find all attributes which match the tag and namespace.
|
||||
|
||||
To find all attributes in this object, call get_attributes with the tag
|
||||
and namespace both set to None (the default). This method searches
|
||||
through the object's members and the attributes stored in
|
||||
_other_attributes which did not fit any of the XML parsing rules for this
|
||||
class.
|
||||
|
||||
Args:
|
||||
tag: str
|
||||
namespace: str
|
||||
version: int Specifies the version of the XML rules to be used when
|
||||
searching for matching attributes.
|
||||
|
||||
Returns:
|
||||
A list of XmlAttribute objects for the matching attributes.
|
||||
"""
|
||||
matches = []
|
||||
ignored1, ignored2, attributes = self.__class__._get_rules(version)
|
||||
if attributes:
|
||||
for qname, attribute_def in attributes.iteritems():
|
||||
if isinstance(attribute_def, (list, tuple)):
|
||||
attribute_def = attribute_def[0]
|
||||
member = getattr(self, attribute_def)
|
||||
# TODO: ensure this hasn't broken existing behavior.
|
||||
#member = getattr(self, attribute_def[0])
|
||||
if member:
|
||||
if _qname_matches(tag, namespace, qname):
|
||||
matches.append(XmlAttribute(qname, member))
|
||||
for qname, value in self._other_attributes.iteritems():
|
||||
if _qname_matches(tag, namespace, qname):
|
||||
matches.append(XmlAttribute(qname, value))
|
||||
return matches
|
||||
|
||||
GetAttributes = get_attributes
|
||||
|
||||
def _harvest_tree(self, tree, version=1):
|
||||
"""Populates object members from the data in the tree Element."""
|
||||
qname, elements, attributes = self.__class__._get_rules(version)
|
||||
for element in tree:
|
||||
if elements and element.tag in elements:
|
||||
definition = elements[element.tag]
|
||||
# If this is a repeating element, make sure the member is set to a
|
||||
# list.
|
||||
if definition[2]:
|
||||
if getattr(self, definition[0]) is None:
|
||||
setattr(self, definition[0], [])
|
||||
getattr(self, definition[0]).append(_xml_element_from_tree(element,
|
||||
definition[1], version))
|
||||
else:
|
||||
setattr(self, definition[0], _xml_element_from_tree(element,
|
||||
definition[1], version))
|
||||
else:
|
||||
self._other_elements.append(_xml_element_from_tree(element, XmlElement,
|
||||
version))
|
||||
for attrib, value in tree.attrib.iteritems():
|
||||
if attributes and attrib in attributes:
|
||||
setattr(self, attributes[attrib], value)
|
||||
else:
|
||||
self._other_attributes[attrib] = value
|
||||
if tree.text:
|
||||
self.text = tree.text
|
||||
|
||||
def _to_tree(self, version=1, encoding=None):
|
||||
new_tree = ElementTree.Element(_get_qname(self, version))
|
||||
self._attach_members(new_tree, version, encoding)
|
||||
return new_tree
|
||||
|
||||
def _attach_members(self, tree, version=1, encoding=None):
|
||||
"""Convert members to XML elements/attributes and add them to the tree.
|
||||
|
||||
Args:
|
||||
tree: An ElementTree.Element which will be modified. The members of
|
||||
this object will be added as child elements or attributes
|
||||
according to the rules described in _expected_elements and
|
||||
_expected_attributes. The elements and attributes stored in
|
||||
other_attributes and other_elements are also added a children
|
||||
of this tree.
|
||||
version: int Ingnored in this method but used by VersionedElement.
|
||||
encoding: str (optional)
|
||||
"""
|
||||
qname, elements, attributes = self.__class__._get_rules(version)
|
||||
encoding = encoding or STRING_ENCODING
|
||||
# Add the expected elements and attributes to the tree.
|
||||
if elements:
|
||||
for tag, element_def in elements.iteritems():
|
||||
member = getattr(self, element_def[0])
|
||||
# If this is a repeating element and there are members in the list.
|
||||
if member and element_def[2]:
|
||||
for instance in member:
|
||||
instance._become_child(tree, version)
|
||||
elif member:
|
||||
member._become_child(tree, version)
|
||||
if attributes:
|
||||
for attribute_tag, member_name in attributes.iteritems():
|
||||
value = getattr(self, member_name)
|
||||
if value:
|
||||
tree.attrib[attribute_tag] = value
|
||||
# Add the unexpected (other) elements and attributes to the tree.
|
||||
for element in self._other_elements:
|
||||
element._become_child(tree, version)
|
||||
for key, value in self._other_attributes.iteritems():
|
||||
# I'm not sure if unicode can be used in the attribute name, so for now
|
||||
# we assume the encoding is correct for the attribute name.
|
||||
if not isinstance(value, unicode):
|
||||
value = value.decode(encoding)
|
||||
tree.attrib[key] = value
|
||||
if self.text:
|
||||
if isinstance(self.text, unicode):
|
||||
tree.text = self.text
|
||||
else:
|
||||
tree.text = self.text.decode(encoding)
|
||||
|
||||
def to_string(self, version=1, encoding=None, pretty_print=None):
|
||||
"""Converts this object to XML."""
|
||||
|
||||
tree_string = ElementTree.tostring(self._to_tree(version, encoding))
|
||||
|
||||
if pretty_print and xmlString is not None:
|
||||
return xmlString(tree_string).toprettyxml()
|
||||
|
||||
return tree_string
|
||||
|
||||
ToString = to_string
|
||||
|
||||
def __str__(self):
|
||||
return self.to_string()
|
||||
|
||||
def _become_child(self, tree, version=1):
|
||||
"""Adds a child element to tree with the XML data in self."""
|
||||
new_child = ElementTree.Element('')
|
||||
tree.append(new_child)
|
||||
new_child.tag = _get_qname(self, version)
|
||||
self._attach_members(new_child, version)
|
||||
|
||||
def __get_extension_elements(self):
|
||||
return self._other_elements
|
||||
|
||||
def __set_extension_elements(self, elements):
|
||||
self._other_elements = elements
|
||||
|
||||
extension_elements = property(__get_extension_elements,
|
||||
__set_extension_elements,
|
||||
"""Provides backwards compatibility for v1 atom.AtomBase classes.""")
|
||||
|
||||
def __get_extension_attributes(self):
|
||||
return self._other_attributes
|
||||
|
||||
def __set_extension_attributes(self, attributes):
|
||||
self._other_attributes = attributes
|
||||
|
||||
extension_attributes = property(__get_extension_attributes,
|
||||
__set_extension_attributes,
|
||||
"""Provides backwards compatibility for v1 atom.AtomBase classes.""")
|
||||
|
||||
def _get_tag(self, version=1):
|
||||
qname = _get_qname(self, version)
|
||||
if qname:
|
||||
return qname[qname.find('}')+1:]
|
||||
return None
|
||||
|
||||
def _get_namespace(self, version=1):
|
||||
qname = _get_qname(self, version)
|
||||
if qname.startswith('{'):
|
||||
return qname[1:qname.find('}')]
|
||||
else:
|
||||
return None
|
||||
|
||||
def _set_tag(self, tag):
|
||||
if isinstance(self._qname, tuple):
|
||||
self._qname = self._qname.copy()
|
||||
if self._qname[0].startswith('{'):
|
||||
self._qname[0] = '{%s}%s' % (self._get_namespace(1), tag)
|
||||
else:
|
||||
self._qname[0] = tag
|
||||
else:
|
||||
if self._qname is not None and self._qname.startswith('{'):
|
||||
self._qname = '{%s}%s' % (self._get_namespace(), tag)
|
||||
else:
|
||||
self._qname = tag
|
||||
|
||||
def _set_namespace(self, namespace):
|
||||
tag = self._get_tag(1)
|
||||
if tag is None:
|
||||
tag = ''
|
||||
if isinstance(self._qname, tuple):
|
||||
self._qname = self._qname.copy()
|
||||
if namespace:
|
||||
self._qname[0] = '{%s}%s' % (namespace, tag)
|
||||
else:
|
||||
self._qname[0] = tag
|
||||
else:
|
||||
if namespace:
|
||||
self._qname = '{%s}%s' % (namespace, tag)
|
||||
else:
|
||||
self._qname = tag
|
||||
|
||||
tag = property(_get_tag, _set_tag,
|
||||
"""Provides backwards compatibility for v1 atom.AtomBase classes.""")
|
||||
|
||||
namespace = property(_get_namespace, _set_namespace,
|
||||
"""Provides backwards compatibility for v1 atom.AtomBase classes.""")
|
||||
|
||||
# Provided for backwards compatibility to atom.ExtensionElement
|
||||
children = extension_elements
|
||||
attributes = extension_attributes
|
||||
|
||||
|
||||
def _get_qname(element, version):
|
||||
if isinstance(element._qname, tuple):
|
||||
if version <= len(element._qname):
|
||||
return element._qname[version-1]
|
||||
else:
|
||||
return element._qname[-1]
|
||||
else:
|
||||
return element._qname
|
||||
|
||||
|
||||
def _qname_matches(tag, namespace, qname):
|
||||
"""Logic determines if a QName matches the desired local tag and namespace.
|
||||
|
||||
This is used in XmlElement.get_elements and XmlElement.get_attributes to
|
||||
find matches in the element's members (among all expected-and-unexpected
|
||||
elements-and-attributes).
|
||||
|
||||
Args:
|
||||
expected_tag: string
|
||||
expected_namespace: string
|
||||
qname: string in the form '{xml_namespace}localtag' or 'tag' if there is
|
||||
no namespace.
|
||||
|
||||
Returns:
|
||||
boolean True if the member's tag and namespace fit the expected tag and
|
||||
namespace.
|
||||
"""
|
||||
# If there is no expected namespace or tag, then everything will match.
|
||||
if qname is None:
|
||||
member_tag = None
|
||||
member_namespace = None
|
||||
else:
|
||||
if qname.startswith('{'):
|
||||
member_namespace = qname[1:qname.index('}')]
|
||||
member_tag = qname[qname.index('}') + 1:]
|
||||
else:
|
||||
member_namespace = None
|
||||
member_tag = qname
|
||||
return ((tag is None and namespace is None)
|
||||
# If there is a tag, but no namespace, see if the local tag matches.
|
||||
or (namespace is None and member_tag == tag)
|
||||
# There was no tag, but there was a namespace so see if the namespaces
|
||||
# match.
|
||||
or (tag is None and member_namespace == namespace)
|
||||
# There was no tag, and the desired elements have no namespace, so check
|
||||
# to see that the member's namespace is None.
|
||||
or (tag is None and namespace == ''
|
||||
and member_namespace is None)
|
||||
# The tag and the namespace both match.
|
||||
or (tag == member_tag
|
||||
and namespace == member_namespace)
|
||||
# The tag matches, and the expected namespace is the empty namespace,
|
||||
# check to make sure the member's namespace is None.
|
||||
or (tag == member_tag and namespace == ''
|
||||
and member_namespace is None))
|
||||
|
||||
|
||||
def parse(xml_string, target_class=None, version=1, encoding=None):
|
||||
"""Parses the XML string according to the rules for the target_class.
|
||||
|
||||
Args:
|
||||
xml_string: str or unicode
|
||||
target_class: XmlElement or a subclass. If None is specified, the
|
||||
XmlElement class is used.
|
||||
version: int (optional) The version of the schema which should be used when
|
||||
converting the XML into an object. The default is 1.
|
||||
encoding: str (optional) The character encoding of the bytes in the
|
||||
xml_string. Default is 'UTF-8'.
|
||||
"""
|
||||
if target_class is None:
|
||||
target_class = XmlElement
|
||||
if isinstance(xml_string, unicode):
|
||||
if encoding is None:
|
||||
xml_string = xml_string.encode(STRING_ENCODING)
|
||||
else:
|
||||
xml_string = xml_string.encode(encoding)
|
||||
tree = ElementTree.fromstring(xml_string)
|
||||
return _xml_element_from_tree(tree, target_class, version)
|
||||
|
||||
|
||||
Parse = parse
|
||||
xml_element_from_string = parse
|
||||
XmlElementFromString = xml_element_from_string
|
||||
|
||||
|
||||
def _xml_element_from_tree(tree, target_class, version=1):
|
||||
if target_class._qname is None:
|
||||
instance = target_class()
|
||||
instance._qname = tree.tag
|
||||
instance._harvest_tree(tree, version)
|
||||
return instance
|
||||
# TODO handle the namespace-only case
|
||||
# Namespace only will be used with Google Spreadsheets rows and
|
||||
# Google Base item attributes.
|
||||
elif tree.tag == _get_qname(target_class, version):
|
||||
instance = target_class()
|
||||
instance._harvest_tree(tree, version)
|
||||
return instance
|
||||
return None
|
||||
|
||||
|
||||
class XmlAttribute(object):
|
||||
|
||||
def __init__(self, qname, value):
|
||||
self._qname = qname
|
||||
self.value = value
|
||||
|
||||
338
atom/data.py
338
atom/data.py
@@ -1,338 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This module is used for version 2 of the Google Data APIs.
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import atom.core
|
||||
|
||||
|
||||
XML_TEMPLATE = '{http://www.w3.org/XML/1998/namespace}%s'
|
||||
ATOM_TEMPLATE = '{http://www.w3.org/2005/Atom}%s'
|
||||
APP_TEMPLATE_V1 = '{http://purl.org/atom/app#}%s'
|
||||
APP_TEMPLATE_V2 = '{http://www.w3.org/2007/app}%s'
|
||||
|
||||
|
||||
class Name(atom.core.XmlElement):
|
||||
"""The atom:name element."""
|
||||
_qname = ATOM_TEMPLATE % 'name'
|
||||
|
||||
|
||||
class Email(atom.core.XmlElement):
|
||||
"""The atom:email element."""
|
||||
_qname = ATOM_TEMPLATE % 'email'
|
||||
|
||||
|
||||
class Uri(atom.core.XmlElement):
|
||||
"""The atom:uri element."""
|
||||
_qname = ATOM_TEMPLATE % 'uri'
|
||||
|
||||
|
||||
class Person(atom.core.XmlElement):
|
||||
"""A foundation class which atom:author and atom:contributor extend.
|
||||
|
||||
A person contains information like name, email address, and web page URI for
|
||||
an author or contributor to an Atom feed.
|
||||
"""
|
||||
name = Name
|
||||
email = Email
|
||||
uri = Uri
|
||||
|
||||
|
||||
class Author(Person):
|
||||
"""The atom:author element.
|
||||
|
||||
An author is a required element in Feed unless each Entry contains an Author.
|
||||
"""
|
||||
_qname = ATOM_TEMPLATE % 'author'
|
||||
|
||||
|
||||
class Contributor(Person):
|
||||
"""The atom:contributor element."""
|
||||
_qname = ATOM_TEMPLATE % 'contributor'
|
||||
|
||||
|
||||
class Link(atom.core.XmlElement):
|
||||
"""The atom:link element."""
|
||||
_qname = ATOM_TEMPLATE % 'link'
|
||||
href = 'href'
|
||||
rel = 'rel'
|
||||
type = 'type'
|
||||
hreflang = 'hreflang'
|
||||
title = 'title'
|
||||
length = 'length'
|
||||
|
||||
|
||||
class Generator(atom.core.XmlElement):
|
||||
"""The atom:generator element."""
|
||||
_qname = ATOM_TEMPLATE % 'generator'
|
||||
uri = 'uri'
|
||||
version = 'version'
|
||||
|
||||
|
||||
class Text(atom.core.XmlElement):
|
||||
"""A foundation class from which atom:title, summary, etc. extend.
|
||||
|
||||
This class should never be instantiated.
|
||||
"""
|
||||
type = 'type'
|
||||
|
||||
|
||||
class Title(Text):
|
||||
"""The atom:title element."""
|
||||
_qname = ATOM_TEMPLATE % 'title'
|
||||
|
||||
|
||||
class Subtitle(Text):
|
||||
"""The atom:subtitle element."""
|
||||
_qname = ATOM_TEMPLATE % 'subtitle'
|
||||
|
||||
|
||||
class Rights(Text):
|
||||
"""The atom:rights element."""
|
||||
_qname = ATOM_TEMPLATE % 'rights'
|
||||
|
||||
|
||||
class Summary(Text):
|
||||
"""The atom:summary element."""
|
||||
_qname = ATOM_TEMPLATE % 'summary'
|
||||
|
||||
|
||||
class Content(Text):
|
||||
"""The atom:content element."""
|
||||
_qname = ATOM_TEMPLATE % 'content'
|
||||
src = 'src'
|
||||
|
||||
|
||||
class Category(atom.core.XmlElement):
|
||||
"""The atom:category element."""
|
||||
_qname = ATOM_TEMPLATE % 'category'
|
||||
term = 'term'
|
||||
scheme = 'scheme'
|
||||
label = 'label'
|
||||
|
||||
|
||||
class Id(atom.core.XmlElement):
|
||||
"""The atom:id element."""
|
||||
_qname = ATOM_TEMPLATE % 'id'
|
||||
|
||||
|
||||
class Icon(atom.core.XmlElement):
|
||||
"""The atom:icon element."""
|
||||
_qname = ATOM_TEMPLATE % 'icon'
|
||||
|
||||
|
||||
class Logo(atom.core.XmlElement):
|
||||
"""The atom:logo element."""
|
||||
_qname = ATOM_TEMPLATE % 'logo'
|
||||
|
||||
|
||||
class Draft(atom.core.XmlElement):
|
||||
"""The app:draft element which indicates if this entry should be public."""
|
||||
_qname = (APP_TEMPLATE_V1 % 'draft', APP_TEMPLATE_V2 % 'draft')
|
||||
|
||||
|
||||
class Control(atom.core.XmlElement):
|
||||
"""The app:control element indicating restrictions on publication.
|
||||
|
||||
The APP control element may contain a draft element indicating whether or
|
||||
not this entry should be publicly available.
|
||||
"""
|
||||
_qname = (APP_TEMPLATE_V1 % 'control', APP_TEMPLATE_V2 % 'control')
|
||||
draft = Draft
|
||||
|
||||
|
||||
class Date(atom.core.XmlElement):
|
||||
"""A parent class for atom:updated, published, etc."""
|
||||
|
||||
|
||||
class Updated(Date):
|
||||
"""The atom:updated element."""
|
||||
_qname = ATOM_TEMPLATE % 'updated'
|
||||
|
||||
|
||||
class Published(Date):
|
||||
"""The atom:published element."""
|
||||
_qname = ATOM_TEMPLATE % 'published'
|
||||
|
||||
|
||||
class LinkFinder(object):
|
||||
"""An "interface" providing methods to find link elements
|
||||
|
||||
Entry elements often contain multiple links which differ in the rel
|
||||
attribute or content type. Often, developers are interested in a specific
|
||||
type of link so this class provides methods to find specific classes of
|
||||
links.
|
||||
|
||||
This class is used as a mixin in Atom entries and feeds.
|
||||
"""
|
||||
|
||||
def find_url(self, rel):
|
||||
"""Returns the URL (as a string) in a link with the desired rel value."""
|
||||
for link in self.link:
|
||||
if link.rel == rel and link.href:
|
||||
return link.href
|
||||
return None
|
||||
|
||||
FindUrl = find_url
|
||||
|
||||
def get_link(self, rel):
|
||||
"""Returns a link object which has the desired rel value.
|
||||
|
||||
If you are interested in the URL instead of the link object,
|
||||
consider using find_url instead.
|
||||
"""
|
||||
for link in self.link:
|
||||
if link.rel == rel and link.href:
|
||||
return link
|
||||
return None
|
||||
|
||||
GetLink = get_link
|
||||
|
||||
def find_self_link(self):
|
||||
"""Find the first link with rel set to 'self'
|
||||
|
||||
Returns:
|
||||
A str containing the link's href or None if none of the links had rel
|
||||
equal to 'self'
|
||||
"""
|
||||
return self.find_url('self')
|
||||
|
||||
FindSelfLink = find_self_link
|
||||
|
||||
def get_self_link(self):
|
||||
return self.get_link('self')
|
||||
|
||||
GetSelfLink = get_self_link
|
||||
|
||||
def find_edit_link(self):
|
||||
return self.find_url('edit')
|
||||
|
||||
FindEditLink = find_edit_link
|
||||
|
||||
def get_edit_link(self):
|
||||
return self.get_link('edit')
|
||||
|
||||
GetEditLink = get_edit_link
|
||||
|
||||
def find_edit_media_link(self):
|
||||
link = self.find_url('edit-media')
|
||||
# Search for media-edit as well since Picasa API used media-edit instead.
|
||||
if link is None:
|
||||
return self.find_url('media-edit')
|
||||
return link
|
||||
|
||||
FindEditMediaLink = find_edit_media_link
|
||||
|
||||
def get_edit_media_link(self):
|
||||
link = self.get_link('edit-media')
|
||||
if link is None:
|
||||
return self.get_link('media-edit')
|
||||
return link
|
||||
|
||||
GetEditMediaLink = get_edit_media_link
|
||||
|
||||
def find_next_link(self):
|
||||
return self.find_url('next')
|
||||
|
||||
FindNextLink = find_next_link
|
||||
|
||||
def get_next_link(self):
|
||||
return self.get_link('next')
|
||||
|
||||
GetNextLink = get_next_link
|
||||
|
||||
def find_license_link(self):
|
||||
return self.find_url('license')
|
||||
|
||||
FindLicenseLink = find_license_link
|
||||
|
||||
def get_license_link(self):
|
||||
return self.get_link('license')
|
||||
|
||||
GetLicenseLink = get_license_link
|
||||
|
||||
def find_alternate_link(self):
|
||||
return self.find_url('alternate')
|
||||
|
||||
FindAlternateLink = find_alternate_link
|
||||
|
||||
def get_alternate_link(self):
|
||||
return self.get_link('alternate')
|
||||
|
||||
GetAlternateLink = get_alternate_link
|
||||
|
||||
|
||||
class FeedEntryParent(atom.core.XmlElement, LinkFinder):
|
||||
"""A super class for atom:feed and entry, contains shared attributes"""
|
||||
author = [Author]
|
||||
category = [Category]
|
||||
contributor = [Contributor]
|
||||
id = Id
|
||||
link = [Link]
|
||||
rights = Rights
|
||||
title = Title
|
||||
updated = Updated
|
||||
|
||||
def __init__(self, atom_id=None, text=None, *args, **kwargs):
|
||||
if atom_id is not None:
|
||||
self.id = atom_id
|
||||
atom.core.XmlElement.__init__(self, text=text, *args, **kwargs)
|
||||
|
||||
|
||||
class Source(FeedEntryParent):
|
||||
"""The atom:source element."""
|
||||
_qname = ATOM_TEMPLATE % 'source'
|
||||
generator = Generator
|
||||
icon = Icon
|
||||
logo = Logo
|
||||
subtitle = Subtitle
|
||||
|
||||
|
||||
class Entry(FeedEntryParent):
|
||||
"""The atom:entry element."""
|
||||
_qname = ATOM_TEMPLATE % 'entry'
|
||||
content = Content
|
||||
published = Published
|
||||
source = Source
|
||||
summary = Summary
|
||||
control = Control
|
||||
|
||||
|
||||
class Feed(Source):
|
||||
"""The atom:feed element which contains entries."""
|
||||
_qname = ATOM_TEMPLATE % 'feed'
|
||||
entry = [Entry]
|
||||
|
||||
|
||||
class ExtensionElement(atom.core.XmlElement):
|
||||
"""Provided for backwards compatibility to the v1 atom.ExtensionElement."""
|
||||
|
||||
def __init__(self, tag=None, namespace=None, attributes=None,
|
||||
children=None, text=None, *args, **kwargs):
|
||||
if namespace:
|
||||
self._qname = '{%s}%s' % (namespace, tag)
|
||||
else:
|
||||
self._qname = tag
|
||||
self.children = children or []
|
||||
self.attributes = attributes or {}
|
||||
self.text = text
|
||||
|
||||
_BecomeChildElement = atom.core.XmlElement._become_child
|
||||
364
atom/http.py
364
atom/http.py
@@ -1,364 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""HttpClients in this module use httplib to make HTTP requests.
|
||||
|
||||
This module make HTTP requests based on httplib, but there are environments
|
||||
in which an httplib based approach will not work (if running in Google App
|
||||
Engine for example). In those cases, higher level classes (like AtomService
|
||||
and GDataService) can swap out the HttpClient to transparently use a
|
||||
different mechanism for making HTTP requests.
|
||||
|
||||
HttpClient: Contains a request method which performs an HTTP call to the
|
||||
server.
|
||||
|
||||
ProxiedHttpClient: Contains a request method which connects to a proxy using
|
||||
settings stored in operating system environment variables then
|
||||
performs an HTTP call to the endpoint server.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import types
|
||||
import os
|
||||
import httplib
|
||||
import atom.url
|
||||
import atom.http_interface
|
||||
import socket
|
||||
import base64
|
||||
import atom.http_core
|
||||
ssl_imported = False
|
||||
ssl = None
|
||||
try:
|
||||
import ssl
|
||||
ssl_imported = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ProxyError(atom.http_interface.Error):
|
||||
pass
|
||||
|
||||
|
||||
class TestConfigurationError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
DEFAULT_CONTENT_TYPE = 'application/atom+xml; charset=UTF-8'
|
||||
|
||||
|
||||
class HttpClient(atom.http_interface.GenericHttpClient):
|
||||
# Added to allow old v1 HttpClient objects to use the new
|
||||
# http_code.HttpClient. Used in unit tests to inject a mock client.
|
||||
v2_http_client = None
|
||||
|
||||
def __init__(self, headers=None):
|
||||
self.debug = False
|
||||
self.headers = headers or {}
|
||||
|
||||
def request(self, operation, url, data=None, headers=None):
|
||||
"""Performs an HTTP call to the server, supports GET, POST, PUT, and
|
||||
DELETE.
|
||||
|
||||
Usage example, perform and HTTP GET on http://www.google.com/:
|
||||
import atom.http
|
||||
client = atom.http.HttpClient()
|
||||
http_response = client.request('GET', 'http://www.google.com/')
|
||||
|
||||
Args:
|
||||
operation: str The HTTP operation to be performed. This is usually one
|
||||
of 'GET', 'POST', 'PUT', or 'DELETE'
|
||||
data: filestream, list of parts, or other object which can be converted
|
||||
to a string. Should be set to None when performing a GET or DELETE.
|
||||
If data is a file-like object which can be read, this method will
|
||||
read a chunk of 100K bytes at a time and send them.
|
||||
If the data is a list of parts to be sent, each part will be
|
||||
evaluated and sent.
|
||||
url: The full URL to which the request should be sent. Can be a string
|
||||
or atom.url.Url.
|
||||
headers: dict of strings. HTTP headers which should be sent
|
||||
in the request.
|
||||
"""
|
||||
all_headers = self.headers.copy()
|
||||
if headers:
|
||||
all_headers.update(headers)
|
||||
|
||||
# If the list of headers does not include a Content-Length, attempt to
|
||||
# calculate it based on the data object.
|
||||
if data and 'Content-Length' not in all_headers:
|
||||
if isinstance(data, types.StringTypes):
|
||||
all_headers['Content-Length'] = str(len(data))
|
||||
else:
|
||||
raise atom.http_interface.ContentLengthRequired('Unable to calculate '
|
||||
'the length of the data parameter. Specify a value for '
|
||||
'Content-Length')
|
||||
|
||||
# Set the content type to the default value if none was set.
|
||||
if 'Content-Type' not in all_headers:
|
||||
all_headers['Content-Type'] = DEFAULT_CONTENT_TYPE
|
||||
|
||||
if self.v2_http_client is not None:
|
||||
http_request = atom.http_core.HttpRequest(method=operation)
|
||||
atom.http_core.Uri.parse_uri(str(url)).modify_request(http_request)
|
||||
http_request.headers = all_headers
|
||||
if data:
|
||||
http_request._body_parts.append(data)
|
||||
return self.v2_http_client.request(http_request=http_request)
|
||||
|
||||
if not isinstance(url, atom.url.Url):
|
||||
if isinstance(url, types.StringTypes):
|
||||
url = atom.url.parse_url(url)
|
||||
else:
|
||||
raise atom.http_interface.UnparsableUrlObject('Unable to parse url '
|
||||
'parameter because it was not a string or atom.url.Url')
|
||||
|
||||
connection = self._prepare_connection(url, all_headers)
|
||||
|
||||
if self.debug:
|
||||
connection.debuglevel = 1
|
||||
|
||||
connection.putrequest(operation, self._get_access_url(url),
|
||||
skip_host=True)
|
||||
if url.port is not None:
|
||||
connection.putheader('Host', '%s:%s' % (url.host, url.port))
|
||||
else:
|
||||
connection.putheader('Host', url.host)
|
||||
|
||||
# Overcome a bug in Python 2.4 and 2.5
|
||||
# httplib.HTTPConnection.putrequest adding
|
||||
# HTTP request header 'Host: www.google.com:443' instead of
|
||||
# 'Host: www.google.com', and thus resulting the error message
|
||||
# 'Token invalid - AuthSub token has wrong scope' in the HTTP response.
|
||||
if (url.protocol == 'https' and int(url.port or 443) == 443 and
|
||||
hasattr(connection, '_buffer') and
|
||||
isinstance(connection._buffer, list)):
|
||||
header_line = 'Host: %s:443' % url.host
|
||||
replacement_header_line = 'Host: %s' % url.host
|
||||
try:
|
||||
connection._buffer[connection._buffer.index(header_line)] = (
|
||||
replacement_header_line)
|
||||
except ValueError: # header_line missing from connection._buffer
|
||||
pass
|
||||
|
||||
# Send the HTTP headers.
|
||||
for header_name in all_headers:
|
||||
connection.putheader(header_name, all_headers[header_name])
|
||||
connection.endheaders()
|
||||
|
||||
# If there is data, send it in the request.
|
||||
if data:
|
||||
if isinstance(data, list):
|
||||
for data_part in data:
|
||||
_send_data_part(data_part, connection)
|
||||
else:
|
||||
_send_data_part(data, connection)
|
||||
|
||||
# Return the HTTP Response from the server.
|
||||
return connection.getresponse()
|
||||
|
||||
def _prepare_connection(self, url, headers):
|
||||
if not isinstance(url, atom.url.Url):
|
||||
if isinstance(url, types.StringTypes):
|
||||
url = atom.url.parse_url(url)
|
||||
else:
|
||||
raise atom.http_interface.UnparsableUrlObject('Unable to parse url '
|
||||
'parameter because it was not a string or atom.url.Url')
|
||||
if url.protocol == 'https':
|
||||
if not url.port:
|
||||
return httplib.HTTPSConnection(url.host)
|
||||
return httplib.HTTPSConnection(url.host, int(url.port))
|
||||
else:
|
||||
if not url.port:
|
||||
return httplib.HTTPConnection(url.host)
|
||||
return httplib.HTTPConnection(url.host, int(url.port))
|
||||
|
||||
def _get_access_url(self, url):
|
||||
return url.to_string()
|
||||
|
||||
|
||||
class ProxiedHttpClient(HttpClient):
|
||||
"""Performs an HTTP request through a proxy.
|
||||
|
||||
The proxy settings are obtained from enviroment variables. The URL of the
|
||||
proxy server is assumed to be stored in the environment variables
|
||||
'https_proxy' and 'http_proxy' respectively. If the proxy server requires
|
||||
a Basic Auth authorization header, the username and password are expected to
|
||||
be in the 'proxy-username' or 'proxy_username' variable and the
|
||||
'proxy-password' or 'proxy_password' variable, or in 'http_proxy' or
|
||||
'https_proxy' as "protocol://[username:password@]host:port".
|
||||
|
||||
After connecting to the proxy server, the request is completed as in
|
||||
HttpClient.request.
|
||||
"""
|
||||
def _prepare_connection(self, url, headers):
|
||||
proxy_settings = os.environ.get('%s_proxy' % url.protocol)
|
||||
if not proxy_settings:
|
||||
# The request was HTTP or HTTPS, but there was no appropriate proxy set.
|
||||
return HttpClient._prepare_connection(self, url, headers)
|
||||
else:
|
||||
#print '!!!!%s' % proxy_settings
|
||||
proxy_auth = _get_proxy_auth(proxy_settings)
|
||||
proxy_netloc = _get_proxy_net_location(proxy_settings)
|
||||
#print '!!!!%s' % proxy_auth
|
||||
#print '!!!!%s' % proxy_netloc
|
||||
if url.protocol == 'https':
|
||||
# Set any proxy auth headers
|
||||
if proxy_auth:
|
||||
proxy_auth = 'Proxy-authorization: %s' % proxy_auth
|
||||
|
||||
# Construct the proxy connect command.
|
||||
port = url.port
|
||||
if not port:
|
||||
port = '443'
|
||||
proxy_connect = 'CONNECT %s:%s HTTP/1.0\r\n' % (url.host, port)
|
||||
|
||||
# Set the user agent to send to the proxy
|
||||
if headers and 'User-Agent' in headers:
|
||||
user_agent = 'User-Agent: %s\r\n' % (headers['User-Agent'])
|
||||
else:
|
||||
user_agent = 'User-Agent: python\r\n'
|
||||
|
||||
proxy_pieces = '%s%s%s\r\n' % (proxy_connect, proxy_auth, user_agent)
|
||||
|
||||
# Find the proxy host and port.
|
||||
proxy_url = atom.url.parse_url(proxy_netloc)
|
||||
if not proxy_url.port:
|
||||
proxy_url.port = '80'
|
||||
|
||||
# Connect to the proxy server, very simple recv and error checking
|
||||
p_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
p_sock.connect((proxy_url.host, int(proxy_url.port)))
|
||||
p_sock.sendall(proxy_pieces)
|
||||
response = ''
|
||||
|
||||
# Wait for the full response.
|
||||
while response.find("\r\n\r\n") == -1:
|
||||
response += p_sock.recv(8192)
|
||||
|
||||
p_status = response.split()[1]
|
||||
if p_status != str(200):
|
||||
raise ProxyError('Error status=%s' % str(p_status))
|
||||
|
||||
# Trivial setup for ssl socket.
|
||||
sslobj = None
|
||||
if ssl_imported:
|
||||
sslobj = ssl.wrap_socket(p_sock, None, None)
|
||||
else:
|
||||
sock_ssl = socket.ssl(p_sock, None, None)
|
||||
sslobj = httplib.FakeSocket(p_sock, sock_ssl)
|
||||
|
||||
# Initalize httplib and replace with the proxy socket.
|
||||
connection = httplib.HTTPConnection(proxy_url.host)
|
||||
connection.sock = sslobj
|
||||
return connection
|
||||
else:
|
||||
# If protocol was not https.
|
||||
# Find the proxy host and port.
|
||||
proxy_url = atom.url.parse_url(proxy_netloc)
|
||||
if not proxy_url.port:
|
||||
proxy_url.port = '80'
|
||||
|
||||
if proxy_auth:
|
||||
headers['Proxy-Authorization'] = proxy_auth.strip()
|
||||
|
||||
return httplib.HTTPConnection(proxy_url.host, int(proxy_url.port))
|
||||
|
||||
def _get_access_url(self, url):
|
||||
return url.to_string()
|
||||
|
||||
|
||||
def _get_proxy_auth(proxy_settings):
|
||||
"""Returns proxy authentication string for header.
|
||||
|
||||
Will check environment variables for proxy authentication info, starting with
|
||||
proxy(_/-)username and proxy(_/-)password before checking the given
|
||||
proxy_settings for a [protocol://]username:password@host[:port] string.
|
||||
|
||||
Args:
|
||||
proxy_settings: String from http_proxy or https_proxy environment variable.
|
||||
|
||||
Returns:
|
||||
Authentication string for proxy, or empty string if no proxy username was
|
||||
found.
|
||||
"""
|
||||
proxy_username = None
|
||||
proxy_password = None
|
||||
|
||||
proxy_username = os.environ.get('proxy-username')
|
||||
if not proxy_username:
|
||||
proxy_username = os.environ.get('proxy_username')
|
||||
proxy_password = os.environ.get('proxy-password')
|
||||
if not proxy_password:
|
||||
proxy_password = os.environ.get('proxy_password')
|
||||
|
||||
if not proxy_username:
|
||||
if '@' in proxy_settings:
|
||||
protocol_and_proxy_auth = proxy_settings.split('@')[0].split(':')
|
||||
if len(protocol_and_proxy_auth) == 3:
|
||||
# 3 elements means we have [<protocol>, //<user>, <password>]
|
||||
proxy_username = protocol_and_proxy_auth[1].lstrip('/')
|
||||
proxy_password = protocol_and_proxy_auth[2]
|
||||
elif len(protocol_and_proxy_auth) == 2:
|
||||
# 2 elements means we have [<user>, <password>]
|
||||
proxy_username = protocol_and_proxy_auth[0]
|
||||
proxy_password = protocol_and_proxy_auth[1]
|
||||
if proxy_username:
|
||||
user_auth = base64.encodestring('%s:%s' % (proxy_username,
|
||||
proxy_password))
|
||||
return 'Basic %s\r\n' % (user_auth.strip())
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def _get_proxy_net_location(proxy_settings):
|
||||
"""Returns proxy host and port.
|
||||
|
||||
Args:
|
||||
proxy_settings: String from http_proxy or https_proxy environment variable.
|
||||
Must be in the form of protocol://[username:password@]host:port
|
||||
|
||||
Returns:
|
||||
String in the form of protocol://host:port
|
||||
"""
|
||||
if '@' in proxy_settings:
|
||||
protocol = proxy_settings.split(':')[0]
|
||||
netloc = proxy_settings.split('@')[1]
|
||||
return '%s://%s' % (protocol, netloc)
|
||||
else:
|
||||
return proxy_settings
|
||||
|
||||
|
||||
def _send_data_part(data, connection):
|
||||
if isinstance(data, types.StringTypes):
|
||||
connection.send(data)
|
||||
return
|
||||
# Check to see if data is a file-like object that has a read method.
|
||||
elif hasattr(data, 'read'):
|
||||
# Read the file and send it a chunk at a time.
|
||||
while 1:
|
||||
binarydata = data.read(100000)
|
||||
if binarydata == '': break
|
||||
connection.send(binarydata)
|
||||
return
|
||||
else:
|
||||
# The data object was not a file.
|
||||
# Try to convert to a string and send the data.
|
||||
connection.send(str(data))
|
||||
return
|
||||
@@ -1,597 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This module is used for version 2 of the Google Data APIs.
|
||||
# TODO: add proxy handling.
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import os
|
||||
import StringIO
|
||||
import urlparse
|
||||
import urllib
|
||||
import httplib
|
||||
ssl = None
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnknownSize(Error):
|
||||
pass
|
||||
|
||||
|
||||
class ProxyError(Error):
|
||||
pass
|
||||
|
||||
|
||||
MIME_BOUNDARY = 'END_OF_PART'
|
||||
|
||||
|
||||
def get_headers(http_response):
|
||||
"""Retrieves all HTTP headers from an HTTP response from the server.
|
||||
|
||||
This method is provided for backwards compatibility for Python2.2 and 2.3.
|
||||
The httplib.HTTPResponse object in 2.2 and 2.3 does not have a getheaders
|
||||
method so this function will use getheaders if available, but if not it
|
||||
will retrieve a few using getheader.
|
||||
"""
|
||||
if hasattr(http_response, 'getheaders'):
|
||||
return http_response.getheaders()
|
||||
else:
|
||||
headers = []
|
||||
for header in (
|
||||
'location', 'content-type', 'content-length', 'age', 'allow',
|
||||
'cache-control', 'content-location', 'content-encoding', 'date',
|
||||
'etag', 'expires', 'last-modified', 'pragma', 'server',
|
||||
'set-cookie', 'transfer-encoding', 'vary', 'via', 'warning',
|
||||
'www-authenticate', 'gdata-version'):
|
||||
value = http_response.getheader(header, None)
|
||||
if value is not None:
|
||||
headers.append((header, value))
|
||||
return headers
|
||||
|
||||
|
||||
class HttpRequest(object):
|
||||
"""Contains all of the parameters for an HTTP 1.1 request.
|
||||
|
||||
The HTTP headers are represented by a dictionary, and it is the
|
||||
responsibility of the user to ensure that duplicate field names are combined
|
||||
into one header value according to the rules in section 4.2 of RFC 2616.
|
||||
"""
|
||||
method = None
|
||||
uri = None
|
||||
|
||||
def __init__(self, uri=None, method=None, headers=None):
|
||||
"""Construct an HTTP request.
|
||||
|
||||
Args:
|
||||
uri: The full path or partial path as a Uri object or a string.
|
||||
method: The HTTP method for the request, examples include 'GET', 'POST',
|
||||
etc.
|
||||
headers: dict of strings The HTTP headers to include in the request.
|
||||
"""
|
||||
self.headers = headers or {}
|
||||
self._body_parts = []
|
||||
if method is not None:
|
||||
self.method = method
|
||||
if isinstance(uri, (str, unicode)):
|
||||
uri = Uri.parse_uri(uri)
|
||||
self.uri = uri or Uri()
|
||||
|
||||
|
||||
def add_body_part(self, data, mime_type, size=None):
|
||||
"""Adds data to the HTTP request body.
|
||||
|
||||
If more than one part is added, this is assumed to be a mime-multipart
|
||||
request. This method is designed to create MIME 1.0 requests as specified
|
||||
in RFC 1341.
|
||||
|
||||
Args:
|
||||
data: str or a file-like object containing a part of the request body.
|
||||
mime_type: str The MIME type describing the data
|
||||
size: int Required if the data is a file like object. If the data is a
|
||||
string, the size is calculated so this parameter is ignored.
|
||||
"""
|
||||
if isinstance(data, str):
|
||||
size = len(data)
|
||||
if size is None:
|
||||
# TODO: support chunked transfer if some of the body is of unknown size.
|
||||
raise UnknownSize('Each part of the body must have a known size.')
|
||||
if 'Content-Length' in self.headers:
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
else:
|
||||
content_length = 0
|
||||
# If this is the first part added to the body, then this is not a multipart
|
||||
# request.
|
||||
if len(self._body_parts) == 0:
|
||||
self.headers['Content-Type'] = mime_type
|
||||
content_length = size
|
||||
self._body_parts.append(data)
|
||||
elif len(self._body_parts) == 1:
|
||||
# This is the first member in a mime-multipart request, so change the
|
||||
# _body_parts list to indicate a multipart payload.
|
||||
self._body_parts.insert(0, 'Media multipart posting')
|
||||
boundary_string = '\r\n--%s\r\n' % (MIME_BOUNDARY,)
|
||||
content_length += len(boundary_string) + size
|
||||
self._body_parts.insert(1, boundary_string)
|
||||
content_length += len('Media multipart posting')
|
||||
# Put the content type of the first part of the body into the multipart
|
||||
# payload.
|
||||
original_type_string = 'Content-Type: %s\r\n\r\n' % (
|
||||
self.headers['Content-Type'],)
|
||||
self._body_parts.insert(2, original_type_string)
|
||||
content_length += len(original_type_string)
|
||||
boundary_string = '\r\n--%s\r\n' % (MIME_BOUNDARY,)
|
||||
self._body_parts.append(boundary_string)
|
||||
content_length += len(boundary_string)
|
||||
# Change the headers to indicate this is now a mime multipart request.
|
||||
self.headers['Content-Type'] = 'multipart/related; boundary="%s"' % (
|
||||
MIME_BOUNDARY,)
|
||||
self.headers['MIME-version'] = '1.0'
|
||||
# Include the mime type of this part.
|
||||
type_string = 'Content-Type: %s\r\n\r\n' % (mime_type)
|
||||
self._body_parts.append(type_string)
|
||||
content_length += len(type_string)
|
||||
self._body_parts.append(data)
|
||||
ending_boundary_string = '\r\n--%s--' % (MIME_BOUNDARY,)
|
||||
self._body_parts.append(ending_boundary_string)
|
||||
content_length += len(ending_boundary_string)
|
||||
else:
|
||||
# This is a mime multipart request.
|
||||
boundary_string = '\r\n--%s\r\n' % (MIME_BOUNDARY,)
|
||||
self._body_parts.insert(-1, boundary_string)
|
||||
content_length += len(boundary_string) + size
|
||||
# Include the mime type of this part.
|
||||
type_string = 'Content-Type: %s\r\n\r\n' % (mime_type)
|
||||
self._body_parts.insert(-1, type_string)
|
||||
content_length += len(type_string)
|
||||
self._body_parts.insert(-1, data)
|
||||
self.headers['Content-Length'] = str(content_length)
|
||||
# I could add an "append_to_body_part" method as well.
|
||||
|
||||
AddBodyPart = add_body_part
|
||||
|
||||
def add_form_inputs(self, form_data,
|
||||
mime_type='application/x-www-form-urlencoded'):
|
||||
"""Form-encodes and adds data to the request body.
|
||||
|
||||
Args:
|
||||
form_data: dict or sequnce or two member tuples which contains the
|
||||
form keys and values.
|
||||
mime_type: str The MIME type of the form data being sent. Defaults
|
||||
to 'application/x-www-form-urlencoded'.
|
||||
"""
|
||||
body = urllib.urlencode(form_data)
|
||||
self.add_body_part(body, mime_type)
|
||||
|
||||
AddFormInputs = add_form_inputs
|
||||
|
||||
def _copy(self):
|
||||
"""Creates a deep copy of this request."""
|
||||
copied_uri = Uri(self.uri.scheme, self.uri.host, self.uri.port,
|
||||
self.uri.path, self.uri.query.copy())
|
||||
new_request = HttpRequest(uri=copied_uri, method=self.method,
|
||||
headers=self.headers.copy())
|
||||
new_request._body_parts = self._body_parts[:]
|
||||
return new_request
|
||||
|
||||
def _dump(self):
|
||||
"""Converts to a printable string for debugging purposes.
|
||||
|
||||
In order to preserve the request, it does not read from file-like objects
|
||||
in the body.
|
||||
"""
|
||||
output = 'HTTP Request\n method: %s\n url: %s\n headers:\n' % (
|
||||
self.method, str(self.uri))
|
||||
for header, value in self.headers.iteritems():
|
||||
output += ' %s: %s\n' % (header, value)
|
||||
output += ' body sections:\n'
|
||||
i = 0
|
||||
for part in self._body_parts:
|
||||
if isinstance(part, (str, unicode)):
|
||||
output += ' %s: %s\n' % (i, part)
|
||||
else:
|
||||
output += ' %s: <file like object>\n' % i
|
||||
i += 1
|
||||
return output
|
||||
|
||||
|
||||
def _apply_defaults(http_request):
|
||||
if http_request.uri.scheme is None:
|
||||
if http_request.uri.port == 443:
|
||||
http_request.uri.scheme = 'https'
|
||||
else:
|
||||
http_request.uri.scheme = 'http'
|
||||
|
||||
|
||||
class Uri(object):
|
||||
"""A URI as used in HTTP 1.1"""
|
||||
scheme = None
|
||||
host = None
|
||||
port = None
|
||||
path = None
|
||||
|
||||
def __init__(self, scheme=None, host=None, port=None, path=None, query=None):
|
||||
"""Constructor for a URI.
|
||||
|
||||
Args:
|
||||
scheme: str This is usually 'http' or 'https'.
|
||||
host: str The host name or IP address of the desired server.
|
||||
post: int The server's port number.
|
||||
path: str The path of the resource following the host. This begins with
|
||||
a /, example: '/calendar/feeds/default/allcalendars/full'
|
||||
query: dict of strings The URL query parameters. The keys and values are
|
||||
both escaped so this dict should contain the unescaped values.
|
||||
For example {'my key': 'val', 'second': '!!!'} will become
|
||||
'?my+key=val&second=%21%21%21' which is appended to the path.
|
||||
"""
|
||||
self.query = query or {}
|
||||
if scheme is not None:
|
||||
self.scheme = scheme
|
||||
if host is not None:
|
||||
self.host = host
|
||||
if port is not None:
|
||||
self.port = port
|
||||
if path:
|
||||
self.path = path
|
||||
|
||||
def _get_query_string(self):
|
||||
param_pairs = []
|
||||
for key, value in self.query.iteritems():
|
||||
param_pairs.append('='.join((urllib.quote_plus(key),
|
||||
urllib.quote_plus(str(value)))))
|
||||
return '&'.join(param_pairs)
|
||||
|
||||
def _get_relative_path(self):
|
||||
"""Returns the path with the query parameters escaped and appended."""
|
||||
param_string = self._get_query_string()
|
||||
if self.path is None:
|
||||
path = '/'
|
||||
else:
|
||||
path = self.path
|
||||
if param_string:
|
||||
return '?'.join([path, param_string])
|
||||
else:
|
||||
return path
|
||||
|
||||
def _to_string(self):
|
||||
if self.scheme is None and self.port == 443:
|
||||
scheme = 'https'
|
||||
elif self.scheme is None:
|
||||
scheme = 'http'
|
||||
else:
|
||||
scheme = self.scheme
|
||||
if self.path is None:
|
||||
path = '/'
|
||||
else:
|
||||
path = self.path
|
||||
if self.port is None:
|
||||
return '%s://%s%s' % (scheme, self.host, self._get_relative_path())
|
||||
else:
|
||||
return '%s://%s:%s%s' % (scheme, self.host, str(self.port),
|
||||
self._get_relative_path())
|
||||
|
||||
def __str__(self):
|
||||
return self._to_string()
|
||||
|
||||
def modify_request(self, http_request=None):
|
||||
"""Sets HTTP request components based on the URI."""
|
||||
if http_request is None:
|
||||
http_request = HttpRequest()
|
||||
if http_request.uri is None:
|
||||
http_request.uri = Uri()
|
||||
# Determine the correct scheme.
|
||||
if self.scheme:
|
||||
http_request.uri.scheme = self.scheme
|
||||
if self.port:
|
||||
http_request.uri.port = self.port
|
||||
if self.host:
|
||||
http_request.uri.host = self.host
|
||||
# Set the relative uri path
|
||||
if self.path:
|
||||
http_request.uri.path = self.path
|
||||
if self.query:
|
||||
http_request.uri.query = self.query.copy()
|
||||
return http_request
|
||||
|
||||
ModifyRequest = modify_request
|
||||
|
||||
def parse_uri(uri_string):
|
||||
"""Creates a Uri object which corresponds to the URI string.
|
||||
|
||||
This method can accept partial URIs, but it will leave missing
|
||||
members of the Uri unset.
|
||||
"""
|
||||
parts = urlparse.urlparse(uri_string)
|
||||
uri = Uri()
|
||||
if parts[0]:
|
||||
uri.scheme = parts[0]
|
||||
if parts[1]:
|
||||
host_parts = parts[1].split(':')
|
||||
if host_parts[0]:
|
||||
uri.host = host_parts[0]
|
||||
if len(host_parts) > 1:
|
||||
uri.port = int(host_parts[1])
|
||||
if parts[2]:
|
||||
uri.path = parts[2]
|
||||
if parts[4]:
|
||||
param_pairs = parts[4].split('&')
|
||||
for pair in param_pairs:
|
||||
pair_parts = pair.split('=')
|
||||
if len(pair_parts) > 1:
|
||||
uri.query[urllib.unquote_plus(pair_parts[0])] = (
|
||||
urllib.unquote_plus(pair_parts[1]))
|
||||
elif len(pair_parts) == 1:
|
||||
uri.query[urllib.unquote_plus(pair_parts[0])] = None
|
||||
return uri
|
||||
|
||||
parse_uri = staticmethod(parse_uri)
|
||||
|
||||
ParseUri = parse_uri
|
||||
|
||||
|
||||
parse_uri = Uri.parse_uri
|
||||
|
||||
|
||||
ParseUri = Uri.parse_uri
|
||||
|
||||
|
||||
class HttpResponse(object):
|
||||
status = None
|
||||
reason = None
|
||||
_body = None
|
||||
|
||||
def __init__(self, status=None, reason=None, headers=None, body=None):
|
||||
self._headers = headers or {}
|
||||
if status is not None:
|
||||
self.status = status
|
||||
if reason is not None:
|
||||
self.reason = reason
|
||||
if body is not None:
|
||||
if hasattr(body, 'read'):
|
||||
self._body = body
|
||||
else:
|
||||
self._body = StringIO.StringIO(body)
|
||||
|
||||
def getheader(self, name, default=None):
|
||||
if name in self._headers:
|
||||
return self._headers[name]
|
||||
else:
|
||||
return default
|
||||
|
||||
def getheaders(self):
|
||||
return self._headers
|
||||
|
||||
def read(self, amt=None):
|
||||
if self._body is None:
|
||||
return None
|
||||
if not amt:
|
||||
return self._body.read()
|
||||
else:
|
||||
return self._body.read(amt)
|
||||
|
||||
|
||||
def _dump_response(http_response):
|
||||
"""Converts to a string for printing debug messages.
|
||||
|
||||
Does not read the body since that may consume the content.
|
||||
"""
|
||||
output = 'HttpResponse\n status: %s\n reason: %s\n headers:' % (
|
||||
http_response.status, http_response.reason)
|
||||
headers = get_headers(http_response)
|
||||
if isinstance(headers, dict):
|
||||
for header, value in headers.iteritems():
|
||||
output += ' %s: %s\n' % (header, value)
|
||||
else:
|
||||
for pair in headers:
|
||||
output += ' %s: %s\n' % (pair[0], pair[1])
|
||||
return output
|
||||
|
||||
|
||||
class HttpClient(object):
|
||||
"""Performs HTTP requests using httplib."""
|
||||
debug = None
|
||||
|
||||
def request(self, http_request):
|
||||
return self._http_request(http_request.method, http_request.uri,
|
||||
http_request.headers, http_request._body_parts)
|
||||
|
||||
Request = request
|
||||
|
||||
def _get_connection(self, uri, headers=None):
|
||||
"""Opens a socket connection to the server to set up an HTTP request.
|
||||
|
||||
Args:
|
||||
uri: The full URL for the request as a Uri object.
|
||||
headers: A dict of string pairs containing the HTTP headers for the
|
||||
request.
|
||||
"""
|
||||
connection = None
|
||||
if uri.scheme == 'https':
|
||||
if not uri.port:
|
||||
connection = httplib.HTTPSConnection(uri.host)
|
||||
else:
|
||||
connection = httplib.HTTPSConnection(uri.host, int(uri.port))
|
||||
else:
|
||||
if not uri.port:
|
||||
connection = httplib.HTTPConnection(uri.host)
|
||||
else:
|
||||
connection = httplib.HTTPConnection(uri.host, int(uri.port))
|
||||
return connection
|
||||
|
||||
def _http_request(self, method, uri, headers=None, body_parts=None):
|
||||
"""Makes an HTTP request using httplib.
|
||||
|
||||
Args:
|
||||
method: str example: 'GET', 'POST', 'PUT', 'DELETE', etc.
|
||||
uri: str or atom.http_core.Uri
|
||||
headers: dict of strings mapping to strings which will be sent as HTTP
|
||||
headers in the request.
|
||||
body_parts: list of strings, objects with a read method, or objects
|
||||
which can be converted to strings using str. Each of these
|
||||
will be sent in order as the body of the HTTP request.
|
||||
"""
|
||||
if isinstance(uri, (str, unicode)):
|
||||
uri = Uri.parse_uri(uri)
|
||||
|
||||
connection = self._get_connection(uri, headers=headers)
|
||||
|
||||
if self.debug:
|
||||
connection.debuglevel = 1
|
||||
|
||||
if connection.host != uri.host:
|
||||
connection.putrequest(method, str(uri))
|
||||
else:
|
||||
connection.putrequest(method, uri._get_relative_path())
|
||||
|
||||
# Overcome a bug in Python 2.4 and 2.5
|
||||
# httplib.HTTPConnection.putrequest adding
|
||||
# HTTP request header 'Host: www.google.com:443' instead of
|
||||
# 'Host: www.google.com', and thus resulting the error message
|
||||
# 'Token invalid - AuthSub token has wrong scope' in the HTTP response.
|
||||
if (uri.scheme == 'https' and int(uri.port or 443) == 443 and
|
||||
hasattr(connection, '_buffer') and
|
||||
isinstance(connection._buffer, list)):
|
||||
header_line = 'Host: %s:443' % uri.host
|
||||
replacement_header_line = 'Host: %s' % uri.host
|
||||
try:
|
||||
connection._buffer[connection._buffer.index(header_line)] = (
|
||||
replacement_header_line)
|
||||
except ValueError: # header_line missing from connection._buffer
|
||||
pass
|
||||
|
||||
# Send the HTTP headers.
|
||||
for header_name, value in headers.iteritems():
|
||||
connection.putheader(header_name, value)
|
||||
connection.endheaders()
|
||||
|
||||
# If there is data, send it in the request.
|
||||
if body_parts and filter(lambda x: x != '', body_parts):
|
||||
for part in body_parts:
|
||||
_send_data_part(part, connection)
|
||||
|
||||
# Return the HTTP Response from the server.
|
||||
return connection.getresponse()
|
||||
|
||||
|
||||
def _send_data_part(data, connection):
|
||||
if isinstance(data, (str, unicode)):
|
||||
# I might want to just allow str, not unicode.
|
||||
connection.send(data)
|
||||
return
|
||||
# Check to see if data is a file-like object that has a read method.
|
||||
elif hasattr(data, 'read'):
|
||||
# Read the file and send it a chunk at a time.
|
||||
while 1:
|
||||
binarydata = data.read(100000)
|
||||
if binarydata == '': break
|
||||
connection.send(binarydata)
|
||||
return
|
||||
else:
|
||||
# The data object was not a file.
|
||||
# Try to convert to a string and send the data.
|
||||
connection.send(str(data))
|
||||
return
|
||||
|
||||
|
||||
class ProxiedHttpClient(HttpClient):
|
||||
|
||||
def _get_connection(self, uri, headers=None):
|
||||
# Check to see if there are proxy settings required for this request.
|
||||
proxy = None
|
||||
if uri.scheme == 'https':
|
||||
proxy = os.environ.get('https_proxy')
|
||||
elif uri.scheme == 'http':
|
||||
proxy = os.environ.get('http_proxy')
|
||||
if not proxy:
|
||||
return HttpClient._get_connection(self, uri, headers=headers)
|
||||
# Now we have the URL of the appropriate proxy server.
|
||||
# Get a username and password for the proxy if required.
|
||||
proxy_auth = _get_proxy_auth()
|
||||
if uri.scheme == 'https':
|
||||
import socket
|
||||
if proxy_auth:
|
||||
proxy_auth = 'Proxy-authorization: %s' % proxy_auth
|
||||
# Construct the proxy connect command.
|
||||
port = uri.port
|
||||
if not port:
|
||||
port = 443
|
||||
proxy_connect = 'CONNECT %s:%s HTTP/1.0\r\n' % (uri.host, port)
|
||||
# Set the user agent to send to the proxy
|
||||
user_agent = ''
|
||||
if headers and 'User-Agent' in headers:
|
||||
user_agent = 'User-Agent: %s\r\n' % (headers['User-Agent'])
|
||||
proxy_pieces = '%s%s%s\r\n' % (proxy_connect, proxy_auth, user_agent)
|
||||
# Find the proxy host and port.
|
||||
proxy_uri = Uri.parse_uri(proxy)
|
||||
if not proxy_uri.port:
|
||||
proxy_uri.port = '80'
|
||||
# Connect to the proxy server, very simple recv and error checking
|
||||
p_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
p_sock.connect((proxy_uri.host, int(proxy_uri.port)))
|
||||
p_sock.sendall(proxy_pieces)
|
||||
response = ''
|
||||
# Wait for the full response.
|
||||
while response.find("\r\n\r\n") == -1:
|
||||
response += p_sock.recv(8192)
|
||||
p_status = response.split()[1]
|
||||
if p_status != str(200):
|
||||
raise ProxyError('Error status=%s' % str(p_status))
|
||||
# Trivial setup for ssl socket.
|
||||
sslobj = None
|
||||
if ssl is not None:
|
||||
sslobj = ssl.wrap_socket(p_sock, None, None)
|
||||
else:
|
||||
sock_ssl = socket.ssl(p_sock, None, Nonesock_)
|
||||
sslobj = httplib.FakeSocket(p_sock, sock_ssl)
|
||||
# Initalize httplib and replace with the proxy socket.
|
||||
connection = httplib.HTTPConnection(proxy_uri.host)
|
||||
connection.sock = sslobj
|
||||
return connection
|
||||
elif uri.scheme == 'http':
|
||||
proxy_uri = Uri.parse_uri(proxy)
|
||||
if not proxy_uri.port:
|
||||
proxy_uri.port = '80'
|
||||
if proxy_auth:
|
||||
headers['Proxy-Authorization'] = proxy_auth.strip()
|
||||
return httplib.HTTPConnection(proxy_uri.host, int(proxy_uri.port))
|
||||
return None
|
||||
|
||||
|
||||
def _get_proxy_auth():
|
||||
import base64
|
||||
proxy_username = os.environ.get('proxy-username')
|
||||
if not proxy_username:
|
||||
proxy_username = os.environ.get('proxy_username')
|
||||
proxy_password = os.environ.get('proxy-password')
|
||||
if not proxy_password:
|
||||
proxy_password = os.environ.get('proxy_password')
|
||||
if proxy_username:
|
||||
user_auth = base64.b64encode('%s:%s' % (proxy_username,
|
||||
proxy_password))
|
||||
return 'Basic %s\r\n' % (user_auth.strip())
|
||||
else:
|
||||
return ''
|
||||
@@ -1,156 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""This module provides a common interface for all HTTP requests.
|
||||
|
||||
HttpResponse: Represents the server's response to an HTTP request. Provides
|
||||
an interface identical to httplib.HTTPResponse which is the response
|
||||
expected from higher level classes which use HttpClient.request.
|
||||
|
||||
GenericHttpClient: Provides an interface (superclass) for an object
|
||||
responsible for making HTTP requests. Subclasses of this object are
|
||||
used in AtomService and GDataService to make requests to the server. By
|
||||
changing the http_client member object, the AtomService is able to make
|
||||
HTTP requests using different logic (for example, when running on
|
||||
Google App Engine, the http_client makes requests using the App Engine
|
||||
urlfetch API).
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import StringIO
|
||||
|
||||
|
||||
USER_AGENT = '%s GData-Python 2.0.14+20110902+custom_mods'
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnparsableUrlObject(Error):
|
||||
pass
|
||||
|
||||
|
||||
class ContentLengthRequired(Error):
|
||||
pass
|
||||
|
||||
|
||||
class HttpResponse(object):
|
||||
def __init__(self, body=None, status=None, reason=None, headers=None):
|
||||
"""Constructor for an HttpResponse object.
|
||||
|
||||
HttpResponse represents the server's response to an HTTP request from
|
||||
the client. The HttpClient.request method returns a httplib.HTTPResponse
|
||||
object and this HttpResponse class is designed to mirror the interface
|
||||
exposed by httplib.HTTPResponse.
|
||||
|
||||
Args:
|
||||
body: A file like object, with a read() method. The body could also
|
||||
be a string, and the constructor will wrap it so that
|
||||
HttpResponse.read(self) will return the full string.
|
||||
status: The HTTP status code as an int. Example: 200, 201, 404.
|
||||
reason: The HTTP status message which follows the code. Example:
|
||||
OK, Created, Not Found
|
||||
headers: A dictionary containing the HTTP headers in the server's
|
||||
response. A common header in the response is Content-Length.
|
||||
"""
|
||||
if body:
|
||||
if hasattr(body, 'read'):
|
||||
self._body = body
|
||||
else:
|
||||
self._body = StringIO.StringIO(body)
|
||||
else:
|
||||
self._body = None
|
||||
if status is not None:
|
||||
self.status = int(status)
|
||||
else:
|
||||
self.status = None
|
||||
self.reason = reason
|
||||
self._headers = headers or {}
|
||||
|
||||
def getheader(self, name, default=None):
|
||||
if name in self._headers:
|
||||
return self._headers[name]
|
||||
else:
|
||||
return default
|
||||
|
||||
def read(self, amt=None):
|
||||
if not amt:
|
||||
return self._body.read()
|
||||
else:
|
||||
return self._body.read(amt)
|
||||
|
||||
|
||||
class GenericHttpClient(object):
|
||||
debug = False
|
||||
|
||||
def __init__(self, http_client, headers=None):
|
||||
"""
|
||||
|
||||
Args:
|
||||
http_client: An object which provides a request method to make an HTTP
|
||||
request. The request method in GenericHttpClient performs a
|
||||
call-through to the contained HTTP client object.
|
||||
headers: A dictionary containing HTTP headers which should be included
|
||||
in every HTTP request. Common persistent headers include
|
||||
'User-Agent'.
|
||||
"""
|
||||
self.http_client = http_client
|
||||
self.headers = headers or {}
|
||||
|
||||
def request(self, operation, url, data=None, headers=None):
|
||||
all_headers = self.headers.copy()
|
||||
if headers:
|
||||
all_headers.update(headers)
|
||||
return self.http_client.request(operation, url, data=data,
|
||||
headers=all_headers)
|
||||
|
||||
def get(self, url, headers=None):
|
||||
return self.request('GET', url, headers=headers)
|
||||
|
||||
def post(self, url, data, headers=None):
|
||||
return self.request('POST', url, data=data, headers=headers)
|
||||
|
||||
def put(self, url, data, headers=None):
|
||||
return self.request('PUT', url, data=data, headers=headers)
|
||||
|
||||
def delete(self, url, headers=None):
|
||||
return self.request('DELETE', url, headers=headers)
|
||||
|
||||
|
||||
class GenericToken(object):
|
||||
"""Represents an Authorization token to be added to HTTP requests.
|
||||
|
||||
Some Authorization headers included calculated fields (digital
|
||||
signatures for example) which are based on the parameters of the HTTP
|
||||
request. Therefore the token is responsible for signing the request
|
||||
and adding the Authorization header.
|
||||
"""
|
||||
def perform_request(self, http_client, operation, url, data=None,
|
||||
headers=None):
|
||||
"""For the GenericToken, no Authorization token is set."""
|
||||
return http_client.request(operation, url, data=data, headers=headers)
|
||||
|
||||
def valid_for_scope(self, url):
|
||||
"""Tells the caller if the token authorizes access to the desired URL.
|
||||
|
||||
Since the generic token doesn't add an auth header, it is not valid for
|
||||
any scope.
|
||||
"""
|
||||
return False
|
||||
@@ -1,132 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import atom.http_interface
|
||||
import atom.url
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NoRecordingFound(Error):
|
||||
pass
|
||||
|
||||
|
||||
class MockRequest(object):
|
||||
"""Holds parameters of an HTTP request for matching against future requests.
|
||||
"""
|
||||
def __init__(self, operation, url, data=None, headers=None):
|
||||
self.operation = operation
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
self.url = url
|
||||
self.data = data
|
||||
self.headers = headers
|
||||
|
||||
|
||||
class MockResponse(atom.http_interface.HttpResponse):
|
||||
"""Simulates an httplib.HTTPResponse object."""
|
||||
def __init__(self, body=None, status=None, reason=None, headers=None):
|
||||
if body and hasattr(body, 'read'):
|
||||
self.body = body.read()
|
||||
else:
|
||||
self.body = body
|
||||
if status is not None:
|
||||
self.status = int(status)
|
||||
else:
|
||||
self.status = None
|
||||
self.reason = reason
|
||||
self._headers = headers or {}
|
||||
|
||||
def read(self):
|
||||
return self.body
|
||||
|
||||
|
||||
class MockHttpClient(atom.http_interface.GenericHttpClient):
|
||||
def __init__(self, headers=None, recordings=None, real_client=None):
|
||||
"""An HttpClient which responds to request with stored data.
|
||||
|
||||
The request-response pairs are stored as tuples in a member list named
|
||||
recordings.
|
||||
|
||||
The MockHttpClient can be switched from replay mode to record mode by
|
||||
setting the real_client member to an instance of an HttpClient which will
|
||||
make real HTTP requests and store the server's response in list of
|
||||
recordings.
|
||||
|
||||
Args:
|
||||
headers: dict containing HTTP headers which should be included in all
|
||||
HTTP requests.
|
||||
recordings: The initial recordings to be used for responses. This list
|
||||
contains tuples in the form: (MockRequest, MockResponse)
|
||||
real_client: An HttpClient which will make a real HTTP request. The
|
||||
response will be converted into a MockResponse and stored in
|
||||
recordings.
|
||||
"""
|
||||
self.recordings = recordings or []
|
||||
self.real_client = real_client
|
||||
self.headers = headers or {}
|
||||
|
||||
def add_response(self, response, operation, url, data=None, headers=None):
|
||||
"""Adds a request-response pair to the recordings list.
|
||||
|
||||
After the recording is added, future matching requests will receive the
|
||||
response.
|
||||
|
||||
Args:
|
||||
response: MockResponse
|
||||
operation: str
|
||||
url: str
|
||||
data: str, Currently the data is ignored when looking for matching
|
||||
requests.
|
||||
headers: dict of strings: Currently the headers are ignored when
|
||||
looking for matching requests.
|
||||
"""
|
||||
request = MockRequest(operation, url, data=data, headers=headers)
|
||||
self.recordings.append((request, response))
|
||||
|
||||
def request(self, operation, url, data=None, headers=None):
|
||||
"""Returns a matching MockResponse from the recordings.
|
||||
|
||||
If the real_client is set, the request will be passed along and the
|
||||
server's response will be added to the recordings and also returned.
|
||||
|
||||
If there is no match, a NoRecordingFound error will be raised.
|
||||
"""
|
||||
if self.real_client is None:
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
for recording in self.recordings:
|
||||
if recording[0].operation == operation and recording[0].url == url:
|
||||
return recording[1]
|
||||
raise NoRecordingFound('No recodings found for %s %s' % (
|
||||
operation, url))
|
||||
else:
|
||||
# There is a real HTTP client, so make the request, and record the
|
||||
# response.
|
||||
response = self.real_client.request(operation, url, data=data,
|
||||
headers=headers)
|
||||
# TODO: copy the headers
|
||||
stored_response = MockResponse(body=response, status=response.status,
|
||||
reason=response.reason)
|
||||
self.add_response(stored_response, operation, url, data=data,
|
||||
headers=headers)
|
||||
return stored_response
|
||||
@@ -1,323 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This module is used for version 2 of the Google Data APIs.
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
import StringIO
|
||||
import pickle
|
||||
import os.path
|
||||
import tempfile
|
||||
import atom.http_core
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NoRecordingFound(Error):
|
||||
pass
|
||||
|
||||
|
||||
class MockHttpClient(object):
|
||||
debug = None
|
||||
real_client = None
|
||||
last_request_was_live = False
|
||||
|
||||
# The following members are used to construct the session cache temp file
|
||||
# name.
|
||||
# These are combined to form the file name
|
||||
# /tmp/cache_prefix.cache_case_name.cache_test_name
|
||||
cache_name_prefix = 'gdata_live_test'
|
||||
cache_case_name = ''
|
||||
cache_test_name = ''
|
||||
|
||||
def __init__(self, recordings=None, real_client=None):
|
||||
self._recordings = recordings or []
|
||||
if real_client is not None:
|
||||
self.real_client = real_client
|
||||
|
||||
def add_response(self, http_request, status, reason, headers=None,
|
||||
body=None):
|
||||
response = MockHttpResponse(status, reason, headers, body)
|
||||
# TODO Scrub the request and the response.
|
||||
self._recordings.append((http_request._copy(), response))
|
||||
|
||||
AddResponse = add_response
|
||||
|
||||
def request(self, http_request):
|
||||
"""Provide a recorded response, or record a response for replay.
|
||||
|
||||
If the real_client is set, the request will be made using the
|
||||
real_client, and the response from the server will be recorded.
|
||||
If the real_client is None (the default), this method will examine
|
||||
the recordings and find the first which matches.
|
||||
"""
|
||||
request = http_request._copy()
|
||||
_scrub_request(request)
|
||||
if self.real_client is None:
|
||||
self.last_request_was_live = False
|
||||
for recording in self._recordings:
|
||||
if _match_request(recording[0], request):
|
||||
return recording[1]
|
||||
else:
|
||||
# Pass along the debug settings to the real client.
|
||||
self.real_client.debug = self.debug
|
||||
# Make an actual request since we can use the real HTTP client.
|
||||
self.last_request_was_live = True
|
||||
response = self.real_client.request(http_request)
|
||||
scrubbed_response = _scrub_response(response)
|
||||
self.add_response(request, scrubbed_response.status,
|
||||
scrubbed_response.reason,
|
||||
dict(atom.http_core.get_headers(scrubbed_response)),
|
||||
scrubbed_response.read())
|
||||
# Return the recording which we just added.
|
||||
return self._recordings[-1][1]
|
||||
raise NoRecordingFound('No recoding was found for request: %s %s' % (
|
||||
request.method, str(request.uri)))
|
||||
|
||||
Request = request
|
||||
|
||||
def _save_recordings(self, filename):
|
||||
recording_file = open(os.path.join(tempfile.gettempdir(), filename),
|
||||
'wb')
|
||||
pickle.dump(self._recordings, recording_file)
|
||||
recording_file.close()
|
||||
|
||||
def _load_recordings(self, filename):
|
||||
recording_file = open(os.path.join(tempfile.gettempdir(), filename),
|
||||
'rb')
|
||||
self._recordings = pickle.load(recording_file)
|
||||
recording_file.close()
|
||||
|
||||
def _delete_recordings(self, filename):
|
||||
full_path = os.path.join(tempfile.gettempdir(), filename)
|
||||
if os.path.exists(full_path):
|
||||
os.remove(full_path)
|
||||
|
||||
def _load_or_use_client(self, filename, http_client):
|
||||
if os.path.exists(os.path.join(tempfile.gettempdir(), filename)):
|
||||
self._load_recordings(filename)
|
||||
else:
|
||||
self.real_client = http_client
|
||||
|
||||
def use_cached_session(self, name=None, real_http_client=None):
|
||||
"""Attempts to load recordings from a previous live request.
|
||||
|
||||
If a temp file with the recordings exists, then it is used to fulfill
|
||||
requests. If the file does not exist, then a real client is used to
|
||||
actually make the desired HTTP requests. Requests and responses are
|
||||
recorded and will be written to the desired temprary cache file when
|
||||
close_session is called.
|
||||
|
||||
Args:
|
||||
name: str (optional) The file name of session file to be used. The file
|
||||
is loaded from the temporary directory of this machine. If no name
|
||||
is passed in, a default name will be constructed using the
|
||||
cache_name_prefix, cache_case_name, and cache_test_name of this
|
||||
object.
|
||||
real_http_client: atom.http_core.HttpClient the real client to be used
|
||||
if the cached recordings are not found. If the default
|
||||
value is used, this will be an
|
||||
atom.http_core.HttpClient.
|
||||
"""
|
||||
if real_http_client is None:
|
||||
real_http_client = atom.http_core.HttpClient()
|
||||
if name is None:
|
||||
self._recordings_cache_name = self.get_cache_file_name()
|
||||
else:
|
||||
self._recordings_cache_name = name
|
||||
self._load_or_use_client(self._recordings_cache_name, real_http_client)
|
||||
|
||||
def close_session(self):
|
||||
"""Saves recordings in the temporary file named in use_cached_session."""
|
||||
if self.real_client is not None:
|
||||
self._save_recordings(self._recordings_cache_name)
|
||||
|
||||
def delete_session(self, name=None):
|
||||
"""Removes recordings from a previous live request."""
|
||||
if name is None:
|
||||
self._delete_recordings(self._recordings_cache_name)
|
||||
else:
|
||||
self._delete_recordings(name)
|
||||
|
||||
def get_cache_file_name(self):
|
||||
return '%s.%s.%s' % (self.cache_name_prefix, self.cache_case_name,
|
||||
self.cache_test_name)
|
||||
|
||||
def _dump(self):
|
||||
"""Provides debug information in a string."""
|
||||
output = 'MockHttpClient\n real_client: %s\n cache file name: %s\n' % (
|
||||
self.real_client, self.get_cache_file_name())
|
||||
output += ' recordings:\n'
|
||||
i = 0
|
||||
for recording in self._recordings:
|
||||
output += ' recording %i is for: %s %s\n' % (
|
||||
i, recording[0].method, str(recording[0].uri))
|
||||
i += 1
|
||||
return output
|
||||
|
||||
|
||||
def _match_request(http_request, stored_request):
|
||||
"""Determines whether a request is similar enough to a stored request
|
||||
to cause the stored response to be returned."""
|
||||
# Check to see if the host names match.
|
||||
if (http_request.uri.host is not None
|
||||
and http_request.uri.host != stored_request.uri.host):
|
||||
return False
|
||||
# Check the request path in the URL (/feeds/private/full/x)
|
||||
elif http_request.uri.path != stored_request.uri.path:
|
||||
return False
|
||||
# Check the method used in the request (GET, POST, etc.)
|
||||
elif http_request.method != stored_request.method:
|
||||
return False
|
||||
# If there is a gsession ID in either request, make sure that it is matched
|
||||
# exactly.
|
||||
elif ('gsessionid' in http_request.uri.query
|
||||
or 'gsessionid' in stored_request.uri.query):
|
||||
if 'gsessionid' not in stored_request.uri.query:
|
||||
return False
|
||||
elif 'gsessionid' not in http_request.uri.query:
|
||||
return False
|
||||
elif (http_request.uri.query['gsessionid']
|
||||
!= stored_request.uri.query['gsessionid']):
|
||||
return False
|
||||
# Ignores differences in the query params (?start-index=5&max-results=20),
|
||||
# the body of the request, the port number, HTTP headers, just to name a
|
||||
# few.
|
||||
return True
|
||||
|
||||
|
||||
def _scrub_request(http_request):
|
||||
""" Removes email address and password from a client login request.
|
||||
|
||||
Since the mock server saves the request and response in plantext, sensitive
|
||||
information like the password should be removed before saving the
|
||||
recordings. At the moment only requests sent to a ClientLogin url are
|
||||
scrubbed.
|
||||
"""
|
||||
if (http_request and http_request.uri and http_request.uri.path and
|
||||
http_request.uri.path.endswith('ClientLogin')):
|
||||
# Remove the email and password from a ClientLogin request.
|
||||
http_request._body_parts = []
|
||||
http_request.add_form_inputs(
|
||||
{'form_data': 'client login request has been scrubbed'})
|
||||
else:
|
||||
# We can remove the body of the post from the recorded request, since
|
||||
# the request body is not used when finding a matching recording.
|
||||
http_request._body_parts = []
|
||||
return http_request
|
||||
|
||||
|
||||
def _scrub_response(http_response):
|
||||
return http_response
|
||||
|
||||
|
||||
class EchoHttpClient(object):
|
||||
"""Sends the request data back in the response.
|
||||
|
||||
Used to check the formatting of the request as it was sent. Always responds
|
||||
with a 200 OK, and some information from the HTTP request is returned in
|
||||
special Echo-X headers in the response. The following headers are added
|
||||
in the response:
|
||||
'Echo-Host': The host name and port number to which the HTTP connection is
|
||||
made. If no port was passed in, the header will contain
|
||||
host:None.
|
||||
'Echo-Uri': The path portion of the URL being requested. /example?x=1&y=2
|
||||
'Echo-Scheme': The beginning of the URL, usually 'http' or 'https'
|
||||
'Echo-Method': The HTTP method being used, 'GET', 'POST', 'PUT', etc.
|
||||
"""
|
||||
|
||||
def request(self, http_request):
|
||||
return self._http_request(http_request.uri, http_request.method,
|
||||
http_request.headers, http_request._body_parts)
|
||||
|
||||
def _http_request(self, uri, method, headers=None, body_parts=None):
|
||||
body = StringIO.StringIO()
|
||||
response = atom.http_core.HttpResponse(status=200, reason='OK', body=body)
|
||||
if headers is None:
|
||||
response._headers = {}
|
||||
else:
|
||||
# Copy headers from the request to the response but convert values to
|
||||
# strings. Server response headers always come in as strings, so an int
|
||||
# should be converted to a corresponding string when echoing.
|
||||
for header, value in headers.iteritems():
|
||||
response._headers[header] = str(value)
|
||||
response._headers['Echo-Host'] = '%s:%s' % (uri.host, str(uri.port))
|
||||
response._headers['Echo-Uri'] = uri._get_relative_path()
|
||||
response._headers['Echo-Scheme'] = uri.scheme
|
||||
response._headers['Echo-Method'] = method
|
||||
for part in body_parts:
|
||||
if isinstance(part, str):
|
||||
body.write(part)
|
||||
elif hasattr(part, 'read'):
|
||||
body.write(part.read())
|
||||
body.seek(0)
|
||||
return response
|
||||
|
||||
|
||||
class SettableHttpClient(object):
|
||||
"""An HTTP Client which responds with the data given in set_response."""
|
||||
|
||||
def __init__(self, status, reason, body, headers):
|
||||
"""Configures the response for the server.
|
||||
|
||||
See set_response for details on the arguments to the constructor.
|
||||
"""
|
||||
self.set_response(status, reason, body, headers)
|
||||
self.last_request = None
|
||||
|
||||
def set_response(self, status, reason, body, headers):
|
||||
"""Determines the response which will be sent for each request.
|
||||
|
||||
Args:
|
||||
status: An int for the HTTP status code, example: 200, 404, etc.
|
||||
reason: String for the HTTP reason, example: OK, NOT FOUND, etc.
|
||||
body: The body of the HTTP response as a string or a file-like
|
||||
object (something with a read method).
|
||||
headers: dict of strings containing the HTTP headers in the response.
|
||||
"""
|
||||
self.response = atom.http_core.HttpResponse(status=status, reason=reason,
|
||||
body=body)
|
||||
self.response._headers = headers.copy()
|
||||
|
||||
def request(self, http_request):
|
||||
self.last_request = http_request
|
||||
return self.response
|
||||
|
||||
|
||||
class MockHttpResponse(atom.http_core.HttpResponse):
|
||||
|
||||
def __init__(self, status=None, reason=None, headers=None, body=None):
|
||||
self._headers = headers or {}
|
||||
if status is not None:
|
||||
self.status = status
|
||||
if reason is not None:
|
||||
self.reason = reason
|
||||
if body is not None:
|
||||
# Instead of using a file-like object for the body, store as a string
|
||||
# so that reads can be repeated.
|
||||
if hasattr(body, 'read'):
|
||||
self._body = body.read()
|
||||
else:
|
||||
self._body = body
|
||||
|
||||
def read(self):
|
||||
return self._body
|
||||
@@ -1,243 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""MockService provides CRUD ops. for mocking calls to AtomPub services.
|
||||
|
||||
MockService: Exposes the publicly used methods of AtomService to provide
|
||||
a mock interface which can be used in unit tests.
|
||||
"""
|
||||
|
||||
import atom.service
|
||||
import pickle
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeffrey Scudder)'
|
||||
|
||||
|
||||
# Recordings contains pairings of HTTP MockRequest objects with MockHttpResponse objects.
|
||||
recordings = []
|
||||
# If set, the mock service HttpRequest are actually made through this object.
|
||||
real_request_handler = None
|
||||
|
||||
def ConcealValueWithSha(source):
|
||||
import sha
|
||||
return sha.new(source[:-5]).hexdigest()
|
||||
|
||||
def DumpRecordings(conceal_func=ConcealValueWithSha):
|
||||
if conceal_func:
|
||||
for recording_pair in recordings:
|
||||
recording_pair[0].ConcealSecrets(conceal_func)
|
||||
return pickle.dumps(recordings)
|
||||
|
||||
def LoadRecordings(recordings_file_or_string):
|
||||
if isinstance(recordings_file_or_string, str):
|
||||
atom.mock_service.recordings = pickle.loads(recordings_file_or_string)
|
||||
elif hasattr(recordings_file_or_string, 'read'):
|
||||
atom.mock_service.recordings = pickle.loads(
|
||||
recordings_file_or_string.read())
|
||||
|
||||
def HttpRequest(service, operation, data, uri, extra_headers=None,
|
||||
url_params=None, escape_params=True, content_type='application/atom+xml'):
|
||||
"""Simulates an HTTP call to the server, makes an actual HTTP request if
|
||||
real_request_handler is set.
|
||||
|
||||
This function operates in two different modes depending on if
|
||||
real_request_handler is set or not. If real_request_handler is not set,
|
||||
HttpRequest will look in this module's recordings list to find a response
|
||||
which matches the parameters in the function call. If real_request_handler
|
||||
is set, this function will call real_request_handler.HttpRequest, add the
|
||||
response to the recordings list, and respond with the actual response.
|
||||
|
||||
Args:
|
||||
service: atom.AtomService object which contains some of the parameters
|
||||
needed to make the request. The following members are used to
|
||||
construct the HTTP call: server (str), additional_headers (dict),
|
||||
port (int), and ssl (bool).
|
||||
operation: str The HTTP operation to be performed. This is usually one of
|
||||
'GET', 'POST', 'PUT', or 'DELETE'
|
||||
data: ElementTree, filestream, list of parts, or other object which can be
|
||||
converted to a string.
|
||||
Should be set to None when performing a GET or PUT.
|
||||
If data is a file-like object which can be read, this method will read
|
||||
a chunk of 100K bytes at a time and send them.
|
||||
If the data is a list of parts to be sent, each part will be evaluated
|
||||
and sent.
|
||||
uri: The beginning of the URL to which the request should be sent.
|
||||
Examples: '/', '/base/feeds/snippets',
|
||||
'/m8/feeds/contacts/default/base'
|
||||
extra_headers: dict of strings. HTTP headers which should be sent
|
||||
in the request. These headers are in addition to those stored in
|
||||
service.additional_headers.
|
||||
url_params: dict of strings. Key value pairs to be added to the URL as
|
||||
URL parameters. For example {'foo':'bar', 'test':'param'} will
|
||||
become ?foo=bar&test=param.
|
||||
escape_params: bool default True. If true, the keys and values in
|
||||
url_params will be URL escaped when the form is constructed
|
||||
(Special characters converted to %XX form.)
|
||||
content_type: str The MIME type for the data being sent. Defaults to
|
||||
'application/atom+xml', this is only used if data is set.
|
||||
"""
|
||||
full_uri = atom.service.BuildUri(uri, url_params, escape_params)
|
||||
(server, port, ssl, uri) = atom.service.ProcessUrl(service, uri)
|
||||
current_request = MockRequest(operation, full_uri, host=server, ssl=ssl,
|
||||
data=data, extra_headers=extra_headers, url_params=url_params,
|
||||
escape_params=escape_params, content_type=content_type)
|
||||
# If the request handler is set, we should actually make the request using
|
||||
# the request handler and record the response to replay later.
|
||||
if real_request_handler:
|
||||
response = real_request_handler.HttpRequest(service, operation, data, uri,
|
||||
extra_headers=extra_headers, url_params=url_params,
|
||||
escape_params=escape_params, content_type=content_type)
|
||||
# TODO: need to copy the HTTP headers from the real response into the
|
||||
# recorded_response.
|
||||
recorded_response = MockHttpResponse(body=response.read(),
|
||||
status=response.status, reason=response.reason)
|
||||
# Insert a tuple which maps the request to the response object returned
|
||||
# when making an HTTP call using the real_request_handler.
|
||||
recordings.append((current_request, recorded_response))
|
||||
return recorded_response
|
||||
else:
|
||||
# Look through available recordings to see if one matches the current
|
||||
# request.
|
||||
for request_response_pair in recordings:
|
||||
if request_response_pair[0].IsMatch(current_request):
|
||||
return request_response_pair[1]
|
||||
return None
|
||||
|
||||
|
||||
class MockRequest(object):
|
||||
"""Represents a request made to an AtomPub server.
|
||||
|
||||
These objects are used to determine if a client request matches a recorded
|
||||
HTTP request to determine what the mock server's response will be.
|
||||
"""
|
||||
|
||||
def __init__(self, operation, uri, host=None, ssl=False, port=None,
|
||||
data=None, extra_headers=None, url_params=None, escape_params=True,
|
||||
content_type='application/atom+xml'):
|
||||
"""Constructor for a MockRequest
|
||||
|
||||
Args:
|
||||
operation: str One of 'GET', 'POST', 'PUT', or 'DELETE' this is the
|
||||
HTTP operation requested on the resource.
|
||||
uri: str The URL describing the resource to be modified or feed to be
|
||||
retrieved. This should include the protocol (http/https) and the host
|
||||
(aka domain). For example, these are some valud full_uris:
|
||||
'http://example.com', 'https://www.google.com/accounts/ClientLogin'
|
||||
host: str (optional) The server name which will be placed at the
|
||||
beginning of the URL if the uri parameter does not begin with 'http'.
|
||||
Examples include 'example.com', 'www.google.com', 'www.blogger.com'.
|
||||
ssl: boolean (optional) If true, the request URL will begin with https
|
||||
instead of http.
|
||||
data: ElementTree, filestream, list of parts, or other object which can be
|
||||
converted to a string. (optional)
|
||||
Should be set to None when performing a GET or PUT.
|
||||
If data is a file-like object which can be read, the constructor
|
||||
will read the entire file into memory. If the data is a list of
|
||||
parts to be sent, each part will be evaluated and stored.
|
||||
extra_headers: dict (optional) HTTP headers included in the request.
|
||||
url_params: dict (optional) Key value pairs which should be added to
|
||||
the URL as URL parameters in the request. For example uri='/',
|
||||
url_parameters={'foo':'1','bar':'2'} could become '/?foo=1&bar=2'.
|
||||
escape_params: boolean (optional) Perform URL escaping on the keys and
|
||||
values specified in url_params. Defaults to True.
|
||||
content_type: str (optional) Provides the MIME type of the data being
|
||||
sent.
|
||||
"""
|
||||
self.operation = operation
|
||||
self.uri = _ConstructFullUrlBase(uri, host=host, ssl=ssl)
|
||||
self.data = data
|
||||
self.extra_headers = extra_headers
|
||||
self.url_params = url_params or {}
|
||||
self.escape_params = escape_params
|
||||
self.content_type = content_type
|
||||
|
||||
def ConcealSecrets(self, conceal_func):
|
||||
"""Conceal secret data in this request."""
|
||||
if self.extra_headers.has_key('Authorization'):
|
||||
self.extra_headers['Authorization'] = conceal_func(
|
||||
self.extra_headers['Authorization'])
|
||||
|
||||
def IsMatch(self, other_request):
|
||||
"""Check to see if the other_request is equivalent to this request.
|
||||
|
||||
Used to determine if a recording matches an incoming request so that a
|
||||
recorded response should be sent to the client.
|
||||
|
||||
The matching is not exact, only the operation and URL are examined
|
||||
currently.
|
||||
|
||||
Args:
|
||||
other_request: MockRequest The request which we want to check this
|
||||
(self) MockRequest against to see if they are equivalent.
|
||||
"""
|
||||
# More accurate matching logic will likely be required.
|
||||
return (self.operation == other_request.operation and self.uri ==
|
||||
other_request.uri)
|
||||
|
||||
|
||||
def _ConstructFullUrlBase(uri, host=None, ssl=False):
|
||||
"""Puts URL components into the form http(s)://full.host.strinf/uri/path
|
||||
|
||||
Used to construct a roughly canonical URL so that URLs which begin with
|
||||
'http://example.com/' can be compared to a uri of '/' when the host is
|
||||
set to 'example.com'
|
||||
|
||||
If the uri contains 'http://host' already, the host and ssl parameters
|
||||
are ignored.
|
||||
|
||||
Args:
|
||||
uri: str The path component of the URL, examples include '/'
|
||||
host: str (optional) The host name which should prepend the URL. Example:
|
||||
'example.com'
|
||||
ssl: boolean (optional) If true, the returned URL will begin with https
|
||||
instead of http.
|
||||
|
||||
Returns:
|
||||
String which has the form http(s)://example.com/uri/string/contents
|
||||
"""
|
||||
if uri.startswith('http'):
|
||||
return uri
|
||||
if ssl:
|
||||
return 'https://%s%s' % (host, uri)
|
||||
else:
|
||||
return 'http://%s%s' % (host, uri)
|
||||
|
||||
|
||||
class MockHttpResponse(object):
|
||||
"""Returned from MockService crud methods as the server's response."""
|
||||
|
||||
def __init__(self, body=None, status=None, reason=None, headers=None):
|
||||
"""Construct a mock HTTPResponse and set members.
|
||||
|
||||
Args:
|
||||
body: str (optional) The HTTP body of the server's response.
|
||||
status: int (optional)
|
||||
reason: str (optional)
|
||||
headers: dict (optional)
|
||||
"""
|
||||
self.body = body
|
||||
self.status = status
|
||||
self.reason = reason
|
||||
self.headers = headers or {}
|
||||
|
||||
def read(self):
|
||||
return self.body
|
||||
|
||||
def getheader(self, header_name):
|
||||
return self.headers[header_name]
|
||||
|
||||
745
atom/service.py
745
atom/service.py
@@ -1,745 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2006, 2007, 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""AtomService provides CRUD ops. in line with the Atom Publishing Protocol.
|
||||
|
||||
AtomService: Encapsulates the ability to perform insert, update and delete
|
||||
operations with the Atom Publishing Protocol on which GData is
|
||||
based. An instance can perform query, insertion, deletion, and
|
||||
update.
|
||||
|
||||
HttpRequest: Function that performs a GET, POST, PUT, or DELETE HTTP request
|
||||
to the specified end point. An AtomService object or a subclass can be
|
||||
used to specify information about the request.
|
||||
"""
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import atom.http_interface
|
||||
import atom.url
|
||||
import atom.http
|
||||
import atom.token_store
|
||||
|
||||
import os
|
||||
import types
|
||||
import httplib
|
||||
import urllib
|
||||
import re
|
||||
import base64
|
||||
import socket
|
||||
import warnings
|
||||
try:
|
||||
from xml.etree import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
from xml.etree import ElementTree
|
||||
except ImportError:
|
||||
from elementtree import ElementTree
|
||||
import atom
|
||||
|
||||
|
||||
class AtomService(object):
|
||||
"""Performs Atom Publishing Protocol CRUD operations.
|
||||
|
||||
The AtomService contains methods to perform HTTP CRUD operations.
|
||||
"""
|
||||
|
||||
# Default values for members
|
||||
port = 80
|
||||
ssl = False
|
||||
# Set the current_token to force the AtomService to use this token
|
||||
# instead of searching for an appropriate token in the token_store.
|
||||
current_token = None
|
||||
auto_store_tokens = True
|
||||
auto_set_current_token = True
|
||||
|
||||
def _get_override_token(self):
|
||||
return self.current_token
|
||||
|
||||
def _set_override_token(self, token):
|
||||
self.current_token = token
|
||||
|
||||
override_token = property(_get_override_token, _set_override_token)
|
||||
|
||||
#@atom.v1_deprecated('Please use atom.client.AtomPubClient instead.')
|
||||
def __init__(self, server=None, additional_headers=None,
|
||||
application_name='', http_client=None, token_store=None):
|
||||
"""Creates a new AtomService client.
|
||||
|
||||
Args:
|
||||
server: string (optional) The start of a URL for the server
|
||||
to which all operations should be directed. Example:
|
||||
'www.google.com'
|
||||
additional_headers: dict (optional) Any additional HTTP headers which
|
||||
should be included with CRUD operations.
|
||||
http_client: An object responsible for making HTTP requests using a
|
||||
request method. If none is provided, a new instance of
|
||||
atom.http.ProxiedHttpClient will be used.
|
||||
token_store: Keeps a collection of authorization tokens which can be
|
||||
applied to requests for a specific URLs. Critical methods are
|
||||
find_token based on a URL (atom.url.Url or a string), add_token,
|
||||
and remove_token.
|
||||
"""
|
||||
self.http_client = http_client or atom.http.ProxiedHttpClient()
|
||||
self.token_store = token_store or atom.token_store.TokenStore()
|
||||
self.server = server
|
||||
self.additional_headers = additional_headers or {}
|
||||
self.additional_headers['User-Agent'] = atom.http_interface.USER_AGENT % (
|
||||
application_name,)
|
||||
# If debug is True, the HTTPConnection will display debug information
|
||||
self._set_debug(False)
|
||||
|
||||
__init__ = atom.v1_deprecated(
|
||||
'Please use atom.client.AtomPubClient instead.')(
|
||||
__init__)
|
||||
|
||||
def _get_debug(self):
|
||||
return self.http_client.debug
|
||||
|
||||
def _set_debug(self, value):
|
||||
self.http_client.debug = value
|
||||
|
||||
debug = property(_get_debug, _set_debug,
|
||||
doc='If True, HTTP debug information is printed.')
|
||||
|
||||
def use_basic_auth(self, username, password, scopes=None):
|
||||
if username is not None and password is not None:
|
||||
if scopes is None:
|
||||
scopes = [atom.token_store.SCOPE_ALL]
|
||||
base_64_string = base64.encodestring('%s:%s' % (username, password))
|
||||
token = BasicAuthToken('Basic %s' % base_64_string.strip(),
|
||||
scopes=[atom.token_store.SCOPE_ALL])
|
||||
if self.auto_set_current_token:
|
||||
self.current_token = token
|
||||
if self.auto_store_tokens:
|
||||
return self.token_store.add_token(token)
|
||||
return True
|
||||
return False
|
||||
|
||||
def UseBasicAuth(self, username, password, for_proxy=False):
|
||||
"""Sets an Authenticaiton: Basic HTTP header containing plaintext.
|
||||
|
||||
Deprecated, use use_basic_auth instead.
|
||||
|
||||
The username and password are base64 encoded and added to an HTTP header
|
||||
which will be included in each request. Note that your username and
|
||||
password are sent in plaintext.
|
||||
|
||||
Args:
|
||||
username: str
|
||||
password: str
|
||||
"""
|
||||
self.use_basic_auth(username, password)
|
||||
|
||||
#@atom.v1_deprecated('Please use atom.client.AtomPubClient for requests.')
|
||||
def request(self, operation, url, data=None, headers=None,
|
||||
url_params=None):
|
||||
if isinstance(url, (str, unicode)):
|
||||
if url.startswith('http:') and self.ssl:
|
||||
# Force all requests to be https if self.ssl is True.
|
||||
url = atom.url.parse_url('https:' + url[5:])
|
||||
elif not url.startswith('http') and self.ssl:
|
||||
url = atom.url.parse_url('https://%s%s' % (self.server, url))
|
||||
elif not url.startswith('http'):
|
||||
url = atom.url.parse_url('http://%s%s' % (self.server, url))
|
||||
else:
|
||||
url = atom.url.parse_url(url)
|
||||
|
||||
if url_params:
|
||||
for name, value in url_params.iteritems():
|
||||
url.params[name] = value
|
||||
|
||||
all_headers = self.additional_headers.copy()
|
||||
if headers:
|
||||
all_headers.update(headers)
|
||||
|
||||
if isinstance(data, types.StringTypes):
|
||||
data = data.encode('utf-8')
|
||||
|
||||
# If the list of headers does not include a Content-Length, attempt to
|
||||
# calculate it based on the data object.
|
||||
if data and 'Content-Length' not in all_headers:
|
||||
content_length = CalculateDataLength(data)
|
||||
if content_length:
|
||||
all_headers['Content-Length'] = str(content_length)
|
||||
|
||||
all_headers['GData-Version'] = '2.0'
|
||||
# Find an Authorization token for this URL if one is available.
|
||||
if self.override_token:
|
||||
auth_token = self.override_token
|
||||
else:
|
||||
auth_token = self.token_store.find_token(url)
|
||||
return auth_token.perform_request(self.http_client, operation, url,
|
||||
data=data, headers=all_headers)
|
||||
|
||||
request = atom.v1_deprecated(
|
||||
'Please use atom.client.AtomPubClient for requests.')(
|
||||
request)
|
||||
|
||||
# CRUD operations
|
||||
def Get(self, uri, extra_headers=None, url_params=None, escape_params=True):
|
||||
"""Query the APP server with the given URI
|
||||
|
||||
The uri is the portion of the URI after the server value
|
||||
(server example: 'www.google.com').
|
||||
|
||||
Example use:
|
||||
To perform a query against Google Base, set the server to
|
||||
'base.google.com' and set the uri to '/base/feeds/...', where ... is
|
||||
your query. For example, to find snippets for all digital cameras uri
|
||||
should be set to: '/base/feeds/snippets?bq=digital+camera'
|
||||
|
||||
Args:
|
||||
uri: string The query in the form of a URI. Example:
|
||||
'/base/feeds/snippets?bq=digital+camera'.
|
||||
extra_headers: dicty (optional) Extra HTTP headers to be included
|
||||
in the GET request. These headers are in addition to
|
||||
those stored in the client's additional_headers property.
|
||||
The client automatically sets the Content-Type and
|
||||
Authorization headers.
|
||||
url_params: dict (optional) Additional URL parameters to be included
|
||||
in the query. These are translated into query arguments
|
||||
in the form '&dict_key=value&...'.
|
||||
Example: {'max-results': '250'} becomes &max-results=250
|
||||
escape_params: boolean (optional) If false, the calling code has already
|
||||
ensured that the query will form a valid URL (all
|
||||
reserved characters have been escaped). If true, this
|
||||
method will escape the query and any URL parameters
|
||||
provided.
|
||||
|
||||
Returns:
|
||||
httplib.HTTPResponse The server's response to the GET request.
|
||||
"""
|
||||
return self.request('GET', uri, data=None, headers=extra_headers,
|
||||
url_params=url_params)
|
||||
|
||||
def Post(self, data, uri, extra_headers=None, url_params=None,
|
||||
escape_params=True, content_type='application/atom+xml; charset=UTF-8'):
|
||||
"""Insert data into an APP server at the given URI.
|
||||
|
||||
Args:
|
||||
data: string, ElementTree._Element, or something with a __str__ method
|
||||
The XML to be sent to the uri.
|
||||
uri: string The location (feed) to which the data should be inserted.
|
||||
Example: '/base/feeds/items'.
|
||||
extra_headers: dict (optional) HTTP headers which are to be included.
|
||||
The client automatically sets the Content-Type,
|
||||
Authorization, and Content-Length headers.
|
||||
url_params: dict (optional) Additional URL parameters to be included
|
||||
in the URI. These are translated into query arguments
|
||||
in the form '&dict_key=value&...'.
|
||||
Example: {'max-results': '250'} becomes &max-results=250
|
||||
escape_params: boolean (optional) If false, the calling code has already
|
||||
ensured that the query will form a valid URL (all
|
||||
reserved characters have been escaped). If true, this
|
||||
method will escape the query and any URL parameters
|
||||
provided.
|
||||
|
||||
Returns:
|
||||
httplib.HTTPResponse Server's response to the POST request.
|
||||
"""
|
||||
if extra_headers is None:
|
||||
extra_headers = {}
|
||||
if content_type:
|
||||
extra_headers['Content-Type'] = content_type
|
||||
return self.request('POST', uri, data=data, headers=extra_headers,
|
||||
url_params=url_params)
|
||||
|
||||
def Put(self, data, uri, extra_headers=None, url_params=None,
|
||||
escape_params=True, content_type='application/atom+xml; charset=UTF-8'):
|
||||
"""Updates an entry at the given URI.
|
||||
|
||||
Args:
|
||||
data: string, ElementTree._Element, or xml_wrapper.ElementWrapper The
|
||||
XML containing the updated data.
|
||||
uri: string A URI indicating entry to which the update will be applied.
|
||||
Example: '/base/feeds/items/ITEM-ID'
|
||||
extra_headers: dict (optional) HTTP headers which are to be included.
|
||||
The client automatically sets the Content-Type,
|
||||
Authorization, and Content-Length headers.
|
||||
url_params: dict (optional) Additional URL parameters to be included
|
||||
in the URI. These are translated into query arguments
|
||||
in the form '&dict_key=value&...'.
|
||||
Example: {'max-results': '250'} becomes &max-results=250
|
||||
escape_params: boolean (optional) If false, the calling code has already
|
||||
ensured that the query will form a valid URL (all
|
||||
reserved characters have been escaped). If true, this
|
||||
method will escape the query and any URL parameters
|
||||
provided.
|
||||
|
||||
Returns:
|
||||
httplib.HTTPResponse Server's response to the PUT request.
|
||||
"""
|
||||
if extra_headers is None:
|
||||
extra_headers = {}
|
||||
if content_type:
|
||||
extra_headers['Content-Type'] = content_type
|
||||
return self.request('PUT', uri, data=data, headers=extra_headers,
|
||||
url_params=url_params)
|
||||
|
||||
def Delete(self, uri, extra_headers=None, url_params=None,
|
||||
escape_params=True):
|
||||
"""Deletes the entry at the given URI.
|
||||
|
||||
Args:
|
||||
uri: string The URI of the entry to be deleted. Example:
|
||||
'/base/feeds/items/ITEM-ID'
|
||||
extra_headers: dict (optional) HTTP headers which are to be included.
|
||||
The client automatically sets the Content-Type and
|
||||
Authorization headers.
|
||||
url_params: dict (optional) Additional URL parameters to be included
|
||||
in the URI. These are translated into query arguments
|
||||
in the form '&dict_key=value&...'.
|
||||
Example: {'max-results': '250'} becomes &max-results=250
|
||||
escape_params: boolean (optional) If false, the calling code has already
|
||||
ensured that the query will form a valid URL (all
|
||||
reserved characters have been escaped). If true, this
|
||||
method will escape the query and any URL parameters
|
||||
provided.
|
||||
|
||||
Returns:
|
||||
httplib.HTTPResponse Server's response to the DELETE request.
|
||||
"""
|
||||
return self.request('DELETE', uri, data=None, headers=extra_headers,
|
||||
url_params=url_params)
|
||||
|
||||
|
||||
class BasicAuthToken(atom.http_interface.GenericToken):
|
||||
def __init__(self, auth_header, scopes=None):
|
||||
"""Creates a token used to add Basic Auth headers to HTTP requests.
|
||||
|
||||
Args:
|
||||
auth_header: str The value for the Authorization header.
|
||||
scopes: list of str or atom.url.Url specifying the beginnings of URLs
|
||||
for which this token can be used. For example, if scopes contains
|
||||
'http://example.com/foo', then this token can be used for a request to
|
||||
'http://example.com/foo/bar' but it cannot be used for a request to
|
||||
'http://example.com/baz'
|
||||
"""
|
||||
self.auth_header = auth_header
|
||||
self.scopes = scopes or []
|
||||
|
||||
def perform_request(self, http_client, operation, url, data=None,
|
||||
headers=None):
|
||||
"""Sets the Authorization header to the basic auth string."""
|
||||
if headers is None:
|
||||
headers = {'Authorization':self.auth_header}
|
||||
else:
|
||||
headers['Authorization'] = self.auth_header
|
||||
return http_client.request(operation, url, data=data, headers=headers)
|
||||
|
||||
def __str__(self):
|
||||
return self.auth_header
|
||||
|
||||
def valid_for_scope(self, url):
|
||||
"""Tells the caller if the token authorizes access to the desired URL.
|
||||
"""
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
for scope in self.scopes:
|
||||
if scope == atom.token_store.SCOPE_ALL:
|
||||
return True
|
||||
if isinstance(scope, (str, unicode)):
|
||||
scope = atom.url.parse_url(scope)
|
||||
if scope == url:
|
||||
return True
|
||||
# Check the host and the path, but ignore the port and protocol.
|
||||
elif scope.host == url.host and not scope.path:
|
||||
return True
|
||||
elif scope.host == url.host and scope.path and not url.path:
|
||||
continue
|
||||
elif scope.host == url.host and url.path.startswith(scope.path):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def PrepareConnection(service, full_uri):
|
||||
"""Opens a connection to the server based on the full URI.
|
||||
|
||||
This method is deprecated, instead use atom.http.HttpClient.request.
|
||||
|
||||
Examines the target URI and the proxy settings, which are set as
|
||||
environment variables, to open a connection with the server. This
|
||||
connection is used to make an HTTP request.
|
||||
|
||||
Args:
|
||||
service: atom.AtomService or a subclass. It must have a server string which
|
||||
represents the server host to which the request should be made. It may also
|
||||
have a dictionary of additional_headers to send in the HTTP request.
|
||||
full_uri: str Which is the target relative (lacks protocol and host) or
|
||||
absolute URL to be opened. Example:
|
||||
'https://www.google.com/accounts/ClientLogin' or
|
||||
'base/feeds/snippets' where the server is set to www.google.com.
|
||||
|
||||
Returns:
|
||||
A tuple containing the httplib.HTTPConnection and the full_uri for the
|
||||
request.
|
||||
"""
|
||||
deprecation('calling deprecated function PrepareConnection')
|
||||
(server, port, ssl, partial_uri) = ProcessUrl(service, full_uri)
|
||||
if ssl:
|
||||
# destination is https
|
||||
proxy = os.environ.get('https_proxy')
|
||||
if proxy:
|
||||
(p_server, p_port, p_ssl, p_uri) = ProcessUrl(service, proxy, True)
|
||||
proxy_username = os.environ.get('proxy-username')
|
||||
if not proxy_username:
|
||||
proxy_username = os.environ.get('proxy_username')
|
||||
proxy_password = os.environ.get('proxy-password')
|
||||
if not proxy_password:
|
||||
proxy_password = os.environ.get('proxy_password')
|
||||
if proxy_username:
|
||||
user_auth = base64.encodestring('%s:%s' % (proxy_username,
|
||||
proxy_password))
|
||||
proxy_authorization = ('Proxy-authorization: Basic %s\r\n' % (
|
||||
user_auth.strip()))
|
||||
else:
|
||||
proxy_authorization = ''
|
||||
proxy_connect = 'CONNECT %s:%s HTTP/1.0\r\n' % (server, port)
|
||||
user_agent = 'User-Agent: %s\r\n' % (
|
||||
service.additional_headers['User-Agent'])
|
||||
proxy_pieces = (proxy_connect + proxy_authorization + user_agent
|
||||
+ '\r\n')
|
||||
|
||||
#now connect, very simple recv and error checking
|
||||
p_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
p_sock.connect((p_server,p_port))
|
||||
p_sock.sendall(proxy_pieces)
|
||||
response = ''
|
||||
|
||||
# Wait for the full response.
|
||||
while response.find("\r\n\r\n") == -1:
|
||||
response += p_sock.recv(8192)
|
||||
|
||||
p_status=response.split()[1]
|
||||
if p_status!=str(200):
|
||||
raise atom.http.ProxyError('Error status=%s' % p_status)
|
||||
|
||||
# Trivial setup for ssl socket.
|
||||
ssl = socket.ssl(p_sock, None, None)
|
||||
fake_sock = httplib.FakeSocket(p_sock, ssl)
|
||||
|
||||
# Initalize httplib and replace with the proxy socket.
|
||||
connection = httplib.HTTPConnection(server)
|
||||
connection.sock=fake_sock
|
||||
full_uri = partial_uri
|
||||
|
||||
else:
|
||||
connection = httplib.HTTPSConnection(server, port)
|
||||
full_uri = partial_uri
|
||||
|
||||
else:
|
||||
# destination is http
|
||||
proxy = os.environ.get('http_proxy')
|
||||
if proxy:
|
||||
(p_server, p_port, p_ssl, p_uri) = ProcessUrl(service.server, proxy, True)
|
||||
proxy_username = os.environ.get('proxy-username')
|
||||
if not proxy_username:
|
||||
proxy_username = os.environ.get('proxy_username')
|
||||
proxy_password = os.environ.get('proxy-password')
|
||||
if not proxy_password:
|
||||
proxy_password = os.environ.get('proxy_password')
|
||||
if proxy_username:
|
||||
UseBasicAuth(service, proxy_username, proxy_password, True)
|
||||
connection = httplib.HTTPConnection(p_server, p_port)
|
||||
if not full_uri.startswith("http://"):
|
||||
if full_uri.startswith("/"):
|
||||
full_uri = "http://%s%s" % (service.server, full_uri)
|
||||
else:
|
||||
full_uri = "http://%s/%s" % (service.server, full_uri)
|
||||
else:
|
||||
connection = httplib.HTTPConnection(server, port)
|
||||
full_uri = partial_uri
|
||||
|
||||
return (connection, full_uri)
|
||||
|
||||
|
||||
def UseBasicAuth(service, username, password, for_proxy=False):
|
||||
"""Sets an Authenticaiton: Basic HTTP header containing plaintext.
|
||||
|
||||
Deprecated, use AtomService.use_basic_auth insread.
|
||||
|
||||
The username and password are base64 encoded and added to an HTTP header
|
||||
which will be included in each request. Note that your username and
|
||||
password are sent in plaintext. The auth header is added to the
|
||||
additional_headers dictionary in the service object.
|
||||
|
||||
Args:
|
||||
service: atom.AtomService or a subclass which has an
|
||||
additional_headers dict as a member.
|
||||
username: str
|
||||
password: str
|
||||
"""
|
||||
deprecation('calling deprecated function UseBasicAuth')
|
||||
base_64_string = base64.encodestring('%s:%s' % (username, password))
|
||||
base_64_string = base_64_string.strip()
|
||||
if for_proxy:
|
||||
header_name = 'Proxy-Authorization'
|
||||
else:
|
||||
header_name = 'Authorization'
|
||||
service.additional_headers[header_name] = 'Basic %s' % (base_64_string,)
|
||||
|
||||
|
||||
def ProcessUrl(service, url, for_proxy=False):
|
||||
"""Processes a passed URL. If the URL does not begin with https?, then
|
||||
the default value for server is used
|
||||
|
||||
This method is deprecated, use atom.url.parse_url instead.
|
||||
"""
|
||||
if not isinstance(url, atom.url.Url):
|
||||
url = atom.url.parse_url(url)
|
||||
|
||||
server = url.host
|
||||
ssl = False
|
||||
port = 80
|
||||
|
||||
if not server:
|
||||
if hasattr(service, 'server'):
|
||||
server = service.server
|
||||
else:
|
||||
server = service
|
||||
if not url.protocol and hasattr(service, 'ssl'):
|
||||
ssl = service.ssl
|
||||
if hasattr(service, 'port'):
|
||||
port = service.port
|
||||
else:
|
||||
if url.protocol == 'https':
|
||||
ssl = True
|
||||
elif url.protocol == 'http':
|
||||
ssl = False
|
||||
if url.port:
|
||||
port = int(url.port)
|
||||
elif port == 80 and ssl:
|
||||
port = 443
|
||||
|
||||
return (server, port, ssl, url.get_request_uri())
|
||||
|
||||
def DictionaryToParamList(url_parameters, escape_params=True):
|
||||
"""Convert a dictionary of URL arguments into a URL parameter string.
|
||||
|
||||
This function is deprcated, use atom.url.Url instead.
|
||||
|
||||
Args:
|
||||
url_parameters: The dictionaty of key-value pairs which will be converted
|
||||
into URL parameters. For example,
|
||||
{'dry-run': 'true', 'foo': 'bar'}
|
||||
will become ['dry-run=true', 'foo=bar'].
|
||||
|
||||
Returns:
|
||||
A list which contains a string for each key-value pair. The strings are
|
||||
ready to be incorporated into a URL by using '&'.join([] + parameter_list)
|
||||
"""
|
||||
# Choose which function to use when modifying the query and parameters.
|
||||
# Use quote_plus when escape_params is true.
|
||||
transform_op = [str, urllib.quote_plus][bool(escape_params)]
|
||||
# Create a list of tuples containing the escaped version of the
|
||||
# parameter-value pairs.
|
||||
parameter_tuples = [(transform_op(param), transform_op(value))
|
||||
for param, value in (url_parameters or {}).items()]
|
||||
# Turn parameter-value tuples into a list of strings in the form
|
||||
# 'PARAMETER=VALUE'.
|
||||
return ['='.join(x) for x in parameter_tuples]
|
||||
|
||||
|
||||
def BuildUri(uri, url_params=None, escape_params=True):
|
||||
"""Converts a uri string and a collection of parameters into a URI.
|
||||
|
||||
This function is deprcated, use atom.url.Url instead.
|
||||
|
||||
Args:
|
||||
uri: string
|
||||
url_params: dict (optional)
|
||||
escape_params: boolean (optional)
|
||||
uri: string The start of the desired URI. This string can alrady contain
|
||||
URL parameters. Examples: '/base/feeds/snippets',
|
||||
'/base/feeds/snippets?bq=digital+camera'
|
||||
url_parameters: dict (optional) Additional URL parameters to be included
|
||||
in the query. These are translated into query arguments
|
||||
in the form '&dict_key=value&...'.
|
||||
Example: {'max-results': '250'} becomes &max-results=250
|
||||
escape_params: boolean (optional) If false, the calling code has already
|
||||
ensured that the query will form a valid URL (all
|
||||
reserved characters have been escaped). If true, this
|
||||
method will escape the query and any URL parameters
|
||||
provided.
|
||||
|
||||
Returns:
|
||||
string The URI consisting of the escaped URL parameters appended to the
|
||||
initial uri string.
|
||||
"""
|
||||
# Prepare URL parameters for inclusion into the GET request.
|
||||
parameter_list = DictionaryToParamList(url_params, escape_params)
|
||||
|
||||
# Append the URL parameters to the URL.
|
||||
if parameter_list:
|
||||
if uri.find('?') != -1:
|
||||
# If there are already URL parameters in the uri string, add the
|
||||
# parameters after a new & character.
|
||||
full_uri = '&'.join([uri] + parameter_list)
|
||||
else:
|
||||
# The uri string did not have any URL parameters (no ? character)
|
||||
# so put a ? between the uri and URL parameters.
|
||||
full_uri = '%s%s' % (uri, '?%s' % ('&'.join([] + parameter_list)))
|
||||
else:
|
||||
full_uri = uri
|
||||
|
||||
return full_uri
|
||||
|
||||
|
||||
def HttpRequest(service, operation, data, uri, extra_headers=None,
|
||||
url_params=None, escape_params=True, content_type='application/atom+xml; charset=UTF-8'):
|
||||
"""Performs an HTTP call to the server, supports GET, POST, PUT, and DELETE.
|
||||
|
||||
This method is deprecated, use atom.http.HttpClient.request instead.
|
||||
|
||||
Usage example, perform and HTTP GET on http://www.google.com/:
|
||||
import atom.service
|
||||
client = atom.service.AtomService()
|
||||
http_response = client.Get('http://www.google.com/')
|
||||
or you could set the client.server to 'www.google.com' and use the
|
||||
following:
|
||||
client.server = 'www.google.com'
|
||||
http_response = client.Get('/')
|
||||
|
||||
Args:
|
||||
service: atom.AtomService object which contains some of the parameters
|
||||
needed to make the request. The following members are used to
|
||||
construct the HTTP call: server (str), additional_headers (dict),
|
||||
port (int), and ssl (bool).
|
||||
operation: str The HTTP operation to be performed. This is usually one of
|
||||
'GET', 'POST', 'PUT', or 'DELETE'
|
||||
data: ElementTree, filestream, list of parts, or other object which can be
|
||||
converted to a string.
|
||||
Should be set to None when performing a GET or PUT.
|
||||
If data is a file-like object which can be read, this method will read
|
||||
a chunk of 100K bytes at a time and send them.
|
||||
If the data is a list of parts to be sent, each part will be evaluated
|
||||
and sent.
|
||||
uri: The beginning of the URL to which the request should be sent.
|
||||
Examples: '/', '/base/feeds/snippets',
|
||||
'/m8/feeds/contacts/default/base'
|
||||
extra_headers: dict of strings. HTTP headers which should be sent
|
||||
in the request. These headers are in addition to those stored in
|
||||
service.additional_headers.
|
||||
url_params: dict of strings. Key value pairs to be added to the URL as
|
||||
URL parameters. For example {'foo':'bar', 'test':'param'} will
|
||||
become ?foo=bar&test=param.
|
||||
escape_params: bool default True. If true, the keys and values in
|
||||
url_params will be URL escaped when the form is constructed
|
||||
(Special characters converted to %XX form.)
|
||||
content_type: str The MIME type for the data being sent. Defaults to
|
||||
'application/atom+xml', this is only used if data is set.
|
||||
"""
|
||||
deprecation('call to deprecated function HttpRequest')
|
||||
full_uri = BuildUri(uri, url_params, escape_params)
|
||||
(connection, full_uri) = PrepareConnection(service, full_uri)
|
||||
|
||||
if extra_headers is None:
|
||||
extra_headers = {}
|
||||
|
||||
# Turn on debug mode if the debug member is set.
|
||||
if service.debug:
|
||||
connection.debuglevel = 1
|
||||
|
||||
connection.putrequest(operation, full_uri)
|
||||
|
||||
# If the list of headers does not include a Content-Length, attempt to
|
||||
# calculate it based on the data object.
|
||||
if (data and not service.additional_headers.has_key('Content-Length') and
|
||||
not extra_headers.has_key('Content-Length')):
|
||||
content_length = CalculateDataLength(data)
|
||||
if content_length:
|
||||
extra_headers['Content-Length'] = str(content_length)
|
||||
|
||||
if content_type:
|
||||
extra_headers['Content-Type'] = content_type
|
||||
|
||||
# Send the HTTP headers.
|
||||
if isinstance(service.additional_headers, dict):
|
||||
for header in service.additional_headers:
|
||||
connection.putheader(header, service.additional_headers[header])
|
||||
if isinstance(extra_headers, dict):
|
||||
for header in extra_headers:
|
||||
connection.putheader(header, extra_headers[header])
|
||||
connection.endheaders()
|
||||
|
||||
# If there is data, send it in the request.
|
||||
if data:
|
||||
if isinstance(data, list):
|
||||
for data_part in data:
|
||||
__SendDataPart(data_part, connection)
|
||||
else:
|
||||
__SendDataPart(data, connection)
|
||||
|
||||
# Return the HTTP Response from the server.
|
||||
return connection.getresponse()
|
||||
|
||||
|
||||
def __SendDataPart(data, connection):
|
||||
"""This method is deprecated, use atom.http._send_data_part"""
|
||||
deprecated('call to deprecated function __SendDataPart')
|
||||
if isinstance(data, str):
|
||||
#TODO add handling for unicode.
|
||||
connection.send(data)
|
||||
return
|
||||
elif ElementTree.iselement(data):
|
||||
connection.send(ElementTree.tostring(data))
|
||||
return
|
||||
# Check to see if data is a file-like object that has a read method.
|
||||
elif hasattr(data, 'read'):
|
||||
# Read the file and send it a chunk at a time.
|
||||
while 1:
|
||||
binarydata = data.read(100000)
|
||||
if binarydata == '': break
|
||||
connection.send(binarydata)
|
||||
return
|
||||
else:
|
||||
# The data object was not a file.
|
||||
# Try to convert to a string and send the data.
|
||||
connection.send(str(data))
|
||||
return
|
||||
|
||||
|
||||
def CalculateDataLength(data):
|
||||
"""Attempts to determine the length of the data to send.
|
||||
|
||||
This method will respond with a length only if the data is a string or
|
||||
and ElementTree element.
|
||||
|
||||
Args:
|
||||
data: object If this is not a string or ElementTree element this funtion
|
||||
will return None.
|
||||
"""
|
||||
if isinstance(data, str):
|
||||
return len(data)
|
||||
elif isinstance(data, list):
|
||||
return None
|
||||
elif ElementTree.iselement(data):
|
||||
return len(ElementTree.tostring(data))
|
||||
elif hasattr(data, 'read'):
|
||||
# If this is a file-like object, don't try to guess the length.
|
||||
return None
|
||||
else:
|
||||
return len(str(data))
|
||||
|
||||
|
||||
def deprecation(message):
|
||||
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
||||
@@ -1,117 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""This module provides a TokenStore class which is designed to manage
|
||||
auth tokens required for different services.
|
||||
|
||||
Each token is valid for a set of scopes which is the start of a URL. An HTTP
|
||||
client will use a token store to find a valid Authorization header to send
|
||||
in requests to the specified URL. If the HTTP client determines that a token
|
||||
has expired or been revoked, it can remove the token from the store so that
|
||||
it will not be used in future requests.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import atom.http_interface
|
||||
import atom.url
|
||||
|
||||
|
||||
SCOPE_ALL = 'http'
|
||||
|
||||
|
||||
class TokenStore(object):
|
||||
"""Manages Authorization tokens which will be sent in HTTP headers."""
|
||||
def __init__(self, scoped_tokens=None):
|
||||
self._tokens = scoped_tokens or {}
|
||||
|
||||
def add_token(self, token):
|
||||
"""Adds a new token to the store (replaces tokens with the same scope).
|
||||
|
||||
Args:
|
||||
token: A subclass of http_interface.GenericToken. The token object is
|
||||
responsible for adding the Authorization header to the HTTP request.
|
||||
The scopes defined in the token are used to determine if the token
|
||||
is valid for a requested scope when find_token is called.
|
||||
|
||||
Returns:
|
||||
True if the token was added, False if the token was not added becase
|
||||
no scopes were provided.
|
||||
"""
|
||||
if not hasattr(token, 'scopes') or not token.scopes:
|
||||
return False
|
||||
|
||||
for scope in token.scopes:
|
||||
self._tokens[str(scope)] = token
|
||||
return True
|
||||
|
||||
def find_token(self, url):
|
||||
"""Selects an Authorization header token which can be used for the URL.
|
||||
|
||||
Args:
|
||||
url: str or atom.url.Url or a list containing the same.
|
||||
The URL which is going to be requested. All
|
||||
tokens are examined to see if any scopes begin match the beginning
|
||||
of the URL. The first match found is returned.
|
||||
|
||||
Returns:
|
||||
The token object which should execute the HTTP request. If there was
|
||||
no token for the url (the url did not begin with any of the token
|
||||
scopes available), then the atom.http_interface.GenericToken will be
|
||||
returned because the GenericToken calls through to the http client
|
||||
without adding an Authorization header.
|
||||
"""
|
||||
if url is None:
|
||||
return None
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
if url in self._tokens:
|
||||
token = self._tokens[url]
|
||||
if token.valid_for_scope(url):
|
||||
return token
|
||||
else:
|
||||
del self._tokens[url]
|
||||
for scope, token in self._tokens.iteritems():
|
||||
if token.valid_for_scope(url):
|
||||
return token
|
||||
return atom.http_interface.GenericToken()
|
||||
|
||||
def remove_token(self, token):
|
||||
"""Removes the token from the token_store.
|
||||
|
||||
This method is used when a token is determined to be invalid. If the
|
||||
token was found by find_token, but resulted in a 401 or 403 error stating
|
||||
that the token was invlid, then the token should be removed to prevent
|
||||
future use.
|
||||
|
||||
Returns:
|
||||
True if a token was found and then removed from the token
|
||||
store. False if the token was not in the TokenStore.
|
||||
"""
|
||||
token_found = False
|
||||
scopes_to_delete = []
|
||||
for scope, stored_token in self._tokens.iteritems():
|
||||
if stored_token == token:
|
||||
scopes_to_delete.append(scope)
|
||||
token_found = True
|
||||
for scope in scopes_to_delete:
|
||||
del self._tokens[scope]
|
||||
return token_found
|
||||
|
||||
def remove_all_tokens(self):
|
||||
self._tokens = {}
|
||||
139
atom/url.py
139
atom/url.py
@@ -1,139 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import urlparse
|
||||
import urllib
|
||||
|
||||
|
||||
DEFAULT_PROTOCOL = 'http'
|
||||
DEFAULT_PORT = 80
|
||||
|
||||
|
||||
def parse_url(url_string):
|
||||
"""Creates a Url object which corresponds to the URL string.
|
||||
|
||||
This method can accept partial URLs, but it will leave missing
|
||||
members of the Url unset.
|
||||
"""
|
||||
parts = urlparse.urlparse(url_string)
|
||||
url = Url()
|
||||
if parts[0]:
|
||||
url.protocol = parts[0]
|
||||
if parts[1]:
|
||||
host_parts = parts[1].split(':')
|
||||
if host_parts[0]:
|
||||
url.host = host_parts[0]
|
||||
if len(host_parts) > 1:
|
||||
url.port = host_parts[1]
|
||||
if parts[2]:
|
||||
url.path = parts[2]
|
||||
if parts[4]:
|
||||
param_pairs = parts[4].split('&')
|
||||
for pair in param_pairs:
|
||||
pair_parts = pair.split('=')
|
||||
if len(pair_parts) > 1:
|
||||
url.params[urllib.unquote_plus(pair_parts[0])] = (
|
||||
urllib.unquote_plus(pair_parts[1]))
|
||||
elif len(pair_parts) == 1:
|
||||
url.params[urllib.unquote_plus(pair_parts[0])] = None
|
||||
return url
|
||||
|
||||
class Url(object):
|
||||
"""Represents a URL and implements comparison logic.
|
||||
|
||||
URL strings which are not identical can still be equivalent, so this object
|
||||
provides a better interface for comparing and manipulating URLs than
|
||||
strings. URL parameters are represented as a dictionary of strings, and
|
||||
defaults are used for the protocol (http) and port (80) if not provided.
|
||||
"""
|
||||
def __init__(self, protocol=None, host=None, port=None, path=None,
|
||||
params=None):
|
||||
self.protocol = protocol
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.path = path
|
||||
self.params = params or {}
|
||||
|
||||
def to_string(self):
|
||||
url_parts = ['', '', '', '', '', '']
|
||||
if self.protocol:
|
||||
url_parts[0] = self.protocol
|
||||
if self.host:
|
||||
if self.port:
|
||||
url_parts[1] = ':'.join((self.host, str(self.port)))
|
||||
else:
|
||||
url_parts[1] = self.host
|
||||
if self.path:
|
||||
url_parts[2] = self.path
|
||||
if self.params:
|
||||
url_parts[4] = self.get_param_string()
|
||||
return urlparse.urlunparse(url_parts)
|
||||
|
||||
def get_param_string(self):
|
||||
param_pairs = []
|
||||
for key, value in self.params.iteritems():
|
||||
param_pairs.append('='.join((urllib.quote_plus(key),
|
||||
urllib.quote_plus(str(value)))))
|
||||
return '&'.join(param_pairs)
|
||||
|
||||
def get_request_uri(self):
|
||||
"""Returns the path with the parameters escaped and appended."""
|
||||
param_string = self.get_param_string()
|
||||
if param_string:
|
||||
return '?'.join([self.path, param_string])
|
||||
else:
|
||||
return self.path
|
||||
|
||||
def __cmp__(self, other):
|
||||
if not isinstance(other, Url):
|
||||
return cmp(self.to_string(), str(other))
|
||||
difference = 0
|
||||
# Compare the protocol
|
||||
if self.protocol and other.protocol:
|
||||
difference = cmp(self.protocol, other.protocol)
|
||||
elif self.protocol and not other.protocol:
|
||||
difference = cmp(self.protocol, DEFAULT_PROTOCOL)
|
||||
elif not self.protocol and other.protocol:
|
||||
difference = cmp(DEFAULT_PROTOCOL, other.protocol)
|
||||
if difference != 0:
|
||||
return difference
|
||||
# Compare the host
|
||||
difference = cmp(self.host, other.host)
|
||||
if difference != 0:
|
||||
return difference
|
||||
# Compare the port
|
||||
if self.port and other.port:
|
||||
difference = cmp(self.port, other.port)
|
||||
elif self.port and not other.port:
|
||||
difference = cmp(self.port, DEFAULT_PORT)
|
||||
elif not self.port and other.port:
|
||||
difference = cmp(DEFAULT_PORT, other.port)
|
||||
if difference != 0:
|
||||
return difference
|
||||
# Compare the path
|
||||
difference = cmp(self.path, other.path)
|
||||
if difference != 0:
|
||||
return difference
|
||||
# Compare the parameters
|
||||
return cmp(self.params, other.params)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_string()
|
||||
|
||||
23
build.bat
23
build.bat
@@ -1,23 +0,0 @@
|
||||
rmdir /q /s gam
|
||||
rmdir /q /s gam-64
|
||||
rmdir /q /s build
|
||||
rmdir /q /s dist
|
||||
del /q /f gam-%1-windows.zip
|
||||
del /q /f gam-%1-windows-x64.zip
|
||||
|
||||
c:\python27-32\scripts\pyinstaller -F --distpath=gam gam.py
|
||||
xcopy LICENSE gam\
|
||||
xcopy whatsnew.txt gam\
|
||||
xcopy cacert.pem gam\
|
||||
xcopy admin-settings-v1.json gam\
|
||||
xcopy cloudprint-v2.json gam\
|
||||
del gam\w9xpopen.exe
|
||||
"%ProgramFiles(x86)%\7-Zip\7z.exe" a -tzip gam-%1-windows.zip gam\ -xr!.svn
|
||||
|
||||
c:\python27\scripts\pyinstaller -F --distpath=gam-64 gam.py
|
||||
xcopy LICENSE gam-64\
|
||||
xcopy whatsnew.txt gam-64\
|
||||
xcopy cacert.pem gam-64\
|
||||
xcopy admin-settings-v1.json gam-64\
|
||||
xcopy cloudprint-v2.json gam-64\
|
||||
"%ProgramFiles(x86)%\7-Zip\7z.exe" a -tzip gam-%1-windows-x64.zip gam-64\ -xr!.svn
|
||||
3338
cacert.pem
3338
cacert.pem
File diff suppressed because it is too large
Load Diff
@@ -1,486 +0,0 @@
|
||||
{
|
||||
"kind": "discovery#restDescription",
|
||||
"discoveryVersion": "v1",
|
||||
"id": "cloudprint:v2",
|
||||
"name": "cloudprint",
|
||||
"version": "v2",
|
||||
"revision": "20150605",
|
||||
"title": "Cloud Print API",
|
||||
"description": "Lets you access Cloud Print Printers",
|
||||
"ownerDomain": "google.com",
|
||||
"ownerName": "Google",
|
||||
"icons": {
|
||||
"x16": "http://www.google.com/images/icons/product/search-16.gif",
|
||||
"x32": "http://www.google.com/images/icons/product/search-32.gif"
|
||||
},
|
||||
"documentationLink": "https://developers.google.com/cloud-print",
|
||||
"protocol": "rest",
|
||||
"baseUrl": "https://www.google.com/",
|
||||
"basePath": "/cloudprint/",
|
||||
"rootUrl": "https://www.google.com/",
|
||||
"servicePath": "/cloudprint/",
|
||||
"parameters": {
|
||||
"prettyPrint": {
|
||||
"type": "boolean",
|
||||
"description": "Returns response with indentations and line breaks.",
|
||||
"default": "true",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"oauth2": {
|
||||
"scopes": {
|
||||
"https://www.googleapis.com/auth/cloudprint": {
|
||||
"description": "Manage Cloud Print"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"Job": {
|
||||
"id": "Job",
|
||||
"type": "object",
|
||||
"description": "Job Object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "Job Title"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "Unique ID"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Jobs": {
|
||||
"id": "Jobs",
|
||||
"type": "object",
|
||||
"description": "List of Jobs.",
|
||||
"properties": {
|
||||
"jobs": {
|
||||
"type": "array",
|
||||
"description": "List of job objects.",
|
||||
"items": {
|
||||
"$ref": "Job"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Printer": {
|
||||
"id": "Printer",
|
||||
"type": "object",
|
||||
"description": "Printer Object",
|
||||
"properties": {
|
||||
"displayName": {
|
||||
"type": "string",
|
||||
"description": "Display Name"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "Unique ID"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Printers": {
|
||||
"id": "Printers",
|
||||
"type": "object",
|
||||
"description": "List of Printers.",
|
||||
"properties": {
|
||||
"printers": {
|
||||
"type": "array",
|
||||
"description": "List of printer objects.",
|
||||
"items": {
|
||||
"$ref": "Printer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"jobs": {
|
||||
"methods": {
|
||||
"delete": {
|
||||
"id": "cloudprint.jobs.delete",
|
||||
"path": "deletejob",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"jobid": {
|
||||
"type": "string",
|
||||
"location": "query",
|
||||
"required": "true"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fetch": {
|
||||
"id": "cloudprint.jobs.fetch",
|
||||
"path": "fetch",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Jobs"
|
||||
}
|
||||
},
|
||||
"getticket": {
|
||||
"id": "cloudprint.jobs.getticket",
|
||||
"path": "ticket",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"jobid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"use_cjt": {
|
||||
"type": "boolean",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
}
|
||||
}
|
||||
},
|
||||
"list": {
|
||||
"id": "cloudprint.jobs.list",
|
||||
"path": "jobs",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"owner": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"q": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"offset": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"limit": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"sortorder": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Jobs"
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"id": "cloudprint.jobs.update",
|
||||
"path": "control",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"jobid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"semantic_state_diff": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Jobs"
|
||||
}
|
||||
},
|
||||
"resubmit": {
|
||||
"id": "cloudprint.jobs.resubmit",
|
||||
"path": "resubmit",
|
||||
"httpMethod": "POST",
|
||||
"description": "resubmit a job to new printer.",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"jobid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"ticket": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Job"
|
||||
}
|
||||
},
|
||||
"submit": {
|
||||
"id": "cloudprint.jobs.submit",
|
||||
"path": "submit",
|
||||
"httpMethod": "POST",
|
||||
"description": "Send a print job to cloud print.",
|
||||
"request": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"ticket": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"contentType": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Job"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"printers": {
|
||||
"methods": {
|
||||
"get": {
|
||||
"id": "cloudprint.printers.get",
|
||||
"path": "printer",
|
||||
"httpMethod": "GET",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"extra_fields": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Printer"
|
||||
}
|
||||
},
|
||||
"list": {
|
||||
"id": "cloudprint.printers.list",
|
||||
"path": "search",
|
||||
"httpMethod": "GET",
|
||||
"description": "List all printers",
|
||||
"parameters": {
|
||||
"q": {
|
||||
"type": "string",
|
||||
"description": "Query list of printers",
|
||||
"location": "query"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "limit results to printers of type",
|
||||
"location": "query"
|
||||
},
|
||||
"connection_status": {
|
||||
"type": "string",
|
||||
"description": "limit results to printers with this status",
|
||||
"location": "query"
|
||||
},
|
||||
"extra_fields": {
|
||||
"type": "string",
|
||||
"description": "include extra fields",
|
||||
"location": "query"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"$ref": "Printers"
|
||||
}
|
||||
},
|
||||
"share": {
|
||||
"id": "cloudprint.printers.share",
|
||||
"path": "share",
|
||||
"httpMethod": "GET",
|
||||
"description": "Share printer with user, group or domain",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"scope": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"role": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"skip_notification": {
|
||||
"type": "boolean",
|
||||
"location": "query"
|
||||
},
|
||||
"public": {
|
||||
"type": "boolean",
|
||||
"location": "query"
|
||||
}
|
||||
}
|
||||
},
|
||||
"unshare": {
|
||||
"id": "cloudprint.printers.unshare",
|
||||
"path": "unshare",
|
||||
"httpMethod": "GET",
|
||||
"description": "unshare printer with user, group or domain",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"scope": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"public": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"id": "cloudprint.printers.delete",
|
||||
"path": "delete",
|
||||
"httpMethod": "GET",
|
||||
"description": "delete a printer",
|
||||
"parameters": {
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
}
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"id": "cloudprint.printers.update",
|
||||
"path": "update",
|
||||
"httpMethod": "GET",
|
||||
"description": "update a printer",
|
||||
"parameters": {
|
||||
"isTosAccepted": {
|
||||
"type": "boolean",
|
||||
"location": "query"
|
||||
},
|
||||
"gcpVersion": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"setupUrl": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"supportUrl": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"firmware": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"currentQuota": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"public": {
|
||||
"type": "boolean",
|
||||
"location": "query"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"manufacturer": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"defaultDisplayName": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"displayName": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"updateUrl": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"ownerId": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"model": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
},
|
||||
"printerid": {
|
||||
"type": "string",
|
||||
"required": "true",
|
||||
"location": "query"
|
||||
},
|
||||
"quotaEnabled": {
|
||||
"type": "boolean",
|
||||
"location": "query"
|
||||
},
|
||||
"dailyQuota": {
|
||||
"type": "string",
|
||||
"location": "query"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,835 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2006 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""Contains classes representing Google Data elements.
|
||||
|
||||
Extends Atom classes to add Google Data specific elements.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'j.s@google.com (Jeffrey Scudder)'
|
||||
|
||||
import os
|
||||
import atom
|
||||
try:
|
||||
from xml.etree import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
from xml.etree import ElementTree
|
||||
except ImportError:
|
||||
from elementtree import ElementTree
|
||||
|
||||
|
||||
# XML namespaces which are often used in GData entities.
|
||||
GDATA_NAMESPACE = 'http://schemas.google.com/g/2005'
|
||||
GDATA_TEMPLATE = '{http://schemas.google.com/g/2005}%s'
|
||||
OPENSEARCH_NAMESPACE = 'http://a9.com/-/spec/opensearchrss/1.0/'
|
||||
OPENSEARCH_TEMPLATE = '{http://a9.com/-/spec/opensearchrss/1.0/}%s'
|
||||
BATCH_NAMESPACE = 'http://schemas.google.com/gdata/batch'
|
||||
GACL_NAMESPACE = 'http://schemas.google.com/acl/2007'
|
||||
GACL_TEMPLATE = '{http://schemas.google.com/acl/2007}%s'
|
||||
|
||||
|
||||
# Labels used in batch request entries to specify the desired CRUD operation.
|
||||
BATCH_INSERT = 'insert'
|
||||
BATCH_UPDATE = 'update'
|
||||
BATCH_DELETE = 'delete'
|
||||
BATCH_QUERY = 'query'
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MissingRequiredParameters(Error):
|
||||
pass
|
||||
|
||||
|
||||
class MediaSource(object):
|
||||
"""GData Entries can refer to media sources, so this class provides a
|
||||
place to store references to these objects along with some metadata.
|
||||
"""
|
||||
|
||||
def __init__(self, file_handle=None, content_type=None, content_length=None,
|
||||
file_path=None, file_name=None):
|
||||
"""Creates an object of type MediaSource.
|
||||
|
||||
Args:
|
||||
file_handle: A file handle pointing to the file to be encapsulated in the
|
||||
MediaSource
|
||||
content_type: string The MIME type of the file. Required if a file_handle
|
||||
is given.
|
||||
content_length: int The size of the file. Required if a file_handle is
|
||||
given.
|
||||
file_path: string (optional) A full path name to the file. Used in
|
||||
place of a file_handle.
|
||||
file_name: string The name of the file without any path information.
|
||||
Required if a file_handle is given.
|
||||
"""
|
||||
self.file_handle = file_handle
|
||||
self.content_type = content_type
|
||||
self.content_length = content_length
|
||||
self.file_name = file_name
|
||||
|
||||
if (file_handle is None and content_type is not None and
|
||||
file_path is not None):
|
||||
self.setFile(file_path, content_type)
|
||||
|
||||
def setFile(self, file_name, content_type):
|
||||
"""A helper function which can create a file handle from a given filename
|
||||
and set the content type and length all at once.
|
||||
|
||||
Args:
|
||||
file_name: string The path and file name to the file containing the media
|
||||
content_type: string A MIME type representing the type of the media
|
||||
"""
|
||||
|
||||
self.file_handle = open(file_name, 'rb')
|
||||
self.content_type = content_type
|
||||
self.content_length = os.path.getsize(file_name)
|
||||
self.file_name = os.path.basename(file_name)
|
||||
|
||||
|
||||
class LinkFinder(atom.LinkFinder):
|
||||
"""An "interface" providing methods to find link elements
|
||||
|
||||
GData Entry elements often contain multiple links which differ in the rel
|
||||
attribute or content type. Often, developers are interested in a specific
|
||||
type of link so this class provides methods to find specific classes of
|
||||
links.
|
||||
|
||||
This class is used as a mixin in GData entries.
|
||||
"""
|
||||
|
||||
def GetSelfLink(self):
|
||||
"""Find the first link with rel set to 'self'
|
||||
|
||||
Returns:
|
||||
An atom.Link or none if none of the links had rel equal to 'self'
|
||||
"""
|
||||
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'self':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetEditLink(self):
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'edit':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetEditMediaLink(self):
|
||||
"""The Picasa API mistakenly returns media-edit rather than edit-media, but
|
||||
this may change soon.
|
||||
"""
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'edit-media':
|
||||
return a_link
|
||||
if a_link.rel == 'media-edit':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetHtmlLink(self):
|
||||
"""Find the first link with rel of alternate and type of text/html
|
||||
|
||||
Returns:
|
||||
An atom.Link or None if no links matched
|
||||
"""
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'alternate' and a_link.type == 'text/html':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetPostLink(self):
|
||||
"""Get a link containing the POST target URL.
|
||||
|
||||
The POST target URL is used to insert new entries.
|
||||
|
||||
Returns:
|
||||
A link object with a rel matching the POST type.
|
||||
"""
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'http://schemas.google.com/g/2005#post':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetAclLink(self):
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'http://schemas.google.com/acl/2007#accessControlList':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetFeedLink(self):
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'http://schemas.google.com/g/2005#feed':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetNextLink(self):
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'next':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
def GetPrevLink(self):
|
||||
for a_link in self.link:
|
||||
if a_link.rel == 'previous':
|
||||
return a_link
|
||||
return None
|
||||
|
||||
|
||||
class TotalResults(atom.AtomBase):
|
||||
"""opensearch:TotalResults for a GData feed"""
|
||||
|
||||
_tag = 'totalResults'
|
||||
_namespace = OPENSEARCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
|
||||
def __init__(self, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def TotalResultsFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(TotalResults, xml_string)
|
||||
|
||||
|
||||
class StartIndex(atom.AtomBase):
|
||||
"""The opensearch:startIndex element in GData feed"""
|
||||
|
||||
_tag = 'startIndex'
|
||||
_namespace = OPENSEARCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
|
||||
def __init__(self, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def StartIndexFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(StartIndex, xml_string)
|
||||
|
||||
|
||||
class ItemsPerPage(atom.AtomBase):
|
||||
"""The opensearch:itemsPerPage element in GData feed"""
|
||||
|
||||
_tag = 'itemsPerPage'
|
||||
_namespace = OPENSEARCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
|
||||
def __init__(self, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def ItemsPerPageFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(ItemsPerPage, xml_string)
|
||||
|
||||
|
||||
class ExtendedProperty(atom.AtomBase):
|
||||
"""The Google Data extendedProperty element.
|
||||
|
||||
Used to store arbitrary key-value information specific to your
|
||||
application. The value can either be a text string stored as an XML
|
||||
attribute (.value), or an XML node (XmlBlob) as a child element.
|
||||
|
||||
This element is used in the Google Calendar data API and the Google
|
||||
Contacts data API.
|
||||
"""
|
||||
|
||||
_tag = 'extendedProperty'
|
||||
_namespace = GDATA_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['name'] = 'name'
|
||||
_attributes['value'] = 'value'
|
||||
|
||||
def __init__(self, name=None, value=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
def GetXmlBlobExtensionElement(self):
|
||||
"""Returns the XML blob as an atom.ExtensionElement.
|
||||
|
||||
Returns:
|
||||
An atom.ExtensionElement representing the blob's XML, or None if no
|
||||
blob was set.
|
||||
"""
|
||||
if len(self.extension_elements) < 1:
|
||||
return None
|
||||
else:
|
||||
return self.extension_elements[0]
|
||||
|
||||
def GetXmlBlobString(self):
|
||||
"""Returns the XML blob as a string.
|
||||
|
||||
Returns:
|
||||
A string containing the blob's XML, or None if no blob was set.
|
||||
"""
|
||||
blob = self.GetXmlBlobExtensionElement()
|
||||
if blob:
|
||||
return blob.ToString()
|
||||
return None
|
||||
|
||||
def SetXmlBlob(self, blob):
|
||||
"""Sets the contents of the extendedProperty to XML as a child node.
|
||||
|
||||
Since the extendedProperty is only allowed one child element as an XML
|
||||
blob, setting the XML blob will erase any preexisting extension elements
|
||||
in this object.
|
||||
|
||||
Args:
|
||||
blob: str, ElementTree Element or atom.ExtensionElement representing
|
||||
the XML blob stored in the extendedProperty.
|
||||
"""
|
||||
# Erase any existing extension_elements, clears the child nodes from the
|
||||
# extendedProperty.
|
||||
self.extension_elements = []
|
||||
if isinstance(blob, atom.ExtensionElement):
|
||||
self.extension_elements.append(blob)
|
||||
elif ElementTree.iselement(blob):
|
||||
self.extension_elements.append(atom._ExtensionElementFromElementTree(
|
||||
blob))
|
||||
else:
|
||||
self.extension_elements.append(atom.ExtensionElementFromString(blob))
|
||||
|
||||
|
||||
def ExtendedPropertyFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(ExtendedProperty, xml_string)
|
||||
|
||||
|
||||
class GDataEntry(atom.Entry, LinkFinder):
|
||||
"""Extends Atom Entry to provide data processing"""
|
||||
|
||||
_tag = atom.Entry._tag
|
||||
_namespace = atom.Entry._namespace
|
||||
_children = atom.Entry._children.copy()
|
||||
_attributes = atom.Entry._attributes.copy()
|
||||
|
||||
def __GetId(self):
|
||||
return self.__id
|
||||
|
||||
# This method was created to strip the unwanted whitespace from the id's
|
||||
# text node.
|
||||
def __SetId(self, id):
|
||||
self.__id = id
|
||||
if id is not None and id.text is not None:
|
||||
self.__id.text = id.text.strip()
|
||||
|
||||
id = property(__GetId, __SetId)
|
||||
|
||||
def IsMedia(self):
|
||||
"""Determines whether or not an entry is a GData Media entry.
|
||||
"""
|
||||
if (self.GetEditMediaLink()):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def GetMediaURL(self):
|
||||
"""Returns the URL to the media content, if the entry is a media entry.
|
||||
Otherwise returns None.
|
||||
"""
|
||||
if not self.IsMedia():
|
||||
return None
|
||||
else:
|
||||
return self.content.src
|
||||
|
||||
|
||||
def GDataEntryFromString(xml_string):
|
||||
"""Creates a new GDataEntry instance given a string of XML."""
|
||||
return atom.CreateClassFromXMLString(GDataEntry, xml_string)
|
||||
|
||||
|
||||
class GDataFeed(atom.Feed, LinkFinder):
|
||||
"""A Feed from a GData service"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = atom.Feed._children.copy()
|
||||
_attributes = atom.Feed._attributes.copy()
|
||||
_children['{%s}totalResults' % OPENSEARCH_NAMESPACE] = ('total_results',
|
||||
TotalResults)
|
||||
_children['{%s}startIndex' % OPENSEARCH_NAMESPACE] = ('start_index',
|
||||
StartIndex)
|
||||
_children['{%s}itemsPerPage' % OPENSEARCH_NAMESPACE] = ('items_per_page',
|
||||
ItemsPerPage)
|
||||
# Add a conversion rule for atom:entry to make it into a GData
|
||||
# Entry.
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [GDataEntry])
|
||||
|
||||
def __GetId(self):
|
||||
return self.__id
|
||||
|
||||
def __SetId(self, id):
|
||||
self.__id = id
|
||||
if id is not None and id.text is not None:
|
||||
self.__id.text = id.text.strip()
|
||||
|
||||
id = property(__GetId, __SetId)
|
||||
|
||||
def __GetGenerator(self):
|
||||
return self.__generator
|
||||
|
||||
def __SetGenerator(self, generator):
|
||||
self.__generator = generator
|
||||
if generator is not None:
|
||||
self.__generator.text = generator.text.strip()
|
||||
|
||||
generator = property(__GetGenerator, __SetGenerator)
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None, entry=None,
|
||||
total_results=None, start_index=None, items_per_page=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
"""Constructor for Source
|
||||
|
||||
Args:
|
||||
author: list (optional) A list of Author instances which belong to this
|
||||
class.
|
||||
category: list (optional) A list of Category instances
|
||||
contributor: list (optional) A list on Contributor instances
|
||||
generator: Generator (optional)
|
||||
icon: Icon (optional)
|
||||
id: Id (optional) The entry's Id element
|
||||
link: list (optional) A list of Link instances
|
||||
logo: Logo (optional)
|
||||
rights: Rights (optional) The entry's Rights element
|
||||
subtitle: Subtitle (optional) The entry's subtitle element
|
||||
title: Title (optional) the entry's title element
|
||||
updated: Updated (optional) the entry's updated element
|
||||
entry: list (optional) A list of the Entry instances contained in the
|
||||
feed.
|
||||
text: String (optional) The text contents of the element. This is the
|
||||
contents of the Entry's XML text node.
|
||||
(Example: <foo>This is the text</foo>)
|
||||
extension_elements: list (optional) A list of ExtensionElement instances
|
||||
which are children of this element.
|
||||
extension_attributes: dict (optional) A dictionary of strings which are
|
||||
the values for additional XML attributes of this element.
|
||||
"""
|
||||
|
||||
self.author = author or []
|
||||
self.category = category or []
|
||||
self.contributor = contributor or []
|
||||
self.generator = generator
|
||||
self.icon = icon
|
||||
self.id = atom_id
|
||||
self.link = link or []
|
||||
self.logo = logo
|
||||
self.rights = rights
|
||||
self.subtitle = subtitle
|
||||
self.title = title
|
||||
self.updated = updated
|
||||
self.entry = entry or []
|
||||
self.total_results = total_results
|
||||
self.start_index = start_index
|
||||
self.items_per_page = items_per_page
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def GDataFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(GDataFeed, xml_string)
|
||||
|
||||
|
||||
class BatchId(atom.AtomBase):
|
||||
_tag = 'id'
|
||||
_namespace = BATCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
|
||||
|
||||
def BatchIdFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchId, xml_string)
|
||||
|
||||
|
||||
class BatchOperation(atom.AtomBase):
|
||||
_tag = 'operation'
|
||||
_namespace = BATCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['type'] = 'type'
|
||||
|
||||
def __init__(self, op_type=None, extension_elements=None,
|
||||
extension_attributes=None,
|
||||
text=None):
|
||||
self.type = op_type
|
||||
atom.AtomBase.__init__(self,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def BatchOperationFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchOperation, xml_string)
|
||||
|
||||
|
||||
class BatchStatus(atom.AtomBase):
|
||||
"""The batch:status element present in a batch response entry.
|
||||
|
||||
A status element contains the code (HTTP response code) and
|
||||
reason as elements. In a single request these fields would
|
||||
be part of the HTTP response, but in a batch request each
|
||||
Entry operation has a corresponding Entry in the response
|
||||
feed which includes status information.
|
||||
|
||||
See http://code.google.com/apis/gdata/batch.html#Handling_Errors
|
||||
"""
|
||||
|
||||
_tag = 'status'
|
||||
_namespace = BATCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['code'] = 'code'
|
||||
_attributes['reason'] = 'reason'
|
||||
_attributes['content-type'] = 'content_type'
|
||||
|
||||
def __init__(self, code=None, reason=None, content_type=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.code = code
|
||||
self.reason = reason
|
||||
self.content_type = content_type
|
||||
atom.AtomBase.__init__(self, extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def BatchStatusFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchStatus, xml_string)
|
||||
|
||||
|
||||
class BatchEntry(GDataEntry):
|
||||
"""An atom:entry for use in batch requests.
|
||||
|
||||
The BatchEntry contains additional members to specify the operation to be
|
||||
performed on this entry and a batch ID so that the server can reference
|
||||
individual operations in the response feed. For more information, see:
|
||||
http://code.google.com/apis/gdata/batch.html
|
||||
"""
|
||||
|
||||
_tag = GDataEntry._tag
|
||||
_namespace = GDataEntry._namespace
|
||||
_children = GDataEntry._children.copy()
|
||||
_children['{%s}operation' % BATCH_NAMESPACE] = ('batch_operation', BatchOperation)
|
||||
_children['{%s}id' % BATCH_NAMESPACE] = ('batch_id', BatchId)
|
||||
_children['{%s}status' % BATCH_NAMESPACE] = ('batch_status', BatchStatus)
|
||||
_attributes = GDataEntry._attributes.copy()
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
contributor=None, atom_id=None, link=None, published=None, rights=None,
|
||||
source=None, summary=None, control=None, title=None, updated=None,
|
||||
batch_operation=None, batch_id=None, batch_status=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.batch_operation = batch_operation
|
||||
self.batch_id = batch_id
|
||||
self.batch_status = batch_status
|
||||
GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content, contributor=contributor, atom_id=atom_id, link=link,
|
||||
published=published, rights=rights, source=source, summary=summary,
|
||||
control=control, title=title, updated=updated,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes, text=text)
|
||||
|
||||
|
||||
def BatchEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchEntry, xml_string)
|
||||
|
||||
|
||||
class BatchInterrupted(atom.AtomBase):
|
||||
"""The batch:interrupted element sent if batch request was interrupted.
|
||||
|
||||
Only appears in a feed if some of the batch entries could not be processed.
|
||||
See: http://code.google.com/apis/gdata/batch.html#Handling_Errors
|
||||
"""
|
||||
|
||||
_tag = 'interrupted'
|
||||
_namespace = BATCH_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['reason'] = 'reason'
|
||||
_attributes['success'] = 'success'
|
||||
_attributes['failures'] = 'failures'
|
||||
_attributes['parsed'] = 'parsed'
|
||||
|
||||
def __init__(self, reason=None, success=None, failures=None, parsed=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.reason = reason
|
||||
self.success = success
|
||||
self.failures = failures
|
||||
self.parsed = parsed
|
||||
atom.AtomBase.__init__(self, extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def BatchInterruptedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchInterrupted, xml_string)
|
||||
|
||||
|
||||
class BatchFeed(GDataFeed):
|
||||
"""A feed containing a list of batch request entries."""
|
||||
|
||||
_tag = GDataFeed._tag
|
||||
_namespace = GDataFeed._namespace
|
||||
_children = GDataFeed._children.copy()
|
||||
_attributes = GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [BatchEntry])
|
||||
_children['{%s}interrupted' % BATCH_NAMESPACE] = ('interrupted', BatchInterrupted)
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None, entry=None,
|
||||
total_results=None, start_index=None, items_per_page=None,
|
||||
interrupted=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.interrupted = interrupted
|
||||
GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results, start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
def AddBatchEntry(self, entry=None, id_url_string=None,
|
||||
batch_id_string=None, operation_string=None):
|
||||
"""Logic for populating members of a BatchEntry and adding to the feed.
|
||||
|
||||
|
||||
If the entry is not a BatchEntry, it is converted to a BatchEntry so
|
||||
that the batch specific members will be present.
|
||||
|
||||
The id_url_string can be used in place of an entry if the batch operation
|
||||
applies to a URL. For example query and delete operations require just
|
||||
the URL of an entry, no body is sent in the HTTP request. If an
|
||||
id_url_string is sent instead of an entry, a BatchEntry is created and
|
||||
added to the feed.
|
||||
|
||||
This method also assigns the desired batch id to the entry so that it
|
||||
can be referenced in the server's response. If the batch_id_string is
|
||||
None, this method will assign a batch_id to be the index at which this
|
||||
entry will be in the feed's entry list.
|
||||
|
||||
Args:
|
||||
entry: BatchEntry, atom.Entry, or another Entry flavor (optional) The
|
||||
entry which will be sent to the server as part of the batch request.
|
||||
The item must have a valid atom id so that the server knows which
|
||||
entry this request references.
|
||||
id_url_string: str (optional) The URL of the entry to be acted on. You
|
||||
can find this URL in the text member of the atom id for an entry.
|
||||
If an entry is not sent, this id will be used to construct a new
|
||||
BatchEntry which will be added to the request feed.
|
||||
batch_id_string: str (optional) The batch ID to be used to reference
|
||||
this batch operation in the results feed. If this parameter is None,
|
||||
the current length of the feed's entry array will be used as a
|
||||
count. Note that batch_ids should either always be specified or
|
||||
never, mixing could potentially result in duplicate batch ids.
|
||||
operation_string: str (optional) The desired batch operation which will
|
||||
set the batch_operation.type member of the entry. Options are
|
||||
'insert', 'update', 'delete', and 'query'
|
||||
|
||||
Raises:
|
||||
MissingRequiredParameters: Raised if neither an id_ url_string nor an
|
||||
entry are provided in the request.
|
||||
|
||||
Returns:
|
||||
The added entry.
|
||||
"""
|
||||
if entry is None and id_url_string is None:
|
||||
raise MissingRequiredParameters('supply either an entry or URL string')
|
||||
if entry is None and id_url_string is not None:
|
||||
entry = BatchEntry(atom_id=atom.Id(text=id_url_string))
|
||||
# TODO: handle cases in which the entry lacks batch_... members.
|
||||
#if not isinstance(entry, BatchEntry):
|
||||
# Convert the entry to a batch entry.
|
||||
if batch_id_string is not None:
|
||||
entry.batch_id = BatchId(text=batch_id_string)
|
||||
elif entry.batch_id is None or entry.batch_id.text is None:
|
||||
entry.batch_id = BatchId(text=str(len(self.entry)))
|
||||
if operation_string is not None:
|
||||
entry.batch_operation = BatchOperation(op_type=operation_string)
|
||||
self.entry.append(entry)
|
||||
return entry
|
||||
|
||||
def AddInsert(self, entry, batch_id_string=None):
|
||||
"""Add an insert request to the operations in this batch request feed.
|
||||
|
||||
If the entry doesn't yet have an operation or a batch id, these will
|
||||
be set to the insert operation and a batch_id specified as a parameter.
|
||||
|
||||
Args:
|
||||
entry: BatchEntry The entry which will be sent in the batch feed as an
|
||||
insert request.
|
||||
batch_id_string: str (optional) The batch ID to be used to reference
|
||||
this batch operation in the results feed. If this parameter is None,
|
||||
the current length of the feed's entry array will be used as a
|
||||
count. Note that batch_ids should either always be specified or
|
||||
never, mixing could potentially result in duplicate batch ids.
|
||||
"""
|
||||
entry = self.AddBatchEntry(entry=entry, batch_id_string=batch_id_string,
|
||||
operation_string=BATCH_INSERT)
|
||||
|
||||
def AddUpdate(self, entry, batch_id_string=None):
|
||||
"""Add an update request to the list of batch operations in this feed.
|
||||
|
||||
Sets the operation type of the entry to insert if it is not already set
|
||||
and assigns the desired batch id to the entry so that it can be
|
||||
referenced in the server's response.
|
||||
|
||||
Args:
|
||||
entry: BatchEntry The entry which will be sent to the server as an
|
||||
update (HTTP PUT) request. The item must have a valid atom id
|
||||
so that the server knows which entry to replace.
|
||||
batch_id_string: str (optional) The batch ID to be used to reference
|
||||
this batch operation in the results feed. If this parameter is None,
|
||||
the current length of the feed's entry array will be used as a
|
||||
count. See also comments for AddInsert.
|
||||
"""
|
||||
entry = self.AddBatchEntry(entry=entry, batch_id_string=batch_id_string,
|
||||
operation_string=BATCH_UPDATE)
|
||||
|
||||
def AddDelete(self, url_string=None, entry=None, batch_id_string=None):
|
||||
"""Adds a delete request to the batch request feed.
|
||||
|
||||
This method takes either the url_string which is the atom id of the item
|
||||
to be deleted, or the entry itself. The atom id of the entry must be
|
||||
present so that the server knows which entry should be deleted.
|
||||
|
||||
Args:
|
||||
url_string: str (optional) The URL of the entry to be deleted. You can
|
||||
find this URL in the text member of the atom id for an entry.
|
||||
entry: BatchEntry (optional) The entry to be deleted.
|
||||
batch_id_string: str (optional)
|
||||
|
||||
Raises:
|
||||
MissingRequiredParameters: Raised if neither a url_string nor an entry
|
||||
are provided in the request.
|
||||
"""
|
||||
entry = self.AddBatchEntry(entry=entry, id_url_string=url_string,
|
||||
batch_id_string=batch_id_string,
|
||||
operation_string=BATCH_DELETE)
|
||||
|
||||
def AddQuery(self, url_string=None, entry=None, batch_id_string=None):
|
||||
"""Adds a query request to the batch request feed.
|
||||
|
||||
This method takes either the url_string which is the query URL
|
||||
whose results will be added to the result feed. The query URL will
|
||||
be encapsulated in a BatchEntry, and you may pass in the BatchEntry
|
||||
with a query URL instead of sending a url_string.
|
||||
|
||||
Args:
|
||||
url_string: str (optional)
|
||||
entry: BatchEntry (optional)
|
||||
batch_id_string: str (optional)
|
||||
|
||||
Raises:
|
||||
MissingRequiredParameters
|
||||
"""
|
||||
entry = self.AddBatchEntry(entry=entry, id_url_string=url_string,
|
||||
batch_id_string=batch_id_string,
|
||||
operation_string=BATCH_QUERY)
|
||||
|
||||
def GetBatchLink(self):
|
||||
for link in self.link:
|
||||
if link.rel == 'http://schemas.google.com/g/2005#batch':
|
||||
return link
|
||||
return None
|
||||
|
||||
|
||||
def BatchFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(BatchFeed, xml_string)
|
||||
|
||||
|
||||
class EntryLink(atom.AtomBase):
|
||||
"""The gd:entryLink element"""
|
||||
|
||||
_tag = 'entryLink'
|
||||
_namespace = GDATA_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
# The entry used to be an atom.Entry, now it is a GDataEntry.
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', GDataEntry)
|
||||
_attributes['rel'] = 'rel'
|
||||
_attributes['readOnly'] = 'read_only'
|
||||
_attributes['href'] = 'href'
|
||||
|
||||
def __init__(self, href=None, read_only=None, rel=None,
|
||||
entry=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.href = href
|
||||
self.read_only = read_only
|
||||
self.rel = rel
|
||||
self.entry = entry
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def EntryLinkFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EntryLink, xml_string)
|
||||
|
||||
|
||||
class FeedLink(atom.AtomBase):
|
||||
"""The gd:feedLink element"""
|
||||
|
||||
_tag = 'feedLink'
|
||||
_namespace = GDATA_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_children['{%s}feed' % atom.ATOM_NAMESPACE] = ('feed', GDataFeed)
|
||||
_attributes['rel'] = 'rel'
|
||||
_attributes['readOnly'] = 'read_only'
|
||||
_attributes['countHint'] = 'count_hint'
|
||||
_attributes['href'] = 'href'
|
||||
|
||||
def __init__(self, count_hint=None, href=None, read_only=None, rel=None,
|
||||
feed=None, extension_elements=None, extension_attributes=None,
|
||||
text=None):
|
||||
self.count_hint = count_hint
|
||||
self.href = href
|
||||
self.read_only = read_only
|
||||
self.rel = rel
|
||||
self.feed = feed
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def FeedLinkFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(FeedLink, xml_string)
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""This package's modules adapt the gdata library to run in other environments
|
||||
|
||||
The first example is the appengine module which contains functions and
|
||||
classes which modify a GDataService object to run on Google App Engine.
|
||||
"""
|
||||
@@ -1,101 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""Provides functions to persist serialized auth tokens in the datastore.
|
||||
|
||||
The get_token and set_token functions should be used in conjunction with
|
||||
gdata.gauth's token_from_blob and token_to_blob to allow auth token objects
|
||||
to be reused across requests. It is up to your own code to ensure that the
|
||||
token key's are unique.
|
||||
"""
|
||||
|
||||
__author__ = 'j.s@google.com (Jeff Scudder)'
|
||||
|
||||
|
||||
from google.appengine.ext import db
|
||||
from google.appengine.api import memcache
|
||||
|
||||
|
||||
class Token(db.Model):
|
||||
"""Datastore Model which stores a serialized auth token."""
|
||||
t = db.BlobProperty()
|
||||
|
||||
|
||||
def get_token(unique_key):
|
||||
"""Searches for a stored token with the desired key.
|
||||
|
||||
Checks memcache and then the datastore if required.
|
||||
|
||||
Args:
|
||||
unique_key: str which uniquely identifies the desired auth token.
|
||||
|
||||
Returns:
|
||||
A string encoding the auth token data. Use gdata.gauth.token_from_blob to
|
||||
convert back into a usable token object. None if the token was not found
|
||||
in memcache or the datastore.
|
||||
"""
|
||||
token_string = memcache.get(unique_key)
|
||||
if token_string is None:
|
||||
# The token wasn't in memcache, so look in the datastore.
|
||||
token = Token.get_by_key_name(unique_key)
|
||||
if token is None:
|
||||
return None
|
||||
return token.t
|
||||
return token_string
|
||||
|
||||
|
||||
def set_token(unique_key, token_str):
|
||||
"""Saves the serialized auth token in the datastore.
|
||||
|
||||
The token is also stored in memcache to speed up retrieval on a cache hit.
|
||||
|
||||
Args:
|
||||
unique_key: The unique name for this token as a string. It is up to your
|
||||
code to ensure that this token value is unique in your application.
|
||||
Previous values will be silently overwitten.
|
||||
token_str: A serialized auth token as a string. I expect that this string
|
||||
will be generated by gdata.gauth.token_to_blob.
|
||||
|
||||
Returns:
|
||||
True if the token was stored sucessfully, False if the token could not be
|
||||
safely cached (if an old value could not be cleared). If the token was
|
||||
set in memcache, but not in the datastore, this function will return None.
|
||||
However, in that situation an exception will likely be raised.
|
||||
|
||||
Raises:
|
||||
Datastore exceptions may be raised from the App Engine SDK in the event of
|
||||
failure.
|
||||
"""
|
||||
# First try to save in memcache.
|
||||
result = memcache.set(unique_key, token_str)
|
||||
# If memcache fails to save the value, clear the cached value.
|
||||
if not result:
|
||||
result = memcache.delete(unique_key)
|
||||
# If we could not clear the cached value for this token, refuse to save.
|
||||
if result == 0:
|
||||
return False
|
||||
# Save to the datastore.
|
||||
if Token(key_name=unique_key, t=token_str).put():
|
||||
return True
|
||||
return None
|
||||
|
||||
|
||||
def delete_token(unique_key):
|
||||
# Clear from memcache.
|
||||
memcache.delete(unique_key)
|
||||
# Clear from the datastore.
|
||||
Token(key_name=unique_key).delete()
|
||||
@@ -1,321 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
"""Provides HTTP functions for gdata.service to use on Google App Engine
|
||||
|
||||
AppEngineHttpClient: Provides an HTTP request method which uses App Engine's
|
||||
urlfetch API. Set the http_client member of a GDataService object to an
|
||||
instance of an AppEngineHttpClient to allow the gdata library to run on
|
||||
Google App Engine.
|
||||
|
||||
run_on_appengine: Function which will modify an existing GDataService object
|
||||
to allow it to run on App Engine. It works by creating a new instance of
|
||||
the AppEngineHttpClient and replacing the GDataService object's
|
||||
http_client.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
import StringIO
|
||||
import pickle
|
||||
import atom.http_interface
|
||||
import atom.token_store
|
||||
from google.appengine.api import urlfetch
|
||||
from google.appengine.ext import db
|
||||
from google.appengine.api import users
|
||||
from google.appengine.api import memcache
|
||||
|
||||
|
||||
def run_on_appengine(gdata_service, store_tokens=True,
|
||||
single_user_mode=False, deadline=None):
|
||||
"""Modifies a GDataService object to allow it to run on App Engine.
|
||||
|
||||
Args:
|
||||
gdata_service: An instance of AtomService, GDataService, or any
|
||||
of their subclasses which has an http_client member and a
|
||||
token_store member.
|
||||
store_tokens: Boolean, defaults to True. If True, the gdata_service
|
||||
will attempt to add each token to it's token_store when
|
||||
SetClientLoginToken or SetAuthSubToken is called. If False
|
||||
the tokens will not automatically be added to the
|
||||
token_store.
|
||||
single_user_mode: Boolean, defaults to False. If True, the current_token
|
||||
member of gdata_service will be set when
|
||||
SetClientLoginToken or SetAuthTubToken is called. If set
|
||||
to True, the current_token is set in the gdata_service
|
||||
and anyone who accesses the object will use the same
|
||||
token.
|
||||
|
||||
Note: If store_tokens is set to False and
|
||||
single_user_mode is set to False, all tokens will be
|
||||
ignored, since the library assumes: the tokens should not
|
||||
be stored in the datastore and they should not be stored
|
||||
in the gdata_service object. This will make it
|
||||
impossible to make requests which require authorization.
|
||||
deadline: int (optional) The number of seconds to wait for a response
|
||||
before timing out on the HTTP request. If no deadline is
|
||||
specified, the deafault deadline for HTTP requests from App
|
||||
Engine is used. The maximum is currently 10 (for 10 seconds).
|
||||
The default deadline for App Engine is 5 seconds.
|
||||
"""
|
||||
gdata_service.http_client = AppEngineHttpClient(deadline=deadline)
|
||||
gdata_service.token_store = AppEngineTokenStore()
|
||||
gdata_service.auto_store_tokens = store_tokens
|
||||
gdata_service.auto_set_current_token = single_user_mode
|
||||
return gdata_service
|
||||
|
||||
|
||||
class AppEngineHttpClient(atom.http_interface.GenericHttpClient):
|
||||
def __init__(self, headers=None, deadline=None):
|
||||
self.debug = False
|
||||
self.headers = headers or {}
|
||||
self.deadline = deadline
|
||||
|
||||
def request(self, operation, url, data=None, headers=None):
|
||||
"""Performs an HTTP call to the server, supports GET, POST, PUT, and
|
||||
DELETE.
|
||||
|
||||
Usage example, perform and HTTP GET on http://www.google.com/:
|
||||
import atom.http
|
||||
client = atom.http.HttpClient()
|
||||
http_response = client.request('GET', 'http://www.google.com/')
|
||||
|
||||
Args:
|
||||
operation: str The HTTP operation to be performed. This is usually one
|
||||
of 'GET', 'POST', 'PUT', or 'DELETE'
|
||||
data: filestream, list of parts, or other object which can be converted
|
||||
to a string. Should be set to None when performing a GET or DELETE.
|
||||
If data is a file-like object which can be read, this method will
|
||||
read a chunk of 100K bytes at a time and send them.
|
||||
If the data is a list of parts to be sent, each part will be
|
||||
evaluated and sent.
|
||||
url: The full URL to which the request should be sent. Can be a string
|
||||
or atom.url.Url.
|
||||
headers: dict of strings. HTTP headers which should be sent
|
||||
in the request.
|
||||
"""
|
||||
all_headers = self.headers.copy()
|
||||
if headers:
|
||||
all_headers.update(headers)
|
||||
|
||||
# Construct the full payload.
|
||||
# Assume that data is None or a string.
|
||||
data_str = data
|
||||
if data:
|
||||
if isinstance(data, list):
|
||||
# If data is a list of different objects, convert them all to strings
|
||||
# and join them together.
|
||||
converted_parts = [_convert_data_part(x) for x in data]
|
||||
data_str = ''.join(converted_parts)
|
||||
else:
|
||||
data_str = _convert_data_part(data)
|
||||
|
||||
# If the list of headers does not include a Content-Length, attempt to
|
||||
# calculate it based on the data object.
|
||||
if data and 'Content-Length' not in all_headers:
|
||||
all_headers['Content-Length'] = str(len(data_str))
|
||||
|
||||
# Set the content type to the default value if none was set.
|
||||
if 'Content-Type' not in all_headers:
|
||||
all_headers['Content-Type'] = 'application/atom+xml'
|
||||
|
||||
# Lookup the urlfetch operation which corresponds to the desired HTTP verb.
|
||||
if operation == 'GET':
|
||||
method = urlfetch.GET
|
||||
elif operation == 'POST':
|
||||
method = urlfetch.POST
|
||||
elif operation == 'PUT':
|
||||
method = urlfetch.PUT
|
||||
elif operation == 'DELETE':
|
||||
method = urlfetch.DELETE
|
||||
else:
|
||||
method = None
|
||||
if self.deadline is None:
|
||||
return HttpResponse(urlfetch.Fetch(url=str(url), payload=data_str,
|
||||
method=method, headers=all_headers, follow_redirects=False))
|
||||
return HttpResponse(urlfetch.Fetch(url=str(url), payload=data_str,
|
||||
method=method, headers=all_headers, follow_redirects=False,
|
||||
deadline=self.deadline))
|
||||
|
||||
|
||||
def _convert_data_part(data):
|
||||
if not data or isinstance(data, str):
|
||||
return data
|
||||
elif hasattr(data, 'read'):
|
||||
# data is a file like object, so read it completely.
|
||||
return data.read()
|
||||
# The data object was not a file.
|
||||
# Try to convert to a string and send the data.
|
||||
return str(data)
|
||||
|
||||
|
||||
class HttpResponse(object):
|
||||
"""Translates a urlfetch resoinse to look like an hhtplib resoinse.
|
||||
|
||||
Used to allow the resoinse from HttpRequest to be usable by gdata.service
|
||||
methods.
|
||||
"""
|
||||
|
||||
def __init__(self, urlfetch_response):
|
||||
self.body = StringIO.StringIO(urlfetch_response.content)
|
||||
self.headers = urlfetch_response.headers
|
||||
self.status = urlfetch_response.status_code
|
||||
self.reason = ''
|
||||
|
||||
def read(self, length=None):
|
||||
if not length:
|
||||
return self.body.read()
|
||||
else:
|
||||
return self.body.read(length)
|
||||
|
||||
def getheader(self, name):
|
||||
if not self.headers.has_key(name):
|
||||
return self.headers[name.lower()]
|
||||
return self.headers[name]
|
||||
|
||||
|
||||
class TokenCollection(db.Model):
|
||||
"""Datastore Model which associates auth tokens with the current user."""
|
||||
user = db.UserProperty()
|
||||
pickled_tokens = db.BlobProperty()
|
||||
|
||||
|
||||
class AppEngineTokenStore(atom.token_store.TokenStore):
|
||||
"""Stores the user's auth tokens in the App Engine datastore.
|
||||
|
||||
Tokens are only written to the datastore if a user is signed in (if
|
||||
users.get_current_user() returns a user object).
|
||||
"""
|
||||
def __init__(self):
|
||||
self.user = None
|
||||
|
||||
def add_token(self, token):
|
||||
"""Associates the token with the current user and stores it.
|
||||
|
||||
If there is no current user, the token will not be stored.
|
||||
|
||||
Returns:
|
||||
False if the token was not stored.
|
||||
"""
|
||||
tokens = load_auth_tokens(self.user)
|
||||
if not hasattr(token, 'scopes') or not token.scopes:
|
||||
return False
|
||||
for scope in token.scopes:
|
||||
tokens[str(scope)] = token
|
||||
key = save_auth_tokens(tokens, self.user)
|
||||
if key:
|
||||
return True
|
||||
return False
|
||||
|
||||
def find_token(self, url):
|
||||
"""Searches the current user's collection of token for a token which can
|
||||
be used for a request to the url.
|
||||
|
||||
Returns:
|
||||
The stored token which belongs to the current user and is valid for the
|
||||
desired URL. If there is no current user, or there is no valid user
|
||||
token in the datastore, a atom.http_interface.GenericToken is returned.
|
||||
"""
|
||||
if url is None:
|
||||
return None
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
tokens = load_auth_tokens(self.user)
|
||||
if url in tokens:
|
||||
token = tokens[url]
|
||||
if token.valid_for_scope(url):
|
||||
return token
|
||||
else:
|
||||
del tokens[url]
|
||||
save_auth_tokens(tokens, self.user)
|
||||
for scope, token in tokens.iteritems():
|
||||
if token.valid_for_scope(url):
|
||||
return token
|
||||
return atom.http_interface.GenericToken()
|
||||
|
||||
def remove_token(self, token):
|
||||
"""Removes the token from the current user's collection in the datastore.
|
||||
|
||||
Returns:
|
||||
False if the token was not removed, this could be because the token was
|
||||
not in the datastore, or because there is no current user.
|
||||
"""
|
||||
token_found = False
|
||||
scopes_to_delete = []
|
||||
tokens = load_auth_tokens(self.user)
|
||||
for scope, stored_token in tokens.iteritems():
|
||||
if stored_token == token:
|
||||
scopes_to_delete.append(scope)
|
||||
token_found = True
|
||||
for scope in scopes_to_delete:
|
||||
del tokens[scope]
|
||||
if token_found:
|
||||
save_auth_tokens(tokens, self.user)
|
||||
return token_found
|
||||
|
||||
def remove_all_tokens(self):
|
||||
"""Removes all of the current user's tokens from the datastore."""
|
||||
save_auth_tokens({}, self.user)
|
||||
|
||||
|
||||
def save_auth_tokens(token_dict, user=None):
|
||||
"""Associates the tokens with the current user and writes to the datastore.
|
||||
|
||||
If there us no current user, the tokens are not written and this function
|
||||
returns None.
|
||||
|
||||
Returns:
|
||||
The key of the datastore entity containing the user's tokens, or None if
|
||||
there was no current user.
|
||||
"""
|
||||
if user is None:
|
||||
user = users.get_current_user()
|
||||
if user is None:
|
||||
return None
|
||||
memcache.set('gdata_pickled_tokens:%s' % user, pickle.dumps(token_dict))
|
||||
user_tokens = TokenCollection.all().filter('user =', user).get()
|
||||
if user_tokens:
|
||||
user_tokens.pickled_tokens = pickle.dumps(token_dict)
|
||||
return user_tokens.put()
|
||||
else:
|
||||
user_tokens = TokenCollection(
|
||||
user=user,
|
||||
pickled_tokens=pickle.dumps(token_dict))
|
||||
return user_tokens.put()
|
||||
|
||||
|
||||
def load_auth_tokens(user=None):
|
||||
"""Reads a dictionary of the current user's tokens from the datastore.
|
||||
|
||||
If there is no current user (a user is not signed in to the app) or the user
|
||||
does not have any tokens, an empty dictionary is returned.
|
||||
"""
|
||||
if user is None:
|
||||
user = users.get_current_user()
|
||||
if user is None:
|
||||
return {}
|
||||
pickled_tokens = memcache.get('gdata_pickled_tokens:%s' % user)
|
||||
if pickled_tokens:
|
||||
return pickle.loads(pickled_tokens)
|
||||
user_tokens = TokenCollection.all().filter('user =', user).get()
|
||||
if user_tokens:
|
||||
memcache.set('gdata_pickled_tokens:%s' % user, user_tokens.pickled_tokens)
|
||||
return pickle.loads(user_tokens.pickled_tokens)
|
||||
return {}
|
||||
|
||||
@@ -1,526 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2007 SIOS Technology, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Contains objects used with Google Apps."""
|
||||
|
||||
__author__ = 'tmatsuo@sios.com (Takashi MATSUO)'
|
||||
|
||||
|
||||
import atom
|
||||
import gdata
|
||||
|
||||
|
||||
# XML namespaces which are often used in Google Apps entity.
|
||||
APPS_NAMESPACE = 'http://schemas.google.com/apps/2006'
|
||||
APPS_TEMPLATE = '{http://schemas.google.com/apps/2006}%s'
|
||||
|
||||
|
||||
class EmailList(atom.AtomBase):
|
||||
"""The Google Apps EmailList element"""
|
||||
|
||||
_tag = 'emailList'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['name'] = 'name'
|
||||
|
||||
def __init__(self, name=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
def EmailListFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EmailList, xml_string)
|
||||
|
||||
|
||||
class Who(atom.AtomBase):
|
||||
"""The Google Apps Who element"""
|
||||
|
||||
_tag = 'who'
|
||||
_namespace = gdata.GDATA_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['rel'] = 'rel'
|
||||
_attributes['email'] = 'email'
|
||||
|
||||
def __init__(self, rel=None, email=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.rel = rel
|
||||
self.email = email
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
def WhoFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Who, xml_string)
|
||||
|
||||
|
||||
class Login(atom.AtomBase):
|
||||
"""The Google Apps Login element"""
|
||||
|
||||
_tag = 'login'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['userName'] = 'user_name'
|
||||
_attributes['password'] = 'password'
|
||||
_attributes['suspended'] = 'suspended'
|
||||
_attributes['admin'] = 'admin'
|
||||
_attributes['changePasswordAtNextLogin'] = 'change_password'
|
||||
_attributes['agreedToTerms'] = 'agreed_to_terms'
|
||||
_attributes['ipWhitelisted'] = 'ip_whitelisted'
|
||||
_attributes['hashFunctionName'] = 'hash_function_name'
|
||||
|
||||
def __init__(self, user_name=None, password=None, suspended=None,
|
||||
ip_whitelisted=None, hash_function_name=None,
|
||||
admin=None, change_password=None, agreed_to_terms=None,
|
||||
extension_elements=None, extension_attributes=None,
|
||||
text=None):
|
||||
self.user_name = user_name
|
||||
self.password = password
|
||||
self.suspended = suspended
|
||||
self.admin = admin
|
||||
self.change_password = change_password
|
||||
self.agreed_to_terms = agreed_to_terms
|
||||
self.ip_whitelisted = ip_whitelisted
|
||||
self.hash_function_name = hash_function_name
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def LoginFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Login, xml_string)
|
||||
|
||||
|
||||
class Quota(atom.AtomBase):
|
||||
"""The Google Apps Quota element"""
|
||||
|
||||
_tag = 'quota'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['limit'] = 'limit'
|
||||
|
||||
def __init__(self, limit=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.limit = limit
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def QuotaFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Quota, xml_string)
|
||||
|
||||
|
||||
class Name(atom.AtomBase):
|
||||
"""The Google Apps Name element"""
|
||||
|
||||
_tag = 'name'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['familyName'] = 'family_name'
|
||||
_attributes['givenName'] = 'given_name'
|
||||
|
||||
def __init__(self, family_name=None, given_name=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.family_name = family_name
|
||||
self.given_name = given_name
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def NameFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Name, xml_string)
|
||||
|
||||
|
||||
class Nickname(atom.AtomBase):
|
||||
"""The Google Apps Nickname element"""
|
||||
|
||||
_tag = 'nickname'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['name'] = 'name'
|
||||
|
||||
def __init__(self, name=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def NicknameFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Nickname, xml_string)
|
||||
|
||||
|
||||
class NicknameEntry(gdata.GDataEntry):
|
||||
"""A Google Apps flavor of an Atom Entry for Nickname"""
|
||||
|
||||
_tag = 'entry'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataEntry._children.copy()
|
||||
_attributes = gdata.GDataEntry._attributes.copy()
|
||||
_children['{%s}login' % APPS_NAMESPACE] = ('login', Login)
|
||||
_children['{%s}nickname' % APPS_NAMESPACE] = ('nickname', Nickname)
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
atom_id=None, link=None, published=None,
|
||||
title=None, updated=None,
|
||||
login=None, nickname=None,
|
||||
extended_property=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
|
||||
gdata.GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content,
|
||||
atom_id=atom_id, link=link, published=published,
|
||||
title=title, updated=updated)
|
||||
self.login = login
|
||||
self.nickname = nickname
|
||||
self.extended_property = extended_property or []
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def NicknameEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(NicknameEntry, xml_string)
|
||||
|
||||
|
||||
class NicknameFeed(gdata.GDataFeed, gdata.LinkFinder):
|
||||
"""A Google Apps Nickname feed flavor of an Atom Feed"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataFeed._children.copy()
|
||||
_attributes = gdata.GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [NicknameEntry])
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None,
|
||||
entry=None, total_results=None, start_index=None,
|
||||
items_per_page=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
gdata.GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results,
|
||||
start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def NicknameFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(NicknameFeed, xml_string)
|
||||
|
||||
|
||||
class UserEntry(gdata.GDataEntry):
|
||||
"""A Google Apps flavor of an Atom Entry"""
|
||||
|
||||
_tag = 'entry'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataEntry._children.copy()
|
||||
_attributes = gdata.GDataEntry._attributes.copy()
|
||||
_children['{%s}login' % APPS_NAMESPACE] = ('login', Login)
|
||||
_children['{%s}name' % APPS_NAMESPACE] = ('name', Name)
|
||||
_children['{%s}quota' % APPS_NAMESPACE] = ('quota', Quota)
|
||||
# This child may already be defined in GDataEntry, confirm before removing.
|
||||
_children['{%s}feedLink' % gdata.GDATA_NAMESPACE] = ('feed_link',
|
||||
[gdata.FeedLink])
|
||||
_children['{%s}who' % gdata.GDATA_NAMESPACE] = ('who', Who)
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
atom_id=None, link=None, published=None,
|
||||
title=None, updated=None,
|
||||
login=None, name=None, quota=None, who=None, feed_link=None,
|
||||
extended_property=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
|
||||
gdata.GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content,
|
||||
atom_id=atom_id, link=link, published=published,
|
||||
title=title, updated=updated)
|
||||
self.login = login
|
||||
self.name = name
|
||||
self.quota = quota
|
||||
self.who = who
|
||||
self.feed_link = feed_link or []
|
||||
self.extended_property = extended_property or []
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def UserEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(UserEntry, xml_string)
|
||||
|
||||
|
||||
class UserFeed(gdata.GDataFeed, gdata.LinkFinder):
|
||||
"""A Google Apps User feed flavor of an Atom Feed"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataFeed._children.copy()
|
||||
_attributes = gdata.GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [UserEntry])
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None,
|
||||
entry=None, total_results=None, start_index=None,
|
||||
items_per_page=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
gdata.GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results,
|
||||
start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def UserFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(UserFeed, xml_string)
|
||||
|
||||
|
||||
class EmailListEntry(gdata.GDataEntry):
|
||||
"""A Google Apps EmailList flavor of an Atom Entry"""
|
||||
|
||||
_tag = 'entry'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataEntry._children.copy()
|
||||
_attributes = gdata.GDataEntry._attributes.copy()
|
||||
_children['{%s}emailList' % APPS_NAMESPACE] = ('email_list', EmailList)
|
||||
# Might be able to remove this _children entry.
|
||||
_children['{%s}feedLink' % gdata.GDATA_NAMESPACE] = ('feed_link',
|
||||
[gdata.FeedLink])
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
atom_id=None, link=None, published=None,
|
||||
title=None, updated=None,
|
||||
email_list=None, feed_link=None,
|
||||
extended_property=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
|
||||
gdata.GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content,
|
||||
atom_id=atom_id, link=link, published=published,
|
||||
title=title, updated=updated)
|
||||
self.email_list = email_list
|
||||
self.feed_link = feed_link or []
|
||||
self.extended_property = extended_property or []
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def EmailListEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EmailListEntry, xml_string)
|
||||
|
||||
|
||||
class EmailListFeed(gdata.GDataFeed, gdata.LinkFinder):
|
||||
"""A Google Apps EmailList feed flavor of an Atom Feed"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataFeed._children.copy()
|
||||
_attributes = gdata.GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [EmailListEntry])
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None,
|
||||
entry=None, total_results=None, start_index=None,
|
||||
items_per_page=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
gdata.GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results,
|
||||
start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def EmailListFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EmailListFeed, xml_string)
|
||||
|
||||
|
||||
class EmailListRecipientEntry(gdata.GDataEntry):
|
||||
"""A Google Apps EmailListRecipient flavor of an Atom Entry"""
|
||||
|
||||
_tag = 'entry'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataEntry._children.copy()
|
||||
_attributes = gdata.GDataEntry._attributes.copy()
|
||||
_children['{%s}who' % gdata.GDATA_NAMESPACE] = ('who', Who)
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
atom_id=None, link=None, published=None,
|
||||
title=None, updated=None,
|
||||
who=None,
|
||||
extended_property=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
|
||||
gdata.GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content,
|
||||
atom_id=atom_id, link=link, published=published,
|
||||
title=title, updated=updated)
|
||||
self.who = who
|
||||
self.extended_property = extended_property or []
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def EmailListRecipientEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EmailListRecipientEntry, xml_string)
|
||||
|
||||
|
||||
class EmailListRecipientFeed(gdata.GDataFeed, gdata.LinkFinder):
|
||||
"""A Google Apps EmailListRecipient feed flavor of an Atom Feed"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataFeed._children.copy()
|
||||
_attributes = gdata.GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry',
|
||||
[EmailListRecipientEntry])
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None,
|
||||
entry=None, total_results=None, start_index=None,
|
||||
items_per_page=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
gdata.GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results,
|
||||
start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
|
||||
def EmailListRecipientFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(EmailListRecipientFeed, xml_string)
|
||||
|
||||
|
||||
class Property(atom.AtomBase):
|
||||
"""The Google Apps Property element"""
|
||||
|
||||
_tag = 'property'
|
||||
_namespace = APPS_NAMESPACE
|
||||
_children = atom.AtomBase._children.copy()
|
||||
_attributes = atom.AtomBase._attributes.copy()
|
||||
_attributes['name'] = 'name'
|
||||
_attributes['value'] = 'value'
|
||||
|
||||
def __init__(self, name=None, value=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def PropertyFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(Property, xml_string)
|
||||
|
||||
|
||||
class PropertyEntry(gdata.GDataEntry):
|
||||
"""A Google Apps Property flavor of an Atom Entry"""
|
||||
|
||||
_tag = 'entry'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataEntry._children.copy()
|
||||
_attributes = gdata.GDataEntry._attributes.copy()
|
||||
_children['{%s}property' % APPS_NAMESPACE] = ('property', [Property])
|
||||
|
||||
def __init__(self, author=None, category=None, content=None,
|
||||
atom_id=None, link=None, published=None,
|
||||
title=None, updated=None,
|
||||
property=None,
|
||||
extended_property=None,
|
||||
extension_elements=None, extension_attributes=None, text=None):
|
||||
|
||||
gdata.GDataEntry.__init__(self, author=author, category=category,
|
||||
content=content,
|
||||
atom_id=atom_id, link=link, published=published,
|
||||
title=title, updated=updated)
|
||||
self.property = property
|
||||
self.extended_property = extended_property or []
|
||||
self.text = text
|
||||
self.extension_elements = extension_elements or []
|
||||
self.extension_attributes = extension_attributes or {}
|
||||
|
||||
|
||||
def PropertyEntryFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(PropertyEntry, xml_string)
|
||||
|
||||
class PropertyFeed(gdata.GDataFeed, gdata.LinkFinder):
|
||||
"""A Google Apps Property feed flavor of an Atom Feed"""
|
||||
|
||||
_tag = 'feed'
|
||||
_namespace = atom.ATOM_NAMESPACE
|
||||
_children = gdata.GDataFeed._children.copy()
|
||||
_attributes = gdata.GDataFeed._attributes.copy()
|
||||
_children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [PropertyEntry])
|
||||
|
||||
def __init__(self, author=None, category=None, contributor=None,
|
||||
generator=None, icon=None, atom_id=None, link=None, logo=None,
|
||||
rights=None, subtitle=None, title=None, updated=None,
|
||||
entry=None, total_results=None, start_index=None,
|
||||
items_per_page=None, extension_elements=None,
|
||||
extension_attributes=None, text=None):
|
||||
gdata.GDataFeed.__init__(self, author=author, category=category,
|
||||
contributor=contributor, generator=generator,
|
||||
icon=icon, atom_id=atom_id, link=link,
|
||||
logo=logo, rights=rights, subtitle=subtitle,
|
||||
title=title, updated=updated, entry=entry,
|
||||
total_results=total_results,
|
||||
start_index=start_index,
|
||||
items_per_page=items_per_page,
|
||||
extension_elements=extension_elements,
|
||||
extension_attributes=extension_attributes,
|
||||
text=text)
|
||||
|
||||
def PropertyFeedFromString(xml_string):
|
||||
return atom.CreateClassFromXMLString(PropertyFeed, xml_string)
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
@@ -1,474 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Allow Google Apps domain administrators to set domain admin settings.
|
||||
|
||||
AdminSettingsService: Set admin settings."""
|
||||
|
||||
__author__ = 'jlee@pbu.edu'
|
||||
|
||||
|
||||
import gdata.apps
|
||||
import gdata.apps.service
|
||||
import gdata.service
|
||||
|
||||
|
||||
API_VER='2.0'
|
||||
|
||||
class AdminSettingsService(gdata.apps.service.PropertyService):
|
||||
"""Client for the Google Apps Admin Settings service."""
|
||||
|
||||
def _serviceUrl(self, setting_id, domain=None):
|
||||
if domain is None:
|
||||
domain = self.domain
|
||||
return '/a/feeds/domain/%s/%s/%s' % (API_VER, domain, setting_id)
|
||||
|
||||
def genericGet(self, location):
|
||||
"""Generic HTTP Get Wrapper
|
||||
|
||||
Args:
|
||||
location: relative uri to Get
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the get operation."""
|
||||
|
||||
uri = self._serviceUrl(location)
|
||||
try:
|
||||
return self._GetProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def GetDefaultLanguage(self):
|
||||
"""Gets Domain Default Language
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
Default Language as a string. All possible values are listed at:
|
||||
http://code.google.com/apis/apps/email_settings/developers_guide_protocol.html#GA_email_language_tags"""
|
||||
|
||||
result = self.genericGet('general/defaultLanguage')
|
||||
return result['defaultLanguage']
|
||||
|
||||
def UpdateDefaultLanguage(self, defaultLanguage):
|
||||
"""Updates Domain Default Language
|
||||
|
||||
Args:
|
||||
defaultLanguage: Domain Language to set
|
||||
possible values are at:
|
||||
http://code.google.com/apis/apps/email_settings/developers_guide_protocol.html#GA_email_language_tags
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the put operation"""
|
||||
|
||||
uri = self._serviceUrl('general/defaultLanguage')
|
||||
properties = {'defaultLanguage': defaultLanguage}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetOrganizationName(self):
|
||||
"""Gets Domain Default Language
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
Organization Name as a string."""
|
||||
|
||||
result = self.genericGet('general/organizationName')
|
||||
return result['organizationName']
|
||||
|
||||
|
||||
def UpdateOrganizationName(self, organizationName):
|
||||
"""Updates Organization Name
|
||||
|
||||
Args:
|
||||
organizationName: Name of organization
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the put operation"""
|
||||
|
||||
uri = self._serviceUrl('general/organizationName')
|
||||
properties = {'organizationName': organizationName}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetMaximumNumberOfUsers(self):
|
||||
"""Gets Maximum Number of Users Allowed
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: An integer, the maximum number of users"""
|
||||
|
||||
result = self.genericGet('general/maximumNumberOfUsers')
|
||||
return int(result['maximumNumberOfUsers'])
|
||||
|
||||
def GetCurrentNumberOfUsers(self):
|
||||
"""Gets Current Number of Users
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: An integer, the current number of users"""
|
||||
|
||||
result = self.genericGet('general/currentNumberOfUsers')
|
||||
return int(result['currentNumberOfUsers'])
|
||||
|
||||
def IsDomainVerified(self):
|
||||
"""Is the domain verified
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: Boolean, is domain verified"""
|
||||
|
||||
result = self.genericGet('accountInformation/isVerified')
|
||||
if result['isVerified'] == 'true':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def GetSupportPIN(self):
|
||||
"""Gets Support PIN
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the Support PIN"""
|
||||
|
||||
result = self.genericGet('accountInformation/supportPIN')
|
||||
return result['supportPIN']
|
||||
|
||||
def GetEdition(self):
|
||||
"""Gets Google Apps Domain Edition
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the domain's edition (premier, education, partner)"""
|
||||
|
||||
result = self.genericGet('accountInformation/edition')
|
||||
return result['edition']
|
||||
|
||||
def GetCustomerPIN(self):
|
||||
"""Gets Customer PIN
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the customer PIN"""
|
||||
|
||||
result = self.genericGet('accountInformation/customerPIN')
|
||||
return result['customerPIN']
|
||||
|
||||
def GetCreationTime(self):
|
||||
"""Gets Domain Creation Time
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the domain's creation time"""
|
||||
|
||||
result = self.genericGet('accountInformation/creationTime')
|
||||
return result['creationTime']
|
||||
|
||||
def GetCountryCode(self):
|
||||
"""Gets Domain Country Code
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the domain's country code. Possible values at:
|
||||
http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm"""
|
||||
|
||||
result = self.genericGet('accountInformation/countryCode')
|
||||
return result['countryCode']
|
||||
|
||||
def GetAdminSecondaryEmail(self):
|
||||
"""Gets Domain Admin Secondary Email Address
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A string, the secondary email address for domain admin"""
|
||||
|
||||
result = self.genericGet('accountInformation/adminSecondaryEmail')
|
||||
return result['adminSecondaryEmail']
|
||||
|
||||
def UpdateAdminSecondaryEmail(self, adminSecondaryEmail):
|
||||
"""Gets Domain Creation Time
|
||||
|
||||
Args:
|
||||
adminSecondaryEmail: string, secondary email address of admin
|
||||
|
||||
Returns: A dict containing the result of the put operation"""
|
||||
|
||||
uri = self._serviceUrl('accountInformation/adminSecondaryEmail')
|
||||
properties = {'adminSecondaryEmail': adminSecondaryEmail}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetDomainLogo(self):
|
||||
"""Gets Domain Logo
|
||||
|
||||
This function does not make use of the Google Apps Admin Settings API,
|
||||
it does an HTTP Get of a url specific to the Google Apps domain. It is
|
||||
included for completeness sake.
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: binary image file"""
|
||||
|
||||
import urllib
|
||||
url = 'http://www.google.com/a/cpanel/'+self.domain+'/images/logo.gif'
|
||||
response = urllib.urlopen(url)
|
||||
return response.read()
|
||||
|
||||
def UpdateDomainLogo(self, logoImage):
|
||||
"""Update Domain's Custom Logo
|
||||
|
||||
Args:
|
||||
logoImage: binary image data
|
||||
|
||||
Returns: A dict containing the result of the put operation"""
|
||||
|
||||
from base64 import b64encode
|
||||
uri = self._serviceUrl('appearance/customLogo')
|
||||
properties = {'logoImage': b64encode(logoImage)}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetCNAMEVerificationStatus(self):
|
||||
"""Gets Domain CNAME Verification Status
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A dict {recordName, verified, verifiedMethod}"""
|
||||
|
||||
return self.genericGet('verification/cname')
|
||||
|
||||
def UpdateCNAMEVerificationStatus(self, verified='true'):
|
||||
"""Updates CNAME Verification Status
|
||||
|
||||
Args:
|
||||
verified: boolean, True will retry verification process
|
||||
|
||||
Returns: A dict containing the result of the put operation"""
|
||||
|
||||
uri = self._serviceUrl('verification/cname')
|
||||
properties = self.GetCNAMEVerificationStatus()
|
||||
properties['verified'] = verified
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetMXVerificationStatus(self):
|
||||
"""Gets Domain MX Verification Status
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A dict {verified, verifiedMethod}"""
|
||||
|
||||
return self.genericGet('verification/mx')
|
||||
|
||||
def UpdateMXVerificationStatus(self, verified='true'):
|
||||
"""Updates MX Verification Status
|
||||
|
||||
Args:
|
||||
verified: boolean, True will retry verification process
|
||||
|
||||
Returns: A dict containing the result of the put operation"""
|
||||
|
||||
uri = self._serviceUrl('verification/mx')
|
||||
properties = self.GetMXVerificationStatus()
|
||||
properties['verified'] = verified
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetSSOSettings(self):
|
||||
"""Gets Domain Single Sign-On Settings
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A dict {samlSignonUri, samlLogoutUri, changePasswordUri, enableSSO, ssoWhitelist, useDomainSpecificIssuer}"""
|
||||
|
||||
return self.genericGet('sso/general')
|
||||
|
||||
def UpdateSSOSettings(self, enableSSO=None, samlSignonUri=None,
|
||||
samlLogoutUri=None, changePasswordUri=None,
|
||||
ssoWhitelist=None, useDomainSpecificIssuer=None):
|
||||
"""Update SSO Settings.
|
||||
|
||||
Args:
|
||||
enableSSO: boolean, SSO Master on/off switch
|
||||
samlSignonUri: string, SSO Login Page
|
||||
samlLogoutUri: string, SSO Logout Page
|
||||
samlPasswordUri: string, SSO Password Change Page
|
||||
ssoWhitelist: string, Range of IP Addresses which will see SSO
|
||||
useDomainSpecificIssuer: boolean, Include Google Apps Domain in Issuer
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('sso/general')
|
||||
|
||||
#Get current settings, replace Nones with ''
|
||||
properties = self.GetSSOSettings()
|
||||
if properties['samlSignonUri'] == None:
|
||||
properties['samlSignonUri'] = ''
|
||||
if properties['samlLogoutUri'] == None:
|
||||
properties['samlLogoutUri'] = ''
|
||||
if properties['changePasswordUri'] == None:
|
||||
properties['changePasswordUri'] = ''
|
||||
if properties['ssoWhitelist'] == None:
|
||||
properties['ssoWhitelist'] = ''
|
||||
|
||||
#update only the values we were passed
|
||||
if enableSSO != None:
|
||||
properties['enableSSO'] = gdata.apps.service._bool2str(enableSSO)
|
||||
if samlSignonUri != None:
|
||||
properties['samlSignonUri'] = samlSignonUri
|
||||
if samlLogoutUri != None:
|
||||
properties['samlLogoutUri'] = samlLogoutUri
|
||||
if changePasswordUri != None:
|
||||
properties['changePasswordUri'] = changePasswordUri
|
||||
if ssoWhitelist != None:
|
||||
properties['ssoWhitelist'] = ssoWhitelist
|
||||
if useDomainSpecificIssuer != None:
|
||||
properties['useDomainSpecificIssuer'] = gdata.apps.service._bool2str(useDomainSpecificIssuer)
|
||||
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetSSOKey(self):
|
||||
"""Gets Domain Single Sign-On Signing Key
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns: A dict {modulus, exponent, algorithm, format}"""
|
||||
|
||||
return self.genericGet('sso/signingkey')
|
||||
|
||||
def UpdateSSOKey(self, signingKey):
|
||||
"""Update SSO Settings.
|
||||
|
||||
Args:
|
||||
signingKey: binary, public key to be uploaded
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation."""
|
||||
|
||||
from base64 import b64encode
|
||||
uri = self._serviceUrl('sso/signingkey')
|
||||
properties = {'signingKey': b64encode(signingKey)}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def IsUserMigrationEnabled(self):
|
||||
"""Is User Migration Enabled
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
boolean, is user migration enabled"""
|
||||
|
||||
result = self.genericGet('email/migration')
|
||||
if result['enableUserMigration'] == 'true':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def UpdateUserMigrationStatus(self, enableUserMigration):
|
||||
"""Update User Migration Status
|
||||
|
||||
Args:
|
||||
enableUserMigration: boolean, user migration enable/disable
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation."""
|
||||
|
||||
uri = self._serviceUrl('email/migration')
|
||||
properties = {'enableUserMigration': enableUserMigration}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetOutboundGatewaySettings(self):
|
||||
"""Get Outbound Gateway Settings
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
A dict {smartHost, smtpMode}"""
|
||||
|
||||
uri = self._serviceUrl('email/gateway')
|
||||
try:
|
||||
return self._GetProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
except TypeError:
|
||||
#if no outbound gateway is set, we get a TypeError,
|
||||
#catch it and return nothing...
|
||||
return {'smartHost': None, 'smtpMode': None}
|
||||
|
||||
def UpdateOutboundGatewaySettings(self, smartHost=None, smtpMode=None):
|
||||
"""Update Outbound Gateway Settings
|
||||
|
||||
Args:
|
||||
smartHost: string, ip address or hostname of outbound gateway
|
||||
smtpMode: string, SMTP or SMTP_TLS
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation."""
|
||||
|
||||
uri = self._serviceUrl('email/gateway')
|
||||
|
||||
#Get current settings, replace Nones with ''
|
||||
properties = self.GetOutboundGatewaySettings()
|
||||
if properties['smartHost'] == None:
|
||||
properties['smartHost'] = ''
|
||||
try:
|
||||
if properties['smtpMode'] == None:
|
||||
properties['smtpMode'] = ''
|
||||
except KeyError:
|
||||
properties['smtpMode'] = ''
|
||||
|
||||
#If we were passed new values for smartHost or smtpMode, update them
|
||||
if smartHost != None:
|
||||
properties['smartHost'] = smartHost
|
||||
if smtpMode != None:
|
||||
properties['smtpMode'] = smtpMode
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def AddEmailRoute(self, routeDestination, routeRewriteTo, routeEnabled, bounceNotifications, accountHandling):
|
||||
"""Adds Domain Email Route
|
||||
|
||||
Args:
|
||||
routeDestination: string, destination ip address or hostname
|
||||
routeRewriteTo: boolean, rewrite smtp envelop To:
|
||||
routeEnabled: boolean, enable disable email routing
|
||||
bounceNotifications: boolean, send bound notificiations to sender
|
||||
accountHandling: string, which to route, "allAccounts", "provisionedAccounts", "unknownAccounts"
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation."""
|
||||
|
||||
uri = self._serviceUrl('emailrouting')
|
||||
properties = {}
|
||||
properties['routeDestination'] = routeDestination
|
||||
properties['routeRewriteTo'] = gdata.apps.service._bool2str(routeRewriteTo)
|
||||
properties['routeEnabled'] = gdata.apps.service._bool2str(routeEnabled)
|
||||
properties['bounceNotifications'] = gdata.apps.service._bool2str(bounceNotifications)
|
||||
properties['accountHandling'] = accountHandling
|
||||
return self._PostProperties(uri, properties)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
# Copyright (C) 2008 Google, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Allow Google Apps domain administrators to audit user data.
|
||||
|
||||
AuditService: Set auditing."""
|
||||
|
||||
__author__ = 'jlee@pbu.edu'
|
||||
|
||||
from base64 import b64encode
|
||||
|
||||
import gdata.apps
|
||||
import gdata.apps.service
|
||||
import gdata.service
|
||||
|
||||
class AuditService(gdata.apps.service.PropertyService):
|
||||
"""Client for the Google Apps Audit service."""
|
||||
|
||||
def _serviceUrl(self, setting_id, domain=None, user=None):
|
||||
if domain is None:
|
||||
domain = self.domain
|
||||
if user is None:
|
||||
return '/a/feeds/compliance/audit/%s/%s' % (setting_id, domain)
|
||||
else:
|
||||
return '/a/feeds/compliance/audit/%s/%s/%s' % (setting_id, domain, user)
|
||||
|
||||
def updatePGPKey(self, pgpkey):
|
||||
"""Updates Public PGP Key Google uses to encrypt audit data
|
||||
|
||||
Args:
|
||||
pgpkey: string, ASCII text of PGP Public Key to be used
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the POST operation."""
|
||||
|
||||
uri = self._serviceUrl('publickey')
|
||||
b64pgpkey = b64encode(pgpkey)
|
||||
properties = {}
|
||||
properties['publicKey'] = b64pgpkey
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def createEmailMonitor(self, source_user, destination_user, end_date,
|
||||
begin_date=None, incoming_headers_only=False,
|
||||
outgoing_headers_only=False, drafts=False,
|
||||
drafts_headers_only=False, chats=False,
|
||||
chats_headers_only=False):
|
||||
"""Creates a email monitor, forwarding the source_users emails/chats
|
||||
|
||||
Args:
|
||||
source_user: string, the user whose email will be audited
|
||||
destination_user: string, the user to receive the audited email
|
||||
end_date: string, the date the audit will end in
|
||||
"yyyy-MM-dd HH:mm" format, required
|
||||
begin_date: string, the date the audit will start in
|
||||
"yyyy-MM-dd HH:mm" format, leave blank to use current time
|
||||
incoming_headers_only: boolean, whether to audit only the headers of
|
||||
mail delivered to source user
|
||||
outgoing_headers_only: boolean, whether to audit only the headers of
|
||||
mail sent from the source user
|
||||
drafts: boolean, whether to audit draft messages of the source user
|
||||
drafts_headers_only: boolean, whether to audit only the headers of
|
||||
mail drafts saved by the user
|
||||
chats: boolean, whether to audit archived chats of the source user
|
||||
chats_headers_only: boolean, whether to audit only the headers of
|
||||
archived chats of the source user
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the POST operation."""
|
||||
|
||||
uri = self._serviceUrl('mail/monitor', user=source_user)
|
||||
properties = {}
|
||||
properties['destUserName'] = destination_user
|
||||
if begin_date is not None:
|
||||
properties['beginDate'] = begin_date
|
||||
properties['endDate'] = end_date
|
||||
if incoming_headers_only:
|
||||
properties['incomingEmailMonitorLevel'] = 'HEADER_ONLY'
|
||||
else:
|
||||
properties['incomingEmailMonitorLevel'] = 'FULL_MESSAGE'
|
||||
if outgoing_headers_only:
|
||||
properties['outgoingEmailMonitorLevel'] = 'HEADER_ONLY'
|
||||
else:
|
||||
properties['outgoingEmailMonitorLevel'] = 'FULL_MESSAGE'
|
||||
if drafts:
|
||||
if drafts_headers_only:
|
||||
properties['draftMonitorLevel'] = 'HEADER_ONLY'
|
||||
else:
|
||||
properties['draftMonitorLevel'] = 'FULL_MESSAGE'
|
||||
if chats:
|
||||
if chats_headers_only:
|
||||
properties['chatMonitorLevel'] = 'HEADER_ONLY'
|
||||
else:
|
||||
properties['chatMonitorLevel'] = 'FULL_MESSAGE'
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def getEmailMonitors(self, user):
|
||||
""""Gets the email monitors for the given user
|
||||
|
||||
Args:
|
||||
user: string, the user to retrieve email monitors for
|
||||
|
||||
Returns:
|
||||
list results of the POST operation
|
||||
|
||||
"""
|
||||
uri = self._serviceUrl('mail/monitor', user=user)
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
def deleteEmailMonitor(self, source_user, destination_user):
|
||||
"""Deletes the email monitor for the given user
|
||||
|
||||
Args:
|
||||
source_user: string, the user who is being monitored
|
||||
destination_user: string, theuser who recieves the monitored emails
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
|
||||
uri = self._serviceUrl('mail/monitor', user=source_user+'/'+destination_user)
|
||||
try:
|
||||
return self._DeleteProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def createAccountInformationRequest(self, user):
|
||||
"""Creates a request for account auditing details
|
||||
|
||||
Args:
|
||||
user: string, the user to request account information for
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the post operation."""
|
||||
|
||||
uri = self._serviceUrl('account', user=user)
|
||||
properties = {}
|
||||
#XML Body is left empty
|
||||
try:
|
||||
return self._PostProperties(uri, properties)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def getAccountInformationRequestStatus(self, user, request_id):
|
||||
"""Gets the status of an account auditing request
|
||||
|
||||
Args:
|
||||
user: string, the user whose account auditing details were requested
|
||||
request_id: string, the request_id
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the get operation."""
|
||||
|
||||
uri = self._serviceUrl('account', user=user+'/'+request_id)
|
||||
try:
|
||||
return self._GetProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def getAllAccountInformationRequestsStatus(self):
|
||||
"""Gets the status of all account auditing requests for the domain
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
list results of the POST operation
|
||||
"""
|
||||
|
||||
uri = self._serviceUrl('account')
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
|
||||
def deleteAccountInformationRequest(self, user, request_id):
|
||||
"""Deletes the request for account auditing information
|
||||
|
||||
Args:
|
||||
user: string, the user whose account auditing details were requested
|
||||
request_id: string, the request_id
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
|
||||
uri = self._serviceUrl('account', user=user+'/'+request_id)
|
||||
try:
|
||||
return self._DeleteProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def createMailboxExportRequest(self, user, begin_date=None, end_date=None, include_deleted=False, search_query=None, headers_only=False):
|
||||
"""Creates a mailbox export request
|
||||
|
||||
Args:
|
||||
user: string, the user whose mailbox export is being requested
|
||||
begin_date: string, date of earliest emails to export, optional, defaults to date of account creation
|
||||
format is 'yyyy-MM-dd HH:mm'
|
||||
end_date: string, date of latest emails to export, optional, defaults to current date
|
||||
format is 'yyyy-MM-dd HH:mm'
|
||||
include_deleted: boolean, whether to include deleted emails in export, mutually exclusive with search_query
|
||||
search_query: string, gmail style search query, matched emails will be exported, mutually exclusive with include_deleted
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the post operation."""
|
||||
|
||||
uri = self._serviceUrl('mail/export', user=user)
|
||||
properties = {}
|
||||
if begin_date is not None:
|
||||
properties['beginDate'] = begin_date
|
||||
if end_date is not None:
|
||||
properties['endDate'] = end_date
|
||||
if include_deleted is not None:
|
||||
properties['includeDeleted'] = gdata.apps.service._bool2str(include_deleted)
|
||||
if search_query is not None:
|
||||
properties['searchQuery'] = search_query
|
||||
if headers_only is True:
|
||||
properties['packageContent'] = 'HEADER_ONLY'
|
||||
else:
|
||||
properties['packageContent'] = 'FULL_MESSAGE'
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def getMailboxExportRequestStatus(self, user, request_id):
|
||||
"""Gets the status of an mailbox export request
|
||||
|
||||
Args:
|
||||
user: string, the user whose mailbox were requested
|
||||
request_id: string, the request_id
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the get operation."""
|
||||
|
||||
uri = self._serviceUrl('mail/export', user=user+'/'+request_id)
|
||||
try:
|
||||
return self._GetProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def getAllMailboxExportRequestsStatus(self):
|
||||
"""Gets the status of all mailbox export requests for the domain
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
list results of the POST operation
|
||||
"""
|
||||
|
||||
uri = self._serviceUrl('mail/export')
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
|
||||
def deleteMailboxExportRequest(self, user, request_id):
|
||||
"""Deletes the request for mailbox export
|
||||
|
||||
Args:
|
||||
user: string, the user whose mailbox were requested
|
||||
request_id: string, the request_id
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
|
||||
uri = self._serviceUrl('mail/export', user=user+'/'+request_id)
|
||||
try:
|
||||
return self._DeleteProperties(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
@@ -1,394 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2008 Google, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Allow Google Apps domain administrators to set users' email settings.
|
||||
|
||||
EmailSettingsService: Set various email settings.
|
||||
"""
|
||||
|
||||
__author__ = 'google-apps-apis@googlegroups.com'
|
||||
|
||||
|
||||
import gdata.apps
|
||||
import gdata.apps.service
|
||||
import gdata.service
|
||||
|
||||
import urllib
|
||||
|
||||
API_VER='2.0'
|
||||
# Forwarding and POP3 options
|
||||
KEEP='KEEP'
|
||||
ARCHIVE='ARCHIVE'
|
||||
DELETE='DELETE'
|
||||
ALL_MAIL='ALL_MAIL'
|
||||
MAIL_FROM_NOW_ON='MAIL_FROM_NOW_ON'
|
||||
|
||||
|
||||
class EmailSettingsService(gdata.apps.service.PropertyService):
|
||||
"""Client for the Google Apps Email Settings service."""
|
||||
|
||||
def _serviceUrl(self, setting_id, username, domain=None):
|
||||
if domain is None:
|
||||
domain = self.domain
|
||||
return '/a/feeds/emailsettings/%s/%s/%s/%s' % (API_VER, domain, username,
|
||||
setting_id)
|
||||
|
||||
def CreateLabel(self, username, label):
|
||||
"""Create a label.
|
||||
|
||||
Args:
|
||||
username: User to create label for.
|
||||
label: Label to create.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the create operation.
|
||||
"""
|
||||
uri = self._serviceUrl('label', username)
|
||||
properties = {'label': label}
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def DeleteLabel(self, username, label):
|
||||
"""Delete a label.
|
||||
|
||||
Args:
|
||||
username: User to delete label for.
|
||||
label: Label to delete.
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
label = urllib.quote_plus(label, '')
|
||||
uri = self._serviceUrl('label/%s' % label, username)
|
||||
return self._DeleteProperties(uri)
|
||||
|
||||
def GetLabels(self, username):
|
||||
"""Get labels for a user.
|
||||
|
||||
Args:
|
||||
username: User to retrieve labels for.
|
||||
|
||||
Returns:
|
||||
A list of labels
|
||||
"""
|
||||
uri = self._serviceUrl('label', username)
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
def CreateFilter(self, username, from_=None, to=None, subject=None,
|
||||
has_the_word=None, does_not_have_the_word=None,
|
||||
has_attachment=None, label=None, should_mark_as_read=None,
|
||||
should_archive=None, should_star=None, forward_to=None,
|
||||
should_trash=None, should_not_spam=None):
|
||||
"""Create a filter.
|
||||
|
||||
Args:
|
||||
username: User to create filter for.
|
||||
from_: Filter from string.
|
||||
to: Filter to string.
|
||||
subject: Filter subject.
|
||||
has_the_word: Words to filter in.
|
||||
does_not_have_the_word: Words to filter out.
|
||||
has_attachment: Boolean for message having attachment.
|
||||
label: Label to apply.
|
||||
should_mark_as_read: Boolean for marking message as read.
|
||||
should_archive: Boolean for archiving message.
|
||||
should_star: Boolean for starring message
|
||||
forward_to: string email address to forward message to
|
||||
should_trash: Boolean for trashing message
|
||||
should_not_spam: Boolean for never sending message to spam
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the create operation.
|
||||
"""
|
||||
uri = self._serviceUrl('filter', username)
|
||||
properties = {}
|
||||
if from_ != None:
|
||||
properties['from'] = from_
|
||||
if to != None:
|
||||
properties['to'] = to
|
||||
if subject != None:
|
||||
properties['subject'] = subject
|
||||
if has_the_word != None:
|
||||
properties['hasTheWord'] = has_the_word
|
||||
if does_not_have_the_word != None:
|
||||
properties['doesNotHaveTheWord'] = does_not_have_the_word
|
||||
if has_attachment != None:
|
||||
properties['hasAttachment'] = gdata.apps.service._bool2str(has_attachment)
|
||||
if label != None:
|
||||
properties['label'] = label
|
||||
if should_mark_as_read != None:
|
||||
properties['shouldMarkAsRead'] = gdata.apps.service._bool2str(should_mark_as_read)
|
||||
if should_archive != None:
|
||||
properties['shouldArchive'] = gdata.apps.service._bool2str(should_archive)
|
||||
if should_star != None:
|
||||
properties['shouldStar'] = gdata.apps.service._bool2str(should_star)
|
||||
if forward_to != None:
|
||||
properties['forwardTo'] = forward_to
|
||||
if should_trash != None:
|
||||
properties['shouldTrash'] = gdata.apps.service._bool2str(should_trash)
|
||||
if should_not_spam != None:
|
||||
properties['neverSpam'] = gdata.apps.service._bool2str(should_not_spam)
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def CreateSendAsAlias(self, username, name, address, reply_to=None,
|
||||
make_default=None):
|
||||
"""Create alias to send mail as.
|
||||
|
||||
Args:
|
||||
username: User to create alias for.
|
||||
name: Name of alias.
|
||||
address: Email address to send from.
|
||||
reply_to: Email address to reply to.
|
||||
make_default: Boolean for whether this is the new default sending alias.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the create operation.
|
||||
"""
|
||||
uri = self._serviceUrl('sendas', username)
|
||||
properties = {}
|
||||
properties['name'] = name
|
||||
properties['address'] = address
|
||||
properties['replyTo'] = reply_to
|
||||
properties['makeDefault'] = gdata.apps.service._bool2str(make_default)
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def GetSendAsAlias(self, username):
|
||||
"""Retrieve send as aliases for a user.
|
||||
|
||||
Args:
|
||||
username: User to retrieve send as aliases for
|
||||
|
||||
Return:
|
||||
Alist containg the user's send as aliases.
|
||||
"""
|
||||
uri = self._serviceUrl('sendas', username)
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
def UpdateWebClipSettings(self, username, enable):
|
||||
"""Update WebClip Settings
|
||||
|
||||
Args:
|
||||
username: User to update forwarding for.
|
||||
enable: Boolean whether to enable Web Clip.
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('webclip', username)
|
||||
properties = {}
|
||||
properties['enable'] = gdata.apps.service._bool2str(enable)
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def UpdateForwarding(self, username, enable, forward_to=None, action=None):
|
||||
"""Update forwarding settings.
|
||||
|
||||
Args:
|
||||
username: User to update forwarding for.
|
||||
enable: Boolean whether to enable this forwarding rule.
|
||||
forward_to: Email address to forward to.
|
||||
action: Action to take after forwarding.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('forwarding', username)
|
||||
properties = {}
|
||||
properties['enable'] = gdata.apps.service._bool2str(enable)
|
||||
if enable is True:
|
||||
properties['forwardTo'] = forward_to
|
||||
properties['action'] = action
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def UpdatePop(self, username, enable, enable_for=None, action=None):
|
||||
"""Update POP3 settings.
|
||||
|
||||
Args:
|
||||
username: User to update POP3 settings for.
|
||||
enable: Boolean whether to enable POP3.
|
||||
enable_for: Which messages to make available via POP3.
|
||||
action: Action to take after user retrieves email via POP3.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('pop', username)
|
||||
properties = {}
|
||||
properties['enable'] = gdata.apps.service._bool2str(enable)
|
||||
if enable is True:
|
||||
properties['enableFor'] = enable_for
|
||||
properties['action'] = action
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetPop(self, username):
|
||||
uri = self._serviceUrl('pop', username)
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def GetImap(self, username):
|
||||
uri = self._serviceUrl('imap', username)
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def UpdateImap(self, username, enable):
|
||||
"""Update IMAP settings.
|
||||
|
||||
Args:
|
||||
username: User to update IMAP settings for.
|
||||
enable: Boolean whether to enable IMAP.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('imap', username)
|
||||
properties = {'enable': gdata.apps.service._bool2str(enable)}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetVacation(self, username):
|
||||
uri = self._serviceUrl('vacation', username)
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def GetForward(self, username):
|
||||
uri = self._serviceUrl('forwarding', username)
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def UpdateVacation(self, username, enable, subject=None, message=None,
|
||||
contacts_only=None, domain_only=None, start_date=None, end_date=None):
|
||||
"""Update vacation settings.
|
||||
|
||||
Args:
|
||||
username: User to update vacation settings for.
|
||||
enable: Boolean whether to enable vacation responses.
|
||||
subject: Vacation message subject.
|
||||
message: Vacation message body.
|
||||
contacts_only: Boolean whether to send message only to contacts.
|
||||
domain_only: Boolean Whether to only send the autoresponse to users in the same primary domain as the user taking the vacation.
|
||||
start_date: String "YYYY-MM-DD" The first day when the vacation responder was enabled for the user. In this version of the API, the startDate is in the UTC timezone, not the user's timezone.
|
||||
end_date: String "YYYY-MM-DD" The last day until which vacation responder is enabled for the user. In this version of the API, the endDate is the UTC timezone, not the user's timezone.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('vacation', username)
|
||||
properties = {}
|
||||
properties['enable'] = gdata.apps.service._bool2str(enable)
|
||||
if enable is True:
|
||||
properties['subject'] = subject
|
||||
properties['message'] = message
|
||||
if contacts_only != None:
|
||||
properties['contactsOnly'] = gdata.apps.service._bool2str(contacts_only)
|
||||
if domain_only != None:
|
||||
properties['domainOnly'] = gdata.apps.service._bool2str(domain_only)
|
||||
if start_date != None:
|
||||
properties['startDate'] = start_date
|
||||
if end_date != None:
|
||||
properties['endDate'] = end_date
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def UpdateSignature(self, username, signature):
|
||||
"""Update signature.
|
||||
|
||||
Args:
|
||||
username: User to update signature for.
|
||||
signature: Signature string.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('signature', username)
|
||||
properties = {'signature': signature}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def GetSignature(self, username):
|
||||
uri = self._serviceUrl('signature', username)
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def CreateDelegate(self, delegate, delegator):
|
||||
"""Create delegate
|
||||
|
||||
Args:
|
||||
delegate: User who will have access to delegator's account
|
||||
delegator: User whose account will be accessible by delegate
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the operation.
|
||||
"""
|
||||
uri = self._serviceUrl('delegation', delegator)
|
||||
properties = {'address': delegate}
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def GetDelegates(self, delegator):
|
||||
"""Retrieve delegates
|
||||
|
||||
Args:
|
||||
delegator: User whose account is accessible by retrieved delegates
|
||||
|
||||
Returns:
|
||||
A dict contaning the delegates
|
||||
"""
|
||||
uri = self._serviceUrl('delegation', delegator)
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
def DeleteDelegate(self, delegate, delegator):
|
||||
"""Delete delegate
|
||||
|
||||
Args:
|
||||
delegate: User account who has access to delegator's account
|
||||
delegator: Email address whose account will no longer be accessible by delegate
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the operation.
|
||||
"""
|
||||
uri = self._serviceUrl('delegation', delegator)+"/%s" % delegate
|
||||
return self._DeleteProperties(uri)
|
||||
|
||||
def UpdateLanguage(self, username, language):
|
||||
"""Update user interface language.
|
||||
|
||||
Args:
|
||||
username: User to update language for.
|
||||
language: Language code.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('language', username)
|
||||
properties = {'language': language}
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def UpdateGeneral(self, username, page_size=None, shortcuts=None, arrows=None,
|
||||
snippets=None, unicode=None):
|
||||
"""Update general settings.
|
||||
|
||||
Args:
|
||||
username: User to update general settings for.
|
||||
page_size: Number of messages to show.
|
||||
shortcuts: Boolean whether shortcuts are enabled.
|
||||
arrows: Boolean whether arrows are enabled.
|
||||
snippets: Boolean whether snippets are enabled.
|
||||
unicode: Wheter unicode is enabled.
|
||||
|
||||
Returns:
|
||||
A dict containing the result of the update operation.
|
||||
"""
|
||||
uri = self._serviceUrl('general', username)
|
||||
properties = {}
|
||||
if page_size != None:
|
||||
properties['pageSize'] = str(page_size)
|
||||
if shortcuts != None:
|
||||
properties['shortcuts'] = gdata.apps.service._bool2str(shortcuts)
|
||||
if arrows != None:
|
||||
properties['arrows'] = gdata.apps.service._bool2str(arrows)
|
||||
if snippets != None:
|
||||
properties['snippets'] = gdata.apps.service._bool2str(snippets)
|
||||
if unicode != None:
|
||||
properties['unicode'] = gdata.apps.service._bool2str(unicode)
|
||||
return self._PutProperties(uri, properties)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
# Copyright (C) 2008 Google, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Allow Google Apps domain administrators to create/modify/delete resource calendars.
|
||||
|
||||
ResCalService: Interact with Resource Calendars."""
|
||||
|
||||
__author__ = 'jlee@pbu.edu'
|
||||
|
||||
import gdata.apps
|
||||
import gdata.apps.service
|
||||
import gdata.service
|
||||
|
||||
class ResCalService(gdata.apps.service.PropertyService):
|
||||
"""Client for the Google Apps Resource Calendar service."""
|
||||
|
||||
def _serviceUrl(self, domain=None):
|
||||
if domain is None:
|
||||
domain = self.domain
|
||||
return '/a/feeds/calendar/resource/2.0/%s' % domain
|
||||
|
||||
def CreateResourceCalendar(self, id, common_name, description=None, type=None):
|
||||
|
||||
uri = self._serviceUrl()
|
||||
properties = {}
|
||||
properties['resourceId'] = id
|
||||
properties['resourceCommonName'] = common_name
|
||||
if description != None:
|
||||
properties['resourceDescription'] = description
|
||||
if type != None:
|
||||
properties['resourceType'] = type
|
||||
return self._PostProperties(uri, properties)
|
||||
|
||||
def RetrieveResourceCalendar(self, id):
|
||||
|
||||
uri = self._serviceUrl()+'/'+id
|
||||
return self._GetProperties(uri)
|
||||
|
||||
def RetrieveAllResourceCalendars(self):
|
||||
|
||||
uri = self._serviceUrl()+'/'
|
||||
return self._GetPropertiesList(uri)
|
||||
|
||||
def UpdateResourceCalendar(self, id, common_name=None, description=None, type=None):
|
||||
|
||||
uri = self._serviceUrl()+'/'+id
|
||||
properties = {}
|
||||
properties['resourceId'] = id
|
||||
if common_name != None:
|
||||
properties['resourceCommonName'] = common_name
|
||||
if description != None:
|
||||
properties['resourceDescription'] = description
|
||||
if type != None:
|
||||
properties['resourceType'] = type
|
||||
return self._PutProperties(uri, properties)
|
||||
|
||||
def DeleteResourceCalendar(self, id):
|
||||
|
||||
uri = self._serviceUrl()+'/'+id
|
||||
return self._DeleteProperties(uri)
|
||||
@@ -1,553 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2007 SIOS Technology, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
__author__ = 'tmatsuo@sios.com (Takashi MATSUO)'
|
||||
|
||||
try:
|
||||
from xml.etree import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
import cElementTree as ElementTree
|
||||
except ImportError:
|
||||
try:
|
||||
from xml.etree import ElementTree
|
||||
except ImportError:
|
||||
from elementtree import ElementTree
|
||||
import urllib
|
||||
import gdata
|
||||
import atom.service
|
||||
import gdata.service
|
||||
import gdata.apps
|
||||
import atom
|
||||
|
||||
API_VER="2.0"
|
||||
HTTP_OK=200
|
||||
|
||||
UNKOWN_ERROR=1000
|
||||
USER_DELETED_RECENTLY=1100
|
||||
USER_SUSPENDED=1101
|
||||
DOMAIN_USER_LIMIT_EXCEEDED=1200
|
||||
DOMAIN_ALIAS_LIMIT_EXCEEDED=1201
|
||||
DOMAIN_SUSPENDED=1202
|
||||
DOMAIN_FEATURE_UNAVAILABLE=1203
|
||||
ENTITY_EXISTS=1300
|
||||
ENTITY_DOES_NOT_EXIST=1301
|
||||
ENTITY_NAME_IS_RESERVED=1302
|
||||
ENTITY_NAME_NOT_VALID=1303
|
||||
INVALID_GIVEN_NAME=1400
|
||||
INVALID_FAMILY_NAME=1401
|
||||
INVALID_PASSWORD=1402
|
||||
INVALID_USERNAME=1403
|
||||
INVALID_HASH_FUNCTION_NAME=1404
|
||||
INVALID_HASH_DIGGEST_LENGTH=1405
|
||||
INVALID_EMAIL_ADDRESS=1406
|
||||
INVALID_QUERY_PARAMETER_VALUE=1407
|
||||
TOO_MANY_RECIPIENTS_ON_EMAIL_LIST=1500
|
||||
|
||||
DEFAULT_QUOTA_LIMIT='2048'
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AppsForYourDomainException(Error):
|
||||
|
||||
def __init__(self, response):
|
||||
|
||||
Error.__init__(self, response)
|
||||
try:
|
||||
self.element_tree = ElementTree.fromstring(response['body'])
|
||||
self.error_code = int(self.element_tree[0].attrib['errorCode'])
|
||||
self.reason = self.element_tree[0].attrib['reason']
|
||||
self.invalidInput = self.element_tree[0].attrib['invalidInput']
|
||||
except:
|
||||
self.error_code = 600
|
||||
|
||||
class AppsService(gdata.service.GDataService):
|
||||
"""Client for the Google Apps Provisioning service."""
|
||||
|
||||
def __init__(self, email=None, password=None, domain=None, source=None,
|
||||
server='apps-apis.google.com', additional_headers=None,
|
||||
**kwargs):
|
||||
"""Creates a client for the Google Apps Provisioning service.
|
||||
|
||||
Args:
|
||||
email: string (optional) The user's email address, used for
|
||||
authentication.
|
||||
password: string (optional) The user's password.
|
||||
domain: string (optional) The Google Apps domain name.
|
||||
source: string (optional) The name of the user's application.
|
||||
server: string (optional) The name of the server to which a connection
|
||||
will be opened. Default value: 'apps-apis.google.com'.
|
||||
**kwargs: The other parameters to pass to gdata.service.GDataService
|
||||
constructor.
|
||||
"""
|
||||
gdata.service.GDataService.__init__(
|
||||
self, email=email, password=password, service='apps', source=source,
|
||||
server=server, additional_headers=additional_headers, **kwargs)
|
||||
self.ssl = True
|
||||
self.port = 443
|
||||
self.domain = domain
|
||||
|
||||
def _baseURL(self):
|
||||
return "/a/feeds/%s" % self.domain
|
||||
|
||||
def AddAllElementsFromAllPages(self, link_finder, func):
|
||||
"""retrieve all pages and add all elements"""
|
||||
next = link_finder.GetNextLink()
|
||||
while next is not None:
|
||||
next_feed = self.Get(next.href, converter=func)
|
||||
for a_entry in next_feed.entry:
|
||||
link_finder.entry.append(a_entry)
|
||||
next = next_feed.GetNextLink()
|
||||
return link_finder
|
||||
|
||||
def RetrievePageOfEmailLists(self, start_email_list_name=None,
|
||||
num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY,
|
||||
backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve one page of email list"""
|
||||
uri = "%s/emailList/%s" % (self._baseURL(), API_VER)
|
||||
if start_email_list_name is not None:
|
||||
uri += "?startEmailListName=%s" % start_email_list_name
|
||||
try:
|
||||
return gdata.apps.EmailListFeedFromString(str(self.GetWithRetries(
|
||||
uri, num_retries=num_retries, delay=delay, backoff=backoff)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def GetGeneratorForAllEmailLists(
|
||||
self, num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve a generator for all emaillists in this domain."""
|
||||
first_page = self.RetrievePageOfEmailLists(num_retries=num_retries,
|
||||
delay=delay,
|
||||
backoff=backoff)
|
||||
return self.GetGeneratorFromLinkFinder(
|
||||
first_page, gdata.apps.EmailListRecipientFeedFromString,
|
||||
num_retries=num_retries, delay=delay, backoff=backoff)
|
||||
|
||||
def RetrieveAllEmailLists(self):
|
||||
"""Retrieve all email list of a domain."""
|
||||
|
||||
ret = self.RetrievePageOfEmailLists()
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.EmailListFeedFromString)
|
||||
|
||||
def RetrieveEmailList(self, list_name):
|
||||
"""Retreive a single email list by the list's name."""
|
||||
|
||||
uri = "%s/emailList/%s/%s" % (
|
||||
self._baseURL(), API_VER, list_name)
|
||||
try:
|
||||
return self.Get(uri, converter=gdata.apps.EmailListEntryFromString)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def RetrieveEmailLists(self, recipient):
|
||||
"""Retrieve All Email List Subscriptions for an Email Address."""
|
||||
|
||||
uri = "%s/emailList/%s?recipient=%s" % (
|
||||
self._baseURL(), API_VER, recipient)
|
||||
try:
|
||||
ret = gdata.apps.EmailListFeedFromString(str(self.Get(uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.EmailListFeedFromString)
|
||||
|
||||
def RemoveRecipientFromEmailList(self, recipient, list_name):
|
||||
"""Remove recipient from email list."""
|
||||
|
||||
uri = "%s/emailList/%s/%s/recipient/%s" % (
|
||||
self._baseURL(), API_VER, list_name, recipient)
|
||||
try:
|
||||
self.Delete(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def RetrievePageOfRecipients(self, list_name, start_recipient=None,
|
||||
num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY,
|
||||
backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve one page of recipient of an email list. """
|
||||
|
||||
uri = "%s/emailList/%s/%s/recipient" % (
|
||||
self._baseURL(), API_VER, list_name)
|
||||
|
||||
if start_recipient is not None:
|
||||
uri += "?startRecipient=%s" % start_recipient
|
||||
try:
|
||||
return gdata.apps.EmailListRecipientFeedFromString(str(
|
||||
self.GetWithRetries(
|
||||
uri, num_retries=num_retries, delay=delay, backoff=backoff)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def GetGeneratorForAllRecipients(
|
||||
self, list_name, num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve a generator for all recipients of a particular emaillist."""
|
||||
first_page = self.RetrievePageOfRecipients(list_name,
|
||||
num_retries=num_retries,
|
||||
delay=delay,
|
||||
backoff=backoff)
|
||||
return self.GetGeneratorFromLinkFinder(
|
||||
first_page, gdata.apps.EmailListRecipientFeedFromString,
|
||||
num_retries=num_retries, delay=delay, backoff=backoff)
|
||||
|
||||
def RetrieveAllRecipients(self, list_name):
|
||||
"""Retrieve all recipient of an email list."""
|
||||
|
||||
ret = self.RetrievePageOfRecipients(list_name)
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.EmailListRecipientFeedFromString)
|
||||
|
||||
def AddRecipientToEmailList(self, recipient, list_name):
|
||||
"""Add a recipient to a email list."""
|
||||
|
||||
uri = "%s/emailList/%s/%s/recipient" % (
|
||||
self._baseURL(), API_VER, list_name)
|
||||
recipient_entry = gdata.apps.EmailListRecipientEntry()
|
||||
recipient_entry.who = gdata.apps.Who(email=recipient)
|
||||
|
||||
try:
|
||||
return gdata.apps.EmailListRecipientEntryFromString(
|
||||
str(self.Post(recipient_entry, uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def DeleteEmailList(self, list_name):
|
||||
"""Delete a email list"""
|
||||
|
||||
uri = "%s/emailList/%s/%s" % (self._baseURL(), API_VER, list_name)
|
||||
try:
|
||||
self.Delete(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def CreateEmailList(self, list_name):
|
||||
"""Create a email list. """
|
||||
|
||||
uri = "%s/emailList/%s" % (self._baseURL(), API_VER)
|
||||
email_list_entry = gdata.apps.EmailListEntry()
|
||||
email_list_entry.email_list = gdata.apps.EmailList(name=list_name)
|
||||
try:
|
||||
return gdata.apps.EmailListEntryFromString(
|
||||
str(self.Post(email_list_entry, uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def DeleteNickname(self, nickname):
|
||||
"""Delete a nickname"""
|
||||
|
||||
uri = "%s/nickname/%s/%s" % (self._baseURL(), API_VER, nickname)
|
||||
try:
|
||||
self.Delete(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def RetrievePageOfNicknames(self, start_nickname=None,
|
||||
num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY,
|
||||
backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve one page of nicknames in the domain"""
|
||||
|
||||
uri = "%s/nickname/%s" % (self._baseURL(), API_VER)
|
||||
if start_nickname is not None:
|
||||
uri += "?startNickname=%s" % start_nickname
|
||||
try:
|
||||
return gdata.apps.NicknameFeedFromString(str(self.GetWithRetries(
|
||||
uri, num_retries=num_retries, delay=delay, backoff=backoff)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def GetGeneratorForAllNicknames(
|
||||
self, num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve a generator for all nicknames in this domain."""
|
||||
first_page = self.RetrievePageOfNicknames(num_retries=num_retries,
|
||||
delay=delay,
|
||||
backoff=backoff)
|
||||
return self.GetGeneratorFromLinkFinder(
|
||||
first_page, gdata.apps.NicknameFeedFromString, num_retries=num_retries,
|
||||
delay=delay, backoff=backoff)
|
||||
|
||||
def RetrieveAllNicknames(self):
|
||||
"""Retrieve all nicknames in the domain"""
|
||||
|
||||
ret = self.RetrievePageOfNicknames()
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.NicknameFeedFromString)
|
||||
|
||||
def GetGeneratorForAllNicknamesOfAUser(
|
||||
self, user_name, num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve a generator for all nicknames of a particular user."""
|
||||
uri = "%s/nickname/%s?username=%s" % (self._baseURL(), API_VER, user_name)
|
||||
try:
|
||||
first_page = gdata.apps.NicknameFeedFromString(str(self.GetWithRetries(
|
||||
uri, num_retries=num_retries, delay=delay, backoff=backoff)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
return self.GetGeneratorFromLinkFinder(
|
||||
first_page, gdata.apps.NicknameFeedFromString, num_retries=num_retries,
|
||||
delay=delay, backoff=backoff)
|
||||
|
||||
def RetrieveNicknames(self, user_name):
|
||||
"""Retrieve nicknames of the user"""
|
||||
|
||||
uri = "%s/nickname/%s?username=%s" % (self._baseURL(), API_VER, user_name)
|
||||
try:
|
||||
ret = gdata.apps.NicknameFeedFromString(str(self.Get(uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.NicknameFeedFromString)
|
||||
|
||||
def RetrieveNickname(self, nickname):
|
||||
"""Retrieve a nickname.
|
||||
|
||||
Args:
|
||||
nickname: string The nickname to retrieve
|
||||
|
||||
Returns:
|
||||
gdata.apps.NicknameEntry
|
||||
"""
|
||||
|
||||
uri = "%s/nickname/%s/%s" % (self._baseURL(), API_VER, nickname)
|
||||
try:
|
||||
return gdata.apps.NicknameEntryFromString(str(self.Get(uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def CreateNickname(self, user_name, nickname):
|
||||
"""Create a nickname"""
|
||||
|
||||
uri = "%s/nickname/%s" % (self._baseURL(), API_VER)
|
||||
nickname_entry = gdata.apps.NicknameEntry()
|
||||
nickname_entry.login = gdata.apps.Login(user_name=user_name)
|
||||
nickname_entry.nickname = gdata.apps.Nickname(name=nickname)
|
||||
|
||||
try:
|
||||
return gdata.apps.NicknameEntryFromString(
|
||||
str(self.Post(nickname_entry, uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def DeleteUser(self, user_name):
|
||||
"""Delete a user account"""
|
||||
|
||||
uri = "%s/user/%s/%s" % (self._baseURL(), API_VER, user_name)
|
||||
try:
|
||||
return self.Delete(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def UpdateUser(self, user_name, user_entry):
|
||||
"""Update a user account."""
|
||||
|
||||
uri = "%s/user/%s/%s" % (self._baseURL(), API_VER, user_name)
|
||||
try:
|
||||
return gdata.apps.UserEntryFromString(str(self.Put(user_entry, uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def CreateUser(self, user_name, family_name, given_name, password,
|
||||
suspended='false', quota_limit=None,
|
||||
password_hash_function=None,
|
||||
change_password=None):
|
||||
"""Create a user account. """
|
||||
|
||||
uri = "%s/user/%s" % (self._baseURL(), API_VER)
|
||||
user_entry = gdata.apps.UserEntry()
|
||||
user_entry.login = gdata.apps.Login(
|
||||
user_name=user_name, password=password, suspended=suspended,
|
||||
hash_function_name=password_hash_function,
|
||||
change_password=change_password)
|
||||
user_entry.name = gdata.apps.Name(family_name=family_name,
|
||||
given_name=given_name)
|
||||
if quota_limit is not None:
|
||||
user_entry.quota = gdata.apps.Quota(limit=str(quota_limit))
|
||||
|
||||
try:
|
||||
return gdata.apps.UserEntryFromString(str(self.Post(user_entry, uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def SuspendUser(self, user_name):
|
||||
user_entry = self.RetrieveUser(user_name)
|
||||
if user_entry.login.suspended != 'true':
|
||||
user_entry.login.suspended = 'true'
|
||||
user_entry = self.UpdateUser(user_name, user_entry)
|
||||
return user_entry
|
||||
|
||||
def RestoreUser(self, user_name):
|
||||
user_entry = self.RetrieveUser(user_name)
|
||||
if user_entry.login.suspended != 'false':
|
||||
user_entry.login.suspended = 'false'
|
||||
user_entry = self.UpdateUser(user_name, user_entry)
|
||||
return user_entry
|
||||
|
||||
def RetrieveUser(self, user_name):
|
||||
"""Retrieve an user account.
|
||||
|
||||
Args:
|
||||
user_name: string The user name to retrieve
|
||||
|
||||
Returns:
|
||||
gdata.apps.UserEntry
|
||||
"""
|
||||
|
||||
uri = "%s/user/%s/%s" % (self._baseURL(), API_VER, user_name)
|
||||
try:
|
||||
return gdata.apps.UserEntryFromString(str(self.Get(uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def RetrievePageOfUsers(self, start_username=None,
|
||||
num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY,
|
||||
backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve one page of users in this domain."""
|
||||
|
||||
uri = "%s/user/%s" % (self._baseURL(), API_VER)
|
||||
if start_username is not None:
|
||||
uri += "?startUsername=%s" % start_username
|
||||
try:
|
||||
return gdata.apps.UserFeedFromString(str(self.GetWithRetries(
|
||||
uri, num_retries=num_retries, delay=delay, backoff=backoff)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise AppsForYourDomainException(e.args[0])
|
||||
|
||||
def GetGeneratorForAllUsers(self,
|
||||
num_retries=gdata.service.DEFAULT_NUM_RETRIES,
|
||||
delay=gdata.service.DEFAULT_DELAY,
|
||||
backoff=gdata.service.DEFAULT_BACKOFF):
|
||||
"""Retrieve a generator for all users in this domain."""
|
||||
first_page = self.RetrievePageOfUsers(num_retries=num_retries, delay=delay,
|
||||
backoff=backoff)
|
||||
return self.GetGeneratorFromLinkFinder(
|
||||
first_page, gdata.apps.UserFeedFromString, num_retries=num_retries,
|
||||
delay=delay, backoff=backoff)
|
||||
|
||||
def RetrieveAllUsers(self):
|
||||
"""Retrieve all users in this domain. OBSOLETE"""
|
||||
|
||||
ret = self.RetrievePageOfUsers()
|
||||
# pagination
|
||||
return self.AddAllElementsFromAllPages(
|
||||
ret, gdata.apps.UserFeedFromString)
|
||||
|
||||
|
||||
class PropertyService(gdata.service.GDataService):
|
||||
"""Client for the Google Apps Property service."""
|
||||
|
||||
def __init__(self, email=None, password=None, domain=None, source=None,
|
||||
server='apps-apis.google.com', additional_headers=None):
|
||||
gdata.service.GDataService.__init__(self, email=email, password=password,
|
||||
service='apps', source=source,
|
||||
server=server,
|
||||
additional_headers=additional_headers)
|
||||
self.ssl = True
|
||||
self.port = 443
|
||||
self.domain = domain
|
||||
|
||||
def AddAllElementsFromAllPages(self, link_finder, func):
|
||||
"""retrieve all pages and add all elements"""
|
||||
next = link_finder.GetNextLink()
|
||||
count = 0
|
||||
while next is not None:
|
||||
next_feed = self.Get(next.href, converter=func)
|
||||
count = count + len(next_feed.entry)
|
||||
for a_entry in next_feed.entry:
|
||||
link_finder.entry.append(a_entry)
|
||||
next = next_feed.GetNextLink()
|
||||
return link_finder
|
||||
|
||||
def _GetPropertyEntry(self, properties):
|
||||
property_entry = gdata.apps.PropertyEntry()
|
||||
property = []
|
||||
for name, value in properties.iteritems():
|
||||
if name is not None and value is not None:
|
||||
property.append(gdata.apps.Property(name=name, value=value))
|
||||
property_entry.property = property
|
||||
return property_entry
|
||||
|
||||
def _PropertyEntry2Dict(self, property_entry):
|
||||
properties = {}
|
||||
for i, property in enumerate(property_entry.property):
|
||||
properties[property.name] = property.value
|
||||
return properties
|
||||
|
||||
def _GetPropertyFeed(self, uri):
|
||||
try:
|
||||
return gdata.apps.PropertyFeedFromString(str(self.Get(uri)))
|
||||
except gdata.service.RequestError, e:
|
||||
raise gdata.apps.service.AppsForYourDomainException(e.args[0])
|
||||
|
||||
def _GetPropertiesList(self, uri):
|
||||
property_feed = self._GetPropertyFeed(uri)
|
||||
# pagination
|
||||
property_feed = self.AddAllElementsFromAllPages(
|
||||
property_feed, gdata.apps.PropertyFeedFromString)
|
||||
properties_list = []
|
||||
for property_entry in property_feed.entry:
|
||||
properties_list.append(self._PropertyEntry2Dict(property_entry))
|
||||
return properties_list
|
||||
|
||||
def _GetProperties(self, uri):
|
||||
try:
|
||||
return self._PropertyEntry2Dict(gdata.apps.PropertyEntryFromString(
|
||||
str(self.Get(uri))))
|
||||
except gdata.service.RequestError, e:
|
||||
raise gdata.apps.service.AppsForYourDomainException(e.args[0])
|
||||
|
||||
def _PostProperties(self, uri, properties):
|
||||
property_entry = self._GetPropertyEntry(properties)
|
||||
try:
|
||||
return self._PropertyEntry2Dict(gdata.apps.PropertyEntryFromString(
|
||||
str(self.Post(property_entry, uri))))
|
||||
except gdata.service.RequestError, e:
|
||||
raise gdata.apps.service.AppsForYourDomainException(e.args[0])
|
||||
|
||||
def _PutProperties(self, uri, properties):
|
||||
property_entry = self._GetPropertyEntry(properties)
|
||||
try:
|
||||
return self._PropertyEntry2Dict(gdata.apps.PropertyEntryFromString(
|
||||
str(self.Put(property_entry, uri))))
|
||||
except gdata.service.RequestError, e:
|
||||
raise gdata.apps.service.AppsForYourDomainException(e.args[0])
|
||||
|
||||
def _DeleteProperties(self, uri):
|
||||
try:
|
||||
self.Delete(uri)
|
||||
except gdata.service.RequestError, e:
|
||||
raise gdata.apps.service.AppsForYourDomainException(e.args[0])
|
||||
|
||||
|
||||
def _bool2str(b):
|
||||
if b is None:
|
||||
return None
|
||||
return str(b is True).lower()
|
||||
952
gdata/auth.py
952
gdata/auth.py
@@ -1,952 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (C) 2007 - 2009 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import cgi
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
import types
|
||||
import urllib
|
||||
import atom.http_interface
|
||||
import atom.token_store
|
||||
import atom.url
|
||||
import gdata.oauth as oauth
|
||||
import gdata.oauth.rsa as oauth_rsa
|
||||
import gdata.tlslite.utils.keyfactory as keyfactory
|
||||
import gdata.tlslite.utils.cryptomath as cryptomath
|
||||
|
||||
import gdata.gauth
|
||||
|
||||
__author__ = 'api.jscudder (Jeff Scudder)'
|
||||
|
||||
|
||||
PROGRAMMATIC_AUTH_LABEL = 'GoogleLogin auth='
|
||||
AUTHSUB_AUTH_LABEL = 'AuthSub token='
|
||||
|
||||
|
||||
"""This module provides functions and objects used with Google authentication.
|
||||
|
||||
Details on Google authorization mechanisms used with the Google Data APIs can
|
||||
be found here:
|
||||
http://code.google.com/apis/gdata/auth.html
|
||||
http://code.google.com/apis/accounts/
|
||||
|
||||
The essential functions are the following.
|
||||
Related to ClientLogin:
|
||||
generate_client_login_request_body: Constructs the body of an HTTP request to
|
||||
obtain a ClientLogin token for a specific
|
||||
service.
|
||||
extract_client_login_token: Creates a ClientLoginToken with the token from a
|
||||
success response to a ClientLogin request.
|
||||
get_captcha_challenge: If the server responded to the ClientLogin request
|
||||
with a CAPTCHA challenge, this method extracts the
|
||||
CAPTCHA URL and identifying CAPTCHA token.
|
||||
|
||||
Related to AuthSub:
|
||||
generate_auth_sub_url: Constructs a full URL for a AuthSub request. The
|
||||
user's browser must be sent to this Google Accounts
|
||||
URL and redirected back to the app to obtain the
|
||||
AuthSub token.
|
||||
extract_auth_sub_token_from_url: Once the user's browser has been
|
||||
redirected back to the web app, use this
|
||||
function to create an AuthSubToken with
|
||||
the correct authorization token and scope.
|
||||
token_from_http_body: Extracts the AuthSubToken value string from the
|
||||
server's response to an AuthSub session token upgrade
|
||||
request.
|
||||
"""
|
||||
|
||||
def generate_client_login_request_body(email, password, service, source,
|
||||
account_type='HOSTED_OR_GOOGLE', captcha_token=None,
|
||||
captcha_response=None):
|
||||
"""Creates the body of the autentication request
|
||||
|
||||
See http://code.google.com/apis/accounts/AuthForInstalledApps.html#Request
|
||||
for more details.
|
||||
|
||||
Args:
|
||||
email: str
|
||||
password: str
|
||||
service: str
|
||||
source: str
|
||||
account_type: str (optional) Defaul is 'HOSTED_OR_GOOGLE', other valid
|
||||
values are 'GOOGLE' and 'HOSTED'
|
||||
captcha_token: str (optional)
|
||||
captcha_response: str (optional)
|
||||
|
||||
Returns:
|
||||
The HTTP body to send in a request for a client login token.
|
||||
"""
|
||||
return gdata.gauth.generate_client_login_request_body(email, password,
|
||||
service, source, account_type, captcha_token, captcha_response)
|
||||
|
||||
|
||||
GenerateClientLoginRequestBody = generate_client_login_request_body
|
||||
|
||||
|
||||
def GenerateClientLoginAuthToken(http_body):
|
||||
"""Returns the token value to use in Authorization headers.
|
||||
|
||||
Reads the token from the server's response to a Client Login request and
|
||||
creates header value to use in requests.
|
||||
|
||||
Args:
|
||||
http_body: str The body of the server's HTTP response to a Client Login
|
||||
request
|
||||
|
||||
Returns:
|
||||
The value half of an Authorization header.
|
||||
"""
|
||||
token = get_client_login_token(http_body)
|
||||
if token:
|
||||
return 'GoogleLogin auth=%s' % token
|
||||
return None
|
||||
|
||||
|
||||
def get_client_login_token(http_body):
|
||||
"""Returns the token value for a ClientLoginToken.
|
||||
|
||||
Reads the token from the server's response to a Client Login request and
|
||||
creates the token value string to use in requests.
|
||||
|
||||
Args:
|
||||
http_body: str The body of the server's HTTP response to a Client Login
|
||||
request
|
||||
|
||||
Returns:
|
||||
The token value string for a ClientLoginToken.
|
||||
"""
|
||||
return gdata.gauth.get_client_login_token_string(http_body)
|
||||
|
||||
|
||||
def extract_client_login_token(http_body, scopes):
|
||||
"""Parses the server's response and returns a ClientLoginToken.
|
||||
|
||||
Args:
|
||||
http_body: str The body of the server's HTTP response to a Client Login
|
||||
request. It is assumed that the login request was successful.
|
||||
scopes: list containing atom.url.Urls or strs. The scopes list contains
|
||||
all of the partial URLs under which the client login token is
|
||||
valid. For example, if scopes contains ['http://example.com/foo']
|
||||
then the client login token would be valid for
|
||||
http://example.com/foo/bar/baz
|
||||
|
||||
Returns:
|
||||
A ClientLoginToken which is valid for the specified scopes.
|
||||
"""
|
||||
token_string = get_client_login_token(http_body)
|
||||
token = ClientLoginToken(scopes=scopes)
|
||||
token.set_token_string(token_string)
|
||||
return token
|
||||
|
||||
|
||||
def get_captcha_challenge(http_body,
|
||||
captcha_base_url='http://www.google.com/accounts/'):
|
||||
"""Returns the URL and token for a CAPTCHA challenge issued by the server.
|
||||
|
||||
Args:
|
||||
http_body: str The body of the HTTP response from the server which
|
||||
contains the CAPTCHA challenge.
|
||||
captcha_base_url: str This function returns a full URL for viewing the
|
||||
challenge image which is built from the server's response. This
|
||||
base_url is used as the beginning of the URL because the server
|
||||
only provides the end of the URL. For example the server provides
|
||||
'Captcha?ctoken=Hi...N' and the URL for the image is
|
||||
'http://www.google.com/accounts/Captcha?ctoken=Hi...N'
|
||||
|
||||
Returns:
|
||||
A dictionary containing the information needed to repond to the CAPTCHA
|
||||
challenge, the image URL and the ID token of the challenge. The
|
||||
dictionary is in the form:
|
||||
{'token': string identifying the CAPTCHA image,
|
||||
'url': string containing the URL of the image}
|
||||
Returns None if there was no CAPTCHA challenge in the response.
|
||||
"""
|
||||
return gdata.gauth.get_captcha_challenge(http_body, captcha_base_url)
|
||||
|
||||
|
||||
GetCaptchaChallenge = get_captcha_challenge
|
||||
|
||||
|
||||
def GenerateOAuthRequestTokenUrl(
|
||||
oauth_input_params, scopes,
|
||||
request_token_url='https://www.google.com/accounts/OAuthGetRequestToken',
|
||||
extra_parameters=None):
|
||||
"""Generate a URL at which a request for OAuth request token is to be sent.
|
||||
|
||||
Args:
|
||||
oauth_input_params: OAuthInputParams OAuth input parameters.
|
||||
scopes: list of strings The URLs of the services to be accessed.
|
||||
request_token_url: string The beginning of the request token URL. This is
|
||||
normally 'https://www.google.com/accounts/OAuthGetRequestToken' or
|
||||
'/accounts/OAuthGetRequestToken'
|
||||
extra_parameters: dict (optional) key-value pairs as any additional
|
||||
parameters to be included in the URL and signature while making a
|
||||
request for fetching an OAuth request token. All the OAuth parameters
|
||||
are added by default. But if provided through this argument, any
|
||||
default parameters will be overwritten. For e.g. a default parameter
|
||||
oauth_version 1.0 can be overwritten if
|
||||
extra_parameters = {'oauth_version': '2.0'}
|
||||
|
||||
Returns:
|
||||
atom.url.Url OAuth request token URL.
|
||||
"""
|
||||
scopes_string = ' '.join([str(scope) for scope in scopes])
|
||||
parameters = {'scope': scopes_string}
|
||||
if extra_parameters:
|
||||
parameters.update(extra_parameters)
|
||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(
|
||||
oauth_input_params.GetConsumer(), http_url=request_token_url,
|
||||
parameters=parameters)
|
||||
oauth_request.sign_request(oauth_input_params.GetSignatureMethod(),
|
||||
oauth_input_params.GetConsumer(), None)
|
||||
return atom.url.parse_url(oauth_request.to_url())
|
||||
|
||||
|
||||
def GenerateOAuthAuthorizationUrl(
|
||||
request_token,
|
||||
authorization_url='https://www.google.com/accounts/OAuthAuthorizeToken',
|
||||
callback_url=None, extra_params=None,
|
||||
include_scopes_in_callback=False, scopes_param_prefix='oauth_token_scope'):
|
||||
"""Generates URL at which user will login to authorize the request token.
|
||||
|
||||
Args:
|
||||
request_token: gdata.auth.OAuthToken OAuth request token.
|
||||
authorization_url: string The beginning of the authorization URL. This is
|
||||
normally 'https://www.google.com/accounts/OAuthAuthorizeToken' or
|
||||
'/accounts/OAuthAuthorizeToken'
|
||||
callback_url: string (optional) The URL user will be sent to after
|
||||
logging in and granting access.
|
||||
extra_params: dict (optional) Additional parameters to be sent.
|
||||
include_scopes_in_callback: Boolean (default=False) if set to True, and
|
||||
if 'callback_url' is present, the 'callback_url' will be modified to
|
||||
include the scope(s) from the request token as a URL parameter. The
|
||||
key for the 'callback' URL's scope parameter will be
|
||||
OAUTH_SCOPE_URL_PARAM_NAME. The benefit of including the scope URL as
|
||||
a parameter to the 'callback' URL, is that the page which receives
|
||||
the OAuth token will be able to tell which URLs the token grants
|
||||
access to.
|
||||
scopes_param_prefix: string (default='oauth_token_scope') The URL
|
||||
parameter key which maps to the list of valid scopes for the token.
|
||||
This URL parameter will be included in the callback URL along with
|
||||
the scopes of the token as value if include_scopes_in_callback=True.
|
||||
|
||||
Returns:
|
||||
atom.url.Url OAuth authorization URL.
|
||||
"""
|
||||
scopes = request_token.scopes
|
||||
if isinstance(scopes, list):
|
||||
scopes = ' '.join(scopes)
|
||||
if include_scopes_in_callback and callback_url:
|
||||
if callback_url.find('?') > -1:
|
||||
callback_url += '&'
|
||||
else:
|
||||
callback_url += '?'
|
||||
callback_url += urllib.urlencode({scopes_param_prefix:scopes})
|
||||
oauth_token = oauth.OAuthToken(request_token.key, request_token.secret)
|
||||
oauth_request = oauth.OAuthRequest.from_token_and_callback(
|
||||
token=oauth_token, callback=callback_url,
|
||||
http_url=authorization_url, parameters=extra_params)
|
||||
return atom.url.parse_url(oauth_request.to_url())
|
||||
|
||||
|
||||
def GenerateOAuthAccessTokenUrl(
|
||||
authorized_request_token,
|
||||
oauth_input_params,
|
||||
access_token_url='https://www.google.com/accounts/OAuthGetAccessToken',
|
||||
oauth_version='1.0',
|
||||
oauth_verifier=None):
|
||||
"""Generates URL at which user will login to authorize the request token.
|
||||
|
||||
Args:
|
||||
authorized_request_token: gdata.auth.OAuthToken OAuth authorized request
|
||||
token.
|
||||
oauth_input_params: OAuthInputParams OAuth input parameters.
|
||||
access_token_url: string The beginning of the authorization URL. This is
|
||||
normally 'https://www.google.com/accounts/OAuthGetAccessToken' or
|
||||
'/accounts/OAuthGetAccessToken'
|
||||
oauth_version: str (default='1.0') oauth_version parameter.
|
||||
oauth_verifier: str (optional) If present, it is assumed that the client
|
||||
will use the OAuth v1.0a protocol which includes passing the
|
||||
oauth_verifier (as returned by the SP) in the access token step.
|
||||
|
||||
Returns:
|
||||
atom.url.Url OAuth access token URL.
|
||||
"""
|
||||
oauth_token = oauth.OAuthToken(authorized_request_token.key,
|
||||
authorized_request_token.secret)
|
||||
parameters = {'oauth_version': oauth_version}
|
||||
if oauth_verifier is not None:
|
||||
parameters['oauth_verifier'] = oauth_verifier
|
||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(
|
||||
oauth_input_params.GetConsumer(), token=oauth_token,
|
||||
http_url=access_token_url, parameters=parameters)
|
||||
oauth_request.sign_request(oauth_input_params.GetSignatureMethod(),
|
||||
oauth_input_params.GetConsumer(), oauth_token)
|
||||
return atom.url.parse_url(oauth_request.to_url())
|
||||
|
||||
|
||||
def GenerateAuthSubUrl(next, scope, secure=False, session=True,
|
||||
request_url='https://www.google.com/accounts/AuthSubRequest',
|
||||
domain='default'):
|
||||
"""Generate a URL at which the user will login and be redirected back.
|
||||
|
||||
Users enter their credentials on a Google login page and a token is sent
|
||||
to the URL specified in next. See documentation for AuthSub login at:
|
||||
http://code.google.com/apis/accounts/AuthForWebApps.html
|
||||
|
||||
Args:
|
||||
request_url: str The beginning of the request URL. This is normally
|
||||
'http://www.google.com/accounts/AuthSubRequest' or
|
||||
'/accounts/AuthSubRequest'
|
||||
next: string The URL user will be sent to after logging in.
|
||||
scope: string The URL of the service to be accessed.
|
||||
secure: boolean (optional) Determines whether or not the issued token
|
||||
is a secure token.
|
||||
session: boolean (optional) Determines whether or not the issued token
|
||||
can be upgraded to a session token.
|
||||
domain: str (optional) The Google Apps domain for this account. If this
|
||||
is not a Google Apps account, use 'default' which is the default
|
||||
value.
|
||||
"""
|
||||
# Translate True/False values for parameters into numeric values acceoted
|
||||
# by the AuthSub service.
|
||||
if secure:
|
||||
secure = 1
|
||||
else:
|
||||
secure = 0
|
||||
|
||||
if session:
|
||||
session = 1
|
||||
else:
|
||||
session = 0
|
||||
|
||||
request_params = urllib.urlencode({'next': next, 'scope': scope,
|
||||
'secure': secure, 'session': session,
|
||||
'hd': domain})
|
||||
if request_url.find('?') == -1:
|
||||
return '%s?%s' % (request_url, request_params)
|
||||
else:
|
||||
# The request URL already contained url parameters so we should add
|
||||
# the parameters using the & seperator
|
||||
return '%s&%s' % (request_url, request_params)
|
||||
|
||||
|
||||
def generate_auth_sub_url(next, scopes, secure=False, session=True,
|
||||
request_url='https://www.google.com/accounts/AuthSubRequest',
|
||||
domain='default', scopes_param_prefix='auth_sub_scopes'):
|
||||
"""Constructs a URL string for requesting a multiscope AuthSub token.
|
||||
|
||||
The generated token will contain a URL parameter to pass along the
|
||||
requested scopes to the next URL. When the Google Accounts page
|
||||
redirects the broswser to the 'next' URL, it appends the single use
|
||||
AuthSub token value to the URL as a URL parameter with the key 'token'.
|
||||
However, the information about which scopes were requested is not
|
||||
included by Google Accounts. This method adds the scopes to the next
|
||||
URL before making the request so that the redirect will be sent to
|
||||
a page, and both the token value and the list of scopes can be
|
||||
extracted from the request URL.
|
||||
|
||||
Args:
|
||||
next: atom.url.URL or string The URL user will be sent to after
|
||||
authorizing this web application to access their data.
|
||||
scopes: list containint strings The URLs of the services to be accessed.
|
||||
secure: boolean (optional) Determines whether or not the issued token
|
||||
is a secure token.
|
||||
session: boolean (optional) Determines whether or not the issued token
|
||||
can be upgraded to a session token.
|
||||
request_url: atom.url.Url or str The beginning of the request URL. This
|
||||
is normally 'http://www.google.com/accounts/AuthSubRequest' or
|
||||
'/accounts/AuthSubRequest'
|
||||
domain: The domain which the account is part of. This is used for Google
|
||||
Apps accounts, the default value is 'default' which means that the
|
||||
requested account is a Google Account (@gmail.com for example)
|
||||
scopes_param_prefix: str (optional) The requested scopes are added as a
|
||||
URL parameter to the next URL so that the page at the 'next' URL can
|
||||
extract the token value and the valid scopes from the URL. The key
|
||||
for the URL parameter defaults to 'auth_sub_scopes'
|
||||
|
||||
Returns:
|
||||
An atom.url.Url which the user's browser should be directed to in order
|
||||
to authorize this application to access their information.
|
||||
"""
|
||||
if isinstance(next, (str, unicode)):
|
||||
next = atom.url.parse_url(next)
|
||||
scopes_string = ' '.join([str(scope) for scope in scopes])
|
||||
next.params[scopes_param_prefix] = scopes_string
|
||||
|
||||
if isinstance(request_url, (str, unicode)):
|
||||
request_url = atom.url.parse_url(request_url)
|
||||
request_url.params['next'] = str(next)
|
||||
request_url.params['scope'] = scopes_string
|
||||
if session:
|
||||
request_url.params['session'] = 1
|
||||
else:
|
||||
request_url.params['session'] = 0
|
||||
if secure:
|
||||
request_url.params['secure'] = 1
|
||||
else:
|
||||
request_url.params['secure'] = 0
|
||||
request_url.params['hd'] = domain
|
||||
return request_url
|
||||
|
||||
|
||||
def AuthSubTokenFromUrl(url):
|
||||
"""Extracts the AuthSub token from the URL.
|
||||
|
||||
Used after the AuthSub redirect has sent the user to the 'next' page and
|
||||
appended the token to the URL. This function returns the value to be used
|
||||
in the Authorization header.
|
||||
|
||||
Args:
|
||||
url: str The URL of the current page which contains the AuthSub token as
|
||||
a URL parameter.
|
||||
"""
|
||||
token = TokenFromUrl(url)
|
||||
if token:
|
||||
return 'AuthSub token=%s' % token
|
||||
return None
|
||||
|
||||
|
||||
def TokenFromUrl(url):
|
||||
"""Extracts the AuthSub token from the URL.
|
||||
|
||||
Returns the raw token value.
|
||||
|
||||
Args:
|
||||
url: str The URL or the query portion of the URL string (after the ?) of
|
||||
the current page which contains the AuthSub token as a URL parameter.
|
||||
"""
|
||||
if url.find('?') > -1:
|
||||
query_params = url.split('?')[1]
|
||||
else:
|
||||
query_params = url
|
||||
for pair in query_params.split('&'):
|
||||
if pair.startswith('token='):
|
||||
return pair[6:]
|
||||
return None
|
||||
|
||||
|
||||
def extract_auth_sub_token_from_url(url,
|
||||
scopes_param_prefix='auth_sub_scopes', rsa_key=None):
|
||||
"""Creates an AuthSubToken and sets the token value and scopes from the URL.
|
||||
|
||||
After the Google Accounts AuthSub pages redirect the user's broswer back to
|
||||
the web application (using the 'next' URL from the request) the web app must
|
||||
extract the token from the current page's URL. The token is provided as a
|
||||
URL parameter named 'token' and if generate_auth_sub_url was used to create
|
||||
the request, the token's valid scopes are included in a URL parameter whose
|
||||
name is specified in scopes_param_prefix.
|
||||
|
||||
Args:
|
||||
url: atom.url.Url or str representing the current URL. The token value
|
||||
and valid scopes should be included as URL parameters.
|
||||
scopes_param_prefix: str (optional) The URL parameter key which maps to
|
||||
the list of valid scopes for the token.
|
||||
|
||||
Returns:
|
||||
An AuthSubToken with the token value from the URL and set to be valid for
|
||||
the scopes passed in on the URL. If no scopes were included in the URL,
|
||||
the AuthSubToken defaults to being valid for no scopes. If there was no
|
||||
'token' parameter in the URL, this function returns None.
|
||||
"""
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
if 'token' not in url.params:
|
||||
return None
|
||||
scopes = []
|
||||
if scopes_param_prefix in url.params:
|
||||
scopes = url.params[scopes_param_prefix].split(' ')
|
||||
token_value = url.params['token']
|
||||
if rsa_key:
|
||||
token = SecureAuthSubToken(rsa_key, scopes=scopes)
|
||||
else:
|
||||
token = AuthSubToken(scopes=scopes)
|
||||
token.set_token_string(token_value)
|
||||
return token
|
||||
|
||||
|
||||
def AuthSubTokenFromHttpBody(http_body):
|
||||
"""Extracts the AuthSub token from an HTTP body string.
|
||||
|
||||
Used to find the new session token after making a request to upgrade a
|
||||
single use AuthSub token.
|
||||
|
||||
Args:
|
||||
http_body: str The repsonse from the server which contains the AuthSub
|
||||
key. For example, this function would find the new session token
|
||||
from the server's response to an upgrade token request.
|
||||
|
||||
Returns:
|
||||
The header value to use for Authorization which contains the AuthSub
|
||||
token.
|
||||
"""
|
||||
token_value = token_from_http_body(http_body)
|
||||
if token_value:
|
||||
return '%s%s' % (AUTHSUB_AUTH_LABEL, token_value)
|
||||
return None
|
||||
|
||||
|
||||
def token_from_http_body(http_body):
|
||||
"""Extracts the AuthSub token from an HTTP body string.
|
||||
|
||||
Used to find the new session token after making a request to upgrade a
|
||||
single use AuthSub token.
|
||||
|
||||
Args:
|
||||
http_body: str The repsonse from the server which contains the AuthSub
|
||||
key. For example, this function would find the new session token
|
||||
from the server's response to an upgrade token request.
|
||||
|
||||
Returns:
|
||||
The raw token value to use in an AuthSubToken object.
|
||||
"""
|
||||
for response_line in http_body.splitlines():
|
||||
if response_line.startswith('Token='):
|
||||
# Strip off Token= and return the token value string.
|
||||
return response_line[6:]
|
||||
return None
|
||||
|
||||
|
||||
TokenFromHttpBody = token_from_http_body
|
||||
|
||||
|
||||
def OAuthTokenFromUrl(url, scopes_param_prefix='oauth_token_scope'):
|
||||
"""Creates an OAuthToken and sets token key and scopes (if present) from URL.
|
||||
|
||||
After the Google Accounts OAuth pages redirect the user's broswer back to
|
||||
the web application (using the 'callback' URL from the request) the web app
|
||||
can extract the token from the current page's URL. The token is same as the
|
||||
request token, but it is either authorized (if user grants access) or
|
||||
unauthorized (if user denies access). The token is provided as a
|
||||
URL parameter named 'oauth_token' and if it was chosen to use
|
||||
GenerateOAuthAuthorizationUrl with include_scopes_in_param=True, the token's
|
||||
valid scopes are included in a URL parameter whose name is specified in
|
||||
scopes_param_prefix.
|
||||
|
||||
Args:
|
||||
url: atom.url.Url or str representing the current URL. The token value
|
||||
and valid scopes should be included as URL parameters.
|
||||
scopes_param_prefix: str (optional) The URL parameter key which maps to
|
||||
the list of valid scopes for the token.
|
||||
|
||||
Returns:
|
||||
An OAuthToken with the token key from the URL and set to be valid for
|
||||
the scopes passed in on the URL. If no scopes were included in the URL,
|
||||
the OAuthToken defaults to being valid for no scopes. If there was no
|
||||
'oauth_token' parameter in the URL, this function returns None.
|
||||
"""
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
if 'oauth_token' not in url.params:
|
||||
return None
|
||||
scopes = []
|
||||
if scopes_param_prefix in url.params:
|
||||
scopes = url.params[scopes_param_prefix].split(' ')
|
||||
token_key = url.params['oauth_token']
|
||||
token = OAuthToken(key=token_key, scopes=scopes)
|
||||
return token
|
||||
|
||||
|
||||
def OAuthTokenFromHttpBody(http_body):
|
||||
"""Parses the HTTP response body and returns an OAuth token.
|
||||
|
||||
The returned OAuth token will just have key and secret parameters set.
|
||||
It won't have any knowledge about the scopes or oauth_input_params. It is
|
||||
your responsibility to make it aware of the remaining parameters.
|
||||
|
||||
Returns:
|
||||
OAuthToken OAuth token.
|
||||
"""
|
||||
token = oauth.OAuthToken.from_string(http_body)
|
||||
oauth_token = OAuthToken(key=token.key, secret=token.secret)
|
||||
return oauth_token
|
||||
|
||||
|
||||
class OAuthSignatureMethod(object):
|
||||
"""Holds valid OAuth signature methods.
|
||||
|
||||
RSA_SHA1: Class to build signature according to RSA-SHA1 algorithm.
|
||||
HMAC_SHA1: Class to build signature according to HMAC-SHA1 algorithm.
|
||||
"""
|
||||
|
||||
HMAC_SHA1 = oauth.OAuthSignatureMethod_HMAC_SHA1
|
||||
|
||||
class RSA_SHA1(oauth_rsa.OAuthSignatureMethod_RSA_SHA1):
|
||||
"""Provides implementation for abstract methods to return RSA certs."""
|
||||
|
||||
def __init__(self, private_key, public_cert):
|
||||
self.private_key = private_key
|
||||
self.public_cert = public_cert
|
||||
|
||||
def _fetch_public_cert(self, unused_oauth_request):
|
||||
return self.public_cert
|
||||
|
||||
def _fetch_private_cert(self, unused_oauth_request):
|
||||
return self.private_key
|
||||
|
||||
|
||||
class OAuthInputParams(object):
|
||||
"""Stores OAuth input parameters.
|
||||
|
||||
This class is a store for OAuth input parameters viz. consumer key and secret,
|
||||
signature method and RSA key.
|
||||
"""
|
||||
|
||||
def __init__(self, signature_method, consumer_key, consumer_secret=None,
|
||||
rsa_key=None, requestor_id=None):
|
||||
"""Initializes object with parameters required for using OAuth mechanism.
|
||||
|
||||
NOTE: Though consumer_secret and rsa_key are optional, either of the two
|
||||
is required depending on the value of the signature_method.
|
||||
|
||||
Args:
|
||||
signature_method: class which provides implementation for strategy class
|
||||
oauth.oauth.OAuthSignatureMethod. Signature method to be used for
|
||||
signing each request. Valid implementations are provided as the
|
||||
constants defined by gdata.auth.OAuthSignatureMethod. Currently
|
||||
they are gdata.auth.OAuthSignatureMethod.RSA_SHA1 and
|
||||
gdata.auth.OAuthSignatureMethod.HMAC_SHA1. Instead of passing in
|
||||
the strategy class, you may pass in a string for 'RSA_SHA1' or
|
||||
'HMAC_SHA1'. If you plan to use OAuth on App Engine (or another
|
||||
WSGI environment) I recommend specifying signature method using a
|
||||
string (the only options are 'RSA_SHA1' and 'HMAC_SHA1'). In these
|
||||
environments there are sometimes issues with pickling an object in
|
||||
which a member references a class or function. Storing a string to
|
||||
refer to the signature method mitigates complications when
|
||||
pickling.
|
||||
consumer_key: string Domain identifying third_party web application.
|
||||
consumer_secret: string (optional) Secret generated during registration.
|
||||
Required only for HMAC_SHA1 signature method.
|
||||
rsa_key: string (optional) Private key required for RSA_SHA1 signature
|
||||
method.
|
||||
requestor_id: string (optional) User email adress to make requests on
|
||||
their behalf. This parameter should only be set when performing
|
||||
2 legged OAuth requests.
|
||||
"""
|
||||
if (signature_method == OAuthSignatureMethod.RSA_SHA1
|
||||
or signature_method == 'RSA_SHA1'):
|
||||
self.__signature_strategy = 'RSA_SHA1'
|
||||
elif (signature_method == OAuthSignatureMethod.HMAC_SHA1
|
||||
or signature_method == 'HMAC_SHA1'):
|
||||
self.__signature_strategy = 'HMAC_SHA1'
|
||||
else:
|
||||
self.__signature_strategy = signature_method
|
||||
self.rsa_key = rsa_key
|
||||
self._consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
|
||||
self.requestor_id = requestor_id
|
||||
|
||||
def __get_signature_method(self):
|
||||
if self.__signature_strategy == 'RSA_SHA1':
|
||||
return OAuthSignatureMethod.RSA_SHA1(self.rsa_key, None)
|
||||
elif self.__signature_strategy == 'HMAC_SHA1':
|
||||
return OAuthSignatureMethod.HMAC_SHA1()
|
||||
else:
|
||||
return self.__signature_strategy()
|
||||
|
||||
def __set_signature_method(self, signature_method):
|
||||
if (signature_method == OAuthSignatureMethod.RSA_SHA1
|
||||
or signature_method == 'RSA_SHA1'):
|
||||
self.__signature_strategy = 'RSA_SHA1'
|
||||
elif (signature_method == OAuthSignatureMethod.HMAC_SHA1
|
||||
or signature_method == 'HMAC_SHA1'):
|
||||
self.__signature_strategy = 'HMAC_SHA1'
|
||||
else:
|
||||
self.__signature_strategy = signature_method
|
||||
|
||||
_signature_method = property(__get_signature_method, __set_signature_method,
|
||||
doc="""Returns object capable of signing the request using RSA of HMAC.
|
||||
|
||||
Replaces the _signature_method member to avoid pickle errors.""")
|
||||
|
||||
def GetSignatureMethod(self):
|
||||
"""Gets the OAuth signature method.
|
||||
|
||||
Returns:
|
||||
object of supertype <oauth.oauth.OAuthSignatureMethod>
|
||||
"""
|
||||
return self._signature_method
|
||||
|
||||
def GetConsumer(self):
|
||||
"""Gets the OAuth consumer.
|
||||
|
||||
Returns:
|
||||
object of type <oauth.oauth.Consumer>
|
||||
"""
|
||||
return self._consumer
|
||||
|
||||
|
||||
class ClientLoginToken(atom.http_interface.GenericToken):
|
||||
"""Stores the Authorization header in auth_header and adds to requests.
|
||||
|
||||
This token will add it's Authorization header to an HTTP request
|
||||
as it is made. Ths token class is simple but
|
||||
some Token classes must calculate portions of the Authorization header
|
||||
based on the request being made, which is why the token is responsible
|
||||
for making requests via an http_client parameter.
|
||||
|
||||
Args:
|
||||
auth_header: str The value for the Authorization header.
|
||||
scopes: list of str or atom.url.Url specifying the beginnings of URLs
|
||||
for which this token can be used. For example, if scopes contains
|
||||
'http://example.com/foo', then this token can be used for a request to
|
||||
'http://example.com/foo/bar' but it cannot be used for a request to
|
||||
'http://example.com/baz'
|
||||
"""
|
||||
def __init__(self, auth_header=None, scopes=None):
|
||||
self.auth_header = auth_header
|
||||
self.scopes = scopes or []
|
||||
|
||||
def __str__(self):
|
||||
return self.auth_header
|
||||
|
||||
def perform_request(self, http_client, operation, url, data=None,
|
||||
headers=None):
|
||||
"""Sets the Authorization header and makes the HTTP request."""
|
||||
if headers is None:
|
||||
headers = {'Authorization':self.auth_header}
|
||||
else:
|
||||
headers['Authorization'] = self.auth_header
|
||||
return http_client.request(operation, url, data=data, headers=headers)
|
||||
|
||||
def get_token_string(self):
|
||||
"""Removes PROGRAMMATIC_AUTH_LABEL to give just the token value."""
|
||||
return self.auth_header[len(PROGRAMMATIC_AUTH_LABEL):]
|
||||
|
||||
def set_token_string(self, token_string):
|
||||
self.auth_header = '%s%s' % (PROGRAMMATIC_AUTH_LABEL, token_string)
|
||||
|
||||
def valid_for_scope(self, url):
|
||||
"""Tells the caller if the token authorizes access to the desired URL.
|
||||
"""
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
for scope in self.scopes:
|
||||
if scope == atom.token_store.SCOPE_ALL:
|
||||
return True
|
||||
if isinstance(scope, (str, unicode)):
|
||||
scope = atom.url.parse_url(scope)
|
||||
if scope == url:
|
||||
return True
|
||||
# Check the host and the path, but ignore the port and protocol.
|
||||
elif scope.host == url.host and not scope.path:
|
||||
return True
|
||||
elif scope.host == url.host and scope.path and not url.path:
|
||||
continue
|
||||
elif scope.host == url.host and url.path.startswith(scope.path):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class AuthSubToken(ClientLoginToken):
|
||||
def get_token_string(self):
|
||||
"""Removes AUTHSUB_AUTH_LABEL to give just the token value."""
|
||||
return self.auth_header[len(AUTHSUB_AUTH_LABEL):]
|
||||
|
||||
def set_token_string(self, token_string):
|
||||
self.auth_header = '%s%s' % (AUTHSUB_AUTH_LABEL, token_string)
|
||||
|
||||
|
||||
class OAuthToken(atom.http_interface.GenericToken):
|
||||
"""Stores the token key, token secret and scopes for which token is valid.
|
||||
|
||||
This token adds the authorization header to each request made. It
|
||||
re-calculates authorization header for every request since the OAuth
|
||||
signature to be added to the authorization header is dependent on the
|
||||
request parameters.
|
||||
|
||||
Attributes:
|
||||
key: str The value for the OAuth token i.e. token key.
|
||||
secret: str The value for the OAuth token secret.
|
||||
scopes: list of str or atom.url.Url specifying the beginnings of URLs
|
||||
for which this token can be used. For example, if scopes contains
|
||||
'http://example.com/foo', then this token can be used for a request to
|
||||
'http://example.com/foo/bar' but it cannot be used for a request to
|
||||
'http://example.com/baz'
|
||||
oauth_input_params: OAuthInputParams OAuth input parameters.
|
||||
"""
|
||||
|
||||
def __init__(self, key=None, secret=None, scopes=None,
|
||||
oauth_input_params=None):
|
||||
self.key = key
|
||||
self.secret = secret
|
||||
self.scopes = scopes or []
|
||||
self.oauth_input_params = oauth_input_params
|
||||
|
||||
def __str__(self):
|
||||
return self.get_token_string()
|
||||
|
||||
def get_token_string(self):
|
||||
"""Returns the token string.
|
||||
|
||||
The token string returned is of format
|
||||
oauth_token=[0]&oauth_token_secret=[1], where [0] and [1] are some strings.
|
||||
|
||||
Returns:
|
||||
A token string of format oauth_token=[0]&oauth_token_secret=[1],
|
||||
where [0] and [1] are some strings. If self.secret is absent, it just
|
||||
returns oauth_token=[0]. If self.key is absent, it just returns
|
||||
oauth_token_secret=[1]. If both are absent, it returns None.
|
||||
"""
|
||||
if self.key and self.secret:
|
||||
return urllib.urlencode({'oauth_token': self.key,
|
||||
'oauth_token_secret': self.secret})
|
||||
elif self.key:
|
||||
return 'oauth_token=%s' % self.key
|
||||
elif self.secret:
|
||||
return 'oauth_token_secret=%s' % self.secret
|
||||
else:
|
||||
return None
|
||||
|
||||
def set_token_string(self, token_string):
|
||||
"""Sets the token key and secret from the token string.
|
||||
|
||||
Args:
|
||||
token_string: str Token string of form
|
||||
oauth_token=[0]&oauth_token_secret=[1]. If oauth_token is not present,
|
||||
self.key will be None. If oauth_token_secret is not present,
|
||||
self.secret will be None.
|
||||
"""
|
||||
token_params = cgi.parse_qs(token_string, keep_blank_values=False)
|
||||
if 'oauth_token' in token_params:
|
||||
self.key = token_params['oauth_token'][0]
|
||||
if 'oauth_token_secret' in token_params:
|
||||
self.secret = token_params['oauth_token_secret'][0]
|
||||
|
||||
def GetAuthHeader(self, http_method, http_url, realm=''):
|
||||
"""Get the authentication header.
|
||||
|
||||
Args:
|
||||
http_method: string HTTP method i.e. operation e.g. GET, POST, PUT, etc.
|
||||
http_url: string or atom.url.Url HTTP URL to which request is made.
|
||||
realm: string (default='') realm parameter to be included in the
|
||||
authorization header.
|
||||
|
||||
Returns:
|
||||
dict Header to be sent with every subsequent request after
|
||||
authentication.
|
||||
"""
|
||||
if isinstance(http_url, types.StringTypes):
|
||||
http_url = atom.url.parse_url(http_url)
|
||||
header = None
|
||||
token = None
|
||||
if self.key or self.secret:
|
||||
token = oauth.OAuthToken(self.key, self.secret)
|
||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(
|
||||
self.oauth_input_params.GetConsumer(), token=token,
|
||||
http_url=str(http_url), http_method=http_method,
|
||||
parameters=http_url.params)
|
||||
oauth_request.sign_request(self.oauth_input_params.GetSignatureMethod(),
|
||||
self.oauth_input_params.GetConsumer(), token)
|
||||
header = oauth_request.to_header(realm=realm)
|
||||
header['Authorization'] = header['Authorization'].replace('+', '%2B')
|
||||
return header
|
||||
|
||||
def perform_request(self, http_client, operation, url, data=None,
|
||||
headers=None):
|
||||
"""Sets the Authorization header and makes the HTTP request."""
|
||||
if not headers:
|
||||
headers = {}
|
||||
if self.oauth_input_params.requestor_id:
|
||||
url.params['xoauth_requestor_id'] = self.oauth_input_params.requestor_id
|
||||
headers.update(self.GetAuthHeader(operation, url))
|
||||
return http_client.request(operation, url, data=data, headers=headers)
|
||||
|
||||
def valid_for_scope(self, url):
|
||||
if isinstance(url, (str, unicode)):
|
||||
url = atom.url.parse_url(url)
|
||||
for scope in self.scopes:
|
||||
if scope == atom.token_store.SCOPE_ALL:
|
||||
return True
|
||||
if isinstance(scope, (str, unicode)):
|
||||
scope = atom.url.parse_url(scope)
|
||||
if scope == url:
|
||||
return True
|
||||
# Check the host and the path, but ignore the port and protocol.
|
||||
elif scope.host == url.host and not scope.path:
|
||||
return True
|
||||
elif scope.host == url.host and scope.path and not url.path:
|
||||
continue
|
||||
elif scope.host == url.host and url.path.startswith(scope.path):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class SecureAuthSubToken(AuthSubToken):
|
||||
"""Stores the rsa private key, token, and scopes for the secure AuthSub token.
|
||||
|
||||
This token adds the authorization header to each request made. It
|
||||
re-calculates authorization header for every request since the secure AuthSub
|
||||
signature to be added to the authorization header is dependent on the
|
||||
request parameters.
|
||||
|
||||
Attributes:
|
||||
rsa_key: string The RSA private key in PEM format that the token will
|
||||
use to sign requests
|
||||
token_string: string (optional) The value for the AuthSub token.
|
||||
scopes: list of str or atom.url.Url specifying the beginnings of URLs
|
||||
for which this token can be used. For example, if scopes contains
|
||||
'http://example.com/foo', then this token can be used for a request to
|
||||
'http://example.com/foo/bar' but it cannot be used for a request to
|
||||
'http://example.com/baz'
|
||||
"""
|
||||
|
||||
def __init__(self, rsa_key, token_string=None, scopes=None):
|
||||
self.rsa_key = keyfactory.parsePEMKey(rsa_key)
|
||||
self.token_string = token_string or ''
|
||||
self.scopes = scopes or []
|
||||
|
||||
def __str__(self):
|
||||
return self.get_token_string()
|
||||
|
||||
def get_token_string(self):
|
||||
return str(self.token_string)
|
||||
|
||||
def set_token_string(self, token_string):
|
||||
self.token_string = token_string
|
||||
|
||||
def GetAuthHeader(self, http_method, http_url):
|
||||
"""Generates the Authorization header.
|
||||
|
||||
The form of the secure AuthSub Authorization header is
|
||||
Authorization: AuthSub token="token" sigalg="sigalg" data="data" sig="sig"
|
||||
and data represents a string in the form
|
||||
data = http_method http_url timestamp nonce
|
||||
|
||||
Args:
|
||||
http_method: string HTTP method i.e. operation e.g. GET, POST, PUT, etc.
|
||||
http_url: string or atom.url.Url HTTP URL to which request is made.
|
||||
|
||||
Returns:
|
||||
dict Header to be sent with every subsequent request after authentication.
|
||||
"""
|
||||
timestamp = int(math.floor(time.time()))
|
||||
nonce = '%lu' % random.randrange(1, 2**64)
|
||||
data = '%s %s %d %s' % (http_method, str(http_url), timestamp, nonce)
|
||||
sig = cryptomath.bytesToBase64(self.rsa_key.hashAndSign(data))
|
||||
header = {'Authorization': '%s"%s" data="%s" sig="%s" sigalg="rsa-sha1"' %
|
||||
(AUTHSUB_AUTH_LABEL, self.token_string, data, sig)}
|
||||
return header
|
||||
|
||||
def perform_request(self, http_client, operation, url, data=None,
|
||||
headers=None):
|
||||
"""Sets the Authorization header and makes the HTTP request."""
|
||||
if not headers:
|
||||
headers = {}
|
||||
headers.update(self.GetAuthHeader(operation, url))
|
||||
return http_client.request(operation, url, data=data, headers=headers)
|
||||
1306
gdata/gauth.py
1306
gdata/gauth.py
File diff suppressed because it is too large
Load Diff
@@ -1,17 +0,0 @@
|
||||
1. Moved oauth.py to __init__.py
|
||||
|
||||
2. Refactored __init__.py for compatibility with python 2.2 (Issue 59)
|
||||
|
||||
3. Refactored rsa.py for compatibility with python 2.2 (Issue 59)
|
||||
|
||||
4. Refactored OAuthRequest.from_token_and_callback since the callback url was
|
||||
getting double url-encoding the callback url in place of single. (Issue 43)
|
||||
|
||||
5. Added build_signature_base_string method to rsa.py since it used the
|
||||
implementation of this method from oauth.OAuthSignatureMethod_HMAC_SHA1 which
|
||||
was incorrect since it enforced the presence of a consumer secret and a token
|
||||
secret. Also, changed its super class from oauth.OAuthSignatureMethod_HMAC_SHA1
|
||||
to oauth.OAuthSignatureMethod (Issue 64)
|
||||
|
||||
6. Refactored <OAuthRequest>.to_header method since it returned non-oauth params
|
||||
as well which was incorrect. (Issue 31)
|
||||
@@ -1,524 +0,0 @@
|
||||
import cgi
|
||||
import urllib
|
||||
import time
|
||||
import random
|
||||
import urlparse
|
||||
import hmac
|
||||
import binascii
|
||||
|
||||
VERSION = '1.0' # Hi Blaine!
|
||||
HTTP_METHOD = 'GET'
|
||||
SIGNATURE_METHOD = 'PLAINTEXT'
|
||||
|
||||
# Generic exception class
|
||||
class OAuthError(RuntimeError):
|
||||
def __init__(self, message='OAuth error occured.'):
|
||||
self.message = message
|
||||
|
||||
# optional WWW-Authenticate header (401 error)
|
||||
def build_authenticate_header(realm=''):
|
||||
return {'WWW-Authenticate': 'OAuth realm="%s"' % realm}
|
||||
|
||||
# url escape
|
||||
def escape(s):
|
||||
# escape '/' too
|
||||
return urllib.quote(s, safe='~')
|
||||
|
||||
# util function: current timestamp
|
||||
# seconds since epoch (UTC)
|
||||
def generate_timestamp():
|
||||
return int(time.time())
|
||||
|
||||
# util function: nonce
|
||||
# pseudorandom number
|
||||
def generate_nonce(length=8):
|
||||
return ''.join([str(random.randint(0, 9)) for i in range(length)])
|
||||
|
||||
# OAuthConsumer is a data type that represents the identity of the Consumer
|
||||
# via its shared secret with the Service Provider.
|
||||
class OAuthConsumer(object):
|
||||
key = None
|
||||
secret = None
|
||||
|
||||
def __init__(self, key, secret):
|
||||
self.key = key
|
||||
self.secret = secret
|
||||
|
||||
# OAuthToken is a data type that represents an End User via either an access
|
||||
# or request token.
|
||||
class OAuthToken(object):
|
||||
# access tokens and request tokens
|
||||
key = None
|
||||
secret = None
|
||||
|
||||
'''
|
||||
key = the token
|
||||
secret = the token secret
|
||||
'''
|
||||
def __init__(self, key, secret):
|
||||
self.key = key
|
||||
self.secret = secret
|
||||
|
||||
def to_string(self):
|
||||
return urllib.urlencode({'oauth_token': self.key, 'oauth_token_secret': self.secret})
|
||||
|
||||
# return a token from something like:
|
||||
# oauth_token_secret=digg&oauth_token=digg
|
||||
def from_string(s):
|
||||
params = cgi.parse_qs(s, keep_blank_values=False)
|
||||
key = params['oauth_token'][0]
|
||||
secret = params['oauth_token_secret'][0]
|
||||
return OAuthToken(key, secret)
|
||||
from_string = staticmethod(from_string)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_string()
|
||||
|
||||
# OAuthRequest represents the request and can be serialized
|
||||
class OAuthRequest(object):
|
||||
'''
|
||||
OAuth parameters:
|
||||
- oauth_consumer_key
|
||||
- oauth_token
|
||||
- oauth_signature_method
|
||||
- oauth_signature
|
||||
- oauth_timestamp
|
||||
- oauth_nonce
|
||||
- oauth_version
|
||||
... any additional parameters, as defined by the Service Provider.
|
||||
'''
|
||||
parameters = None # oauth parameters
|
||||
http_method = HTTP_METHOD
|
||||
http_url = None
|
||||
version = VERSION
|
||||
|
||||
def __init__(self, http_method=HTTP_METHOD, http_url=None, parameters=None):
|
||||
self.http_method = http_method
|
||||
self.http_url = http_url
|
||||
self.parameters = parameters or {}
|
||||
|
||||
def set_parameter(self, parameter, value):
|
||||
self.parameters[parameter] = value
|
||||
|
||||
def get_parameter(self, parameter):
|
||||
try:
|
||||
return self.parameters[parameter]
|
||||
except:
|
||||
raise OAuthError('Parameter not found: %s' % parameter)
|
||||
|
||||
def _get_timestamp_nonce(self):
|
||||
return self.get_parameter('oauth_timestamp'), self.get_parameter('oauth_nonce')
|
||||
|
||||
# get any non-oauth parameters
|
||||
def get_nonoauth_parameters(self):
|
||||
parameters = {}
|
||||
for k, v in self.parameters.iteritems():
|
||||
# ignore oauth parameters
|
||||
if k.find('oauth_') < 0:
|
||||
parameters[k] = v
|
||||
return parameters
|
||||
|
||||
# serialize as a header for an HTTPAuth request
|
||||
def to_header(self, realm=''):
|
||||
auth_header = 'OAuth realm="%s"' % realm
|
||||
# add the oauth parameters
|
||||
if self.parameters:
|
||||
for k, v in self.parameters.iteritems():
|
||||
if k[:6] == 'oauth_':
|
||||
auth_header += ', %s="%s"' % (k, escape(str(v)))
|
||||
return {'Authorization': auth_header}
|
||||
|
||||
# serialize as post data for a POST request
|
||||
def to_postdata(self):
|
||||
return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) for k, v in self.parameters.iteritems()])
|
||||
|
||||
# serialize as a url for a GET request
|
||||
def to_url(self):
|
||||
return '%s?%s' % (self.get_normalized_http_url(), self.to_postdata())
|
||||
|
||||
# return a string that consists of all the parameters that need to be signed
|
||||
def get_normalized_parameters(self):
|
||||
params = self.parameters
|
||||
try:
|
||||
# exclude the signature if it exists
|
||||
del params['oauth_signature']
|
||||
except:
|
||||
pass
|
||||
key_values = params.items()
|
||||
# sort lexicographically, first after key, then after value
|
||||
key_values.sort()
|
||||
# combine key value pairs in string and escape
|
||||
return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) for k, v in key_values])
|
||||
|
||||
# just uppercases the http method
|
||||
def get_normalized_http_method(self):
|
||||
return self.http_method.upper()
|
||||
|
||||
# parses the url and rebuilds it to be scheme://host/path
|
||||
def get_normalized_http_url(self):
|
||||
parts = urlparse.urlparse(self.http_url)
|
||||
url_string = '%s://%s%s' % (parts[0], parts[1], parts[2]) # scheme, netloc, path
|
||||
return url_string
|
||||
|
||||
# set the signature parameter to the result of build_signature
|
||||
def sign_request(self, signature_method, consumer, token):
|
||||
# set the signature method
|
||||
self.set_parameter('oauth_signature_method', signature_method.get_name())
|
||||
# set the signature
|
||||
self.set_parameter('oauth_signature', self.build_signature(signature_method, consumer, token))
|
||||
|
||||
def build_signature(self, signature_method, consumer, token):
|
||||
# call the build signature method within the signature method
|
||||
return signature_method.build_signature(self, consumer, token)
|
||||
|
||||
def from_request(http_method, http_url, headers=None, parameters=None, query_string=None):
|
||||
# combine multiple parameter sources
|
||||
if parameters is None:
|
||||
parameters = {}
|
||||
|
||||
# headers
|
||||
if headers and 'Authorization' in headers:
|
||||
auth_header = headers['Authorization']
|
||||
# check that the authorization header is OAuth
|
||||
if auth_header.index('OAuth') > -1:
|
||||
try:
|
||||
# get the parameters from the header
|
||||
header_params = OAuthRequest._split_header(auth_header)
|
||||
parameters.update(header_params)
|
||||
except:
|
||||
raise OAuthError('Unable to parse OAuth parameters from Authorization header.')
|
||||
|
||||
# GET or POST query string
|
||||
if query_string:
|
||||
query_params = OAuthRequest._split_url_string(query_string)
|
||||
parameters.update(query_params)
|
||||
|
||||
# URL parameters
|
||||
param_str = urlparse.urlparse(http_url)[4] # query
|
||||
url_params = OAuthRequest._split_url_string(param_str)
|
||||
parameters.update(url_params)
|
||||
|
||||
if parameters:
|
||||
return OAuthRequest(http_method, http_url, parameters)
|
||||
|
||||
return None
|
||||
from_request = staticmethod(from_request)
|
||||
|
||||
def from_consumer_and_token(oauth_consumer, token=None, http_method=HTTP_METHOD, http_url=None, parameters=None):
|
||||
if not parameters:
|
||||
parameters = {}
|
||||
|
||||
defaults = {
|
||||
'oauth_consumer_key': oauth_consumer.key,
|
||||
'oauth_timestamp': generate_timestamp(),
|
||||
'oauth_nonce': generate_nonce(),
|
||||
'oauth_version': OAuthRequest.version,
|
||||
}
|
||||
|
||||
defaults.update(parameters)
|
||||
parameters = defaults
|
||||
|
||||
if token:
|
||||
parameters['oauth_token'] = token.key
|
||||
|
||||
return OAuthRequest(http_method, http_url, parameters)
|
||||
from_consumer_and_token = staticmethod(from_consumer_and_token)
|
||||
|
||||
def from_token_and_callback(token, callback=None, http_method=HTTP_METHOD, http_url=None, parameters=None):
|
||||
if not parameters:
|
||||
parameters = {}
|
||||
|
||||
parameters['oauth_token'] = token.key
|
||||
|
||||
if callback:
|
||||
parameters['oauth_callback'] = callback
|
||||
|
||||
return OAuthRequest(http_method, http_url, parameters)
|
||||
from_token_and_callback = staticmethod(from_token_and_callback)
|
||||
|
||||
# util function: turn Authorization: header into parameters, has to do some unescaping
|
||||
def _split_header(header):
|
||||
params = {}
|
||||
parts = header.split(',')
|
||||
for param in parts:
|
||||
# ignore realm parameter
|
||||
if param.find('OAuth realm') > -1:
|
||||
continue
|
||||
# remove whitespace
|
||||
param = param.strip()
|
||||
# split key-value
|
||||
param_parts = param.split('=', 1)
|
||||
# remove quotes and unescape the value
|
||||
params[param_parts[0]] = urllib.unquote(param_parts[1].strip('\"'))
|
||||
return params
|
||||
_split_header = staticmethod(_split_header)
|
||||
|
||||
# util function: turn url string into parameters, has to do some unescaping
|
||||
def _split_url_string(param_str):
|
||||
parameters = cgi.parse_qs(param_str, keep_blank_values=False)
|
||||
for k, v in parameters.iteritems():
|
||||
parameters[k] = urllib.unquote(v[0])
|
||||
return parameters
|
||||
_split_url_string = staticmethod(_split_url_string)
|
||||
|
||||
# OAuthServer is a worker to check a requests validity against a data store
|
||||
class OAuthServer(object):
|
||||
timestamp_threshold = 300 # in seconds, five minutes
|
||||
version = VERSION
|
||||
signature_methods = None
|
||||
data_store = None
|
||||
|
||||
def __init__(self, data_store=None, signature_methods=None):
|
||||
self.data_store = data_store
|
||||
self.signature_methods = signature_methods or {}
|
||||
|
||||
def set_data_store(self, oauth_data_store):
|
||||
self.data_store = data_store
|
||||
|
||||
def get_data_store(self):
|
||||
return self.data_store
|
||||
|
||||
def add_signature_method(self, signature_method):
|
||||
self.signature_methods[signature_method.get_name()] = signature_method
|
||||
return self.signature_methods
|
||||
|
||||
# process a request_token request
|
||||
# returns the request token on success
|
||||
def fetch_request_token(self, oauth_request):
|
||||
try:
|
||||
# get the request token for authorization
|
||||
token = self._get_token(oauth_request, 'request')
|
||||
except OAuthError:
|
||||
# no token required for the initial token request
|
||||
version = self._get_version(oauth_request)
|
||||
consumer = self._get_consumer(oauth_request)
|
||||
self._check_signature(oauth_request, consumer, None)
|
||||
# fetch a new token
|
||||
token = self.data_store.fetch_request_token(consumer)
|
||||
return token
|
||||
|
||||
# process an access_token request
|
||||
# returns the access token on success
|
||||
def fetch_access_token(self, oauth_request):
|
||||
version = self._get_version(oauth_request)
|
||||
consumer = self._get_consumer(oauth_request)
|
||||
# get the request token
|
||||
token = self._get_token(oauth_request, 'request')
|
||||
self._check_signature(oauth_request, consumer, token)
|
||||
new_token = self.data_store.fetch_access_token(consumer, token)
|
||||
return new_token
|
||||
|
||||
# verify an api call, checks all the parameters
|
||||
def verify_request(self, oauth_request):
|
||||
# -> consumer and token
|
||||
version = self._get_version(oauth_request)
|
||||
consumer = self._get_consumer(oauth_request)
|
||||
# get the access token
|
||||
token = self._get_token(oauth_request, 'access')
|
||||
self._check_signature(oauth_request, consumer, token)
|
||||
parameters = oauth_request.get_nonoauth_parameters()
|
||||
return consumer, token, parameters
|
||||
|
||||
# authorize a request token
|
||||
def authorize_token(self, token, user):
|
||||
return self.data_store.authorize_request_token(token, user)
|
||||
|
||||
# get the callback url
|
||||
def get_callback(self, oauth_request):
|
||||
return oauth_request.get_parameter('oauth_callback')
|
||||
|
||||
# optional support for the authenticate header
|
||||
def build_authenticate_header(self, realm=''):
|
||||
return {'WWW-Authenticate': 'OAuth realm="%s"' % realm}
|
||||
|
||||
# verify the correct version request for this server
|
||||
def _get_version(self, oauth_request):
|
||||
try:
|
||||
version = oauth_request.get_parameter('oauth_version')
|
||||
except:
|
||||
version = VERSION
|
||||
if version and version != self.version:
|
||||
raise OAuthError('OAuth version %s not supported.' % str(version))
|
||||
return version
|
||||
|
||||
# figure out the signature with some defaults
|
||||
def _get_signature_method(self, oauth_request):
|
||||
try:
|
||||
signature_method = oauth_request.get_parameter('oauth_signature_method')
|
||||
except:
|
||||
signature_method = SIGNATURE_METHOD
|
||||
try:
|
||||
# get the signature method object
|
||||
signature_method = self.signature_methods[signature_method]
|
||||
except:
|
||||
signature_method_names = ', '.join(self.signature_methods.keys())
|
||||
raise OAuthError('Signature method %s not supported try one of the following: %s' % (signature_method, signature_method_names))
|
||||
|
||||
return signature_method
|
||||
|
||||
def _get_consumer(self, oauth_request):
|
||||
consumer_key = oauth_request.get_parameter('oauth_consumer_key')
|
||||
if not consumer_key:
|
||||
raise OAuthError('Invalid consumer key.')
|
||||
consumer = self.data_store.lookup_consumer(consumer_key)
|
||||
if not consumer:
|
||||
raise OAuthError('Invalid consumer.')
|
||||
return consumer
|
||||
|
||||
# try to find the token for the provided request token key
|
||||
def _get_token(self, oauth_request, token_type='access'):
|
||||
token_field = oauth_request.get_parameter('oauth_token')
|
||||
token = self.data_store.lookup_token(token_type, token_field)
|
||||
if not token:
|
||||
raise OAuthError('Invalid %s token: %s' % (token_type, token_field))
|
||||
return token
|
||||
|
||||
def _check_signature(self, oauth_request, consumer, token):
|
||||
timestamp, nonce = oauth_request._get_timestamp_nonce()
|
||||
self._check_timestamp(timestamp)
|
||||
self._check_nonce(consumer, token, nonce)
|
||||
signature_method = self._get_signature_method(oauth_request)
|
||||
try:
|
||||
signature = oauth_request.get_parameter('oauth_signature')
|
||||
except:
|
||||
raise OAuthError('Missing signature.')
|
||||
# validate the signature
|
||||
valid_sig = signature_method.check_signature(oauth_request, consumer, token, signature)
|
||||
if not valid_sig:
|
||||
key, base = signature_method.build_signature_base_string(oauth_request, consumer, token)
|
||||
raise OAuthError('Invalid signature. Expected signature base string: %s' % base)
|
||||
built = signature_method.build_signature(oauth_request, consumer, token)
|
||||
|
||||
def _check_timestamp(self, timestamp):
|
||||
# verify that timestamp is recentish
|
||||
timestamp = int(timestamp)
|
||||
now = int(time.time())
|
||||
lapsed = now - timestamp
|
||||
if lapsed > self.timestamp_threshold:
|
||||
raise OAuthError('Expired timestamp: given %d and now %s has a greater difference than threshold %d' % (timestamp, now, self.timestamp_threshold))
|
||||
|
||||
def _check_nonce(self, consumer, token, nonce):
|
||||
# verify that the nonce is uniqueish
|
||||
nonce = self.data_store.lookup_nonce(consumer, token, nonce)
|
||||
if nonce:
|
||||
raise OAuthError('Nonce already used: %s' % str(nonce))
|
||||
|
||||
# OAuthClient is a worker to attempt to execute a request
|
||||
class OAuthClient(object):
|
||||
consumer = None
|
||||
token = None
|
||||
|
||||
def __init__(self, oauth_consumer, oauth_token):
|
||||
self.consumer = oauth_consumer
|
||||
self.token = oauth_token
|
||||
|
||||
def get_consumer(self):
|
||||
return self.consumer
|
||||
|
||||
def get_token(self):
|
||||
return self.token
|
||||
|
||||
def fetch_request_token(self, oauth_request):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def fetch_access_token(self, oauth_request):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def access_resource(self, oauth_request):
|
||||
# -> some protected resource
|
||||
raise NotImplementedError
|
||||
|
||||
# OAuthDataStore is a database abstraction used to lookup consumers and tokens
|
||||
class OAuthDataStore(object):
|
||||
|
||||
def lookup_consumer(self, key):
|
||||
# -> OAuthConsumer
|
||||
raise NotImplementedError
|
||||
|
||||
def lookup_token(self, oauth_consumer, token_type, token_token):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def lookup_nonce(self, oauth_consumer, oauth_token, nonce, timestamp):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def fetch_request_token(self, oauth_consumer):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def fetch_access_token(self, oauth_consumer, oauth_token):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
def authorize_request_token(self, oauth_token, user):
|
||||
# -> OAuthToken
|
||||
raise NotImplementedError
|
||||
|
||||
# OAuthSignatureMethod is a strategy class that implements a signature method
|
||||
class OAuthSignatureMethod(object):
|
||||
def get_name(self):
|
||||
# -> str
|
||||
raise NotImplementedError
|
||||
|
||||
def build_signature_base_string(self, oauth_request, oauth_consumer, oauth_token):
|
||||
# -> str key, str raw
|
||||
raise NotImplementedError
|
||||
|
||||
def build_signature(self, oauth_request, oauth_consumer, oauth_token):
|
||||
# -> str
|
||||
raise NotImplementedError
|
||||
|
||||
def check_signature(self, oauth_request, consumer, token, signature):
|
||||
built = self.build_signature(oauth_request, consumer, token)
|
||||
return built == signature
|
||||
|
||||
class OAuthSignatureMethod_HMAC_SHA1(OAuthSignatureMethod):
|
||||
|
||||
def get_name(self):
|
||||
return 'HMAC-SHA1'
|
||||
|
||||
def build_signature_base_string(self, oauth_request, consumer, token):
|
||||
sig = (
|
||||
escape(oauth_request.get_normalized_http_method()),
|
||||
escape(oauth_request.get_normalized_http_url()),
|
||||
escape(oauth_request.get_normalized_parameters()),
|
||||
)
|
||||
|
||||
key = '%s&' % escape(consumer.secret)
|
||||
if token:
|
||||
key += escape(token.secret)
|
||||
raw = '&'.join(sig)
|
||||
return key, raw
|
||||
|
||||
def build_signature(self, oauth_request, consumer, token):
|
||||
# build the base signature string
|
||||
key, raw = self.build_signature_base_string(oauth_request, consumer, token)
|
||||
|
||||
# hmac object
|
||||
try:
|
||||
import hashlib # 2.5
|
||||
hashed = hmac.new(key, raw, hashlib.sha1)
|
||||
except:
|
||||
import sha # deprecated
|
||||
hashed = hmac.new(key, raw, sha)
|
||||
|
||||
# calculate the digest base 64
|
||||
return binascii.b2a_base64(hashed.digest())[:-1]
|
||||
|
||||
class OAuthSignatureMethod_PLAINTEXT(OAuthSignatureMethod):
|
||||
|
||||
def get_name(self):
|
||||
return 'PLAINTEXT'
|
||||
|
||||
def build_signature_base_string(self, oauth_request, consumer, token):
|
||||
# concatenate the consumer key and secret
|
||||
sig = escape(consumer.secret) + '&'
|
||||
if token:
|
||||
sig = sig + escape(token.secret)
|
||||
return sig
|
||||
|
||||
def build_signature(self, oauth_request, consumer, token):
|
||||
return self.build_signature_base_string(oauth_request, consumer, token)
|
||||
@@ -1,120 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
requires tlslite - http://trevp.net/tlslite/
|
||||
|
||||
"""
|
||||
|
||||
import binascii
|
||||
|
||||
from gdata.tlslite.utils import keyfactory
|
||||
from gdata.tlslite.utils import cryptomath
|
||||
|
||||
# XXX andy: ugly local import due to module name, oauth.oauth
|
||||
import gdata.oauth as oauth
|
||||
|
||||
class OAuthSignatureMethod_RSA_SHA1(oauth.OAuthSignatureMethod):
|
||||
def get_name(self):
|
||||
return "RSA-SHA1"
|
||||
|
||||
def _fetch_public_cert(self, oauth_request):
|
||||
# not implemented yet, ideas are:
|
||||
# (1) do a lookup in a table of trusted certs keyed off of consumer
|
||||
# (2) fetch via http using a url provided by the requester
|
||||
# (3) some sort of specific discovery code based on request
|
||||
#
|
||||
# either way should return a string representation of the certificate
|
||||
raise NotImplementedError
|
||||
|
||||
def _fetch_private_cert(self, oauth_request):
|
||||
# not implemented yet, ideas are:
|
||||
# (1) do a lookup in a table of trusted certs keyed off of consumer
|
||||
#
|
||||
# either way should return a string representation of the certificate
|
||||
raise NotImplementedError
|
||||
|
||||
def build_signature_base_string(self, oauth_request, consumer, token):
|
||||
sig = (
|
||||
oauth.escape(oauth_request.get_normalized_http_method()),
|
||||
oauth.escape(oauth_request.get_normalized_http_url()),
|
||||
oauth.escape(oauth_request.get_normalized_parameters()),
|
||||
)
|
||||
key = ''
|
||||
raw = '&'.join(sig)
|
||||
return key, raw
|
||||
|
||||
def build_signature(self, oauth_request, consumer, token):
|
||||
key, base_string = self.build_signature_base_string(oauth_request,
|
||||
consumer,
|
||||
token)
|
||||
|
||||
# Fetch the private key cert based on the request
|
||||
cert = self._fetch_private_cert(oauth_request)
|
||||
|
||||
# Pull the private key from the certificate
|
||||
privatekey = keyfactory.parsePrivateKey(cert)
|
||||
|
||||
# Convert base_string to bytes
|
||||
#base_string_bytes = cryptomath.createByteArraySequence(base_string)
|
||||
|
||||
# Sign using the key
|
||||
signed = privatekey.hashAndSign(base_string)
|
||||
|
||||
return binascii.b2a_base64(signed)[:-1]
|
||||
|
||||
def check_signature(self, oauth_request, consumer, token, signature):
|
||||
decoded_sig = base64.b64decode(signature);
|
||||
|
||||
key, base_string = self.build_signature_base_string(oauth_request,
|
||||
consumer,
|
||||
token)
|
||||
|
||||
# Fetch the public key cert based on the request
|
||||
cert = self._fetch_public_cert(oauth_request)
|
||||
|
||||
# Pull the public key from the certificate
|
||||
publickey = keyfactory.parsePEMKey(cert, public=True)
|
||||
|
||||
# Check the signature
|
||||
ok = publickey.hashAndVerify(decoded_sig, base_string)
|
||||
|
||||
return ok
|
||||
|
||||
|
||||
class TestOAuthSignatureMethod_RSA_SHA1(OAuthSignatureMethod_RSA_SHA1):
|
||||
def _fetch_public_cert(self, oauth_request):
|
||||
cert = """
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIBpjCCAQ+gAwIBAgIBATANBgkqhkiG9w0BAQUFADAZMRcwFQYDVQQDDA5UZXN0
|
||||
IFByaW5jaXBhbDAeFw03MDAxMDEwODAwMDBaFw0zODEyMzEwODAwMDBaMBkxFzAV
|
||||
BgNVBAMMDlRlc3QgUHJpbmNpcGFsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
|
||||
gQC0YjCwIfYoprq/FQO6lb3asXrxLlJFuCvtinTF5p0GxvQGu5O3gYytUvtC2JlY
|
||||
zypSRjVxwxrsuRcP3e641SdASwfrmzyvIgP08N4S0IFzEURkV1wp/IpH7kH41Etb
|
||||
mUmrXSwfNZsnQRE5SYSOhh+LcK2wyQkdgcMv11l4KoBkcwIDAQABMA0GCSqGSIb3
|
||||
DQEBBQUAA4GBAGZLPEuJ5SiJ2ryq+CmEGOXfvlTtEL2nuGtr9PewxkgnOjZpUy+d
|
||||
4TvuXJbNQc8f4AMWL/tO9w0Fk80rWKp9ea8/df4qMq5qlFWlx6yOLQxumNOmECKb
|
||||
WpkUQDIDJEoFUzKMVuJf4KO/FJ345+BNLGgbJ6WujreoM1X/gYfdnJ/J
|
||||
-----END CERTIFICATE-----
|
||||
"""
|
||||
return cert
|
||||
|
||||
def _fetch_private_cert(self, oauth_request):
|
||||
cert = """
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
|
||||
A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d
|
||||
7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ
|
||||
hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H
|
||||
X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm
|
||||
uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw
|
||||
rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z
|
||||
zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn
|
||||
qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG
|
||||
WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno
|
||||
cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+
|
||||
3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8
|
||||
AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
|
||||
Lw03eHTNQghS0A==
|
||||
-----END PRIVATE KEY-----
|
||||
"""
|
||||
return cert
|
||||
1717
gdata/service.py
1717
gdata/service.py
File diff suppressed because it is too large
Load Diff
@@ -1,120 +0,0 @@
|
||||
"""Base class for SharedKeyDB and VerifierDB."""
|
||||
|
||||
import anydbm
|
||||
import thread
|
||||
|
||||
class BaseDB:
|
||||
def __init__(self, filename, type):
|
||||
self.type = type
|
||||
self.filename = filename
|
||||
if self.filename:
|
||||
self.db = None
|
||||
else:
|
||||
self.db = {}
|
||||
self.lock = thread.allocate_lock()
|
||||
|
||||
def create(self):
|
||||
"""Create a new on-disk database.
|
||||
|
||||
@raise anydbm.error: If there's a problem creating the database.
|
||||
"""
|
||||
if self.filename:
|
||||
self.db = anydbm.open(self.filename, "n") #raises anydbm.error
|
||||
self.db["--Reserved--type"] = self.type
|
||||
self.db.sync()
|
||||
else:
|
||||
self.db = {}
|
||||
|
||||
def open(self):
|
||||
"""Open a pre-existing on-disk database.
|
||||
|
||||
@raise anydbm.error: If there's a problem opening the database.
|
||||
@raise ValueError: If the database is not of the right type.
|
||||
"""
|
||||
if not self.filename:
|
||||
raise ValueError("Can only open on-disk databases")
|
||||
self.db = anydbm.open(self.filename, "w") #raises anydbm.error
|
||||
try:
|
||||
if self.db["--Reserved--type"] != self.type:
|
||||
raise ValueError("Not a %s database" % self.type)
|
||||
except KeyError:
|
||||
raise ValueError("Not a recognized database")
|
||||
|
||||
def __getitem__(self, username):
|
||||
if self.db == None:
|
||||
raise AssertionError("DB not open")
|
||||
|
||||
self.lock.acquire()
|
||||
try:
|
||||
valueStr = self.db[username]
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
return self._getItem(username, valueStr)
|
||||
|
||||
def __setitem__(self, username, value):
|
||||
if self.db == None:
|
||||
raise AssertionError("DB not open")
|
||||
|
||||
valueStr = self._setItem(username, value)
|
||||
|
||||
self.lock.acquire()
|
||||
try:
|
||||
self.db[username] = valueStr
|
||||
if self.filename:
|
||||
self.db.sync()
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def __delitem__(self, username):
|
||||
if self.db == None:
|
||||
raise AssertionError("DB not open")
|
||||
|
||||
self.lock.acquire()
|
||||
try:
|
||||
del(self.db[username])
|
||||
if self.filename:
|
||||
self.db.sync()
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def __contains__(self, username):
|
||||
"""Check if the database contains the specified username.
|
||||
|
||||
@type username: str
|
||||
@param username: The username to check for.
|
||||
|
||||
@rtype: bool
|
||||
@return: True if the database contains the username, False
|
||||
otherwise.
|
||||
|
||||
"""
|
||||
if self.db == None:
|
||||
raise AssertionError("DB not open")
|
||||
|
||||
self.lock.acquire()
|
||||
try:
|
||||
return self.db.has_key(username)
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def check(self, username, param):
|
||||
value = self.__getitem__(username)
|
||||
return self._checkItem(value, username, param)
|
||||
|
||||
def keys(self):
|
||||
"""Return a list of usernames in the database.
|
||||
|
||||
@rtype: list
|
||||
@return: The usernames in the database.
|
||||
"""
|
||||
if self.db == None:
|
||||
raise AssertionError("DB not open")
|
||||
|
||||
self.lock.acquire()
|
||||
try:
|
||||
usernames = self.db.keys()
|
||||
finally:
|
||||
self.lock.release()
|
||||
usernames = [u for u in usernames if not u.startswith("--Reserved--")]
|
||||
return usernames
|
||||
@@ -1,146 +0,0 @@
|
||||
"""Class for post-handshake certificate checking."""
|
||||
|
||||
from utils.cryptomath import hashAndBase64
|
||||
from X509 import X509
|
||||
from X509CertChain import X509CertChain
|
||||
from errors import *
|
||||
|
||||
|
||||
class Checker:
|
||||
"""This class is passed to a handshake function to check the other
|
||||
party's certificate chain.
|
||||
|
||||
If a handshake function completes successfully, but the Checker
|
||||
judges the other party's certificate chain to be missing or
|
||||
inadequate, a subclass of
|
||||
L{tlslite.errors.TLSAuthenticationError} will be raised.
|
||||
|
||||
Currently, the Checker can check either an X.509 or a cryptoID
|
||||
chain (for the latter, cryptoIDlib must be installed).
|
||||
"""
|
||||
|
||||
def __init__(self, cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
checkResumedSession=False):
|
||||
"""Create a new Checker instance.
|
||||
|
||||
You must pass in one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: A cryptoID which the other party's certificate
|
||||
chain must match. The cryptoIDlib module must be installed.
|
||||
Mutually exclusive with all of the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: A cryptoID protocol URI which the other
|
||||
party's certificate chain must match. Requires the 'cryptoID'
|
||||
argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: A hex-encoded X.509 end-entity
|
||||
fingerprint which the other party's end-entity certificate must
|
||||
match. Mutually exclusive with the 'cryptoID' and
|
||||
'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed. Mutually exclusive with the 'cryptoID' and
|
||||
'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type checkResumedSession: bool
|
||||
@param checkResumedSession: If resumed sessions should be
|
||||
checked. This defaults to False, on the theory that if the
|
||||
session was checked once, we don't need to bother
|
||||
re-checking it.
|
||||
"""
|
||||
|
||||
if cryptoID and (x509Fingerprint or x509TrustList):
|
||||
raise ValueError()
|
||||
if x509Fingerprint and x509TrustList:
|
||||
raise ValueError()
|
||||
if x509CommonName and not x509TrustList:
|
||||
raise ValueError()
|
||||
if protocol and not cryptoID:
|
||||
raise ValueError()
|
||||
if cryptoID:
|
||||
import cryptoIDlib #So we raise an error here
|
||||
if x509TrustList:
|
||||
import cryptlib_py #So we raise an error here
|
||||
self.cryptoID = cryptoID
|
||||
self.protocol = protocol
|
||||
self.x509Fingerprint = x509Fingerprint
|
||||
self.x509TrustList = x509TrustList
|
||||
self.x509CommonName = x509CommonName
|
||||
self.checkResumedSession = checkResumedSession
|
||||
|
||||
def __call__(self, connection):
|
||||
"""Check a TLSConnection.
|
||||
|
||||
When a Checker is passed to a handshake function, this will
|
||||
be called at the end of the function.
|
||||
|
||||
@type connection: L{tlslite.TLSConnection.TLSConnection}
|
||||
@param connection: The TLSConnection to examine.
|
||||
|
||||
@raise tlslite.errors.TLSAuthenticationError: If the other
|
||||
party's certificate chain is missing or bad.
|
||||
"""
|
||||
if not self.checkResumedSession and connection.resumed:
|
||||
return
|
||||
|
||||
if self.cryptoID or self.x509Fingerprint or self.x509TrustList:
|
||||
if connection._client:
|
||||
chain = connection.session.serverCertChain
|
||||
else:
|
||||
chain = connection.session.clientCertChain
|
||||
|
||||
if self.x509Fingerprint or self.x509TrustList:
|
||||
if isinstance(chain, X509CertChain):
|
||||
if self.x509Fingerprint:
|
||||
if chain.getFingerprint() != self.x509Fingerprint:
|
||||
raise TLSFingerprintError(\
|
||||
"X.509 fingerprint mismatch: %s, %s" % \
|
||||
(chain.getFingerprint(), self.x509Fingerprint))
|
||||
else: #self.x509TrustList
|
||||
if not chain.validate(self.x509TrustList):
|
||||
raise TLSValidationError("X.509 validation failure")
|
||||
if self.x509CommonName and \
|
||||
(chain.getCommonName() != self.x509CommonName):
|
||||
raise TLSAuthorizationError(\
|
||||
"X.509 Common Name mismatch: %s, %s" % \
|
||||
(chain.getCommonName(), self.x509CommonName))
|
||||
elif chain:
|
||||
raise TLSAuthenticationTypeError()
|
||||
else:
|
||||
raise TLSNoAuthenticationError()
|
||||
elif self.cryptoID:
|
||||
import cryptoIDlib.CertChain
|
||||
if isinstance(chain, cryptoIDlib.CertChain.CertChain):
|
||||
if chain.cryptoID != self.cryptoID:
|
||||
raise TLSFingerprintError(\
|
||||
"cryptoID mismatch: %s, %s" % \
|
||||
(chain.cryptoID, self.cryptoID))
|
||||
if self.protocol:
|
||||
if not chain.checkProtocol(self.protocol):
|
||||
raise TLSAuthorizationError(\
|
||||
"cryptoID protocol mismatch")
|
||||
if not chain.validate():
|
||||
raise TLSValidationError("cryptoID validation failure")
|
||||
elif chain:
|
||||
raise TLSAuthenticationTypeError()
|
||||
else:
|
||||
raise TLSNoAuthenticationError()
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
"""Class returned by TLSConnection.makefile()."""
|
||||
|
||||
class FileObject:
|
||||
"""This class provides a file object interface to a
|
||||
L{tlslite.TLSConnection.TLSConnection}.
|
||||
|
||||
Call makefile() on a TLSConnection to create a FileObject instance.
|
||||
|
||||
This class was copied, with minor modifications, from the
|
||||
_fileobject class in socket.py. Note that fileno() is not
|
||||
implemented."""
|
||||
|
||||
default_bufsize = 16384 #TREV: changed from 8192
|
||||
|
||||
def __init__(self, sock, mode='rb', bufsize=-1):
|
||||
self._sock = sock
|
||||
self.mode = mode # Not actually used in this version
|
||||
if bufsize < 0:
|
||||
bufsize = self.default_bufsize
|
||||
self.bufsize = bufsize
|
||||
self.softspace = False
|
||||
if bufsize == 0:
|
||||
self._rbufsize = 1
|
||||
elif bufsize == 1:
|
||||
self._rbufsize = self.default_bufsize
|
||||
else:
|
||||
self._rbufsize = bufsize
|
||||
self._wbufsize = bufsize
|
||||
self._rbuf = "" # A string
|
||||
self._wbuf = [] # A list of strings
|
||||
|
||||
def _getclosed(self):
|
||||
return self._sock is not None
|
||||
closed = property(_getclosed, doc="True if the file is closed")
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
if self._sock:
|
||||
for result in self._sock._decrefAsync(): #TREV
|
||||
pass
|
||||
finally:
|
||||
self._sock = None
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
self.close()
|
||||
except:
|
||||
# close() may fail if __init__ didn't complete
|
||||
pass
|
||||
|
||||
def flush(self):
|
||||
if self._wbuf:
|
||||
buffer = "".join(self._wbuf)
|
||||
self._wbuf = []
|
||||
self._sock.sendall(buffer)
|
||||
|
||||
#def fileno(self):
|
||||
# raise NotImplementedError() #TREV
|
||||
|
||||
def write(self, data):
|
||||
data = str(data) # XXX Should really reject non-string non-buffers
|
||||
if not data:
|
||||
return
|
||||
self._wbuf.append(data)
|
||||
if (self._wbufsize == 0 or
|
||||
self._wbufsize == 1 and '\n' in data or
|
||||
self._get_wbuf_len() >= self._wbufsize):
|
||||
self.flush()
|
||||
|
||||
def writelines(self, list):
|
||||
# XXX We could do better here for very long lists
|
||||
# XXX Should really reject non-string non-buffers
|
||||
self._wbuf.extend(filter(None, map(str, list)))
|
||||
if (self._wbufsize <= 1 or
|
||||
self._get_wbuf_len() >= self._wbufsize):
|
||||
self.flush()
|
||||
|
||||
def _get_wbuf_len(self):
|
||||
buf_len = 0
|
||||
for x in self._wbuf:
|
||||
buf_len += len(x)
|
||||
return buf_len
|
||||
|
||||
def read(self, size=-1):
|
||||
data = self._rbuf
|
||||
if size < 0:
|
||||
# Read until EOF
|
||||
buffers = []
|
||||
if data:
|
||||
buffers.append(data)
|
||||
self._rbuf = ""
|
||||
if self._rbufsize <= 1:
|
||||
recv_size = self.default_bufsize
|
||||
else:
|
||||
recv_size = self._rbufsize
|
||||
while True:
|
||||
data = self._sock.recv(recv_size)
|
||||
if not data:
|
||||
break
|
||||
buffers.append(data)
|
||||
return "".join(buffers)
|
||||
else:
|
||||
# Read until size bytes or EOF seen, whichever comes first
|
||||
buf_len = len(data)
|
||||
if buf_len >= size:
|
||||
self._rbuf = data[size:]
|
||||
return data[:size]
|
||||
buffers = []
|
||||
if data:
|
||||
buffers.append(data)
|
||||
self._rbuf = ""
|
||||
while True:
|
||||
left = size - buf_len
|
||||
recv_size = max(self._rbufsize, left)
|
||||
data = self._sock.recv(recv_size)
|
||||
if not data:
|
||||
break
|
||||
buffers.append(data)
|
||||
n = len(data)
|
||||
if n >= left:
|
||||
self._rbuf = data[left:]
|
||||
buffers[-1] = data[:left]
|
||||
break
|
||||
buf_len += n
|
||||
return "".join(buffers)
|
||||
|
||||
def readline(self, size=-1):
|
||||
data = self._rbuf
|
||||
if size < 0:
|
||||
# Read until \n or EOF, whichever comes first
|
||||
if self._rbufsize <= 1:
|
||||
# Speed up unbuffered case
|
||||
assert data == ""
|
||||
buffers = []
|
||||
recv = self._sock.recv
|
||||
while data != "\n":
|
||||
data = recv(1)
|
||||
if not data:
|
||||
break
|
||||
buffers.append(data)
|
||||
return "".join(buffers)
|
||||
nl = data.find('\n')
|
||||
if nl >= 0:
|
||||
nl += 1
|
||||
self._rbuf = data[nl:]
|
||||
return data[:nl]
|
||||
buffers = []
|
||||
if data:
|
||||
buffers.append(data)
|
||||
self._rbuf = ""
|
||||
while True:
|
||||
data = self._sock.recv(self._rbufsize)
|
||||
if not data:
|
||||
break
|
||||
buffers.append(data)
|
||||
nl = data.find('\n')
|
||||
if nl >= 0:
|
||||
nl += 1
|
||||
self._rbuf = data[nl:]
|
||||
buffers[-1] = data[:nl]
|
||||
break
|
||||
return "".join(buffers)
|
||||
else:
|
||||
# Read until size bytes or \n or EOF seen, whichever comes first
|
||||
nl = data.find('\n', 0, size)
|
||||
if nl >= 0:
|
||||
nl += 1
|
||||
self._rbuf = data[nl:]
|
||||
return data[:nl]
|
||||
buf_len = len(data)
|
||||
if buf_len >= size:
|
||||
self._rbuf = data[size:]
|
||||
return data[:size]
|
||||
buffers = []
|
||||
if data:
|
||||
buffers.append(data)
|
||||
self._rbuf = ""
|
||||
while True:
|
||||
data = self._sock.recv(self._rbufsize)
|
||||
if not data:
|
||||
break
|
||||
buffers.append(data)
|
||||
left = size - buf_len
|
||||
nl = data.find('\n', 0, left)
|
||||
if nl >= 0:
|
||||
nl += 1
|
||||
self._rbuf = data[nl:]
|
||||
buffers[-1] = data[:nl]
|
||||
break
|
||||
n = len(data)
|
||||
if n >= left:
|
||||
self._rbuf = data[left:]
|
||||
buffers[-1] = data[:left]
|
||||
break
|
||||
buf_len += n
|
||||
return "".join(buffers)
|
||||
|
||||
def readlines(self, sizehint=0):
|
||||
total = 0
|
||||
list = []
|
||||
while True:
|
||||
line = self.readline()
|
||||
if not line:
|
||||
break
|
||||
list.append(line)
|
||||
total += len(line)
|
||||
if sizehint and total >= sizehint:
|
||||
break
|
||||
return list
|
||||
|
||||
# Iterator protocols
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
line = self.readline()
|
||||
if not line:
|
||||
raise StopIteration
|
||||
return line
|
||||
@@ -1,159 +0,0 @@
|
||||
"""Class for setting handshake parameters."""
|
||||
|
||||
from constants import CertificateType
|
||||
from utils import cryptomath
|
||||
from utils import cipherfactory
|
||||
|
||||
class HandshakeSettings:
|
||||
"""This class encapsulates various parameters that can be used with
|
||||
a TLS handshake.
|
||||
@sort: minKeySize, maxKeySize, cipherNames, certificateTypes,
|
||||
minVersion, maxVersion
|
||||
|
||||
@type minKeySize: int
|
||||
@ivar minKeySize: The minimum bit length for asymmetric keys.
|
||||
|
||||
If the other party tries to use SRP, RSA, or Diffie-Hellman
|
||||
parameters smaller than this length, an alert will be
|
||||
signalled. The default is 1023.
|
||||
|
||||
@type maxKeySize: int
|
||||
@ivar maxKeySize: The maximum bit length for asymmetric keys.
|
||||
|
||||
If the other party tries to use SRP, RSA, or Diffie-Hellman
|
||||
parameters larger than this length, an alert will be signalled.
|
||||
The default is 8193.
|
||||
|
||||
@type cipherNames: list
|
||||
@ivar cipherNames: The allowed ciphers, in order of preference.
|
||||
|
||||
The allowed values in this list are 'aes256', 'aes128', '3des', and
|
||||
'rc4'. If these settings are used with a client handshake, they
|
||||
determine the order of the ciphersuites offered in the ClientHello
|
||||
message.
|
||||
|
||||
If these settings are used with a server handshake, the server will
|
||||
choose whichever ciphersuite matches the earliest entry in this
|
||||
list.
|
||||
|
||||
NOTE: If '3des' is used in this list, but TLS Lite can't find an
|
||||
add-on library that supports 3DES, then '3des' will be silently
|
||||
removed.
|
||||
|
||||
The default value is ['aes256', 'aes128', '3des', 'rc4'].
|
||||
|
||||
@type certificateTypes: list
|
||||
@ivar certificateTypes: The allowed certificate types, in order of
|
||||
preference.
|
||||
|
||||
The allowed values in this list are 'x509' and 'cryptoID'. This
|
||||
list is only used with a client handshake. The client will
|
||||
advertise to the server which certificate types are supported, and
|
||||
will check that the server uses one of the appropriate types.
|
||||
|
||||
NOTE: If 'cryptoID' is used in this list, but cryptoIDlib is not
|
||||
installed, then 'cryptoID' will be silently removed.
|
||||
|
||||
@type minVersion: tuple
|
||||
@ivar minVersion: The minimum allowed SSL/TLS version.
|
||||
|
||||
This variable can be set to (3,0) for SSL 3.0, (3,1) for
|
||||
TLS 1.0, or (3,2) for TLS 1.1. If the other party wishes to
|
||||
use a lower version, a protocol_version alert will be signalled.
|
||||
The default is (3,0).
|
||||
|
||||
@type maxVersion: tuple
|
||||
@ivar maxVersion: The maximum allowed SSL/TLS version.
|
||||
|
||||
This variable can be set to (3,0) for SSL 3.0, (3,1) for
|
||||
TLS 1.0, or (3,2) for TLS 1.1. If the other party wishes to
|
||||
use a higher version, a protocol_version alert will be signalled.
|
||||
The default is (3,2). (WARNING: Some servers may (improperly)
|
||||
reject clients which offer support for TLS 1.1. In this case,
|
||||
try lowering maxVersion to (3,1)).
|
||||
"""
|
||||
def __init__(self):
|
||||
self.minKeySize = 1023
|
||||
self.maxKeySize = 8193
|
||||
self.cipherNames = ["aes256", "aes128", "3des", "rc4"]
|
||||
self.cipherImplementations = ["cryptlib", "openssl", "pycrypto",
|
||||
"python"]
|
||||
self.certificateTypes = ["x509", "cryptoID"]
|
||||
self.minVersion = (3,0)
|
||||
self.maxVersion = (3,2)
|
||||
|
||||
#Filters out options that are not supported
|
||||
def _filter(self):
|
||||
other = HandshakeSettings()
|
||||
other.minKeySize = self.minKeySize
|
||||
other.maxKeySize = self.maxKeySize
|
||||
other.cipherNames = self.cipherNames
|
||||
other.cipherImplementations = self.cipherImplementations
|
||||
other.certificateTypes = self.certificateTypes
|
||||
other.minVersion = self.minVersion
|
||||
other.maxVersion = self.maxVersion
|
||||
|
||||
if not cipherfactory.tripleDESPresent:
|
||||
other.cipherNames = [e for e in self.cipherNames if e != "3des"]
|
||||
if len(other.cipherNames)==0:
|
||||
raise ValueError("No supported ciphers")
|
||||
|
||||
try:
|
||||
import cryptoIDlib
|
||||
except ImportError:
|
||||
other.certificateTypes = [e for e in self.certificateTypes \
|
||||
if e != "cryptoID"]
|
||||
if len(other.certificateTypes)==0:
|
||||
raise ValueError("No supported certificate types")
|
||||
|
||||
if not cryptomath.cryptlibpyLoaded:
|
||||
other.cipherImplementations = [e for e in \
|
||||
self.cipherImplementations if e != "cryptlib"]
|
||||
if not cryptomath.m2cryptoLoaded:
|
||||
other.cipherImplementations = [e for e in \
|
||||
other.cipherImplementations if e != "openssl"]
|
||||
if not cryptomath.pycryptoLoaded:
|
||||
other.cipherImplementations = [e for e in \
|
||||
other.cipherImplementations if e != "pycrypto"]
|
||||
if len(other.cipherImplementations)==0:
|
||||
raise ValueError("No supported cipher implementations")
|
||||
|
||||
if other.minKeySize<512:
|
||||
raise ValueError("minKeySize too small")
|
||||
if other.minKeySize>16384:
|
||||
raise ValueError("minKeySize too large")
|
||||
if other.maxKeySize<512:
|
||||
raise ValueError("maxKeySize too small")
|
||||
if other.maxKeySize>16384:
|
||||
raise ValueError("maxKeySize too large")
|
||||
for s in other.cipherNames:
|
||||
if s not in ("aes256", "aes128", "rc4", "3des"):
|
||||
raise ValueError("Unknown cipher name: '%s'" % s)
|
||||
for s in other.cipherImplementations:
|
||||
if s not in ("cryptlib", "openssl", "python", "pycrypto"):
|
||||
raise ValueError("Unknown cipher implementation: '%s'" % s)
|
||||
for s in other.certificateTypes:
|
||||
if s not in ("x509", "cryptoID"):
|
||||
raise ValueError("Unknown certificate type: '%s'" % s)
|
||||
|
||||
if other.minVersion > other.maxVersion:
|
||||
raise ValueError("Versions set incorrectly")
|
||||
|
||||
if not other.minVersion in ((3,0), (3,1), (3,2)):
|
||||
raise ValueError("minVersion set incorrectly")
|
||||
|
||||
if not other.maxVersion in ((3,0), (3,1), (3,2)):
|
||||
raise ValueError("maxVersion set incorrectly")
|
||||
|
||||
return other
|
||||
|
||||
def _getCertificateTypes(self):
|
||||
l = []
|
||||
for ct in self.certificateTypes:
|
||||
if ct == "x509":
|
||||
l.append(CertificateType.x509)
|
||||
elif ct == "cryptoID":
|
||||
l.append(CertificateType.cryptoID)
|
||||
else:
|
||||
raise AssertionError()
|
||||
return l
|
||||
@@ -1,131 +0,0 @@
|
||||
"""Class representing a TLS session."""
|
||||
|
||||
from utils.compat import *
|
||||
from mathtls import *
|
||||
from constants import *
|
||||
|
||||
class Session:
|
||||
"""
|
||||
This class represents a TLS session.
|
||||
|
||||
TLS distinguishes between connections and sessions. A new
|
||||
handshake creates both a connection and a session. Data is
|
||||
transmitted over the connection.
|
||||
|
||||
The session contains a more permanent record of the handshake. The
|
||||
session can be inspected to determine handshake results. The
|
||||
session can also be used to create a new connection through
|
||||
"session resumption". If the client and server both support this,
|
||||
they can create a new connection based on an old session without
|
||||
the overhead of a full handshake.
|
||||
|
||||
The session for a L{tlslite.TLSConnection.TLSConnection} can be
|
||||
retrieved from the connection's 'session' attribute.
|
||||
|
||||
@type srpUsername: str
|
||||
@ivar srpUsername: The client's SRP username (or None).
|
||||
|
||||
@type sharedKeyUsername: str
|
||||
@ivar sharedKeyUsername: The client's shared-key username (or
|
||||
None).
|
||||
|
||||
@type clientCertChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@ivar clientCertChain: The client's certificate chain (or None).
|
||||
|
||||
@type serverCertChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@ivar serverCertChain: The server's certificate chain (or None).
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.masterSecret = createByteArraySequence([])
|
||||
self.sessionID = createByteArraySequence([])
|
||||
self.cipherSuite = 0
|
||||
self.srpUsername = None
|
||||
self.sharedKeyUsername = None
|
||||
self.clientCertChain = None
|
||||
self.serverCertChain = None
|
||||
self.resumable = False
|
||||
self.sharedKey = False
|
||||
|
||||
def _clone(self):
|
||||
other = Session()
|
||||
other.masterSecret = self.masterSecret
|
||||
other.sessionID = self.sessionID
|
||||
other.cipherSuite = self.cipherSuite
|
||||
other.srpUsername = self.srpUsername
|
||||
other.sharedKeyUsername = self.sharedKeyUsername
|
||||
other.clientCertChain = self.clientCertChain
|
||||
other.serverCertChain = self.serverCertChain
|
||||
other.resumable = self.resumable
|
||||
other.sharedKey = self.sharedKey
|
||||
return other
|
||||
|
||||
def _calcMasterSecret(self, version, premasterSecret, clientRandom,
|
||||
serverRandom):
|
||||
if version == (3,0):
|
||||
self.masterSecret = PRF_SSL(premasterSecret,
|
||||
concatArrays(clientRandom, serverRandom), 48)
|
||||
elif version in ((3,1), (3,2)):
|
||||
self.masterSecret = PRF(premasterSecret, "master secret",
|
||||
concatArrays(clientRandom, serverRandom), 48)
|
||||
else:
|
||||
raise AssertionError()
|
||||
|
||||
def valid(self):
|
||||
"""If this session can be used for session resumption.
|
||||
|
||||
@rtype: bool
|
||||
@return: If this session can be used for session resumption.
|
||||
"""
|
||||
return self.resumable or self.sharedKey
|
||||
|
||||
def _setResumable(self, boolean):
|
||||
#Only let it be set if this isn't a shared key
|
||||
if not self.sharedKey:
|
||||
#Only let it be set to True if the sessionID is non-null
|
||||
if (not boolean) or (boolean and self.sessionID):
|
||||
self.resumable = boolean
|
||||
|
||||
def getCipherName(self):
|
||||
"""Get the name of the cipher used with this connection.
|
||||
|
||||
@rtype: str
|
||||
@return: The name of the cipher used with this connection.
|
||||
Either 'aes128', 'aes256', 'rc4', or '3des'.
|
||||
"""
|
||||
if self.cipherSuite in CipherSuite.aes128Suites:
|
||||
return "aes128"
|
||||
elif self.cipherSuite in CipherSuite.aes256Suites:
|
||||
return "aes256"
|
||||
elif self.cipherSuite in CipherSuite.rc4Suites:
|
||||
return "rc4"
|
||||
elif self.cipherSuite in CipherSuite.tripleDESSuites:
|
||||
return "3des"
|
||||
else:
|
||||
return None
|
||||
|
||||
def _createSharedKey(self, sharedKeyUsername, sharedKey):
|
||||
if len(sharedKeyUsername)>16:
|
||||
raise ValueError()
|
||||
if len(sharedKey)>47:
|
||||
raise ValueError()
|
||||
|
||||
self.sharedKeyUsername = sharedKeyUsername
|
||||
|
||||
self.sessionID = createByteArrayZeros(16)
|
||||
for x in range(len(sharedKeyUsername)):
|
||||
self.sessionID[x] = ord(sharedKeyUsername[x])
|
||||
|
||||
premasterSecret = createByteArrayZeros(48)
|
||||
sharedKey = chr(len(sharedKey)) + sharedKey
|
||||
for x in range(48):
|
||||
premasterSecret[x] = ord(sharedKey[x % len(sharedKey)])
|
||||
|
||||
self.masterSecret = PRF(premasterSecret, "shared secret",
|
||||
createByteArraySequence([]), 48)
|
||||
self.sharedKey = True
|
||||
return self
|
||||
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
"""Class for caching TLS sessions."""
|
||||
|
||||
import thread
|
||||
import time
|
||||
|
||||
class SessionCache:
|
||||
"""This class is used by the server to cache TLS sessions.
|
||||
|
||||
Caching sessions allows the client to use TLS session resumption
|
||||
and avoid the expense of a full handshake. To use this class,
|
||||
simply pass a SessionCache instance into the server handshake
|
||||
function.
|
||||
|
||||
This class is thread-safe.
|
||||
"""
|
||||
|
||||
#References to these instances
|
||||
#are also held by the caller, who may change the 'resumable'
|
||||
#flag, so the SessionCache must return the same instances
|
||||
#it was passed in.
|
||||
|
||||
def __init__(self, maxEntries=10000, maxAge=14400):
|
||||
"""Create a new SessionCache.
|
||||
|
||||
@type maxEntries: int
|
||||
@param maxEntries: The maximum size of the cache. When this
|
||||
limit is reached, the oldest sessions will be deleted as
|
||||
necessary to make room for new ones. The default is 10000.
|
||||
|
||||
@type maxAge: int
|
||||
@param maxAge: The number of seconds before a session expires
|
||||
from the cache. The default is 14400 (i.e. 4 hours)."""
|
||||
|
||||
self.lock = thread.allocate_lock()
|
||||
|
||||
# Maps sessionIDs to sessions
|
||||
self.entriesDict = {}
|
||||
|
||||
#Circular list of (sessionID, timestamp) pairs
|
||||
self.entriesList = [(None,None)] * maxEntries
|
||||
|
||||
self.firstIndex = 0
|
||||
self.lastIndex = 0
|
||||
self.maxAge = maxAge
|
||||
|
||||
def __getitem__(self, sessionID):
|
||||
self.lock.acquire()
|
||||
try:
|
||||
self._purge() #Delete old items, so we're assured of a new one
|
||||
session = self.entriesDict[sessionID]
|
||||
|
||||
#When we add sessions they're resumable, but it's possible
|
||||
#for the session to be invalidated later on (if a fatal alert
|
||||
#is returned), so we have to check for resumability before
|
||||
#returning the session.
|
||||
|
||||
if session.valid():
|
||||
return session
|
||||
else:
|
||||
raise KeyError()
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
|
||||
def __setitem__(self, sessionID, session):
|
||||
self.lock.acquire()
|
||||
try:
|
||||
#Add the new element
|
||||
self.entriesDict[sessionID] = session
|
||||
self.entriesList[self.lastIndex] = (sessionID, time.time())
|
||||
self.lastIndex = (self.lastIndex+1) % len(self.entriesList)
|
||||
|
||||
#If the cache is full, we delete the oldest element to make an
|
||||
#empty space
|
||||
if self.lastIndex == self.firstIndex:
|
||||
del(self.entriesDict[self.entriesList[self.firstIndex][0]])
|
||||
self.firstIndex = (self.firstIndex+1) % len(self.entriesList)
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
#Delete expired items
|
||||
def _purge(self):
|
||||
currentTime = time.time()
|
||||
|
||||
#Search through the circular list, deleting expired elements until
|
||||
#we reach a non-expired element. Since elements in list are
|
||||
#ordered in time, we can break once we reach the first non-expired
|
||||
#element
|
||||
index = self.firstIndex
|
||||
while index != self.lastIndex:
|
||||
if currentTime - self.entriesList[index][1] > self.maxAge:
|
||||
del(self.entriesDict[self.entriesList[index][0]])
|
||||
index = (index+1) % len(self.entriesList)
|
||||
else:
|
||||
break
|
||||
self.firstIndex = index
|
||||
|
||||
def _test():
|
||||
import doctest, SessionCache
|
||||
return doctest.testmod(SessionCache)
|
||||
|
||||
if __name__ == "__main__":
|
||||
_test()
|
||||
@@ -1,58 +0,0 @@
|
||||
"""Class for storing shared keys."""
|
||||
|
||||
from utils.cryptomath import *
|
||||
from utils.compat import *
|
||||
from mathtls import *
|
||||
from Session import Session
|
||||
from BaseDB import BaseDB
|
||||
|
||||
class SharedKeyDB(BaseDB):
|
||||
"""This class represent an in-memory or on-disk database of shared
|
||||
keys.
|
||||
|
||||
A SharedKeyDB can be passed to a server handshake function to
|
||||
authenticate a client based on one of the shared keys.
|
||||
|
||||
This class is thread-safe.
|
||||
"""
|
||||
|
||||
def __init__(self, filename=None):
|
||||
"""Create a new SharedKeyDB.
|
||||
|
||||
@type filename: str
|
||||
@param filename: Filename for an on-disk database, or None for
|
||||
an in-memory database. If the filename already exists, follow
|
||||
this with a call to open(). To create a new on-disk database,
|
||||
follow this with a call to create().
|
||||
"""
|
||||
BaseDB.__init__(self, filename, "shared key")
|
||||
|
||||
def _getItem(self, username, valueStr):
|
||||
session = Session()
|
||||
session._createSharedKey(username, valueStr)
|
||||
return session
|
||||
|
||||
def __setitem__(self, username, sharedKey):
|
||||
"""Add a shared key to the database.
|
||||
|
||||
@type username: str
|
||||
@param username: The username to associate the shared key with.
|
||||
Must be less than or equal to 16 characters in length, and must
|
||||
not already be in the database.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: The shared key to add. Must be less than 48
|
||||
characters in length.
|
||||
"""
|
||||
BaseDB.__setitem__(self, username, sharedKey)
|
||||
|
||||
def _setItem(self, username, value):
|
||||
if len(username)>16:
|
||||
raise ValueError("username too long")
|
||||
if len(value)>=48:
|
||||
raise ValueError("shared key too long")
|
||||
return value
|
||||
|
||||
def _checkItem(self, value, username, param):
|
||||
newSession = self._getItem(username, param)
|
||||
return value.masterSecret == newSession.masterSecret
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,90 +0,0 @@
|
||||
"""Class for storing SRP password verifiers."""
|
||||
|
||||
from utils.cryptomath import *
|
||||
from utils.compat import *
|
||||
import mathtls
|
||||
from BaseDB import BaseDB
|
||||
|
||||
class VerifierDB(BaseDB):
|
||||
"""This class represent an in-memory or on-disk database of SRP
|
||||
password verifiers.
|
||||
|
||||
A VerifierDB can be passed to a server handshake to authenticate
|
||||
a client based on one of the verifiers.
|
||||
|
||||
This class is thread-safe.
|
||||
"""
|
||||
def __init__(self, filename=None):
|
||||
"""Create a new VerifierDB instance.
|
||||
|
||||
@type filename: str
|
||||
@param filename: Filename for an on-disk database, or None for
|
||||
an in-memory database. If the filename already exists, follow
|
||||
this with a call to open(). To create a new on-disk database,
|
||||
follow this with a call to create().
|
||||
"""
|
||||
BaseDB.__init__(self, filename, "verifier")
|
||||
|
||||
def _getItem(self, username, valueStr):
|
||||
(N, g, salt, verifier) = valueStr.split(" ")
|
||||
N = base64ToNumber(N)
|
||||
g = base64ToNumber(g)
|
||||
salt = base64ToString(salt)
|
||||
verifier = base64ToNumber(verifier)
|
||||
return (N, g, salt, verifier)
|
||||
|
||||
def __setitem__(self, username, verifierEntry):
|
||||
"""Add a verifier entry to the database.
|
||||
|
||||
@type username: str
|
||||
@param username: The username to associate the verifier with.
|
||||
Must be less than 256 characters in length. Must not already
|
||||
be in the database.
|
||||
|
||||
@type verifierEntry: tuple
|
||||
@param verifierEntry: The verifier entry to add. Use
|
||||
L{tlslite.VerifierDB.VerifierDB.makeVerifier} to create a
|
||||
verifier entry.
|
||||
"""
|
||||
BaseDB.__setitem__(self, username, verifierEntry)
|
||||
|
||||
|
||||
def _setItem(self, username, value):
|
||||
if len(username)>=256:
|
||||
raise ValueError("username too long")
|
||||
N, g, salt, verifier = value
|
||||
N = numberToBase64(N)
|
||||
g = numberToBase64(g)
|
||||
salt = stringToBase64(salt)
|
||||
verifier = numberToBase64(verifier)
|
||||
valueStr = " ".join( (N, g, salt, verifier) )
|
||||
return valueStr
|
||||
|
||||
def _checkItem(self, value, username, param):
|
||||
(N, g, salt, verifier) = value
|
||||
x = mathtls.makeX(salt, username, param)
|
||||
v = powMod(g, x, N)
|
||||
return (verifier == v)
|
||||
|
||||
|
||||
def makeVerifier(username, password, bits):
|
||||
"""Create a verifier entry which can be stored in a VerifierDB.
|
||||
|
||||
@type username: str
|
||||
@param username: The username for this verifier. Must be less
|
||||
than 256 characters in length.
|
||||
|
||||
@type password: str
|
||||
@param password: The password for this verifier.
|
||||
|
||||
@type bits: int
|
||||
@param bits: This values specifies which SRP group parameters
|
||||
to use. It must be one of (1024, 1536, 2048, 3072, 4096, 6144,
|
||||
8192). Larger values are more secure but slower. 2048 is a
|
||||
good compromise between safety and speed.
|
||||
|
||||
@rtype: tuple
|
||||
@return: A tuple which may be stored in a VerifierDB.
|
||||
"""
|
||||
return mathtls.makeVerifier(username, password, bits)
|
||||
makeVerifier = staticmethod(makeVerifier)
|
||||
@@ -1,133 +0,0 @@
|
||||
"""Class representing an X.509 certificate."""
|
||||
|
||||
from utils.ASN1Parser import ASN1Parser
|
||||
from utils.cryptomath import *
|
||||
from utils.keyfactory import _createPublicRSAKey
|
||||
|
||||
|
||||
class X509:
|
||||
"""This class represents an X.509 certificate.
|
||||
|
||||
@type bytes: L{array.array} of unsigned bytes
|
||||
@ivar bytes: The DER-encoded ASN.1 certificate
|
||||
|
||||
@type publicKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@ivar publicKey: The subject public key from the certificate.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.bytes = createByteArraySequence([])
|
||||
self.publicKey = None
|
||||
|
||||
def parse(self, s):
|
||||
"""Parse a PEM-encoded X.509 certificate.
|
||||
|
||||
@type s: str
|
||||
@param s: A PEM-encoded X.509 certificate (i.e. a base64-encoded
|
||||
certificate wrapped with "-----BEGIN CERTIFICATE-----" and
|
||||
"-----END CERTIFICATE-----" tags).
|
||||
"""
|
||||
|
||||
start = s.find("-----BEGIN CERTIFICATE-----")
|
||||
end = s.find("-----END CERTIFICATE-----")
|
||||
if start == -1:
|
||||
raise SyntaxError("Missing PEM prefix")
|
||||
if end == -1:
|
||||
raise SyntaxError("Missing PEM postfix")
|
||||
s = s[start+len("-----BEGIN CERTIFICATE-----") : end]
|
||||
|
||||
bytes = base64ToBytes(s)
|
||||
self.parseBinary(bytes)
|
||||
return self
|
||||
|
||||
def parseBinary(self, bytes):
|
||||
"""Parse a DER-encoded X.509 certificate.
|
||||
|
||||
@type bytes: str or L{array.array} of unsigned bytes
|
||||
@param bytes: A DER-encoded X.509 certificate.
|
||||
"""
|
||||
|
||||
if isinstance(bytes, type("")):
|
||||
bytes = stringToBytes(bytes)
|
||||
|
||||
self.bytes = bytes
|
||||
p = ASN1Parser(bytes)
|
||||
|
||||
#Get the tbsCertificate
|
||||
tbsCertificateP = p.getChild(0)
|
||||
|
||||
#Is the optional version field present?
|
||||
#This determines which index the key is at.
|
||||
if tbsCertificateP.value[0]==0xA0:
|
||||
subjectPublicKeyInfoIndex = 6
|
||||
else:
|
||||
subjectPublicKeyInfoIndex = 5
|
||||
|
||||
#Get the subjectPublicKeyInfo
|
||||
subjectPublicKeyInfoP = tbsCertificateP.getChild(\
|
||||
subjectPublicKeyInfoIndex)
|
||||
|
||||
#Get the algorithm
|
||||
algorithmP = subjectPublicKeyInfoP.getChild(0)
|
||||
rsaOID = algorithmP.value
|
||||
if list(rsaOID) != [6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0]:
|
||||
raise SyntaxError("Unrecognized AlgorithmIdentifier")
|
||||
|
||||
#Get the subjectPublicKey
|
||||
subjectPublicKeyP = subjectPublicKeyInfoP.getChild(1)
|
||||
|
||||
#Adjust for BIT STRING encapsulation
|
||||
if (subjectPublicKeyP.value[0] !=0):
|
||||
raise SyntaxError()
|
||||
subjectPublicKeyP = ASN1Parser(subjectPublicKeyP.value[1:])
|
||||
|
||||
#Get the modulus and exponent
|
||||
modulusP = subjectPublicKeyP.getChild(0)
|
||||
publicExponentP = subjectPublicKeyP.getChild(1)
|
||||
|
||||
#Decode them into numbers
|
||||
n = bytesToNumber(modulusP.value)
|
||||
e = bytesToNumber(publicExponentP.value)
|
||||
|
||||
#Create a public key instance
|
||||
self.publicKey = _createPublicRSAKey(n, e)
|
||||
|
||||
def getFingerprint(self):
|
||||
"""Get the hex-encoded fingerprint of this certificate.
|
||||
|
||||
@rtype: str
|
||||
@return: A hex-encoded fingerprint.
|
||||
"""
|
||||
return sha.sha(self.bytes).hexdigest()
|
||||
|
||||
def getCommonName(self):
|
||||
"""Get the Subject's Common Name from the certificate.
|
||||
|
||||
The cryptlib_py module must be installed in order to use this
|
||||
function.
|
||||
|
||||
@rtype: str or None
|
||||
@return: The CN component of the certificate's subject DN, if
|
||||
present.
|
||||
"""
|
||||
import cryptlib_py
|
||||
import array
|
||||
c = cryptlib_py.cryptImportCert(self.bytes, cryptlib_py.CRYPT_UNUSED)
|
||||
name = cryptlib_py.CRYPT_CERTINFO_COMMONNAME
|
||||
try:
|
||||
try:
|
||||
length = cryptlib_py.cryptGetAttributeString(c, name, None)
|
||||
returnVal = array.array('B', [0] * length)
|
||||
cryptlib_py.cryptGetAttributeString(c, name, returnVal)
|
||||
returnVal = returnVal.tostring()
|
||||
except cryptlib_py.CryptException, e:
|
||||
if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
|
||||
returnVal = None
|
||||
return returnVal
|
||||
finally:
|
||||
cryptlib_py.cryptDestroyCert(c)
|
||||
|
||||
def writeBytes(self):
|
||||
return self.bytes
|
||||
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
"""Class representing an X.509 certificate chain."""
|
||||
|
||||
from utils import cryptomath
|
||||
|
||||
class X509CertChain:
|
||||
"""This class represents a chain of X.509 certificates.
|
||||
|
||||
@type x509List: list
|
||||
@ivar x509List: A list of L{tlslite.X509.X509} instances,
|
||||
starting with the end-entity certificate and with every
|
||||
subsequent certificate certifying the previous.
|
||||
"""
|
||||
|
||||
def __init__(self, x509List=None):
|
||||
"""Create a new X509CertChain.
|
||||
|
||||
@type x509List: list
|
||||
@param x509List: A list of L{tlslite.X509.X509} instances,
|
||||
starting with the end-entity certificate and with every
|
||||
subsequent certificate certifying the previous.
|
||||
"""
|
||||
if x509List:
|
||||
self.x509List = x509List
|
||||
else:
|
||||
self.x509List = []
|
||||
|
||||
def getNumCerts(self):
|
||||
"""Get the number of certificates in this chain.
|
||||
|
||||
@rtype: int
|
||||
"""
|
||||
return len(self.x509List)
|
||||
|
||||
def getEndEntityPublicKey(self):
|
||||
"""Get the public key from the end-entity certificate.
|
||||
|
||||
@rtype: L{tlslite.utils.RSAKey.RSAKey}
|
||||
"""
|
||||
if self.getNumCerts() == 0:
|
||||
raise AssertionError()
|
||||
return self.x509List[0].publicKey
|
||||
|
||||
def getFingerprint(self):
|
||||
"""Get the hex-encoded fingerprint of the end-entity certificate.
|
||||
|
||||
@rtype: str
|
||||
@return: A hex-encoded fingerprint.
|
||||
"""
|
||||
if self.getNumCerts() == 0:
|
||||
raise AssertionError()
|
||||
return self.x509List[0].getFingerprint()
|
||||
|
||||
def getCommonName(self):
|
||||
"""Get the Subject's Common Name from the end-entity certificate.
|
||||
|
||||
The cryptlib_py module must be installed in order to use this
|
||||
function.
|
||||
|
||||
@rtype: str or None
|
||||
@return: The CN component of the certificate's subject DN, if
|
||||
present.
|
||||
"""
|
||||
if self.getNumCerts() == 0:
|
||||
raise AssertionError()
|
||||
return self.x509List[0].getCommonName()
|
||||
|
||||
def validate(self, x509TrustList):
|
||||
"""Check the validity of the certificate chain.
|
||||
|
||||
This checks that every certificate in the chain validates with
|
||||
the subsequent one, until some certificate validates with (or
|
||||
is identical to) one of the passed-in root certificates.
|
||||
|
||||
The cryptlib_py module must be installed in order to use this
|
||||
function.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
certificate chain must extend to one of these certificates to
|
||||
be considered valid.
|
||||
"""
|
||||
|
||||
import cryptlib_py
|
||||
c1 = None
|
||||
c2 = None
|
||||
lastC = None
|
||||
rootC = None
|
||||
|
||||
try:
|
||||
rootFingerprints = [c.getFingerprint() for c in x509TrustList]
|
||||
|
||||
#Check that every certificate in the chain validates with the
|
||||
#next one
|
||||
for cert1, cert2 in zip(self.x509List, self.x509List[1:]):
|
||||
|
||||
#If we come upon a root certificate, we're done.
|
||||
if cert1.getFingerprint() in rootFingerprints:
|
||||
return True
|
||||
|
||||
c1 = cryptlib_py.cryptImportCert(cert1.writeBytes(),
|
||||
cryptlib_py.CRYPT_UNUSED)
|
||||
c2 = cryptlib_py.cryptImportCert(cert2.writeBytes(),
|
||||
cryptlib_py.CRYPT_UNUSED)
|
||||
try:
|
||||
cryptlib_py.cryptCheckCert(c1, c2)
|
||||
except:
|
||||
return False
|
||||
cryptlib_py.cryptDestroyCert(c1)
|
||||
c1 = None
|
||||
cryptlib_py.cryptDestroyCert(c2)
|
||||
c2 = None
|
||||
|
||||
#If the last certificate is one of the root certificates, we're
|
||||
#done.
|
||||
if self.x509List[-1].getFingerprint() in rootFingerprints:
|
||||
return True
|
||||
|
||||
#Otherwise, find a root certificate that the last certificate
|
||||
#chains to, and validate them.
|
||||
lastC = cryptlib_py.cryptImportCert(self.x509List[-1].writeBytes(),
|
||||
cryptlib_py.CRYPT_UNUSED)
|
||||
for rootCert in x509TrustList:
|
||||
rootC = cryptlib_py.cryptImportCert(rootCert.writeBytes(),
|
||||
cryptlib_py.CRYPT_UNUSED)
|
||||
if self._checkChaining(lastC, rootC):
|
||||
try:
|
||||
cryptlib_py.cryptCheckCert(lastC, rootC)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
return False
|
||||
finally:
|
||||
if not (c1 is None):
|
||||
cryptlib_py.cryptDestroyCert(c1)
|
||||
if not (c2 is None):
|
||||
cryptlib_py.cryptDestroyCert(c2)
|
||||
if not (lastC is None):
|
||||
cryptlib_py.cryptDestroyCert(lastC)
|
||||
if not (rootC is None):
|
||||
cryptlib_py.cryptDestroyCert(rootC)
|
||||
|
||||
|
||||
|
||||
def _checkChaining(self, lastC, rootC):
|
||||
import cryptlib_py
|
||||
import array
|
||||
def compareNames(name):
|
||||
try:
|
||||
length = cryptlib_py.cryptGetAttributeString(lastC, name, None)
|
||||
lastName = array.array('B', [0] * length)
|
||||
cryptlib_py.cryptGetAttributeString(lastC, name, lastName)
|
||||
lastName = lastName.tostring()
|
||||
except cryptlib_py.CryptException, e:
|
||||
if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
|
||||
lastName = None
|
||||
try:
|
||||
length = cryptlib_py.cryptGetAttributeString(rootC, name, None)
|
||||
rootName = array.array('B', [0] * length)
|
||||
cryptlib_py.cryptGetAttributeString(rootC, name, rootName)
|
||||
rootName = rootName.tostring()
|
||||
except cryptlib_py.CryptException, e:
|
||||
if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
|
||||
rootName = None
|
||||
|
||||
return lastName == rootName
|
||||
|
||||
cryptlib_py.cryptSetAttribute(lastC,
|
||||
cryptlib_py.CRYPT_CERTINFO_ISSUERNAME,
|
||||
cryptlib_py.CRYPT_UNUSED)
|
||||
|
||||
if not compareNames(cryptlib_py.CRYPT_CERTINFO_COUNTRYNAME):
|
||||
return False
|
||||
if not compareNames(cryptlib_py.CRYPT_CERTINFO_LOCALITYNAME):
|
||||
return False
|
||||
if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONNAME):
|
||||
return False
|
||||
if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONALUNITNAME):
|
||||
return False
|
||||
if not compareNames(cryptlib_py.CRYPT_CERTINFO_COMMONNAME):
|
||||
return False
|
||||
return True
|
||||
@@ -1,39 +0,0 @@
|
||||
"""
|
||||
TLS Lite is a free python library that implements SSL v3, TLS v1, and
|
||||
TLS v1.1. TLS Lite supports non-traditional authentication methods
|
||||
such as SRP, shared keys, and cryptoIDs, in addition to X.509
|
||||
certificates. TLS Lite is pure python, however it can access OpenSSL,
|
||||
cryptlib, pycrypto, and GMPY for faster crypto operations. TLS Lite
|
||||
integrates with httplib, xmlrpclib, poplib, imaplib, smtplib,
|
||||
SocketServer, asyncore, and Twisted.
|
||||
|
||||
To use, do::
|
||||
|
||||
from tlslite.api import *
|
||||
|
||||
Then use the L{tlslite.TLSConnection.TLSConnection} class with a socket,
|
||||
or use one of the integration classes in L{tlslite.integration}.
|
||||
|
||||
@version: 0.3.8
|
||||
"""
|
||||
__version__ = "0.3.8"
|
||||
|
||||
__all__ = ["api",
|
||||
"BaseDB",
|
||||
"Checker",
|
||||
"constants",
|
||||
"errors",
|
||||
"FileObject",
|
||||
"HandshakeSettings",
|
||||
"mathtls",
|
||||
"messages",
|
||||
"Session",
|
||||
"SessionCache",
|
||||
"SharedKeyDB",
|
||||
"TLSConnection",
|
||||
"TLSRecordLayer",
|
||||
"VerifierDB",
|
||||
"X509",
|
||||
"X509CertChain",
|
||||
"integration",
|
||||
"utils"]
|
||||
@@ -1,75 +0,0 @@
|
||||
"""Import this module for easy access to TLS Lite objects.
|
||||
|
||||
The TLS Lite API consists of classes, functions, and variables spread
|
||||
throughout this package. Instead of importing them individually with::
|
||||
|
||||
from tlslite.TLSConnection import TLSConnection
|
||||
from tlslite.HandshakeSettings import HandshakeSettings
|
||||
from tlslite.errors import *
|
||||
.
|
||||
.
|
||||
|
||||
It's easier to do::
|
||||
|
||||
from tlslite.api import *
|
||||
|
||||
This imports all the important objects (TLSConnection, Checker,
|
||||
HandshakeSettings, etc.) into the global namespace. In particular, it
|
||||
imports::
|
||||
|
||||
from constants import AlertLevel, AlertDescription, Fault
|
||||
from errors import *
|
||||
from Checker import Checker
|
||||
from HandshakeSettings import HandshakeSettings
|
||||
from Session import Session
|
||||
from SessionCache import SessionCache
|
||||
from SharedKeyDB import SharedKeyDB
|
||||
from TLSConnection import TLSConnection
|
||||
from VerifierDB import VerifierDB
|
||||
from X509 import X509
|
||||
from X509CertChain import X509CertChain
|
||||
|
||||
from integration.HTTPTLSConnection import HTTPTLSConnection
|
||||
from integration.POP3_TLS import POP3_TLS
|
||||
from integration.IMAP4_TLS import IMAP4_TLS
|
||||
from integration.SMTP_TLS import SMTP_TLS
|
||||
from integration.XMLRPCTransport import XMLRPCTransport
|
||||
from integration.TLSSocketServerMixIn import TLSSocketServerMixIn
|
||||
from integration.TLSAsyncDispatcherMixIn import TLSAsyncDispatcherMixIn
|
||||
from integration.TLSTwistedProtocolWrapper import TLSTwistedProtocolWrapper
|
||||
from utils.cryptomath import cryptlibpyLoaded, m2cryptoLoaded,
|
||||
gmpyLoaded, pycryptoLoaded, prngName
|
||||
from utils.keyfactory import generateRSAKey, parsePEMKey, parseXMLKey,
|
||||
parseAsPublicKey, parsePrivateKey
|
||||
"""
|
||||
|
||||
from constants import AlertLevel, AlertDescription, Fault
|
||||
from errors import *
|
||||
from Checker import Checker
|
||||
from HandshakeSettings import HandshakeSettings
|
||||
from Session import Session
|
||||
from SessionCache import SessionCache
|
||||
from SharedKeyDB import SharedKeyDB
|
||||
from TLSConnection import TLSConnection
|
||||
from VerifierDB import VerifierDB
|
||||
from X509 import X509
|
||||
from X509CertChain import X509CertChain
|
||||
|
||||
from integration.HTTPTLSConnection import HTTPTLSConnection
|
||||
from integration.TLSSocketServerMixIn import TLSSocketServerMixIn
|
||||
from integration.TLSAsyncDispatcherMixIn import TLSAsyncDispatcherMixIn
|
||||
from integration.POP3_TLS import POP3_TLS
|
||||
from integration.IMAP4_TLS import IMAP4_TLS
|
||||
from integration.SMTP_TLS import SMTP_TLS
|
||||
from integration.XMLRPCTransport import XMLRPCTransport
|
||||
try:
|
||||
import twisted
|
||||
del(twisted)
|
||||
from integration.TLSTwistedProtocolWrapper import TLSTwistedProtocolWrapper
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from utils.cryptomath import cryptlibpyLoaded, m2cryptoLoaded, gmpyLoaded, \
|
||||
pycryptoLoaded, prngName
|
||||
from utils.keyfactory import generateRSAKey, parsePEMKey, parseXMLKey, \
|
||||
parseAsPublicKey, parsePrivateKey
|
||||
@@ -1,225 +0,0 @@
|
||||
"""Constants used in various places."""
|
||||
|
||||
class CertificateType:
|
||||
x509 = 0
|
||||
openpgp = 1
|
||||
cryptoID = 2
|
||||
|
||||
class HandshakeType:
|
||||
hello_request = 0
|
||||
client_hello = 1
|
||||
server_hello = 2
|
||||
certificate = 11
|
||||
server_key_exchange = 12
|
||||
certificate_request = 13
|
||||
server_hello_done = 14
|
||||
certificate_verify = 15
|
||||
client_key_exchange = 16
|
||||
finished = 20
|
||||
|
||||
class ContentType:
|
||||
change_cipher_spec = 20
|
||||
alert = 21
|
||||
handshake = 22
|
||||
application_data = 23
|
||||
all = (20,21,22,23)
|
||||
|
||||
class AlertLevel:
|
||||
warning = 1
|
||||
fatal = 2
|
||||
|
||||
class AlertDescription:
|
||||
"""
|
||||
@cvar bad_record_mac: A TLS record failed to decrypt properly.
|
||||
|
||||
If this occurs during a shared-key or SRP handshake it most likely
|
||||
indicates a bad password. It may also indicate an implementation
|
||||
error, or some tampering with the data in transit.
|
||||
|
||||
This alert will be signalled by the server if the SRP password is bad. It
|
||||
may also be signalled by the server if the SRP username is unknown to the
|
||||
server, but it doesn't wish to reveal that fact.
|
||||
|
||||
This alert will be signalled by the client if the shared-key username is
|
||||
bad.
|
||||
|
||||
@cvar handshake_failure: A problem occurred while handshaking.
|
||||
|
||||
This typically indicates a lack of common ciphersuites between client and
|
||||
server, or some other disagreement (about SRP parameters or key sizes,
|
||||
for example).
|
||||
|
||||
@cvar protocol_version: The other party's SSL/TLS version was unacceptable.
|
||||
|
||||
This indicates that the client and server couldn't agree on which version
|
||||
of SSL or TLS to use.
|
||||
|
||||
@cvar user_canceled: The handshake is being cancelled for some reason.
|
||||
|
||||
"""
|
||||
|
||||
close_notify = 0
|
||||
unexpected_message = 10
|
||||
bad_record_mac = 20
|
||||
decryption_failed = 21
|
||||
record_overflow = 22
|
||||
decompression_failure = 30
|
||||
handshake_failure = 40
|
||||
no_certificate = 41 #SSLv3
|
||||
bad_certificate = 42
|
||||
unsupported_certificate = 43
|
||||
certificate_revoked = 44
|
||||
certificate_expired = 45
|
||||
certificate_unknown = 46
|
||||
illegal_parameter = 47
|
||||
unknown_ca = 48
|
||||
access_denied = 49
|
||||
decode_error = 50
|
||||
decrypt_error = 51
|
||||
export_restriction = 60
|
||||
protocol_version = 70
|
||||
insufficient_security = 71
|
||||
internal_error = 80
|
||||
user_canceled = 90
|
||||
no_renegotiation = 100
|
||||
unknown_srp_username = 120
|
||||
missing_srp_username = 121
|
||||
untrusted_srp_parameters = 122
|
||||
|
||||
class CipherSuite:
|
||||
TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA = 0x0050
|
||||
TLS_SRP_SHA_WITH_AES_128_CBC_SHA = 0x0053
|
||||
TLS_SRP_SHA_WITH_AES_256_CBC_SHA = 0x0056
|
||||
|
||||
TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA = 0x0051
|
||||
TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA = 0x0054
|
||||
TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA = 0x0057
|
||||
|
||||
TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A
|
||||
TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F
|
||||
TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035
|
||||
TLS_RSA_WITH_RC4_128_SHA = 0x0005
|
||||
|
||||
srpSuites = []
|
||||
srpSuites.append(TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA)
|
||||
srpSuites.append(TLS_SRP_SHA_WITH_AES_128_CBC_SHA)
|
||||
srpSuites.append(TLS_SRP_SHA_WITH_AES_256_CBC_SHA)
|
||||
def getSrpSuites(ciphers):
|
||||
suites = []
|
||||
for cipher in ciphers:
|
||||
if cipher == "aes128":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA)
|
||||
elif cipher == "aes256":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA)
|
||||
elif cipher == "3des":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA)
|
||||
return suites
|
||||
getSrpSuites = staticmethod(getSrpSuites)
|
||||
|
||||
srpRsaSuites = []
|
||||
srpRsaSuites.append(TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
srpRsaSuites.append(TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA)
|
||||
srpRsaSuites.append(TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA)
|
||||
def getSrpRsaSuites(ciphers):
|
||||
suites = []
|
||||
for cipher in ciphers:
|
||||
if cipher == "aes128":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA)
|
||||
elif cipher == "aes256":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA)
|
||||
elif cipher == "3des":
|
||||
suites.append(CipherSuite.TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
return suites
|
||||
getSrpRsaSuites = staticmethod(getSrpRsaSuites)
|
||||
|
||||
rsaSuites = []
|
||||
rsaSuites.append(TLS_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
rsaSuites.append(TLS_RSA_WITH_AES_128_CBC_SHA)
|
||||
rsaSuites.append(TLS_RSA_WITH_AES_256_CBC_SHA)
|
||||
rsaSuites.append(TLS_RSA_WITH_RC4_128_SHA)
|
||||
def getRsaSuites(ciphers):
|
||||
suites = []
|
||||
for cipher in ciphers:
|
||||
if cipher == "aes128":
|
||||
suites.append(CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA)
|
||||
elif cipher == "aes256":
|
||||
suites.append(CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA)
|
||||
elif cipher == "rc4":
|
||||
suites.append(CipherSuite.TLS_RSA_WITH_RC4_128_SHA)
|
||||
elif cipher == "3des":
|
||||
suites.append(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
return suites
|
||||
getRsaSuites = staticmethod(getRsaSuites)
|
||||
|
||||
tripleDESSuites = []
|
||||
tripleDESSuites.append(TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA)
|
||||
tripleDESSuites.append(TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
tripleDESSuites.append(TLS_RSA_WITH_3DES_EDE_CBC_SHA)
|
||||
|
||||
aes128Suites = []
|
||||
aes128Suites.append(TLS_SRP_SHA_WITH_AES_128_CBC_SHA)
|
||||
aes128Suites.append(TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA)
|
||||
aes128Suites.append(TLS_RSA_WITH_AES_128_CBC_SHA)
|
||||
|
||||
aes256Suites = []
|
||||
aes256Suites.append(TLS_SRP_SHA_WITH_AES_256_CBC_SHA)
|
||||
aes256Suites.append(TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA)
|
||||
aes256Suites.append(TLS_RSA_WITH_AES_256_CBC_SHA)
|
||||
|
||||
rc4Suites = []
|
||||
rc4Suites.append(TLS_RSA_WITH_RC4_128_SHA)
|
||||
|
||||
|
||||
class Fault:
|
||||
badUsername = 101
|
||||
badPassword = 102
|
||||
badA = 103
|
||||
clientSrpFaults = range(101,104)
|
||||
|
||||
badVerifyMessage = 601
|
||||
clientCertFaults = range(601,602)
|
||||
|
||||
badPremasterPadding = 501
|
||||
shortPremasterSecret = 502
|
||||
clientNoAuthFaults = range(501,503)
|
||||
|
||||
badIdentifier = 401
|
||||
badSharedKey = 402
|
||||
clientSharedKeyFaults = range(401,403)
|
||||
|
||||
badB = 201
|
||||
serverFaults = range(201,202)
|
||||
|
||||
badFinished = 300
|
||||
badMAC = 301
|
||||
badPadding = 302
|
||||
genericFaults = range(300,303)
|
||||
|
||||
faultAlerts = {\
|
||||
badUsername: (AlertDescription.unknown_srp_username, \
|
||||
AlertDescription.bad_record_mac),\
|
||||
badPassword: (AlertDescription.bad_record_mac,),\
|
||||
badA: (AlertDescription.illegal_parameter,),\
|
||||
badIdentifier: (AlertDescription.handshake_failure,),\
|
||||
badSharedKey: (AlertDescription.bad_record_mac,),\
|
||||
badPremasterPadding: (AlertDescription.bad_record_mac,),\
|
||||
shortPremasterSecret: (AlertDescription.bad_record_mac,),\
|
||||
badVerifyMessage: (AlertDescription.decrypt_error,),\
|
||||
badFinished: (AlertDescription.decrypt_error,),\
|
||||
badMAC: (AlertDescription.bad_record_mac,),\
|
||||
badPadding: (AlertDescription.bad_record_mac,)
|
||||
}
|
||||
|
||||
faultNames = {\
|
||||
badUsername: "bad username",\
|
||||
badPassword: "bad password",\
|
||||
badA: "bad A",\
|
||||
badIdentifier: "bad identifier",\
|
||||
badSharedKey: "bad sharedkey",\
|
||||
badPremasterPadding: "bad premaster padding",\
|
||||
shortPremasterSecret: "short premaster secret",\
|
||||
badVerifyMessage: "bad verify message",\
|
||||
badFinished: "bad finished message",\
|
||||
badMAC: "bad MAC",\
|
||||
badPadding: "bad padding"
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
"""Exception classes.
|
||||
@sort: TLSError, TLSAbruptCloseError, TLSAlert, TLSLocalAlert, TLSRemoteAlert,
|
||||
TLSAuthenticationError, TLSNoAuthenticationError, TLSAuthenticationTypeError,
|
||||
TLSFingerprintError, TLSAuthorizationError, TLSValidationError, TLSFaultError
|
||||
"""
|
||||
|
||||
from constants import AlertDescription, AlertLevel
|
||||
|
||||
class TLSError(Exception):
|
||||
"""Base class for all TLS Lite exceptions."""
|
||||
pass
|
||||
|
||||
class TLSAbruptCloseError(TLSError):
|
||||
"""The socket was closed without a proper TLS shutdown.
|
||||
|
||||
The TLS specification mandates that an alert of some sort
|
||||
must be sent before the underlying socket is closed. If the socket
|
||||
is closed without this, it could signify that an attacker is trying
|
||||
to truncate the connection. It could also signify a misbehaving
|
||||
TLS implementation, or a random network failure.
|
||||
"""
|
||||
pass
|
||||
|
||||
class TLSAlert(TLSError):
|
||||
"""A TLS alert has been signalled."""
|
||||
pass
|
||||
|
||||
_descriptionStr = {\
|
||||
AlertDescription.close_notify: "close_notify",\
|
||||
AlertDescription.unexpected_message: "unexpected_message",\
|
||||
AlertDescription.bad_record_mac: "bad_record_mac",\
|
||||
AlertDescription.decryption_failed: "decryption_failed",\
|
||||
AlertDescription.record_overflow: "record_overflow",\
|
||||
AlertDescription.decompression_failure: "decompression_failure",\
|
||||
AlertDescription.handshake_failure: "handshake_failure",\
|
||||
AlertDescription.no_certificate: "no certificate",\
|
||||
AlertDescription.bad_certificate: "bad_certificate",\
|
||||
AlertDescription.unsupported_certificate: "unsupported_certificate",\
|
||||
AlertDescription.certificate_revoked: "certificate_revoked",\
|
||||
AlertDescription.certificate_expired: "certificate_expired",\
|
||||
AlertDescription.certificate_unknown: "certificate_unknown",\
|
||||
AlertDescription.illegal_parameter: "illegal_parameter",\
|
||||
AlertDescription.unknown_ca: "unknown_ca",\
|
||||
AlertDescription.access_denied: "access_denied",\
|
||||
AlertDescription.decode_error: "decode_error",\
|
||||
AlertDescription.decrypt_error: "decrypt_error",\
|
||||
AlertDescription.export_restriction: "export_restriction",\
|
||||
AlertDescription.protocol_version: "protocol_version",\
|
||||
AlertDescription.insufficient_security: "insufficient_security",\
|
||||
AlertDescription.internal_error: "internal_error",\
|
||||
AlertDescription.user_canceled: "user_canceled",\
|
||||
AlertDescription.no_renegotiation: "no_renegotiation",\
|
||||
AlertDescription.unknown_srp_username: "unknown_srp_username",\
|
||||
AlertDescription.missing_srp_username: "missing_srp_username"}
|
||||
|
||||
class TLSLocalAlert(TLSAlert):
|
||||
"""A TLS alert has been signalled by the local implementation.
|
||||
|
||||
@type description: int
|
||||
@ivar description: Set to one of the constants in
|
||||
L{tlslite.constants.AlertDescription}
|
||||
|
||||
@type level: int
|
||||
@ivar level: Set to one of the constants in
|
||||
L{tlslite.constants.AlertLevel}
|
||||
|
||||
@type message: str
|
||||
@ivar message: Description of what went wrong.
|
||||
"""
|
||||
def __init__(self, alert, message=None):
|
||||
self.description = alert.description
|
||||
self.level = alert.level
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
alertStr = TLSAlert._descriptionStr.get(self.description)
|
||||
if alertStr == None:
|
||||
alertStr = str(self.description)
|
||||
if self.message:
|
||||
return alertStr + ": " + self.message
|
||||
else:
|
||||
return alertStr
|
||||
|
||||
class TLSRemoteAlert(TLSAlert):
|
||||
"""A TLS alert has been signalled by the remote implementation.
|
||||
|
||||
@type description: int
|
||||
@ivar description: Set to one of the constants in
|
||||
L{tlslite.constants.AlertDescription}
|
||||
|
||||
@type level: int
|
||||
@ivar level: Set to one of the constants in
|
||||
L{tlslite.constants.AlertLevel}
|
||||
"""
|
||||
def __init__(self, alert):
|
||||
self.description = alert.description
|
||||
self.level = alert.level
|
||||
|
||||
def __str__(self):
|
||||
alertStr = TLSAlert._descriptionStr.get(self.description)
|
||||
if alertStr == None:
|
||||
alertStr = str(self.description)
|
||||
return alertStr
|
||||
|
||||
class TLSAuthenticationError(TLSError):
|
||||
"""The handshake succeeded, but the other party's authentication
|
||||
was inadequate.
|
||||
|
||||
This exception will only be raised when a
|
||||
L{tlslite.Checker.Checker} has been passed to a handshake function.
|
||||
The Checker will be invoked once the handshake completes, and if
|
||||
the Checker objects to how the other party authenticated, a
|
||||
subclass of this exception will be raised.
|
||||
"""
|
||||
pass
|
||||
|
||||
class TLSNoAuthenticationError(TLSAuthenticationError):
|
||||
"""The Checker was expecting the other party to authenticate with a
|
||||
certificate chain, but this did not occur."""
|
||||
pass
|
||||
|
||||
class TLSAuthenticationTypeError(TLSAuthenticationError):
|
||||
"""The Checker was expecting the other party to authenticate with a
|
||||
different type of certificate chain."""
|
||||
pass
|
||||
|
||||
class TLSFingerprintError(TLSAuthenticationError):
|
||||
"""The Checker was expecting the other party to authenticate with a
|
||||
certificate chain that matches a different fingerprint."""
|
||||
pass
|
||||
|
||||
class TLSAuthorizationError(TLSAuthenticationError):
|
||||
"""The Checker was expecting the other party to authenticate with a
|
||||
certificate chain that has a different authorization."""
|
||||
pass
|
||||
|
||||
class TLSValidationError(TLSAuthenticationError):
|
||||
"""The Checker has determined that the other party's certificate
|
||||
chain is invalid."""
|
||||
pass
|
||||
|
||||
class TLSFaultError(TLSError):
|
||||
"""The other party responded incorrectly to an induced fault.
|
||||
|
||||
This exception will only occur during fault testing, when a
|
||||
TLSConnection's fault variable is set to induce some sort of
|
||||
faulty behavior, and the other party doesn't respond appropriately.
|
||||
"""
|
||||
pass
|
||||
@@ -1,235 +0,0 @@
|
||||
"""
|
||||
A state machine for using TLS Lite with asynchronous I/O.
|
||||
"""
|
||||
|
||||
class AsyncStateMachine:
|
||||
"""
|
||||
This is an abstract class that's used to integrate TLS Lite with
|
||||
asyncore and Twisted.
|
||||
|
||||
This class signals wantsReadsEvent() and wantsWriteEvent(). When
|
||||
the underlying socket has become readable or writeable, the event
|
||||
should be passed to this class by calling inReadEvent() or
|
||||
inWriteEvent(). This class will then try to read or write through
|
||||
the socket, and will update its state appropriately.
|
||||
|
||||
This class will forward higher-level events to its subclass. For
|
||||
example, when a complete TLS record has been received,
|
||||
outReadEvent() will be called with the decrypted data.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._clear()
|
||||
|
||||
def _clear(self):
|
||||
#These store the various asynchronous operations (i.e.
|
||||
#generators). Only one of them, at most, is ever active at a
|
||||
#time.
|
||||
self.handshaker = None
|
||||
self.closer = None
|
||||
self.reader = None
|
||||
self.writer = None
|
||||
|
||||
#This stores the result from the last call to the
|
||||
#currently active operation. If 0 it indicates that the
|
||||
#operation wants to read, if 1 it indicates that the
|
||||
#operation wants to write. If None, there is no active
|
||||
#operation.
|
||||
self.result = None
|
||||
|
||||
def _checkAssert(self, maxActive=1):
|
||||
#This checks that only one operation, at most, is
|
||||
#active, and that self.result is set appropriately.
|
||||
activeOps = 0
|
||||
if self.handshaker:
|
||||
activeOps += 1
|
||||
if self.closer:
|
||||
activeOps += 1
|
||||
if self.reader:
|
||||
activeOps += 1
|
||||
if self.writer:
|
||||
activeOps += 1
|
||||
|
||||
if self.result == None:
|
||||
if activeOps != 0:
|
||||
raise AssertionError()
|
||||
elif self.result in (0,1):
|
||||
if activeOps != 1:
|
||||
raise AssertionError()
|
||||
else:
|
||||
raise AssertionError()
|
||||
if activeOps > maxActive:
|
||||
raise AssertionError()
|
||||
|
||||
def wantsReadEvent(self):
|
||||
"""If the state machine wants to read.
|
||||
|
||||
If an operation is active, this returns whether or not the
|
||||
operation wants to read from the socket. If an operation is
|
||||
not active, this returns None.
|
||||
|
||||
@rtype: bool or None
|
||||
@return: If the state machine wants to read.
|
||||
"""
|
||||
if self.result != None:
|
||||
return self.result == 0
|
||||
return None
|
||||
|
||||
def wantsWriteEvent(self):
|
||||
"""If the state machine wants to write.
|
||||
|
||||
If an operation is active, this returns whether or not the
|
||||
operation wants to write to the socket. If an operation is
|
||||
not active, this returns None.
|
||||
|
||||
@rtype: bool or None
|
||||
@return: If the state machine wants to write.
|
||||
"""
|
||||
if self.result != None:
|
||||
return self.result == 1
|
||||
return None
|
||||
|
||||
def outConnectEvent(self):
|
||||
"""Called when a handshake operation completes.
|
||||
|
||||
May be overridden in subclass.
|
||||
"""
|
||||
pass
|
||||
|
||||
def outCloseEvent(self):
|
||||
"""Called when a close operation completes.
|
||||
|
||||
May be overridden in subclass.
|
||||
"""
|
||||
pass
|
||||
|
||||
def outReadEvent(self, readBuffer):
|
||||
"""Called when a read operation completes.
|
||||
|
||||
May be overridden in subclass."""
|
||||
pass
|
||||
|
||||
def outWriteEvent(self):
|
||||
"""Called when a write operation completes.
|
||||
|
||||
May be overridden in subclass."""
|
||||
pass
|
||||
|
||||
def inReadEvent(self):
|
||||
"""Tell the state machine it can read from the socket."""
|
||||
try:
|
||||
self._checkAssert()
|
||||
if self.handshaker:
|
||||
self._doHandshakeOp()
|
||||
elif self.closer:
|
||||
self._doCloseOp()
|
||||
elif self.reader:
|
||||
self._doReadOp()
|
||||
elif self.writer:
|
||||
self._doWriteOp()
|
||||
else:
|
||||
self.reader = self.tlsConnection.readAsync(16384)
|
||||
self._doReadOp()
|
||||
except:
|
||||
self._clear()
|
||||
raise
|
||||
|
||||
def inWriteEvent(self):
|
||||
"""Tell the state machine it can write to the socket."""
|
||||
try:
|
||||
self._checkAssert()
|
||||
if self.handshaker:
|
||||
self._doHandshakeOp()
|
||||
elif self.closer:
|
||||
self._doCloseOp()
|
||||
elif self.reader:
|
||||
self._doReadOp()
|
||||
elif self.writer:
|
||||
self._doWriteOp()
|
||||
else:
|
||||
self.outWriteEvent()
|
||||
except:
|
||||
self._clear()
|
||||
raise
|
||||
|
||||
def _doHandshakeOp(self):
|
||||
try:
|
||||
self.result = self.handshaker.next()
|
||||
except StopIteration:
|
||||
self.handshaker = None
|
||||
self.result = None
|
||||
self.outConnectEvent()
|
||||
|
||||
def _doCloseOp(self):
|
||||
try:
|
||||
self.result = self.closer.next()
|
||||
except StopIteration:
|
||||
self.closer = None
|
||||
self.result = None
|
||||
self.outCloseEvent()
|
||||
|
||||
def _doReadOp(self):
|
||||
self.result = self.reader.next()
|
||||
if not self.result in (0,1):
|
||||
readBuffer = self.result
|
||||
self.reader = None
|
||||
self.result = None
|
||||
self.outReadEvent(readBuffer)
|
||||
|
||||
def _doWriteOp(self):
|
||||
try:
|
||||
self.result = self.writer.next()
|
||||
except StopIteration:
|
||||
self.writer = None
|
||||
self.result = None
|
||||
|
||||
def setHandshakeOp(self, handshaker):
|
||||
"""Start a handshake operation.
|
||||
|
||||
@type handshaker: generator
|
||||
@param handshaker: A generator created by using one of the
|
||||
asynchronous handshake functions (i.e. handshakeServerAsync, or
|
||||
handshakeClientxxx(..., async=True).
|
||||
"""
|
||||
try:
|
||||
self._checkAssert(0)
|
||||
self.handshaker = handshaker
|
||||
self._doHandshakeOp()
|
||||
except:
|
||||
self._clear()
|
||||
raise
|
||||
|
||||
def setServerHandshakeOp(self, **args):
|
||||
"""Start a handshake operation.
|
||||
|
||||
The arguments passed to this function will be forwarded to
|
||||
L{tlslite.TLSConnection.TLSConnection.handshakeServerAsync}.
|
||||
"""
|
||||
handshaker = self.tlsConnection.handshakeServerAsync(**args)
|
||||
self.setHandshakeOp(handshaker)
|
||||
|
||||
def setCloseOp(self):
|
||||
"""Start a close operation.
|
||||
"""
|
||||
try:
|
||||
self._checkAssert(0)
|
||||
self.closer = self.tlsConnection.closeAsync()
|
||||
self._doCloseOp()
|
||||
except:
|
||||
self._clear()
|
||||
raise
|
||||
|
||||
def setWriteOp(self, writeBuffer):
|
||||
"""Start a write operation.
|
||||
|
||||
@type writeBuffer: str
|
||||
@param writeBuffer: The string to transmit.
|
||||
"""
|
||||
try:
|
||||
self._checkAssert(0)
|
||||
self.writer = self.tlsConnection.writeAsync(writeBuffer)
|
||||
self._doWriteOp()
|
||||
except:
|
||||
self._clear()
|
||||
raise
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
"""
|
||||
A helper class for using TLS Lite with stdlib clients
|
||||
(httplib, xmlrpclib, imaplib, poplib).
|
||||
"""
|
||||
|
||||
from gdata.tlslite.Checker import Checker
|
||||
|
||||
class ClientHelper:
|
||||
"""This is a helper class used to integrate TLS Lite with various
|
||||
TLS clients (e.g. poplib, smtplib, httplib, etc.)"""
|
||||
|
||||
def __init__(self,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings = None):
|
||||
"""
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The constructor does not perform the TLS handshake itself, but
|
||||
simply stores these arguments for later. The handshake is
|
||||
performed only when this class needs to connect with the
|
||||
server. Then you should be prepared to handle TLS-specific
|
||||
exceptions. See the client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
|
||||
self.username = None
|
||||
self.password = None
|
||||
self.sharedKey = None
|
||||
self.certChain = None
|
||||
self.privateKey = None
|
||||
self.checker = None
|
||||
|
||||
#SRP Authentication
|
||||
if username and password and not \
|
||||
(sharedKey or certChain or privateKey):
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
#Shared Key Authentication
|
||||
elif username and sharedKey and not \
|
||||
(password or certChain or privateKey):
|
||||
self.username = username
|
||||
self.sharedKey = sharedKey
|
||||
|
||||
#Certificate Chain Authentication
|
||||
elif certChain and privateKey and not \
|
||||
(username or password or sharedKey):
|
||||
self.certChain = certChain
|
||||
self.privateKey = privateKey
|
||||
|
||||
#No Authentication
|
||||
elif not password and not username and not \
|
||||
sharedKey and not certChain and not privateKey:
|
||||
pass
|
||||
|
||||
else:
|
||||
raise ValueError("Bad parameters")
|
||||
|
||||
#Authenticate the server based on its cryptoID or fingerprint
|
||||
if sharedKey and (cryptoID or protocol or x509Fingerprint):
|
||||
raise ValueError("Can't use shared keys with other forms of"\
|
||||
"authentication")
|
||||
|
||||
self.checker = Checker(cryptoID, protocol, x509Fingerprint,
|
||||
x509TrustList, x509CommonName)
|
||||
self.settings = settings
|
||||
|
||||
self.tlsSession = None
|
||||
|
||||
def _handshake(self, tlsConnection):
|
||||
if self.username and self.password:
|
||||
tlsConnection.handshakeClientSRP(username=self.username,
|
||||
password=self.password,
|
||||
checker=self.checker,
|
||||
settings=self.settings,
|
||||
session=self.tlsSession)
|
||||
elif self.username and self.sharedKey:
|
||||
tlsConnection.handshakeClientSharedKey(username=self.username,
|
||||
sharedKey=self.sharedKey,
|
||||
settings=self.settings)
|
||||
else:
|
||||
tlsConnection.handshakeClientCert(certChain=self.certChain,
|
||||
privateKey=self.privateKey,
|
||||
checker=self.checker,
|
||||
settings=self.settings,
|
||||
session=self.tlsSession)
|
||||
self.tlsSession = tlsConnection.session
|
||||
@@ -1,169 +0,0 @@
|
||||
"""TLS Lite + httplib."""
|
||||
|
||||
import socket
|
||||
import httplib
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from gdata.tlslite.integration.ClientHelper import ClientHelper
|
||||
|
||||
|
||||
class HTTPBaseTLSConnection(httplib.HTTPConnection):
|
||||
"""This abstract class provides a framework for adding TLS support
|
||||
to httplib."""
|
||||
|
||||
default_port = 443
|
||||
|
||||
def __init__(self, host, port=None, strict=None):
|
||||
if strict == None:
|
||||
#Python 2.2 doesn't support strict
|
||||
httplib.HTTPConnection.__init__(self, host, port)
|
||||
else:
|
||||
httplib.HTTPConnection.__init__(self, host, port, strict)
|
||||
|
||||
def connect(self):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if hasattr(sock, 'settimeout'):
|
||||
sock.settimeout(10)
|
||||
sock.connect((self.host, self.port))
|
||||
|
||||
#Use a TLSConnection to emulate a socket
|
||||
self.sock = TLSConnection(sock)
|
||||
|
||||
#When httplib closes this, close the socket
|
||||
self.sock.closeSocket = True
|
||||
self._handshake(self.sock)
|
||||
|
||||
def _handshake(self, tlsConnection):
|
||||
"""Called to perform some sort of handshake.
|
||||
|
||||
This method must be overridden in a subclass to do some type of
|
||||
handshake. This method will be called after the socket has
|
||||
been connected but before any data has been sent. If this
|
||||
method does not raise an exception, the TLS connection will be
|
||||
considered valid.
|
||||
|
||||
This method may (or may not) be called every time an HTTP
|
||||
request is performed, depending on whether the underlying HTTP
|
||||
connection is persistent.
|
||||
|
||||
@type tlsConnection: L{tlslite.TLSConnection.TLSConnection}
|
||||
@param tlsConnection: The connection to perform the handshake
|
||||
on.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class HTTPTLSConnection(HTTPBaseTLSConnection, ClientHelper):
|
||||
"""This class extends L{HTTPBaseTLSConnection} to support the
|
||||
common types of handshaking."""
|
||||
|
||||
def __init__(self, host, port=None,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings = None):
|
||||
"""Create a new HTTPTLSConnection.
|
||||
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The constructor does not perform the TLS handshake itself, but
|
||||
simply stores these arguments for later. The handshake is
|
||||
performed only when this class needs to connect with the
|
||||
server. Thus you should be prepared to handle TLS-specific
|
||||
exceptions when calling methods inherited from
|
||||
L{httplib.HTTPConnection} such as request(), connect(), and
|
||||
send(). See the client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type host: str
|
||||
@param host: Server to connect to.
|
||||
|
||||
@type port: int
|
||||
@param port: Port to connect to.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
|
||||
HTTPBaseTLSConnection.__init__(self, host, port)
|
||||
|
||||
ClientHelper.__init__(self,
|
||||
username, password, sharedKey,
|
||||
certChain, privateKey,
|
||||
cryptoID, protocol,
|
||||
x509Fingerprint,
|
||||
x509TrustList, x509CommonName,
|
||||
settings)
|
||||
|
||||
def _handshake(self, tlsConnection):
|
||||
ClientHelper._handshake(self, tlsConnection)
|
||||
@@ -1,132 +0,0 @@
|
||||
"""TLS Lite + imaplib."""
|
||||
|
||||
import socket
|
||||
from imaplib import IMAP4
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from gdata.tlslite.integration.ClientHelper import ClientHelper
|
||||
|
||||
# IMAP TLS PORT
|
||||
IMAP4_TLS_PORT = 993
|
||||
|
||||
class IMAP4_TLS(IMAP4, ClientHelper):
|
||||
"""This class extends L{imaplib.IMAP4} with TLS support."""
|
||||
|
||||
def __init__(self, host = '', port = IMAP4_TLS_PORT,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings=None):
|
||||
"""Create a new IMAP4_TLS.
|
||||
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The caller should be prepared to handle TLS-specific
|
||||
exceptions. See the client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type host: str
|
||||
@param host: Server to connect to.
|
||||
|
||||
@type port: int
|
||||
@param port: Port to connect to.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
|
||||
ClientHelper.__init__(self,
|
||||
username, password, sharedKey,
|
||||
certChain, privateKey,
|
||||
cryptoID, protocol,
|
||||
x509Fingerprint,
|
||||
x509TrustList, x509CommonName,
|
||||
settings)
|
||||
|
||||
IMAP4.__init__(self, host, port)
|
||||
|
||||
|
||||
def open(self, host = '', port = IMAP4_TLS_PORT):
|
||||
"""Setup connection to remote server on "host:port".
|
||||
|
||||
This connection will be used by the routines:
|
||||
read, readline, send, shutdown.
|
||||
"""
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((host, port))
|
||||
self.sock = TLSConnection(self.sock)
|
||||
self.sock.closeSocket = True
|
||||
ClientHelper._handshake(self, self.sock)
|
||||
self.file = self.sock.makefile('rb')
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
class IntegrationHelper:
|
||||
|
||||
def __init__(self,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings = None):
|
||||
|
||||
self.username = None
|
||||
self.password = None
|
||||
self.sharedKey = None
|
||||
self.certChain = None
|
||||
self.privateKey = None
|
||||
self.checker = None
|
||||
|
||||
#SRP Authentication
|
||||
if username and password and not \
|
||||
(sharedKey or certChain or privateKey):
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
#Shared Key Authentication
|
||||
elif username and sharedKey and not \
|
||||
(password or certChain or privateKey):
|
||||
self.username = username
|
||||
self.sharedKey = sharedKey
|
||||
|
||||
#Certificate Chain Authentication
|
||||
elif certChain and privateKey and not \
|
||||
(username or password or sharedKey):
|
||||
self.certChain = certChain
|
||||
self.privateKey = privateKey
|
||||
|
||||
#No Authentication
|
||||
elif not password and not username and not \
|
||||
sharedKey and not certChain and not privateKey:
|
||||
pass
|
||||
|
||||
else:
|
||||
raise ValueError("Bad parameters")
|
||||
|
||||
#Authenticate the server based on its cryptoID or fingerprint
|
||||
if sharedKey and (cryptoID or protocol or x509Fingerprint):
|
||||
raise ValueError("Can't use shared keys with other forms of"\
|
||||
"authentication")
|
||||
|
||||
self.checker = Checker(cryptoID, protocol, x509Fingerprint,
|
||||
x509TrustList, x509CommonName)
|
||||
self.settings = settings
|
||||
@@ -1,142 +0,0 @@
|
||||
"""TLS Lite + poplib."""
|
||||
|
||||
import socket
|
||||
from poplib import POP3
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from gdata.tlslite.integration.ClientHelper import ClientHelper
|
||||
|
||||
# POP TLS PORT
|
||||
POP3_TLS_PORT = 995
|
||||
|
||||
class POP3_TLS(POP3, ClientHelper):
|
||||
"""This class extends L{poplib.POP3} with TLS support."""
|
||||
|
||||
def __init__(self, host, port = POP3_TLS_PORT,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings=None):
|
||||
"""Create a new POP3_TLS.
|
||||
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The caller should be prepared to handle TLS-specific
|
||||
exceptions. See the client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type host: str
|
||||
@param host: Server to connect to.
|
||||
|
||||
@type port: int
|
||||
@param port: Port to connect to.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
|
||||
self.host = host
|
||||
self.port = port
|
||||
msg = "getaddrinfo returns an empty list"
|
||||
self.sock = None
|
||||
for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
try:
|
||||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
except socket.error, msg:
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
if not self.sock:
|
||||
raise socket.error, msg
|
||||
|
||||
### New code below (all else copied from poplib)
|
||||
ClientHelper.__init__(self,
|
||||
username, password, sharedKey,
|
||||
certChain, privateKey,
|
||||
cryptoID, protocol,
|
||||
x509Fingerprint,
|
||||
x509TrustList, x509CommonName,
|
||||
settings)
|
||||
|
||||
self.sock = TLSConnection(self.sock)
|
||||
self.sock.closeSocket = True
|
||||
ClientHelper._handshake(self, self.sock)
|
||||
###
|
||||
|
||||
self.file = self.sock.makefile('rb')
|
||||
self._debugging = 0
|
||||
self.welcome = self._getresp()
|
||||
@@ -1,114 +0,0 @@
|
||||
"""TLS Lite + smtplib."""
|
||||
|
||||
from smtplib import SMTP
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from gdata.tlslite.integration.ClientHelper import ClientHelper
|
||||
|
||||
class SMTP_TLS(SMTP):
|
||||
"""This class extends L{smtplib.SMTP} with TLS support."""
|
||||
|
||||
def starttls(self,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings=None):
|
||||
"""Puts the connection to the SMTP server into TLS mode.
|
||||
|
||||
If the server supports TLS, this will encrypt the rest of the SMTP
|
||||
session.
|
||||
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The caller should be prepared to handle TLS-specific
|
||||
exceptions. See the client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
(resp, reply) = self.docmd("STARTTLS")
|
||||
if resp == 220:
|
||||
helper = ClientHelper(
|
||||
username, password, sharedKey,
|
||||
certChain, privateKey,
|
||||
cryptoID, protocol,
|
||||
x509Fingerprint,
|
||||
x509TrustList, x509CommonName,
|
||||
settings)
|
||||
conn = TLSConnection(self.sock)
|
||||
conn.closeSocket = True
|
||||
helper._handshake(conn)
|
||||
self.sock = conn
|
||||
self.file = conn.makefile('rb')
|
||||
return (resp, reply)
|
||||
@@ -1,139 +0,0 @@
|
||||
"""TLS Lite + asyncore."""
|
||||
|
||||
|
||||
import asyncore
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from AsyncStateMachine import AsyncStateMachine
|
||||
|
||||
|
||||
class TLSAsyncDispatcherMixIn(AsyncStateMachine):
|
||||
"""This class can be "mixed in" with an
|
||||
L{asyncore.dispatcher} to add TLS support.
|
||||
|
||||
This class essentially sits between the dispatcher and the select
|
||||
loop, intercepting events and only calling the dispatcher when
|
||||
applicable.
|
||||
|
||||
In the case of handle_read(), a read operation will be activated,
|
||||
and when it completes, the bytes will be placed in a buffer where
|
||||
the dispatcher can retrieve them by calling recv(), and the
|
||||
dispatcher's handle_read() will be called.
|
||||
|
||||
In the case of handle_write(), the dispatcher's handle_write() will
|
||||
be called, and when it calls send(), a write operation will be
|
||||
activated.
|
||||
|
||||
To use this class, you must combine it with an asyncore.dispatcher,
|
||||
and pass in a handshake operation with setServerHandshakeOp().
|
||||
|
||||
Below is an example of using this class with medusa. This class is
|
||||
mixed in with http_channel to create http_tls_channel. Note:
|
||||
1. the mix-in is listed first in the inheritance list
|
||||
|
||||
2. the input buffer size must be at least 16K, otherwise the
|
||||
dispatcher might not read all the bytes from the TLS layer,
|
||||
leaving some bytes in limbo.
|
||||
|
||||
3. IE seems to have a problem receiving a whole HTTP response in a
|
||||
single TLS record, so HTML pages containing '\\r\\n\\r\\n' won't
|
||||
be displayed on IE.
|
||||
|
||||
Add the following text into 'start_medusa.py', in the 'HTTP Server'
|
||||
section::
|
||||
|
||||
from tlslite.api import *
|
||||
s = open("./serverX509Cert.pem").read()
|
||||
x509 = X509()
|
||||
x509.parse(s)
|
||||
certChain = X509CertChain([x509])
|
||||
|
||||
s = open("./serverX509Key.pem").read()
|
||||
privateKey = parsePEMKey(s, private=True)
|
||||
|
||||
class http_tls_channel(TLSAsyncDispatcherMixIn,
|
||||
http_server.http_channel):
|
||||
ac_in_buffer_size = 16384
|
||||
|
||||
def __init__ (self, server, conn, addr):
|
||||
http_server.http_channel.__init__(self, server, conn, addr)
|
||||
TLSAsyncDispatcherMixIn.__init__(self, conn)
|
||||
self.tlsConnection.ignoreAbruptClose = True
|
||||
self.setServerHandshakeOp(certChain=certChain,
|
||||
privateKey=privateKey)
|
||||
|
||||
hs.channel_class = http_tls_channel
|
||||
|
||||
If the TLS layer raises an exception, the exception will be caught
|
||||
in asyncore.dispatcher, which will call close() on this class. The
|
||||
TLS layer always closes the TLS connection before raising an
|
||||
exception, so the close operation will complete right away, causing
|
||||
asyncore.dispatcher.close() to be called, which closes the socket
|
||||
and removes this instance from the asyncore loop.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, sock=None):
|
||||
AsyncStateMachine.__init__(self)
|
||||
|
||||
if sock:
|
||||
self.tlsConnection = TLSConnection(sock)
|
||||
|
||||
#Calculate the sibling I'm being mixed in with.
|
||||
#This is necessary since we override functions
|
||||
#like readable(), handle_read(), etc., but we
|
||||
#also want to call the sibling's versions.
|
||||
for cl in self.__class__.__bases__:
|
||||
if cl != TLSAsyncDispatcherMixIn and cl != AsyncStateMachine:
|
||||
self.siblingClass = cl
|
||||
break
|
||||
else:
|
||||
raise AssertionError()
|
||||
|
||||
def readable(self):
|
||||
result = self.wantsReadEvent()
|
||||
if result != None:
|
||||
return result
|
||||
return self.siblingClass.readable(self)
|
||||
|
||||
def writable(self):
|
||||
result = self.wantsWriteEvent()
|
||||
if result != None:
|
||||
return result
|
||||
return self.siblingClass.writable(self)
|
||||
|
||||
def handle_read(self):
|
||||
self.inReadEvent()
|
||||
|
||||
def handle_write(self):
|
||||
self.inWriteEvent()
|
||||
|
||||
def outConnectEvent(self):
|
||||
self.siblingClass.handle_connect(self)
|
||||
|
||||
def outCloseEvent(self):
|
||||
asyncore.dispatcher.close(self)
|
||||
|
||||
def outReadEvent(self, readBuffer):
|
||||
self.readBuffer = readBuffer
|
||||
self.siblingClass.handle_read(self)
|
||||
|
||||
def outWriteEvent(self):
|
||||
self.siblingClass.handle_write(self)
|
||||
|
||||
def recv(self, bufferSize=16384):
|
||||
if bufferSize < 16384 or self.readBuffer == None:
|
||||
raise AssertionError()
|
||||
returnValue = self.readBuffer
|
||||
self.readBuffer = None
|
||||
return returnValue
|
||||
|
||||
def send(self, writeBuffer):
|
||||
self.setWriteOp(writeBuffer)
|
||||
return len(writeBuffer)
|
||||
|
||||
def close(self):
|
||||
if hasattr(self, "tlsConnection"):
|
||||
self.setCloseOp()
|
||||
else:
|
||||
asyncore.dispatcher.close(self)
|
||||
@@ -1,59 +0,0 @@
|
||||
"""TLS Lite + SocketServer."""
|
||||
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
|
||||
class TLSSocketServerMixIn:
|
||||
"""
|
||||
This class can be mixed in with any L{SocketServer.TCPServer} to
|
||||
add TLS support.
|
||||
|
||||
To use this class, define a new class that inherits from it and
|
||||
some L{SocketServer.TCPServer} (with the mix-in first). Then
|
||||
implement the handshake() method, doing some sort of server
|
||||
handshake on the connection argument. If the handshake method
|
||||
returns True, the RequestHandler will be triggered. Below is a
|
||||
complete example of a threaded HTTPS server::
|
||||
|
||||
from SocketServer import *
|
||||
from BaseHTTPServer import *
|
||||
from SimpleHTTPServer import *
|
||||
from tlslite.api import *
|
||||
|
||||
s = open("./serverX509Cert.pem").read()
|
||||
x509 = X509()
|
||||
x509.parse(s)
|
||||
certChain = X509CertChain([x509])
|
||||
|
||||
s = open("./serverX509Key.pem").read()
|
||||
privateKey = parsePEMKey(s, private=True)
|
||||
|
||||
sessionCache = SessionCache()
|
||||
|
||||
class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn,
|
||||
HTTPServer):
|
||||
def handshake(self, tlsConnection):
|
||||
try:
|
||||
tlsConnection.handshakeServer(certChain=certChain,
|
||||
privateKey=privateKey,
|
||||
sessionCache=sessionCache)
|
||||
tlsConnection.ignoreAbruptClose = True
|
||||
return True
|
||||
except TLSError, error:
|
||||
print "Handshake failure:", str(error)
|
||||
return False
|
||||
|
||||
httpd = MyHTTPServer(('localhost', 443), SimpleHTTPRequestHandler)
|
||||
httpd.serve_forever()
|
||||
"""
|
||||
|
||||
|
||||
def finish_request(self, sock, client_address):
|
||||
tlsConnection = TLSConnection(sock)
|
||||
if self.handshake(tlsConnection) == True:
|
||||
self.RequestHandlerClass(tlsConnection, client_address, self)
|
||||
tlsConnection.close()
|
||||
|
||||
#Implement this method to do some form of handshaking. Return True
|
||||
#if the handshake finishes properly and the request is authorized.
|
||||
def handshake(self, tlsConnection):
|
||||
raise NotImplementedError()
|
||||
@@ -1,196 +0,0 @@
|
||||
"""TLS Lite + Twisted."""
|
||||
|
||||
from twisted.protocols.policies import ProtocolWrapper, WrappingFactory
|
||||
from twisted.python.failure import Failure
|
||||
|
||||
from AsyncStateMachine import AsyncStateMachine
|
||||
from gdata.tlslite.TLSConnection import TLSConnection
|
||||
from gdata.tlslite.errors import *
|
||||
|
||||
import socket
|
||||
import errno
|
||||
|
||||
|
||||
#The TLSConnection is created around a "fake socket" that
|
||||
#plugs it into the underlying Twisted transport
|
||||
class _FakeSocket:
|
||||
def __init__(self, wrapper):
|
||||
self.wrapper = wrapper
|
||||
self.data = ""
|
||||
|
||||
def send(self, data):
|
||||
ProtocolWrapper.write(self.wrapper, data)
|
||||
return len(data)
|
||||
|
||||
def recv(self, numBytes):
|
||||
if self.data == "":
|
||||
raise socket.error, (errno.EWOULDBLOCK, "")
|
||||
returnData = self.data[:numBytes]
|
||||
self.data = self.data[numBytes:]
|
||||
return returnData
|
||||
|
||||
class TLSTwistedProtocolWrapper(ProtocolWrapper, AsyncStateMachine):
|
||||
"""This class can wrap Twisted protocols to add TLS support.
|
||||
|
||||
Below is a complete example of using TLS Lite with a Twisted echo
|
||||
server.
|
||||
|
||||
There are two server implementations below. Echo is the original
|
||||
protocol, which is oblivious to TLS. Echo1 subclasses Echo and
|
||||
negotiates TLS when the client connects. Echo2 subclasses Echo and
|
||||
negotiates TLS when the client sends "STARTTLS"::
|
||||
|
||||
from twisted.internet.protocol import Protocol, Factory
|
||||
from twisted.internet import reactor
|
||||
from twisted.protocols.policies import WrappingFactory
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
from twisted.python import log
|
||||
from twisted.python.failure import Failure
|
||||
import sys
|
||||
from tlslite.api import *
|
||||
|
||||
s = open("./serverX509Cert.pem").read()
|
||||
x509 = X509()
|
||||
x509.parse(s)
|
||||
certChain = X509CertChain([x509])
|
||||
|
||||
s = open("./serverX509Key.pem").read()
|
||||
privateKey = parsePEMKey(s, private=True)
|
||||
|
||||
verifierDB = VerifierDB("verifierDB")
|
||||
verifierDB.open()
|
||||
|
||||
class Echo(LineReceiver):
|
||||
def connectionMade(self):
|
||||
self.transport.write("Welcome to the echo server!\\r\\n")
|
||||
|
||||
def lineReceived(self, line):
|
||||
self.transport.write(line + "\\r\\n")
|
||||
|
||||
class Echo1(Echo):
|
||||
def connectionMade(self):
|
||||
if not self.transport.tlsStarted:
|
||||
self.transport.setServerHandshakeOp(certChain=certChain,
|
||||
privateKey=privateKey,
|
||||
verifierDB=verifierDB)
|
||||
else:
|
||||
Echo.connectionMade(self)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
pass #Handle any TLS exceptions here
|
||||
|
||||
class Echo2(Echo):
|
||||
def lineReceived(self, data):
|
||||
if data == "STARTTLS":
|
||||
self.transport.setServerHandshakeOp(certChain=certChain,
|
||||
privateKey=privateKey,
|
||||
verifierDB=verifierDB)
|
||||
else:
|
||||
Echo.lineReceived(self, data)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
pass #Handle any TLS exceptions here
|
||||
|
||||
factory = Factory()
|
||||
factory.protocol = Echo1
|
||||
#factory.protocol = Echo2
|
||||
|
||||
wrappingFactory = WrappingFactory(factory)
|
||||
wrappingFactory.protocol = TLSTwistedProtocolWrapper
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
reactor.listenTCP(1079, wrappingFactory)
|
||||
reactor.run()
|
||||
|
||||
This class works as follows:
|
||||
|
||||
Data comes in and is given to the AsyncStateMachine for handling.
|
||||
AsyncStateMachine will forward events to this class, and we'll
|
||||
pass them on to the ProtocolHandler, which will proxy them to the
|
||||
wrapped protocol. The wrapped protocol may then call back into
|
||||
this class, and these calls will be proxied into the
|
||||
AsyncStateMachine.
|
||||
|
||||
The call graph looks like this:
|
||||
- self.dataReceived
|
||||
- AsyncStateMachine.inReadEvent
|
||||
- self.out(Connect|Close|Read)Event
|
||||
- ProtocolWrapper.(connectionMade|loseConnection|dataReceived)
|
||||
- self.(loseConnection|write|writeSequence)
|
||||
- AsyncStateMachine.(setCloseOp|setWriteOp)
|
||||
"""
|
||||
|
||||
#WARNING: IF YOU COPY-AND-PASTE THE ABOVE CODE, BE SURE TO REMOVE
|
||||
#THE EXTRA ESCAPING AROUND "\\r\\n"
|
||||
|
||||
def __init__(self, factory, wrappedProtocol):
|
||||
ProtocolWrapper.__init__(self, factory, wrappedProtocol)
|
||||
AsyncStateMachine.__init__(self)
|
||||
self.fakeSocket = _FakeSocket(self)
|
||||
self.tlsConnection = TLSConnection(self.fakeSocket)
|
||||
self.tlsStarted = False
|
||||
self.connectionLostCalled = False
|
||||
|
||||
def connectionMade(self):
|
||||
try:
|
||||
ProtocolWrapper.connectionMade(self)
|
||||
except TLSError, e:
|
||||
self.connectionLost(Failure(e))
|
||||
ProtocolWrapper.loseConnection(self)
|
||||
|
||||
def dataReceived(self, data):
|
||||
try:
|
||||
if not self.tlsStarted:
|
||||
ProtocolWrapper.dataReceived(self, data)
|
||||
else:
|
||||
self.fakeSocket.data += data
|
||||
while self.fakeSocket.data:
|
||||
AsyncStateMachine.inReadEvent(self)
|
||||
except TLSError, e:
|
||||
self.connectionLost(Failure(e))
|
||||
ProtocolWrapper.loseConnection(self)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
if not self.connectionLostCalled:
|
||||
ProtocolWrapper.connectionLost(self, reason)
|
||||
self.connectionLostCalled = True
|
||||
|
||||
|
||||
def outConnectEvent(self):
|
||||
ProtocolWrapper.connectionMade(self)
|
||||
|
||||
def outCloseEvent(self):
|
||||
ProtocolWrapper.loseConnection(self)
|
||||
|
||||
def outReadEvent(self, data):
|
||||
if data == "":
|
||||
ProtocolWrapper.loseConnection(self)
|
||||
else:
|
||||
ProtocolWrapper.dataReceived(self, data)
|
||||
|
||||
|
||||
def setServerHandshakeOp(self, **args):
|
||||
self.tlsStarted = True
|
||||
AsyncStateMachine.setServerHandshakeOp(self, **args)
|
||||
|
||||
def loseConnection(self):
|
||||
if not self.tlsStarted:
|
||||
ProtocolWrapper.loseConnection(self)
|
||||
else:
|
||||
AsyncStateMachine.setCloseOp(self)
|
||||
|
||||
def write(self, data):
|
||||
if not self.tlsStarted:
|
||||
ProtocolWrapper.write(self, data)
|
||||
else:
|
||||
#Because of the FakeSocket, write operations are guaranteed to
|
||||
#terminate immediately.
|
||||
AsyncStateMachine.setWriteOp(self, data)
|
||||
|
||||
def writeSequence(self, seq):
|
||||
if not self.tlsStarted:
|
||||
ProtocolWrapper.writeSequence(self, seq)
|
||||
else:
|
||||
#Because of the FakeSocket, write operations are guaranteed to
|
||||
#terminate immediately.
|
||||
AsyncStateMachine.setWriteOp(self, "".join(seq))
|
||||
@@ -1,137 +0,0 @@
|
||||
"""TLS Lite + xmlrpclib."""
|
||||
|
||||
import xmlrpclib
|
||||
import httplib
|
||||
from gdata.tlslite.integration.HTTPTLSConnection import HTTPTLSConnection
|
||||
from gdata.tlslite.integration.ClientHelper import ClientHelper
|
||||
|
||||
|
||||
class XMLRPCTransport(xmlrpclib.Transport, ClientHelper):
|
||||
"""Handles an HTTPS transaction to an XML-RPC server."""
|
||||
|
||||
def __init__(self,
|
||||
username=None, password=None, sharedKey=None,
|
||||
certChain=None, privateKey=None,
|
||||
cryptoID=None, protocol=None,
|
||||
x509Fingerprint=None,
|
||||
x509TrustList=None, x509CommonName=None,
|
||||
settings=None):
|
||||
"""Create a new XMLRPCTransport.
|
||||
|
||||
An instance of this class can be passed to L{xmlrpclib.ServerProxy}
|
||||
to use TLS with XML-RPC calls::
|
||||
|
||||
from tlslite.api import XMLRPCTransport
|
||||
from xmlrpclib import ServerProxy
|
||||
|
||||
transport = XMLRPCTransport(user="alice", password="abra123")
|
||||
server = ServerProxy("https://localhost", transport)
|
||||
|
||||
For client authentication, use one of these argument
|
||||
combinations:
|
||||
- username, password (SRP)
|
||||
- username, sharedKey (shared-key)
|
||||
- certChain, privateKey (certificate)
|
||||
|
||||
For server authentication, you can either rely on the
|
||||
implicit mutual authentication performed by SRP or
|
||||
shared-keys, or you can do certificate-based server
|
||||
authentication with one of these argument combinations:
|
||||
- cryptoID[, protocol] (requires cryptoIDlib)
|
||||
- x509Fingerprint
|
||||
- x509TrustList[, x509CommonName] (requires cryptlib_py)
|
||||
|
||||
Certificate-based server authentication is compatible with
|
||||
SRP or certificate-based client authentication. It is
|
||||
not compatible with shared-keys.
|
||||
|
||||
The constructor does not perform the TLS handshake itself, but
|
||||
simply stores these arguments for later. The handshake is
|
||||
performed only when this class needs to connect with the
|
||||
server. Thus you should be prepared to handle TLS-specific
|
||||
exceptions when calling methods of L{xmlrpclib.ServerProxy}. See the
|
||||
client handshake functions in
|
||||
L{tlslite.TLSConnection.TLSConnection} for details on which
|
||||
exceptions might be raised.
|
||||
|
||||
@type username: str
|
||||
@param username: SRP or shared-key username. Requires the
|
||||
'password' or 'sharedKey' argument.
|
||||
|
||||
@type password: str
|
||||
@param password: SRP password for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type sharedKey: str
|
||||
@param sharedKey: Shared key for mutual authentication.
|
||||
Requires the 'username' argument.
|
||||
|
||||
@type certChain: L{tlslite.X509CertChain.X509CertChain} or
|
||||
L{cryptoIDlib.CertChain.CertChain}
|
||||
@param certChain: Certificate chain for client authentication.
|
||||
Requires the 'privateKey' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}
|
||||
@param privateKey: Private key for client authentication.
|
||||
Requires the 'certChain' argument. Excludes the SRP or
|
||||
shared-key related arguments.
|
||||
|
||||
@type cryptoID: str
|
||||
@param cryptoID: cryptoID for server authentication. Mutually
|
||||
exclusive with the 'x509...' arguments.
|
||||
|
||||
@type protocol: str
|
||||
@param protocol: cryptoID protocol URI for server
|
||||
authentication. Requires the 'cryptoID' argument.
|
||||
|
||||
@type x509Fingerprint: str
|
||||
@param x509Fingerprint: Hex-encoded X.509 fingerprint for
|
||||
server authentication. Mutually exclusive with the 'cryptoID'
|
||||
and 'x509TrustList' arguments.
|
||||
|
||||
@type x509TrustList: list of L{tlslite.X509.X509}
|
||||
@param x509TrustList: A list of trusted root certificates. The
|
||||
other party must present a certificate chain which extends to
|
||||
one of these root certificates. The cryptlib_py module must be
|
||||
installed to use this parameter. Mutually exclusive with the
|
||||
'cryptoID' and 'x509Fingerprint' arguments.
|
||||
|
||||
@type x509CommonName: str
|
||||
@param x509CommonName: The end-entity certificate's 'CN' field
|
||||
must match this value. For a web server, this is typically a
|
||||
server name such as 'www.amazon.com'. Mutually exclusive with
|
||||
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the
|
||||
'x509TrustList' argument.
|
||||
|
||||
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
|
||||
@param settings: Various settings which can be used to control
|
||||
the ciphersuites, certificate types, and SSL/TLS versions
|
||||
offered by the client.
|
||||
"""
|
||||
|
||||
ClientHelper.__init__(self,
|
||||
username, password, sharedKey,
|
||||
certChain, privateKey,
|
||||
cryptoID, protocol,
|
||||
x509Fingerprint,
|
||||
x509TrustList, x509CommonName,
|
||||
settings)
|
||||
|
||||
|
||||
def make_connection(self, host):
|
||||
# create a HTTPS connection object from a host descriptor
|
||||
host, extra_headers, x509 = self.get_host_info(host)
|
||||
http = HTTPTLSConnection(host, None,
|
||||
self.username, self.password,
|
||||
self.sharedKey,
|
||||
self.certChain, self.privateKey,
|
||||
self.checker.cryptoID,
|
||||
self.checker.protocol,
|
||||
self.checker.x509Fingerprint,
|
||||
self.checker.x509TrustList,
|
||||
self.checker.x509CommonName,
|
||||
self.settings)
|
||||
http2 = httplib.HTTP()
|
||||
http2._setup(http)
|
||||
return http2
|
||||
@@ -1,17 +0,0 @@
|
||||
"""Classes for integrating TLS Lite with other packages."""
|
||||
|
||||
__all__ = ["AsyncStateMachine",
|
||||
"HTTPTLSConnection",
|
||||
"POP3_TLS",
|
||||
"IMAP4_TLS",
|
||||
"SMTP_TLS",
|
||||
"XMLRPCTransport",
|
||||
"TLSSocketServerMixIn",
|
||||
"TLSAsyncDispatcherMixIn",
|
||||
"TLSTwistedProtocolWrapper"]
|
||||
|
||||
try:
|
||||
import twisted
|
||||
del twisted
|
||||
except ImportError:
|
||||
del __all__[__all__.index("TLSTwistedProtocolWrapper")]
|
||||
@@ -1,170 +0,0 @@
|
||||
"""Miscellaneous helper functions."""
|
||||
|
||||
from utils.compat import *
|
||||
from utils.cryptomath import *
|
||||
|
||||
import hmac
|
||||
import md5
|
||||
import sha
|
||||
|
||||
#1024, 1536, 2048, 3072, 4096, 6144, and 8192 bit groups]
|
||||
goodGroupParameters = [(2,0xEEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3),\
|
||||
(2,0x9DEF3CAFB939277AB1F12A8617A47BBBDBA51DF499AC4C80BEEEA9614B19CC4D5F4F5F556E27CBDE51C6A94BE4607A291558903BA0D0F84380B655BB9A22E8DCDF028A7CEC67F0D08134B1C8B97989149B609E0BE3BAB63D47548381DBC5B1FC764E3F4B53DD9DA1158BFD3E2B9C8CF56EDF019539349627DB2FD53D24B7C48665772E437D6C7F8CE442734AF7CCB7AE837C264AE3A9BEB87F8A2FE9B8B5292E5A021FFF5E91479E8CE7A28C2442C6F315180F93499A234DCF76E3FED135F9BB),\
|
||||
(2,0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB694B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73),\
|
||||
(2,0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF),\
|
||||
(5,0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF),\
|
||||
(5,0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF),\
|
||||
(5,0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF)]
|
||||
|
||||
def P_hash(hashModule, secret, seed, length):
|
||||
bytes = createByteArrayZeros(length)
|
||||
secret = bytesToString(secret)
|
||||
seed = bytesToString(seed)
|
||||
A = seed
|
||||
index = 0
|
||||
while 1:
|
||||
A = hmac.HMAC(secret, A, hashModule).digest()
|
||||
output = hmac.HMAC(secret, A+seed, hashModule).digest()
|
||||
for c in output:
|
||||
if index >= length:
|
||||
return bytes
|
||||
bytes[index] = ord(c)
|
||||
index += 1
|
||||
return bytes
|
||||
|
||||
def PRF(secret, label, seed, length):
|
||||
#Split the secret into left and right halves
|
||||
S1 = secret[ : int(math.ceil(len(secret)/2.0))]
|
||||
S2 = secret[ int(math.floor(len(secret)/2.0)) : ]
|
||||
|
||||
#Run the left half through P_MD5 and the right half through P_SHA1
|
||||
p_md5 = P_hash(md5, S1, concatArrays(stringToBytes(label), seed), length)
|
||||
p_sha1 = P_hash(sha, S2, concatArrays(stringToBytes(label), seed), length)
|
||||
|
||||
#XOR the output values and return the result
|
||||
for x in range(length):
|
||||
p_md5[x] ^= p_sha1[x]
|
||||
return p_md5
|
||||
|
||||
|
||||
def PRF_SSL(secret, seed, length):
|
||||
secretStr = bytesToString(secret)
|
||||
seedStr = bytesToString(seed)
|
||||
bytes = createByteArrayZeros(length)
|
||||
index = 0
|
||||
for x in range(26):
|
||||
A = chr(ord('A')+x) * (x+1) # 'A', 'BB', 'CCC', etc..
|
||||
input = secretStr + sha.sha(A + secretStr + seedStr).digest()
|
||||
output = md5.md5(input).digest()
|
||||
for c in output:
|
||||
if index >= length:
|
||||
return bytes
|
||||
bytes[index] = ord(c)
|
||||
index += 1
|
||||
return bytes
|
||||
|
||||
def makeX(salt, username, password):
|
||||
if len(username)>=256:
|
||||
raise ValueError("username too long")
|
||||
if len(salt)>=256:
|
||||
raise ValueError("salt too long")
|
||||
return stringToNumber(sha.sha(salt + sha.sha(username + ":" + password)\
|
||||
.digest()).digest())
|
||||
|
||||
#This function is used by VerifierDB.makeVerifier
|
||||
def makeVerifier(username, password, bits):
|
||||
bitsIndex = {1024:0, 1536:1, 2048:2, 3072:3, 4096:4, 6144:5, 8192:6}[bits]
|
||||
g,N = goodGroupParameters[bitsIndex]
|
||||
salt = bytesToString(getRandomBytes(16))
|
||||
x = makeX(salt, username, password)
|
||||
verifier = powMod(g, x, N)
|
||||
return N, g, salt, verifier
|
||||
|
||||
def PAD(n, x):
|
||||
nLength = len(numberToString(n))
|
||||
s = numberToString(x)
|
||||
if len(s) < nLength:
|
||||
s = ("\0" * (nLength-len(s))) + s
|
||||
return s
|
||||
|
||||
def makeU(N, A, B):
|
||||
return stringToNumber(sha.sha(PAD(N, A) + PAD(N, B)).digest())
|
||||
|
||||
def makeK(N, g):
|
||||
return stringToNumber(sha.sha(numberToString(N) + PAD(N, g)).digest())
|
||||
|
||||
|
||||
"""
|
||||
MAC_SSL
|
||||
Modified from Python HMAC by Trevor
|
||||
"""
|
||||
|
||||
class MAC_SSL:
|
||||
"""MAC_SSL class.
|
||||
|
||||
This supports the API for Cryptographic Hash Functions (PEP 247).
|
||||
"""
|
||||
|
||||
def __init__(self, key, msg = None, digestmod = None):
|
||||
"""Create a new MAC_SSL object.
|
||||
|
||||
key: key for the keyed hash object.
|
||||
msg: Initial input for the hash, if provided.
|
||||
digestmod: A module supporting PEP 247. Defaults to the md5 module.
|
||||
"""
|
||||
if digestmod is None:
|
||||
import md5
|
||||
digestmod = md5
|
||||
|
||||
if key == None: #TREVNEW - for faster copying
|
||||
return #TREVNEW
|
||||
|
||||
self.digestmod = digestmod
|
||||
self.outer = digestmod.new()
|
||||
self.inner = digestmod.new()
|
||||
self.digest_size = digestmod.digest_size
|
||||
|
||||
ipad = "\x36" * 40
|
||||
opad = "\x5C" * 40
|
||||
|
||||
self.inner.update(key)
|
||||
self.inner.update(ipad)
|
||||
self.outer.update(key)
|
||||
self.outer.update(opad)
|
||||
if msg is not None:
|
||||
self.update(msg)
|
||||
|
||||
|
||||
def update(self, msg):
|
||||
"""Update this hashing object with the string msg.
|
||||
"""
|
||||
self.inner.update(msg)
|
||||
|
||||
def copy(self):
|
||||
"""Return a separate copy of this hashing object.
|
||||
|
||||
An update to this copy won't affect the original object.
|
||||
"""
|
||||
other = MAC_SSL(None) #TREVNEW - for faster copying
|
||||
other.digest_size = self.digest_size #TREVNEW
|
||||
other.digestmod = self.digestmod
|
||||
other.inner = self.inner.copy()
|
||||
other.outer = self.outer.copy()
|
||||
return other
|
||||
|
||||
def digest(self):
|
||||
"""Return the hash value of this hashing object.
|
||||
|
||||
This returns a string containing 8-bit data. The object is
|
||||
not altered in any way by this function; you can continue
|
||||
updating the object after calling this function.
|
||||
"""
|
||||
h = self.outer.copy()
|
||||
h.update(self.inner.digest())
|
||||
return h.digest()
|
||||
|
||||
def hexdigest(self):
|
||||
"""Like digest(), but returns a string of hexadecimal digits instead.
|
||||
"""
|
||||
return "".join([hex(ord(x))[2:].zfill(2)
|
||||
for x in tuple(self.digest())])
|
||||
@@ -1,561 +0,0 @@
|
||||
"""Classes representing TLS messages."""
|
||||
|
||||
from utils.compat import *
|
||||
from utils.cryptomath import *
|
||||
from errors import *
|
||||
from utils.codec import *
|
||||
from constants import *
|
||||
from X509 import X509
|
||||
from X509CertChain import X509CertChain
|
||||
|
||||
import sha
|
||||
import md5
|
||||
|
||||
class RecordHeader3:
|
||||
def __init__(self):
|
||||
self.type = 0
|
||||
self.version = (0,0)
|
||||
self.length = 0
|
||||
self.ssl2 = False
|
||||
|
||||
def create(self, version, type, length):
|
||||
self.type = type
|
||||
self.version = version
|
||||
self.length = length
|
||||
return self
|
||||
|
||||
def write(self):
|
||||
w = Writer(5)
|
||||
w.add(self.type, 1)
|
||||
w.add(self.version[0], 1)
|
||||
w.add(self.version[1], 1)
|
||||
w.add(self.length, 2)
|
||||
return w.bytes
|
||||
|
||||
def parse(self, p):
|
||||
self.type = p.get(1)
|
||||
self.version = (p.get(1), p.get(1))
|
||||
self.length = p.get(2)
|
||||
self.ssl2 = False
|
||||
return self
|
||||
|
||||
class RecordHeader2:
|
||||
def __init__(self):
|
||||
self.type = 0
|
||||
self.version = (0,0)
|
||||
self.length = 0
|
||||
self.ssl2 = True
|
||||
|
||||
def parse(self, p):
|
||||
if p.get(1)!=128:
|
||||
raise SyntaxError()
|
||||
self.type = ContentType.handshake
|
||||
self.version = (2,0)
|
||||
#We don't support 2-byte-length-headers; could be a problem
|
||||
self.length = p.get(1)
|
||||
return self
|
||||
|
||||
|
||||
class Msg:
|
||||
def preWrite(self, trial):
|
||||
if trial:
|
||||
w = Writer()
|
||||
else:
|
||||
length = self.write(True)
|
||||
w = Writer(length)
|
||||
return w
|
||||
|
||||
def postWrite(self, w, trial):
|
||||
if trial:
|
||||
return w.index
|
||||
else:
|
||||
return w.bytes
|
||||
|
||||
class Alert(Msg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.alert
|
||||
self.level = 0
|
||||
self.description = 0
|
||||
|
||||
def create(self, description, level=AlertLevel.fatal):
|
||||
self.level = level
|
||||
self.description = description
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.setLengthCheck(2)
|
||||
self.level = p.get(1)
|
||||
self.description = p.get(1)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self):
|
||||
w = Writer(2)
|
||||
w.add(self.level, 1)
|
||||
w.add(self.description, 1)
|
||||
return w.bytes
|
||||
|
||||
|
||||
class HandshakeMsg(Msg):
|
||||
def preWrite(self, handshakeType, trial):
|
||||
if trial:
|
||||
w = Writer()
|
||||
w.add(handshakeType, 1)
|
||||
w.add(0, 3)
|
||||
else:
|
||||
length = self.write(True)
|
||||
w = Writer(length)
|
||||
w.add(handshakeType, 1)
|
||||
w.add(length-4, 3)
|
||||
return w
|
||||
|
||||
|
||||
class ClientHello(HandshakeMsg):
|
||||
def __init__(self, ssl2=False):
|
||||
self.contentType = ContentType.handshake
|
||||
self.ssl2 = ssl2
|
||||
self.client_version = (0,0)
|
||||
self.random = createByteArrayZeros(32)
|
||||
self.session_id = createByteArraySequence([])
|
||||
self.cipher_suites = [] # a list of 16-bit values
|
||||
self.certificate_types = [CertificateType.x509]
|
||||
self.compression_methods = [] # a list of 8-bit values
|
||||
self.srp_username = None # a string
|
||||
|
||||
def create(self, version, random, session_id, cipher_suites,
|
||||
certificate_types=None, srp_username=None):
|
||||
self.client_version = version
|
||||
self.random = random
|
||||
self.session_id = session_id
|
||||
self.cipher_suites = cipher_suites
|
||||
self.certificate_types = certificate_types
|
||||
self.compression_methods = [0]
|
||||
self.srp_username = srp_username
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
if self.ssl2:
|
||||
self.client_version = (p.get(1), p.get(1))
|
||||
cipherSpecsLength = p.get(2)
|
||||
sessionIDLength = p.get(2)
|
||||
randomLength = p.get(2)
|
||||
self.cipher_suites = p.getFixList(3, int(cipherSpecsLength/3))
|
||||
self.session_id = p.getFixBytes(sessionIDLength)
|
||||
self.random = p.getFixBytes(randomLength)
|
||||
if len(self.random) < 32:
|
||||
zeroBytes = 32-len(self.random)
|
||||
self.random = createByteArrayZeros(zeroBytes) + self.random
|
||||
self.compression_methods = [0]#Fake this value
|
||||
|
||||
#We're not doing a stopLengthCheck() for SSLv2, oh well..
|
||||
else:
|
||||
p.startLengthCheck(3)
|
||||
self.client_version = (p.get(1), p.get(1))
|
||||
self.random = p.getFixBytes(32)
|
||||
self.session_id = p.getVarBytes(1)
|
||||
self.cipher_suites = p.getVarList(2, 2)
|
||||
self.compression_methods = p.getVarList(1, 1)
|
||||
if not p.atLengthCheck():
|
||||
totalExtLength = p.get(2)
|
||||
soFar = 0
|
||||
while soFar != totalExtLength:
|
||||
extType = p.get(2)
|
||||
extLength = p.get(2)
|
||||
if extType == 6:
|
||||
self.srp_username = bytesToString(p.getVarBytes(1))
|
||||
elif extType == 7:
|
||||
self.certificate_types = p.getVarList(1, 1)
|
||||
else:
|
||||
p.getFixBytes(extLength)
|
||||
soFar += 4 + extLength
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.client_hello, trial)
|
||||
w.add(self.client_version[0], 1)
|
||||
w.add(self.client_version[1], 1)
|
||||
w.addFixSeq(self.random, 1)
|
||||
w.addVarSeq(self.session_id, 1, 1)
|
||||
w.addVarSeq(self.cipher_suites, 2, 2)
|
||||
w.addVarSeq(self.compression_methods, 1, 1)
|
||||
|
||||
extLength = 0
|
||||
if self.certificate_types and self.certificate_types != \
|
||||
[CertificateType.x509]:
|
||||
extLength += 5 + len(self.certificate_types)
|
||||
if self.srp_username:
|
||||
extLength += 5 + len(self.srp_username)
|
||||
if extLength > 0:
|
||||
w.add(extLength, 2)
|
||||
|
||||
if self.certificate_types and self.certificate_types != \
|
||||
[CertificateType.x509]:
|
||||
w.add(7, 2)
|
||||
w.add(len(self.certificate_types)+1, 2)
|
||||
w.addVarSeq(self.certificate_types, 1, 1)
|
||||
if self.srp_username:
|
||||
w.add(6, 2)
|
||||
w.add(len(self.srp_username)+1, 2)
|
||||
w.addVarSeq(stringToBytes(self.srp_username), 1, 1)
|
||||
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
|
||||
class ServerHello(HandshakeMsg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.handshake
|
||||
self.server_version = (0,0)
|
||||
self.random = createByteArrayZeros(32)
|
||||
self.session_id = createByteArraySequence([])
|
||||
self.cipher_suite = 0
|
||||
self.certificate_type = CertificateType.x509
|
||||
self.compression_method = 0
|
||||
|
||||
def create(self, version, random, session_id, cipher_suite,
|
||||
certificate_type):
|
||||
self.server_version = version
|
||||
self.random = random
|
||||
self.session_id = session_id
|
||||
self.cipher_suite = cipher_suite
|
||||
self.certificate_type = certificate_type
|
||||
self.compression_method = 0
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
self.server_version = (p.get(1), p.get(1))
|
||||
self.random = p.getFixBytes(32)
|
||||
self.session_id = p.getVarBytes(1)
|
||||
self.cipher_suite = p.get(2)
|
||||
self.compression_method = p.get(1)
|
||||
if not p.atLengthCheck():
|
||||
totalExtLength = p.get(2)
|
||||
soFar = 0
|
||||
while soFar != totalExtLength:
|
||||
extType = p.get(2)
|
||||
extLength = p.get(2)
|
||||
if extType == 7:
|
||||
self.certificate_type = p.get(1)
|
||||
else:
|
||||
p.getFixBytes(extLength)
|
||||
soFar += 4 + extLength
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.server_hello, trial)
|
||||
w.add(self.server_version[0], 1)
|
||||
w.add(self.server_version[1], 1)
|
||||
w.addFixSeq(self.random, 1)
|
||||
w.addVarSeq(self.session_id, 1, 1)
|
||||
w.add(self.cipher_suite, 2)
|
||||
w.add(self.compression_method, 1)
|
||||
|
||||
extLength = 0
|
||||
if self.certificate_type and self.certificate_type != \
|
||||
CertificateType.x509:
|
||||
extLength += 5
|
||||
|
||||
if extLength != 0:
|
||||
w.add(extLength, 2)
|
||||
|
||||
if self.certificate_type and self.certificate_type != \
|
||||
CertificateType.x509:
|
||||
w.add(7, 2)
|
||||
w.add(1, 2)
|
||||
w.add(self.certificate_type, 1)
|
||||
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class Certificate(HandshakeMsg):
|
||||
def __init__(self, certificateType):
|
||||
self.certificateType = certificateType
|
||||
self.contentType = ContentType.handshake
|
||||
self.certChain = None
|
||||
|
||||
def create(self, certChain):
|
||||
self.certChain = certChain
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
if self.certificateType == CertificateType.x509:
|
||||
chainLength = p.get(3)
|
||||
index = 0
|
||||
certificate_list = []
|
||||
while index != chainLength:
|
||||
certBytes = p.getVarBytes(3)
|
||||
x509 = X509()
|
||||
x509.parseBinary(certBytes)
|
||||
certificate_list.append(x509)
|
||||
index += len(certBytes)+3
|
||||
if certificate_list:
|
||||
self.certChain = X509CertChain(certificate_list)
|
||||
elif self.certificateType == CertificateType.cryptoID:
|
||||
s = bytesToString(p.getVarBytes(2))
|
||||
if s:
|
||||
try:
|
||||
import cryptoIDlib.CertChain
|
||||
except ImportError:
|
||||
raise SyntaxError(\
|
||||
"cryptoID cert chain received, cryptoIDlib not present")
|
||||
self.certChain = cryptoIDlib.CertChain.CertChain().parse(s)
|
||||
else:
|
||||
raise AssertionError()
|
||||
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.certificate, trial)
|
||||
if self.certificateType == CertificateType.x509:
|
||||
chainLength = 0
|
||||
if self.certChain:
|
||||
certificate_list = self.certChain.x509List
|
||||
else:
|
||||
certificate_list = []
|
||||
#determine length
|
||||
for cert in certificate_list:
|
||||
bytes = cert.writeBytes()
|
||||
chainLength += len(bytes)+3
|
||||
#add bytes
|
||||
w.add(chainLength, 3)
|
||||
for cert in certificate_list:
|
||||
bytes = cert.writeBytes()
|
||||
w.addVarSeq(bytes, 1, 3)
|
||||
elif self.certificateType == CertificateType.cryptoID:
|
||||
if self.certChain:
|
||||
bytes = stringToBytes(self.certChain.write())
|
||||
else:
|
||||
bytes = createByteArraySequence([])
|
||||
w.addVarSeq(bytes, 1, 2)
|
||||
else:
|
||||
raise AssertionError()
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class CertificateRequest(HandshakeMsg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.handshake
|
||||
self.certificate_types = []
|
||||
#treat as opaque bytes for now
|
||||
self.certificate_authorities = createByteArraySequence([])
|
||||
|
||||
def create(self, certificate_types, certificate_authorities):
|
||||
self.certificate_types = certificate_types
|
||||
self.certificate_authorities = certificate_authorities
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
self.certificate_types = p.getVarList(1, 1)
|
||||
self.certificate_authorities = p.getVarBytes(2)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.certificate_request,
|
||||
trial)
|
||||
w.addVarSeq(self.certificate_types, 1, 1)
|
||||
w.addVarSeq(self.certificate_authorities, 1, 2)
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class ServerKeyExchange(HandshakeMsg):
|
||||
def __init__(self, cipherSuite):
|
||||
self.cipherSuite = cipherSuite
|
||||
self.contentType = ContentType.handshake
|
||||
self.srp_N = 0L
|
||||
self.srp_g = 0L
|
||||
self.srp_s = createByteArraySequence([])
|
||||
self.srp_B = 0L
|
||||
self.signature = createByteArraySequence([])
|
||||
|
||||
def createSRP(self, srp_N, srp_g, srp_s, srp_B):
|
||||
self.srp_N = srp_N
|
||||
self.srp_g = srp_g
|
||||
self.srp_s = srp_s
|
||||
self.srp_B = srp_B
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
self.srp_N = bytesToNumber(p.getVarBytes(2))
|
||||
self.srp_g = bytesToNumber(p.getVarBytes(2))
|
||||
self.srp_s = p.getVarBytes(1)
|
||||
self.srp_B = bytesToNumber(p.getVarBytes(2))
|
||||
if self.cipherSuite in CipherSuite.srpRsaSuites:
|
||||
self.signature = p.getVarBytes(2)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.server_key_exchange,
|
||||
trial)
|
||||
w.addVarSeq(numberToBytes(self.srp_N), 1, 2)
|
||||
w.addVarSeq(numberToBytes(self.srp_g), 1, 2)
|
||||
w.addVarSeq(self.srp_s, 1, 1)
|
||||
w.addVarSeq(numberToBytes(self.srp_B), 1, 2)
|
||||
if self.cipherSuite in CipherSuite.srpRsaSuites:
|
||||
w.addVarSeq(self.signature, 1, 2)
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
def hash(self, clientRandom, serverRandom):
|
||||
oldCipherSuite = self.cipherSuite
|
||||
self.cipherSuite = None
|
||||
try:
|
||||
bytes = clientRandom + serverRandom + self.write()[4:]
|
||||
s = bytesToString(bytes)
|
||||
return stringToBytes(md5.md5(s).digest() + sha.sha(s).digest())
|
||||
finally:
|
||||
self.cipherSuite = oldCipherSuite
|
||||
|
||||
class ServerHelloDone(HandshakeMsg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.handshake
|
||||
|
||||
def create(self):
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.server_hello_done, trial)
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class ClientKeyExchange(HandshakeMsg):
|
||||
def __init__(self, cipherSuite, version=None):
|
||||
self.cipherSuite = cipherSuite
|
||||
self.version = version
|
||||
self.contentType = ContentType.handshake
|
||||
self.srp_A = 0
|
||||
self.encryptedPreMasterSecret = createByteArraySequence([])
|
||||
|
||||
def createSRP(self, srp_A):
|
||||
self.srp_A = srp_A
|
||||
return self
|
||||
|
||||
def createRSA(self, encryptedPreMasterSecret):
|
||||
self.encryptedPreMasterSecret = encryptedPreMasterSecret
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
if self.cipherSuite in CipherSuite.srpSuites + \
|
||||
CipherSuite.srpRsaSuites:
|
||||
self.srp_A = bytesToNumber(p.getVarBytes(2))
|
||||
elif self.cipherSuite in CipherSuite.rsaSuites:
|
||||
if self.version in ((3,1), (3,2)):
|
||||
self.encryptedPreMasterSecret = p.getVarBytes(2)
|
||||
elif self.version == (3,0):
|
||||
self.encryptedPreMasterSecret = \
|
||||
p.getFixBytes(len(p.bytes)-p.index)
|
||||
else:
|
||||
raise AssertionError()
|
||||
else:
|
||||
raise AssertionError()
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.client_key_exchange,
|
||||
trial)
|
||||
if self.cipherSuite in CipherSuite.srpSuites + \
|
||||
CipherSuite.srpRsaSuites:
|
||||
w.addVarSeq(numberToBytes(self.srp_A), 1, 2)
|
||||
elif self.cipherSuite in CipherSuite.rsaSuites:
|
||||
if self.version in ((3,1), (3,2)):
|
||||
w.addVarSeq(self.encryptedPreMasterSecret, 1, 2)
|
||||
elif self.version == (3,0):
|
||||
w.addFixSeq(self.encryptedPreMasterSecret, 1)
|
||||
else:
|
||||
raise AssertionError()
|
||||
else:
|
||||
raise AssertionError()
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class CertificateVerify(HandshakeMsg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.handshake
|
||||
self.signature = createByteArraySequence([])
|
||||
|
||||
def create(self, signature):
|
||||
self.signature = signature
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
self.signature = p.getVarBytes(2)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.certificate_verify,
|
||||
trial)
|
||||
w.addVarSeq(self.signature, 1, 2)
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class ChangeCipherSpec(Msg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.change_cipher_spec
|
||||
self.type = 1
|
||||
|
||||
def create(self):
|
||||
self.type = 1
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.setLengthCheck(1)
|
||||
self.type = p.get(1)
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = Msg.preWrite(self, trial)
|
||||
w.add(self.type,1)
|
||||
return Msg.postWrite(self, w, trial)
|
||||
|
||||
|
||||
class Finished(HandshakeMsg):
|
||||
def __init__(self, version):
|
||||
self.contentType = ContentType.handshake
|
||||
self.version = version
|
||||
self.verify_data = createByteArraySequence([])
|
||||
|
||||
def create(self, verify_data):
|
||||
self.verify_data = verify_data
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
p.startLengthCheck(3)
|
||||
if self.version == (3,0):
|
||||
self.verify_data = p.getFixBytes(36)
|
||||
elif self.version in ((3,1), (3,2)):
|
||||
self.verify_data = p.getFixBytes(12)
|
||||
else:
|
||||
raise AssertionError()
|
||||
p.stopLengthCheck()
|
||||
return self
|
||||
|
||||
def write(self, trial=False):
|
||||
w = HandshakeMsg.preWrite(self, HandshakeType.finished, trial)
|
||||
w.addFixSeq(self.verify_data, 1)
|
||||
return HandshakeMsg.postWrite(self, w, trial)
|
||||
|
||||
class ApplicationData(Msg):
|
||||
def __init__(self):
|
||||
self.contentType = ContentType.application_data
|
||||
self.bytes = createByteArraySequence([])
|
||||
|
||||
def create(self, bytes):
|
||||
self.bytes = bytes
|
||||
return self
|
||||
|
||||
def parse(self, p):
|
||||
self.bytes = p.bytes
|
||||
return self
|
||||
|
||||
def write(self):
|
||||
return self.bytes
|
||||
@@ -1,31 +0,0 @@
|
||||
"""Abstract class for AES."""
|
||||
|
||||
class AES:
|
||||
def __init__(self, key, mode, IV, implementation):
|
||||
if len(key) not in (16, 24, 32):
|
||||
raise AssertionError()
|
||||
if mode != 2:
|
||||
raise AssertionError()
|
||||
if len(IV) != 16:
|
||||
raise AssertionError()
|
||||
self.isBlockCipher = True
|
||||
self.block_size = 16
|
||||
self.implementation = implementation
|
||||
if len(key)==16:
|
||||
self.name = "aes128"
|
||||
elif len(key)==24:
|
||||
self.name = "aes192"
|
||||
elif len(key)==32:
|
||||
self.name = "aes256"
|
||||
else:
|
||||
raise AssertionError()
|
||||
|
||||
#CBC-Mode encryption, returns ciphertext
|
||||
#WARNING: *MAY* modify the input as well
|
||||
def encrypt(self, plaintext):
|
||||
assert(len(plaintext) % 16 == 0)
|
||||
|
||||
#CBC-Mode decryption, returns plaintext
|
||||
#WARNING: *MAY* modify the input as well
|
||||
def decrypt(self, ciphertext):
|
||||
assert(len(ciphertext) % 16 == 0)
|
||||
@@ -1,34 +0,0 @@
|
||||
"""Class for parsing ASN.1"""
|
||||
from compat import *
|
||||
from codec import *
|
||||
|
||||
#Takes a byte array which has a DER TLV field at its head
|
||||
class ASN1Parser:
|
||||
def __init__(self, bytes):
|
||||
p = Parser(bytes)
|
||||
p.get(1) #skip Type
|
||||
|
||||
#Get Length
|
||||
self.length = self._getASN1Length(p)
|
||||
|
||||
#Get Value
|
||||
self.value = p.getFixBytes(self.length)
|
||||
|
||||
#Assuming this is a sequence...
|
||||
def getChild(self, which):
|
||||
p = Parser(self.value)
|
||||
for x in range(which+1):
|
||||
markIndex = p.index
|
||||
p.get(1) #skip Type
|
||||
length = self._getASN1Length(p)
|
||||
p.getFixBytes(length)
|
||||
return ASN1Parser(p.bytes[markIndex : p.index])
|
||||
|
||||
#Decode the ASN.1 DER length field
|
||||
def _getASN1Length(self, p):
|
||||
firstLength = p.get(1)
|
||||
if firstLength<=127:
|
||||
return firstLength
|
||||
else:
|
||||
lengthLength = firstLength & 0x7F
|
||||
return p.get(lengthLength)
|
||||
@@ -1,34 +0,0 @@
|
||||
"""Cryptlib AES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from AES import *
|
||||
|
||||
if cryptlibpyLoaded:
|
||||
|
||||
def new(key, mode, IV):
|
||||
return Cryptlib_AES(key, mode, IV)
|
||||
|
||||
class Cryptlib_AES(AES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
AES.__init__(self, key, mode, IV, "cryptlib")
|
||||
self.context = cryptlib_py.cryptCreateContext(cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_AES)
|
||||
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_MODE, cryptlib_py.CRYPT_MODE_CBC)
|
||||
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_KEYSIZE, len(key))
|
||||
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_KEY, key)
|
||||
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_IV, IV)
|
||||
|
||||
def __del__(self):
|
||||
cryptlib_py.cryptDestroyContext(self.context)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
AES.encrypt(self, plaintext)
|
||||
bytes = stringToBytes(plaintext)
|
||||
cryptlib_py.cryptEncrypt(self.context, bytes)
|
||||
return bytesToString(bytes)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
AES.decrypt(self, ciphertext)
|
||||
bytes = stringToBytes(ciphertext)
|
||||
cryptlib_py.cryptDecrypt(self.context, bytes)
|
||||
return bytesToString(bytes)
|
||||
@@ -1,28 +0,0 @@
|
||||
"""Cryptlib RC4 implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from RC4 import RC4
|
||||
|
||||
if cryptlibpyLoaded:
|
||||
|
||||
def new(key):
|
||||
return Cryptlib_RC4(key)
|
||||
|
||||
class Cryptlib_RC4(RC4):
|
||||
|
||||
def __init__(self, key):
|
||||
RC4.__init__(self, key, "cryptlib")
|
||||
self.context = cryptlib_py.cryptCreateContext(cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_RC4)
|
||||
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_KEYSIZE, len(key))
|
||||
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_KEY, key)
|
||||
|
||||
def __del__(self):
|
||||
cryptlib_py.cryptDestroyContext(self.context)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
bytes = stringToBytes(plaintext)
|
||||
cryptlib_py.cryptEncrypt(self.context, bytes)
|
||||
return bytesToString(bytes)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.encrypt(ciphertext)
|
||||
@@ -1,35 +0,0 @@
|
||||
"""Cryptlib 3DES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
|
||||
from TripleDES import *
|
||||
|
||||
if cryptlibpyLoaded:
|
||||
|
||||
def new(key, mode, IV):
|
||||
return Cryptlib_TripleDES(key, mode, IV)
|
||||
|
||||
class Cryptlib_TripleDES(TripleDES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
TripleDES.__init__(self, key, mode, IV, "cryptlib")
|
||||
self.context = cryptlib_py.cryptCreateContext(cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_3DES)
|
||||
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_MODE, cryptlib_py.CRYPT_MODE_CBC)
|
||||
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_KEYSIZE, len(key))
|
||||
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_KEY, key)
|
||||
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_IV, IV)
|
||||
|
||||
def __del__(self):
|
||||
cryptlib_py.cryptDestroyContext(self.context)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
TripleDES.encrypt(self, plaintext)
|
||||
bytes = stringToBytes(plaintext)
|
||||
cryptlib_py.cryptEncrypt(self.context, bytes)
|
||||
return bytesToString(bytes)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
TripleDES.decrypt(self, ciphertext)
|
||||
bytes = stringToBytes(ciphertext)
|
||||
cryptlib_py.cryptDecrypt(self.context, bytes)
|
||||
return bytesToString(bytes)
|
||||
@@ -1,49 +0,0 @@
|
||||
"""OpenSSL/M2Crypto AES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from AES import *
|
||||
|
||||
if m2cryptoLoaded:
|
||||
|
||||
def new(key, mode, IV):
|
||||
return OpenSSL_AES(key, mode, IV)
|
||||
|
||||
class OpenSSL_AES(AES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
AES.__init__(self, key, mode, IV, "openssl")
|
||||
self.key = key
|
||||
self.IV = IV
|
||||
|
||||
def _createContext(self, encrypt):
|
||||
context = m2.cipher_ctx_new()
|
||||
if len(self.key)==16:
|
||||
cipherType = m2.aes_128_cbc()
|
||||
if len(self.key)==24:
|
||||
cipherType = m2.aes_192_cbc()
|
||||
if len(self.key)==32:
|
||||
cipherType = m2.aes_256_cbc()
|
||||
m2.cipher_init(context, cipherType, self.key, self.IV, encrypt)
|
||||
return context
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
AES.encrypt(self, plaintext)
|
||||
context = self._createContext(1)
|
||||
ciphertext = m2.cipher_update(context, plaintext)
|
||||
m2.cipher_ctx_free(context)
|
||||
self.IV = ciphertext[-self.block_size:]
|
||||
return ciphertext
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
AES.decrypt(self, ciphertext)
|
||||
context = self._createContext(0)
|
||||
#I think M2Crypto has a bug - it fails to decrypt and return the last block passed in.
|
||||
#To work around this, we append sixteen zeros to the string, below:
|
||||
plaintext = m2.cipher_update(context, ciphertext+('\0'*16))
|
||||
|
||||
#If this bug is ever fixed, then plaintext will end up having a garbage
|
||||
#plaintext block on the end. That's okay - the below code will discard it.
|
||||
plaintext = plaintext[:len(ciphertext)]
|
||||
m2.cipher_ctx_free(context)
|
||||
self.IV = ciphertext[-self.block_size:]
|
||||
return plaintext
|
||||
@@ -1,25 +0,0 @@
|
||||
"""OpenSSL/M2Crypto RC4 implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from RC4 import RC4
|
||||
|
||||
if m2cryptoLoaded:
|
||||
|
||||
def new(key):
|
||||
return OpenSSL_RC4(key)
|
||||
|
||||
class OpenSSL_RC4(RC4):
|
||||
|
||||
def __init__(self, key):
|
||||
RC4.__init__(self, key, "openssl")
|
||||
self.rc4 = m2.rc4_new()
|
||||
m2.rc4_set_key(self.rc4, key)
|
||||
|
||||
def __del__(self):
|
||||
m2.rc4_free(self.rc4)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
return m2.rc4_update(self.rc4, plaintext)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.encrypt(ciphertext)
|
||||
@@ -1,148 +0,0 @@
|
||||
"""OpenSSL/M2Crypto RSA implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
|
||||
from RSAKey import *
|
||||
from Python_RSAKey import Python_RSAKey
|
||||
|
||||
#copied from M2Crypto.util.py, so when we load the local copy of m2
|
||||
#we can still use it
|
||||
def password_callback(v, prompt1='Enter private key passphrase:',
|
||||
prompt2='Verify passphrase:'):
|
||||
from getpass import getpass
|
||||
while 1:
|
||||
try:
|
||||
p1=getpass(prompt1)
|
||||
if v:
|
||||
p2=getpass(prompt2)
|
||||
if p1==p2:
|
||||
break
|
||||
else:
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
return None
|
||||
return p1
|
||||
|
||||
|
||||
if m2cryptoLoaded:
|
||||
class OpenSSL_RSAKey(RSAKey):
|
||||
def __init__(self, n=0, e=0):
|
||||
self.rsa = None
|
||||
self._hasPrivateKey = False
|
||||
if (n and not e) or (e and not n):
|
||||
raise AssertionError()
|
||||
if n and e:
|
||||
self.rsa = m2.rsa_new()
|
||||
m2.rsa_set_n(self.rsa, numberToMPI(n))
|
||||
m2.rsa_set_e(self.rsa, numberToMPI(e))
|
||||
|
||||
def __del__(self):
|
||||
if self.rsa:
|
||||
m2.rsa_free(self.rsa)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == 'e':
|
||||
if not self.rsa:
|
||||
return 0
|
||||
return mpiToNumber(m2.rsa_get_e(self.rsa))
|
||||
elif name == 'n':
|
||||
if not self.rsa:
|
||||
return 0
|
||||
return mpiToNumber(m2.rsa_get_n(self.rsa))
|
||||
else:
|
||||
raise AttributeError
|
||||
|
||||
def hasPrivateKey(self):
|
||||
return self._hasPrivateKey
|
||||
|
||||
def hash(self):
|
||||
return Python_RSAKey(self.n, self.e).hash()
|
||||
|
||||
def _rawPrivateKeyOp(self, m):
|
||||
s = numberToString(m)
|
||||
byteLength = numBytes(self.n)
|
||||
if len(s)== byteLength:
|
||||
pass
|
||||
elif len(s) == byteLength-1:
|
||||
s = '\0' + s
|
||||
else:
|
||||
raise AssertionError()
|
||||
c = stringToNumber(m2.rsa_private_encrypt(self.rsa, s,
|
||||
m2.no_padding))
|
||||
return c
|
||||
|
||||
def _rawPublicKeyOp(self, c):
|
||||
s = numberToString(c)
|
||||
byteLength = numBytes(self.n)
|
||||
if len(s)== byteLength:
|
||||
pass
|
||||
elif len(s) == byteLength-1:
|
||||
s = '\0' + s
|
||||
else:
|
||||
raise AssertionError()
|
||||
m = stringToNumber(m2.rsa_public_decrypt(self.rsa, s,
|
||||
m2.no_padding))
|
||||
return m
|
||||
|
||||
def acceptsPassword(self): return True
|
||||
|
||||
def write(self, password=None):
|
||||
bio = m2.bio_new(m2.bio_s_mem())
|
||||
if self._hasPrivateKey:
|
||||
if password:
|
||||
def f(v): return password
|
||||
m2.rsa_write_key(self.rsa, bio, m2.des_ede_cbc(), f)
|
||||
else:
|
||||
def f(): pass
|
||||
m2.rsa_write_key_no_cipher(self.rsa, bio, f)
|
||||
else:
|
||||
if password:
|
||||
raise AssertionError()
|
||||
m2.rsa_write_pub_key(self.rsa, bio)
|
||||
s = m2.bio_read(bio, m2.bio_ctrl_pending(bio))
|
||||
m2.bio_free(bio)
|
||||
return s
|
||||
|
||||
def writeXMLPublicKey(self, indent=''):
|
||||
return Python_RSAKey(self.n, self.e).write(indent)
|
||||
|
||||
def generate(bits):
|
||||
key = OpenSSL_RSAKey()
|
||||
def f():pass
|
||||
key.rsa = m2.rsa_generate_key(bits, 3, f)
|
||||
key._hasPrivateKey = True
|
||||
return key
|
||||
generate = staticmethod(generate)
|
||||
|
||||
def parse(s, passwordCallback=None):
|
||||
if s.startswith("-----BEGIN "):
|
||||
if passwordCallback==None:
|
||||
callback = password_callback
|
||||
else:
|
||||
def f(v, prompt1=None, prompt2=None):
|
||||
return passwordCallback()
|
||||
callback = f
|
||||
bio = m2.bio_new(m2.bio_s_mem())
|
||||
try:
|
||||
m2.bio_write(bio, s)
|
||||
key = OpenSSL_RSAKey()
|
||||
if s.startswith("-----BEGIN RSA PRIVATE KEY-----"):
|
||||
def f():pass
|
||||
key.rsa = m2.rsa_read_key(bio, callback)
|
||||
if key.rsa == None:
|
||||
raise SyntaxError()
|
||||
key._hasPrivateKey = True
|
||||
elif s.startswith("-----BEGIN PUBLIC KEY-----"):
|
||||
key.rsa = m2.rsa_read_pub_key(bio)
|
||||
if key.rsa == None:
|
||||
raise SyntaxError()
|
||||
key._hasPrivateKey = False
|
||||
else:
|
||||
raise SyntaxError()
|
||||
return key
|
||||
finally:
|
||||
m2.bio_free(bio)
|
||||
else:
|
||||
raise SyntaxError()
|
||||
|
||||
parse = staticmethod(parse)
|
||||
@@ -1,44 +0,0 @@
|
||||
"""OpenSSL/M2Crypto 3DES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from TripleDES import *
|
||||
|
||||
if m2cryptoLoaded:
|
||||
|
||||
def new(key, mode, IV):
|
||||
return OpenSSL_TripleDES(key, mode, IV)
|
||||
|
||||
class OpenSSL_TripleDES(TripleDES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
TripleDES.__init__(self, key, mode, IV, "openssl")
|
||||
self.key = key
|
||||
self.IV = IV
|
||||
|
||||
def _createContext(self, encrypt):
|
||||
context = m2.cipher_ctx_new()
|
||||
cipherType = m2.des_ede3_cbc()
|
||||
m2.cipher_init(context, cipherType, self.key, self.IV, encrypt)
|
||||
return context
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
TripleDES.encrypt(self, plaintext)
|
||||
context = self._createContext(1)
|
||||
ciphertext = m2.cipher_update(context, plaintext)
|
||||
m2.cipher_ctx_free(context)
|
||||
self.IV = ciphertext[-self.block_size:]
|
||||
return ciphertext
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
TripleDES.decrypt(self, ciphertext)
|
||||
context = self._createContext(0)
|
||||
#I think M2Crypto has a bug - it fails to decrypt and return the last block passed in.
|
||||
#To work around this, we append sixteen zeros to the string, below:
|
||||
plaintext = m2.cipher_update(context, ciphertext+('\0'*16))
|
||||
|
||||
#If this bug is ever fixed, then plaintext will end up having a garbage
|
||||
#plaintext block on the end. That's okay - the below code will ignore it.
|
||||
plaintext = plaintext[:len(ciphertext)]
|
||||
m2.cipher_ctx_free(context)
|
||||
self.IV = ciphertext[-self.block_size:]
|
||||
return plaintext
|
||||
@@ -1,22 +0,0 @@
|
||||
"""PyCrypto AES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from AES import *
|
||||
|
||||
if pycryptoLoaded:
|
||||
import Crypto.Cipher.AES
|
||||
|
||||
def new(key, mode, IV):
|
||||
return PyCrypto_AES(key, mode, IV)
|
||||
|
||||
class PyCrypto_AES(AES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
AES.__init__(self, key, mode, IV, "pycrypto")
|
||||
self.context = Crypto.Cipher.AES.new(key, mode, IV)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
return self.context.encrypt(plaintext)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.context.decrypt(ciphertext)
|
||||
@@ -1,22 +0,0 @@
|
||||
"""PyCrypto RC4 implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from RC4 import *
|
||||
|
||||
if pycryptoLoaded:
|
||||
import Crypto.Cipher.ARC4
|
||||
|
||||
def new(key):
|
||||
return PyCrypto_RC4(key)
|
||||
|
||||
class PyCrypto_RC4(RC4):
|
||||
|
||||
def __init__(self, key):
|
||||
RC4.__init__(self, key, "pycrypto")
|
||||
self.context = Crypto.Cipher.ARC4.new(key)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
return self.context.encrypt(plaintext)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.context.decrypt(ciphertext)
|
||||
@@ -1,61 +0,0 @@
|
||||
"""PyCrypto RSA implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
|
||||
from RSAKey import *
|
||||
from Python_RSAKey import Python_RSAKey
|
||||
|
||||
if pycryptoLoaded:
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
|
||||
class PyCrypto_RSAKey(RSAKey):
|
||||
def __init__(self, n=0, e=0, d=0, p=0, q=0, dP=0, dQ=0, qInv=0):
|
||||
if not d:
|
||||
self.rsa = RSA.construct( (n, e) )
|
||||
else:
|
||||
self.rsa = RSA.construct( (n, e, d, p, q) )
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.rsa, name)
|
||||
|
||||
def hasPrivateKey(self):
|
||||
return self.rsa.has_private()
|
||||
|
||||
def hash(self):
|
||||
return Python_RSAKey(self.n, self.e).hash()
|
||||
|
||||
def _rawPrivateKeyOp(self, m):
|
||||
s = numberToString(m)
|
||||
byteLength = numBytes(self.n)
|
||||
if len(s)== byteLength:
|
||||
pass
|
||||
elif len(s) == byteLength-1:
|
||||
s = '\0' + s
|
||||
else:
|
||||
raise AssertionError()
|
||||
c = stringToNumber(self.rsa.decrypt((s,)))
|
||||
return c
|
||||
|
||||
def _rawPublicKeyOp(self, c):
|
||||
s = numberToString(c)
|
||||
byteLength = numBytes(self.n)
|
||||
if len(s)== byteLength:
|
||||
pass
|
||||
elif len(s) == byteLength-1:
|
||||
s = '\0' + s
|
||||
else:
|
||||
raise AssertionError()
|
||||
m = stringToNumber(self.rsa.encrypt(s, None)[0])
|
||||
return m
|
||||
|
||||
def writeXMLPublicKey(self, indent=''):
|
||||
return Python_RSAKey(self.n, self.e).write(indent)
|
||||
|
||||
def generate(bits):
|
||||
key = PyCrypto_RSAKey()
|
||||
def f(numBytes):
|
||||
return bytesToString(getRandomBytes(numBytes))
|
||||
key.rsa = RSA.generate(bits, f)
|
||||
return key
|
||||
generate = staticmethod(generate)
|
||||
@@ -1,22 +0,0 @@
|
||||
"""PyCrypto 3DES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
from TripleDES import *
|
||||
|
||||
if pycryptoLoaded:
|
||||
import Crypto.Cipher.DES3
|
||||
|
||||
def new(key, mode, IV):
|
||||
return PyCrypto_TripleDES(key, mode, IV)
|
||||
|
||||
class PyCrypto_TripleDES(TripleDES):
|
||||
|
||||
def __init__(self, key, mode, IV):
|
||||
TripleDES.__init__(self, key, mode, IV, "pycrypto")
|
||||
self.context = Crypto.Cipher.DES3.new(key, mode, IV)
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
return self.context.encrypt(plaintext)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.context.decrypt(ciphertext)
|
||||
@@ -1,68 +0,0 @@
|
||||
"""Pure-Python AES implementation."""
|
||||
|
||||
from cryptomath import *
|
||||
|
||||
from AES import *
|
||||
from rijndael import rijndael
|
||||
|
||||
def new(key, mode, IV):
|
||||
return Python_AES(key, mode, IV)
|
||||
|
||||
class Python_AES(AES):
|
||||
def __init__(self, key, mode, IV):
|
||||
AES.__init__(self, key, mode, IV, "python")
|
||||
self.rijndael = rijndael(key, 16)
|
||||
self.IV = IV
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
AES.encrypt(self, plaintext)
|
||||
|
||||
plaintextBytes = stringToBytes(plaintext)
|
||||
chainBytes = stringToBytes(self.IV)
|
||||
|
||||
#CBC Mode: For each block...
|
||||
for x in range(len(plaintextBytes)/16):
|
||||
|
||||
#XOR with the chaining block
|
||||
blockBytes = plaintextBytes[x*16 : (x*16)+16]
|
||||
for y in range(16):
|
||||
blockBytes[y] ^= chainBytes[y]
|
||||
blockString = bytesToString(blockBytes)
|
||||
|
||||
#Encrypt it
|
||||
encryptedBytes = stringToBytes(self.rijndael.encrypt(blockString))
|
||||
|
||||
#Overwrite the input with the output
|
||||
for y in range(16):
|
||||
plaintextBytes[(x*16)+y] = encryptedBytes[y]
|
||||
|
||||
#Set the next chaining block
|
||||
chainBytes = encryptedBytes
|
||||
|
||||
self.IV = bytesToString(chainBytes)
|
||||
return bytesToString(plaintextBytes)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
AES.decrypt(self, ciphertext)
|
||||
|
||||
ciphertextBytes = stringToBytes(ciphertext)
|
||||
chainBytes = stringToBytes(self.IV)
|
||||
|
||||
#CBC Mode: For each block...
|
||||
for x in range(len(ciphertextBytes)/16):
|
||||
|
||||
#Decrypt it
|
||||
blockBytes = ciphertextBytes[x*16 : (x*16)+16]
|
||||
blockString = bytesToString(blockBytes)
|
||||
decryptedBytes = stringToBytes(self.rijndael.decrypt(blockString))
|
||||
|
||||
#XOR with the chaining block and overwrite the input with output
|
||||
for y in range(16):
|
||||
decryptedBytes[y] ^= chainBytes[y]
|
||||
ciphertextBytes[(x*16)+y] = decryptedBytes[y]
|
||||
|
||||
#Set the next chaining block
|
||||
chainBytes = blockBytes
|
||||
|
||||
self.IV = bytesToString(chainBytes)
|
||||
return bytesToString(ciphertextBytes)
|
||||
@@ -1,39 +0,0 @@
|
||||
"""Pure-Python RC4 implementation."""
|
||||
|
||||
from RC4 import RC4
|
||||
from cryptomath import *
|
||||
|
||||
def new(key):
|
||||
return Python_RC4(key)
|
||||
|
||||
class Python_RC4(RC4):
|
||||
def __init__(self, key):
|
||||
RC4.__init__(self, key, "python")
|
||||
keyBytes = stringToBytes(key)
|
||||
S = [i for i in range(256)]
|
||||
j = 0
|
||||
for i in range(256):
|
||||
j = (j + S[i] + keyBytes[i % len(keyBytes)]) % 256
|
||||
S[i], S[j] = S[j], S[i]
|
||||
|
||||
self.S = S
|
||||
self.i = 0
|
||||
self.j = 0
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
plaintextBytes = stringToBytes(plaintext)
|
||||
S = self.S
|
||||
i = self.i
|
||||
j = self.j
|
||||
for x in range(len(plaintextBytes)):
|
||||
i = (i + 1) % 256
|
||||
j = (j + S[i]) % 256
|
||||
S[i], S[j] = S[j], S[i]
|
||||
t = (S[i] + S[j]) % 256
|
||||
plaintextBytes[x] ^= S[t]
|
||||
self.i = i
|
||||
self.j = j
|
||||
return bytesToString(plaintextBytes)
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
return self.encrypt(ciphertext)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user