コード例 #1
0
class SMessageProtocol(protocol.Protocol):
    def __init__(self):
        self.smessage = SMessage(server_private, client_public)

    def dataReceived(self, data):
        # decrypt_message
        message = self.smessage.unwrap(data)
        print(message)
        # encrypt -> send message
        self.transport.write(self.smessage.wrap(message))
コード例 #2
0
class SMessageProtocol(protocol.Protocol):
    def __init__(self):
        self.smessage = SMessage(server_private, client_public)

    def dataReceived(self, data):
        # decrypt_message
        message = self.smessage.unwrap(data)
        print(message)
        # encrypt -> send message
        self.transport.write(self.smessage.wrap(message))
コード例 #3
0
ファイル: __init__.py プロジェクト: vixentael/acra
def create_acrastruct(data, acra_public_key, context=None):
    random_kp = GenerateKeyPair(KEY_PAIR_TYPE.EC)
    smessage = SMessage(random_kp.export_private_key(), acra_public_key)
    random_key = generate_key()
    wrapped_random_key = smessage.wrap(random_key)

    scell = SCellSeal(random_key)
    encrypted_data = scell.encrypt(data, context)
    del random_key
    encrypted_data_len = struct.pack('<Q', len(encrypted_data))

    acrastruct = (BEGIN_TAG + random_kp.export_public_key() +
                  wrapped_random_key + encrypted_data_len + encrypted_data)
    del random_kp
    del wrapped_random_key
    return acrastruct
コード例 #4
0
 def decrypt(self, msg, pubkey=None, privkey=None):
     if issubclass(type(msg), ComradKey) or issubclass(
             type(msg), ComradEncryptedKey):
         msg = msg.data
     pubkey = pubkey if pubkey else self.pubkey
     privkey = privkey if privkey else self.privkey
     return SMessage(privkey.data, pubkey.data).unwrap(msg)
コード例 #5
0
 def __init__(self):
     self.smessage = SMessage(server_private, client_public)
コード例 #6
0
# 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 rabbitMQ
import pika
import uuid
from pythemis.smessage import SMessage

client_private = 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_public = 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"

smessage = SMessage(client_private, server_public)


class SsessionRpcClient(object):
    def __init__(self):
        self.connection = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        self.channel = self.connection.channel()
        result = self.channel.queue_declare(exclusive=True)
        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:
            # decrypt acceptedd message
コード例 #7
0
#

"""
echo client for tornado
"""

import tornado.httpclient

from pythemis.smessage import SMessage

client_private = 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_public = 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(client_private, server_public)
try:
    response = http_client.fetch(
        tornado.httpclient.HTTPRequest(
            "http://127.0.0.1:26260", "POST",
            headers={'Content-Type': 'application/octet-stream'},
            # encrypt message
            body=smessage.wrap(b"This is test message")))
    # decrypt request body(message)
    message = smessage.unwrap(response.body)
    print(message)
except tornado.httpclient.HTTPError as e:
    print("Error: " + str(e))
except Exception as e:
    print("Error: " + str(e))
http_client.close()
コード例 #8
0
# 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 server for rabbitMQ
"""

import pika
from pythemis.smessage import SMessage

client_public = b"\x55\x45\x43\x32\x00\x00\x00\x2d\x13\x8b\xdf\x0c\x02\x1f\x09\x88\x39\xd9\x73\x3a\x84\x8f\xa8\x50\xd9\x2b\xed\x3d\x38\xcf\x1d\xd0\xce\xf4\xae\xdb\xcf\xaf\xcb\x6b\xa5\x4a\x08\x11\x21"

server_private = b"\x52\x45\x43\x32\x00\x00\x00\x2d\x49\x87\x04\x6b\x00\xf2\x06\x07\x7d\xc7\x1c\x59\xa1\x8f\x39\xfc\x94\x81\x3f\x9e\xc5\xba\x70\x6f\x93\x08\x8d\xe3\x85\x82\x5b\xf8\x3f\xc6\x9f\x0b\xdf"

smessage = SMessage(server_private, client_public)

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))

channel = connection.channel()

channel.queue_declare(queue='smessage_queue')


def on_request(ch, method, props, body):
    # decrypt received message
    message = smessage.unwrap(body)
    print(message.decode('utf-8'))
    ch.basic_publish(
        exchange='',
コード例 #9
0
# 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 rabbitMQ
import pika
import uuid
from pythemis.smessage import SMessage

client_private = 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_public = 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"

smessage = SMessage(client_private, server_public)


class SsessionRpcClient(object):
    def __init__(self):
        self.connection = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        self.channel = self.connection.channel()
        result = self.channel.queue_declare(exclusive=True)
        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:
コード例 #10
0
 def __init__(self):
     self.smessage = SMessage(server_private, client_public)