Esempio n. 1
0
def on_request(ch, method, props, body):
    message = smessage.unwrap(body)
    #decrypt received message
    print(message)
    ch.basic_publish(
        exchange='',
        routing_key=props.reply_to,
        properties=pika.BasicProperties(correlation_id=props.correlation_id),
        body=smessage.wrap(message))
    #encrypt and send reply message
    ch.basic_ack(delivery_tag=method.delivery_tag)
 def post(self):
     message = smessage.unwrap(self.request.body);         #decrypt accepted message
     print(message);
     self.write(smessage.wrap(message));                #encrypt and send message
def on_request(ch, method, props, body):
    message = smessage.unwrap(body); #decrypt received message
    print message;
    ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties(correlation_id = props.correlation_id), body=smessage.wrap(message));
    #encrypt and send reply message
    ch.basic_ack(delivery_tag = method.delivery_tag);
        if self.corr_id == props.correlation_id:
            self.response = smessage.unwrap(body)  # decrypt acceptedd message

    def call(self, message):
        self.response = None
        self.corr_id = str(uuid.uuid4())
        self.channel.basic_publish(
            exchange="",
            routing_key="smessage_queue",
            properties=pika.BasicProperties(reply_to=self.callback_queue, correlation_id=self.corr_id),
            body=message,
        )
        while self.response is None:
            self.connection.process_data_events()
        return self.response


smessage_rpc = SsessionRpcClient()

response = smessage_rpc.call(smessage.wrap(b"This is test message!"))
# encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #2!"))
# encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #3!"))
# encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #4!"))
# encrypt and send message


print response
        if self.corr_id == props.correlation_id:
            self.response = smessage.unwrap(body)  #decrypt acceptedd message

    def call(self, message):
        self.response = None
        self.corr_id = str(uuid.uuid4())
        self.channel.basic_publish(exchange='',
                                   routing_key='smessage_queue',
                                   properties=pika.BasicProperties(
                                       reply_to=self.callback_queue,
                                       correlation_id=self.corr_id,
                                   ),
                                   body=message)
        while self.response is None:
            self.connection.process_data_events()
        return self.response


smessage_rpc = SsessionRpcClient()

response = smessage_rpc.call(smessage.wrap(b"This is test message!"))
#encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #2!"))
#encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #3!"))
#encrypt and send message
response = smessage_rpc.call(smessage.wrap(b"This is test message #4!"))
#encrypt and send message

print response
        self.callback_queue = result.method.queue
        self.channel.basic_consume(self.on_response, no_ack=True, queue=self.callback_queue)

    def on_response(self, ch, method, props, body):
        if self.corr_id == props.correlation_id:
            self.response = smessage.unwrap(body) #decrypt acceptedd message

    def call(self, message):
        self.response = None
        self.corr_id = str(uuid.uuid4())
        self.channel.basic_publish(exchange='',
                                   routing_key='smessage_queue',
                                   properties=pika.BasicProperties(
                                         reply_to = self.callback_queue,
                                         correlation_id = self.corr_id,
                                         ),
                                   body=message)
        while self.response is None:
            self.connection.process_data_events()
        return self.response

smessage_rpc = SsessionRpcClient()

response = smessage_rpc.call(smessage.wrap("This is test message!")); #encrypt and send message
response = smessage_rpc.call(smessage.wrap("This is test message #2!")); #encrypt and send message
response = smessage_rpc.call(smessage.wrap("This is test message #3!")); #encrypt and send message
response = smessage_rpc.call(smessage.wrap("This is test message #4!")); #encrypt and send message


print response;
Esempio n. 7
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.
#

#echo client for tornado
from pythemis import smessage;
import tornado.ioloop
import tornado.httpclient;

client_priv = b"\x52\x45\x43\x32\x00\x00\x00\x2d\x51\xf4\xaa\x72\x00\x9f\x0f\x09\xce\xbe\x09\x33\xc2\x5e\x9a\x05\x99\x53\x9d\xb2\x32\xa2\x34\x64\x7a\xde\xde\x83\x8f\x65\xa9\x2a\x14\x6d\xaa\x90\x01"

server_pub  = b"\x55\x45\x43\x32\x00\x00\x00\x2d\x75\x58\x33\xd4\x02\x12\xdf\x1f\xe9\xea\x48\x11\xe1\xf9\x71\x8e\x24\x11\xcb\xfd\xc0\xa3\x6e\xd6\xac\x88\xb6\x44\xc2\x9a\x24\x84\xee\x50\x4c\x3e\xa0"

http_client = tornado.httpclient.HTTPClient();
smessage=smessage.smessage(client_priv, server_pub);
try:
    response = http_client.fetch(tornado.httpclient.HTTPRequest("http://127.0.0.1:26260", "POST", None, smessage.wrap(b"This is test message")));
    #decrypt request body(message)
    message = smessage.unwrap(response.body);         #encrypt message
    print(message);                                #send message
    
except tornado.httpclient.HTTPError as e:
    print("Error: " + str(e));
except Exception as e:
    print("Error: " + str(e));
http_client.close();
Esempio n. 8
0
 def post(self):
     message = smessage.unwrap(self.request.body)
     #decrypt accepted message
     print(message)
     self.write(smessage.wrap(message))