예제 #1
0
파일: server.py 프로젝트: drbild/xtt-python
    def __init__(self):
        self.native = _ffi.new('struct xtt_server_cookie_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        rc = _lib.xtt_initialize_server_cookie_context(self.native)
        if rc != RC.SUCCESS:
            raise error_from_code(rc)
예제 #2
0
파일: server.py 프로젝트: drbild/xtt-python
    def __init__(self, cert, key):
        self.native = _ffi.new('struct xtt_server_certificate_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        rc = _lib.xtt_initialize_server_certificate_context_ed25519(
            self.native, cert.native, key.native)
        if rc != RC.SUCCESS:
            error_from_code(rc)
예제 #3
0
    def __init__(self, root_id, root_pubkey):
        self.native = _ffi.new('struct xtt_server_root_certificate_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        rc = _lib.xtt_initialize_server_root_certificate_context_ecdsap256(
            self.native, root_id.native, root_pubkey.native)
        if rc != RC.SUCCESS:
            error_from_code(rc)
예제 #4
0
파일: server.py 프로젝트: drbild/xtt-python
    def __init__(self, pub_key, basename):
        self.native = _ffi.new('struct xtt_group_public_key_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        rc = _lib.xtt_initialize_group_public_key_context_lrsw(
            self.native, basename, len(basename), pub_key.native)
        if rc != RC.SUCCESS:
            raise MemoryError("Unable to allocate native object")
예제 #5
0
    def __init__(self, group_id, priv_key, credential, basename):
        self.native = _ffi.new('struct xtt_client_group_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        rc = _lib.xtt_initialize_client_group_context_lrsw(
            self.native, group_id.native, priv_key.native, credential.native,
            basename, len(basename))
        if rc != RC.SUCCESS:
            raise MemoryError("Unable to allocate native object")
예제 #6
0
    def __init__(self, size, value=None):
        self.native = _ffi.new('unsigned char[]', size)

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        self._raw = _ffi.cast('struct xtt_server_certificate_raw_type*',
                              self.native)

        if value:
            self.data = value
예제 #7
0
파일: asn1.py 프로젝트: drbild/xtt-python
def asn1_from_ed25519_private_key(priv_key):
    """
    Returns the ASN.1 encoding of a ED25519 private ket.

    :priv_key: an ED25519PrivateKey instance
    :returns: the ASN.1 encoding as a byte string
    """
    encoded_len = _lib.xtt_asn1_private_key_length()
    encoded = _ffi.new('unsigned char[]', encoded_len)
    rc = _lib.xtt_asn1_from_ed25519_private_key(priv_key.native, encoded,
                                                len(encoded))
    if rc == RC.SUCCESS:
        return _ffi.buffer(encoded)[:]
    else:
        raise error_from_code(rc)
예제 #8
0
파일: server.py 프로젝트: drbild/xtt-python
    def __init__(self):
        self.native = _ffi.new('struct xtt_server_handshake_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        self._in = Buffer(_lib.max_handshake_client_message_length())
        self._out = Buffer(_lib.max_handshake_server_message_length())
        self._io = BufferView()

        self._client_requested_id = Identity()
        self._client_claimed_group = GroupId()

        rc = _lib.xtt_initialize_server_handshake_context(
            self.native, self._in.native, self._in.size, self._out.native,
            self._out.size)

        if rc != RC.SUCCESS:
            raise error_from_code(rc)
예제 #9
0
파일: asn1.py 프로젝트: xaptum/xtt-python
def x509_from_ecdsap256_key_pair(pub_key, priv_key, common_name):
    """
    Creates a self-signed x509 certificate for a common name and
    ECDSAP256 key pair.

    :pub_key: an ECDSAP256PublicKey instance
    :priv_key: an ECDSAP256PrivateKey instance
    :common_name: an XTTIdentity instance
    :returns: the certificate as a byte string
    """
    cert_len = _lib.xtt_x509_certificate_length()
    cert = _ffi.new('unsigned char[]', cert_len)
    rc = _lib.xtt_x509_from_ecdsap256_keypair(pub_key.native, priv_key.native,
                                              common_name.native, cert,
                                              len(cert))
    if rc == RC.SUCCESS:
        return _ffi.buffer(cert)[:]
    else:
        raise error_from_code(rc)
예제 #10
0
    def __init__(self, version, suite_spec):
        self.native = _ffi.new('struct xtt_client_handshake_context*')

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")

        self._in = Buffer(_lib.max_handshake_server_message_length())
        self._out = Buffer(_lib.max_handshake_client_message_length())
        self._io = BufferView()

        self._version = version
        self._suite_spec = suite_spec

        self._server_root_id = CertificateRootId()

        rc = _lib.xtt_initialize_client_handshake_context(
            self.native, self._in.native, self._in.size, self._out.native,
            self._out.size, version, suite_spec)

        if rc != RC.SUCCESS:
            raise error_from_code(rc)
예제 #11
0
    def __init__(self, size):
        self.size = size
        self.native = _ffi.new('unsigned char[]', self.size)

        if self.native == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")
예제 #12
0
    def __init__(self):
        self._size = _ffi.new('uint16_t[1]')
        self._data = _ffi.new('unsigned char *[1]')

        if self._size == _ffi.NULL or self._data == _ffi.NULL:
            raise MemoryError("Unable to allocate native object")