Exemplo n.º 1
0
    def create_session(self):
        desc = ua.ApplicationDescription()
        desc.ApplicationUri = self.application_uri
        desc.ProductUri = self.product_uri
        desc.ApplicationName = ua.LocalizedText(self.name)
        desc.ApplicationType = ua.ApplicationType.Client

        params = ua.CreateSessionParameters()
        params.ClientNonce = utils.create_nonce()
        params.ClientCertificate = b''
        params.ClientDescription = desc
        params.EndpointUrl = self.server_url.geturl()
        params.SessionName = self.description + " Session" + str(
            self._session_counter)
        params.RequestedSessionTimeout = 3600000
        params.MaxResponseMessageSize = 0  # means no max size
        response = self.bclient.create_session(params)
        #print("Certificate is ", response.ServerCertificate)
        self.server_certificate = response.ServerCertificate
        for ep in response.ServerEndpoints:
            if ep.SecurityMode == self.security_mode:
                # remember PolicyId's: we will use them in activate_session()
                for token in ep.UserIdentityTokens:
                    self.policy_ids[token.TokenType] = token.PolicyId
        self.session_timeout = response.RevisedSessionTimeout
        self.keepalive = KeepAlive(
            self,
            min(self.session_timeout, self.secure_channel_timeout) *
            0.7)  # 0.7 is from spec
        self.keepalive.start()
        return response
Exemplo n.º 2
0
    def create_session(self):
        desc = ua.ApplicationDescription()
        desc.ApplicationUri = self.application_uri
        desc.ProductUri = self.product_uri
        desc.ApplicationName = ua.LocalizedText(self.name)
        desc.ApplicationType = ua.ApplicationType.Client

        params = ua.CreateSessionParameters()
        params.ClientNonce = utils.create_nonce()
        params.ClientCertificate = b""
        params.ClientDescription = desc
        params.EndpointUrl = self.server_url.geturl()
        params.SessionName = self.description + " Session" + str(self._session_counter)
        params.RequestedSessionTimeout = 3600000
        params.MaxResponseMessageSize = 0  # means no max size
        response = self.bclient.create_session(params)
        print("Certificate is ", response.ServerCertificate)
        self.server_certificate = response.ServerCertificate
        for ep in response.ServerEndpoints:
            if ep.SecurityMode == self.security_mode:
                # remember PolicyId's: we will use them in activate_session()
                for token in ep.UserIdentityTokens:
                    self.policy_ids[token.TokenType] = token.PolicyId
        self.session_timeout = response.RevisedSessionTimeout
        self.keepalive = KeepAlive(
            self, min(self.session_timeout, self.secure_channel_timeout) * 0.7
        )  # 0.7 is from spec
        self.keepalive.start()
        return response
Exemplo n.º 3
0
 def _open_secure_channel(self, params):
     self.logger.info("open secure channel")
     if not self.channel or params.RequestType == ua.SecurityTokenRequestType.Issue:
         self.channel = ua.OpenSecureChannelResult()
         self.channel.SecurityToken.TokenId = 13  # random value
         self.channel.SecurityToken.ChannelId = self.iserver.get_new_channel_id()
         self.channel.SecurityToken.RevisedLifetime = params.RequestedLifetime
     self.channel.SecurityToken.TokenId += 1
     self.channel.SecurityToken.CreatedAt = datetime.now()
     self.channel.SecurityToken.RevisedLifetime = params.RequestedLifetime
     self.channel.ServerNonce = utils.create_nonce()
     return self.channel
Exemplo n.º 4
0
 def _open_secure_channel(self, params):
     self.logger.info("open secure channel")
     if not self.channel or params.RequestType == ua.SecurityTokenRequestType.Issue:
         self.channel = ua.OpenSecureChannelResult()
         self.channel.SecurityToken.TokenId = 13  # random value
         self.channel.SecurityToken.ChannelId = self.iserver.get_new_channel_id()
         self.channel.SecurityToken.RevisedLifetime = params.RequestedLifetime
     self.channel.SecurityToken.TokenId += 1
     self.channel.SecurityToken.CreatedAt = datetime.now()
     self.channel.SecurityToken.RevisedLifetime = params.RequestedLifetime
     self.channel.ServerNonce = utils.create_nonce()
     return self.channel
Exemplo n.º 5
0
 def __init__(self, internal_server, aspace, submgr, name):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.aspace = aspace
     self.submgr = submgr
     self.name = name
     self.state = SessionState.Created
     self.session_id = ua.NodeId(self._counter)
     InternalSession._counter += 1
     self.authentication_token = ua.NodeId(self._auth_counter)
     InternalSession._auth_counter += 1
     self.nonce = utils.create_nonce() 
     self.subscriptions = []
     self.logger.warning("Created internal session %s", self.name)
     self._lock = Lock()
Exemplo n.º 6
0
 def __init__(self, internal_server, aspace, submgr, name, user=User.Anonymous):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.aspace = aspace
     self.subscription_service = submgr
     self.name = name
     self.user = user
     self.state = SessionState.Created
     self.session_id = ua.NodeId(self._counter)
     InternalSession._counter += 1
     self.authentication_token = ua.NodeId(self._auth_counter)
     InternalSession._auth_counter += 1
     self.nonce = utils.create_nonce()
     self.subscriptions = []
     #self.logger.debug("Created internal session %s for user %s", self.name, self.user)
     print("Created internal session {} for user {}".format(self.name, self.user))
     self._lock = Lock()
Exemplo n.º 7
0
    def create_session(self):
        desc = ua.ApplicationDescription()
        desc.ApplicationUri = self.application_uri
        desc.ProductUri = self.product_uri
        desc.ApplicationName = ua.LocalizedText(self.name)
        desc.ApplicationType = ua.ApplicationType.Client

        params = ua.CreateSessionParameters()
        params.ClientNonce = utils.create_nonce()
        params.ClientCertificate = b''
        params.ClientDescription = desc
        params.EndpointUrl = self.server_url.geturl()
        params.SessionName = self.description + " Session" + str(self._session_counter)
        params.RequestedSessionTimeout = 3600000
        params.MaxResponseMessageSize = 0  # means no max size
        response = self.bclient.create_session(params)
        self.session_timeout = response.RevisedSessionTimeout
        self.keepalive = KeepAlive(self, min(self.session_timeout, self.secure_channel_timeout) * 0.7)  # 0.7 is from spec
        self.keepalive.start()
        return response
Exemplo n.º 8
0
 def __init__(self,
              internal_server,
              aspace,
              submgr,
              name,
              user=User.Anonymous):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.aspace = aspace
     self.subscription_service = submgr
     self.name = name
     self.user = user
     self.state = SessionState.Created
     self.session_id = ua.NodeId(self._counter)
     InternalSession._counter += 1
     self.authentication_token = ua.NodeId(self._auth_counter)
     InternalSession._auth_counter += 1
     self.nonce = utils.create_nonce()
     self.subscriptions = []
     #self.logger.debug("Created internal session %s for user %s", self.name, self.user)
     print("Created internal session {} for user {}".format(
         self.name, self.user))
     self._lock = Lock()
Exemplo n.º 9
0
    def create_session(self):
        desc = ua.ApplicationDescription()
        desc.ApplicationUri = self.application_uri
        desc.ProductUri = self.product_uri
        desc.ApplicationName = ua.LocalizedText(self.name)
        desc.ApplicationType = ua.ApplicationType.Client

        params = ua.CreateSessionParameters()
        params.ClientNonce = utils.create_nonce()
        params.ClientCertificate = b''
        params.ClientDescription = desc
        params.EndpointUrl = self.server_url.geturl()
        params.SessionName = self.description + " Session" + str(
            self._session_counter)
        params.RequestedSessionTimeout = 3600000
        params.MaxResponseMessageSize = 0  # means no max size
        response = self.bclient.create_session(params)
        self.session_timeout = response.RevisedSessionTimeout
        self.keepalive = KeepAlive(
            self,
            min(self.session_timeout, self.secure_channel_timeout) *
            0.7)  # 0.7 is from spec
        self.keepalive.start()
        return response