]>
git.frykholm.com Git - friends.git/blob - friends/salmoning/__init__.py
3 # Copyright 2010 Google Inc. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 """Support library for the Salmon Protocol.
20 See Salmon I-D for specification. This module
21 implements a support library for Salmon on top of the
22 Magic Envelope library and other bits.
25 __author__
= 'jpanzer@google.com (John Panzer)'
29 #import xml.dom.minidom as dom
34 class SalmonProtocol(object):
35 """Implementation of Salmon Protocol."""
37 magicenv
= magicsig
.MagicEnvelopeProtocol()
39 def _GetKeypair(self
, signer_uri
):
40 return self
.key_retriever
.LookupPublicKey(signer_uri
)
42 def SignSalmon(self
, text
, mimetype
, requestor_id
):
43 """Signs a Salmon on behalfo the the current_user.
45 Input text must be in a recognized format so authorship can be
49 text: Text of message to be signed.
50 mimetype: The MIME type of the message to sign.
51 requestor_id: The id of the requestor (usually current logged in user).
53 The Magic Envelope parameters from section 3.1 of the
54 Magic Signatures spec, as a dict.
57 assert mimetype
== 'application/atom+xml'
59 requestor_id
= magicsig
.NormalizeUserIdToUri(requestor_id
)
61 if not self
.magicenv
.IsAllowedSigner(text
,
62 magicsig
.NormalizeUserIdToUri(requestor_id
)):
63 # TODO: Fix authorship if missing author, raise
64 # exception otherwise.
67 env
= magicsig
.Envelope(
69 raw_data_to_sign
=text
,
70 signer_uri
=requestor_id
,
71 signer_key
=self
._GetKeypair
(requestor_id
),
72 data_type
='application/atom+xml',
79 def ParseSalmon(self
, text
, mimetype
):
80 """Parses a salmon from text with given mimetype.
83 The salmon data as a dict, with fields:
86 self
.magicenv
.key_retriever
= self
.key_retriever
88 return magicsig
.Envelope(
91 document
=text
).ToAtom()