def list_all_yaml_files(self, *args):
        ret_list = []
        util.loadConfig()
        for conf_file in os.listdir(util.configLocation):
            if os.path.isfile(os.path.join(util.configLocation, conf_file)):
                m = re.search(".yaml", conf_file)
                if m != None:
                    ret_list.append(conf_file)

        if len(ret_list) == 0:
            ret_list.insert(0, "Error:")
            ret_list.append("No yaml files found at <[" + util.configLocation + "]>")

        return ret_list
Exemple #2
0
    def test_WINNF_FT_S_SDS_10(self, config_filename):
        """Certificate of wrong type presented during registration.

    Checks that SAS UUT response with fatal alert message.
    """
        config = loadConfig(config_filename)
        try:
            # This uses the same base_url as Registration().
            self.assertTlsHandshakeFailure(
                self._sas.cbsd_sas_active_base_url,
                client_cert=config['domainProxyCert'],
                client_key=config['domainProxyKey'])
        except AssertionError as e:
            self.SasReset()
            # Load Devices
            device_a = json.load(
                open(os.path.join('testcases', 'testdata', 'device_a.json')))
            # Register the devices
            devices = [device_a]
            request = {'registrationRequest': devices}
            response = self._sas.Registration(
                request,
                ssl_cert=config['domainProxyCert'],
                ssl_key=config['domainProxyKey'])['registrationResponse']
            # Check Registration Response
            self.assertEqual(response[0]['response']['responseCode'], 104)
Exemple #3
0
    def test_WINNF_FT_S_SSS_10(self, config_filename):
        """Certificate of wrong type presented during Full Activity Dump.

    Checks that SAS UUT response with fatal alert message.
    """
        config = loadConfig(config_filename)

        # Reset the SAS UUT
        self.SasReset()

        # Notify SAS UUT about peer SAS
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({'certificateHash': certificate_hash,\
                                         'url': SAS_TEST_HARNESS_URL})
        try:
            self.assertTlsHandshakeFailure(client_cert=config['sasCert'],
                                           client_key=config['sasKey'])
        except AssertionError:
            trigger_succeed = False
            try:
                self.TriggerFullActivityDumpAndWaitUntilComplete(
                    config['sasCert'], config['sasKey'])
                trigger_succeed = True
            except HTTPError as e:
                # Check if HTTP status is 403
                self.assertEqual(e.error_code, 403)
            self.assertFalse(trigger_succeed,
                             "Full Activity Dump is expected to fail")
Exemple #4
0
  def test_WINNF_FT_S_SCS_15(self,config_filename):
    """Certificate with inapplicable fields presented during registration. 
    
    Checks that SAS UUT response with tls connection succedded and response should be 104.    
    """
    config = loadConfig(config_filename)
    
    # Load the keys/certs and check that TLS handshake is valid
    device_a_cert = config['clientCert']
    device_a_key = config['clientKey']
    # This uses the same base_url as Registration().
    self.assertTlsHandshakeSucceed(self._sas.cbsd_sas_active_base_url,
                                   ['AES128-GCM-SHA256'],
                                   device_a_cert, device_a_key)
   
    # Load device and inject fccId and userId
    device_a = json.load(open(os.path.join('testcases', 'testdata', 'device_a.json')))
    self.SasReset() 
    self._sas_admin.InjectFccId({'fccId': device_a['fccId']})
    self._sas_admin.InjectUserId({'userId': device_a['userId']})
    
    # Send registration Request with certs(inapplicable fields) to SAS UUT 
    request = {'registrationRequest': [device_a]}
    response = self._sas.Registration(request,ssl_cert=device_a_cert,ssl_key=device_a_key)['registrationResponse'][0]

    # Check registration response
    self.assertEqual(response['response']['responseCode'],104)
    def test_WINNF_FT_S_PCR_5(self, config_filename):
        """Unsuccessful PPA Creation with one or more CBSDs Outside Service Area.

    Checks SAS UUT rejects creation of a PPA boundary if at least one of
    the CBSDs included in the CBSD cluster list does not belong to the PAL holder.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Inject the PAL records.
        for pal_record in config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Register devices and check the response.
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [record['palId'] for record in config['palRecords']]

        # Create PPA creation request to SAS UUT.
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT and expect the failure response.
        # SAS does not create a PPA and generates an error.
        self.assertPpaCreationFailure(ppa_creation_request)
  def test_WINNF_FT_S_GPR_3(self, config_filename):
    """GWPZ Exclusion Zone
      One or more CBSDs, located inside a GWPZ, request Grants and are rejected
    """
    config = loadConfig(config_filename)

    # Step1: Admin Test Harness injects a GWPZ into the SAS UUT
    self._sas_admin.InjectWisp(config['gwpzRecord'])

    # Step2: Admin Test Harness triggers CPAS and waits until completion of CPAS
    self.TriggerDailyActivitiesImmediatelyAndWaitUntilComplete()

    # Step3: DP Test Harness registers N > 0 CBSDs
    cbsd_ids = self.assertRegistered(config['registrationRequests'], config['conditionalRegistrationData'])

    # Step4: DP Test Harness requests one Grant per registered CBSD
    grant_request = config['grantRequests']
    addCbsdIdsToRequests(cbsd_ids, grant_request)

    request = {'grantRequest': grant_request}
    response = self._sas.Grant(request)['grantResponse']
    self.assertEqual(len(response), len(grant_request))

    for response_num, response in enumerate(response):
      self.assertEqual(response['cbsdId'], request['grantRequest'][response_num]['cbsdId'])
      self.assertEqual(response['response']['responseCode'], 400)
    def test_WINNF_FT_S_QPR_2(self, config_filename):
        """[Configurable] Rejecting Registration of CBSD inside the NRAO/NRRO
      Quiet Zone.
    """
        config = loadConfig(config_filename)
        # Very light checking of the config file.
        self.assertValidConfig(config, {
            'registrationRequests': list,
            'conditionalRegistrationData': list
        })

        # Whitelist FCC IDs and User IDs.
        for device in config['registrationRequests']:
            self._sas_admin.InjectFccId({'fccId': device['fccId']})
            self._sas_admin.InjectUserId({'userId': device['userId']})

        # Pre-load conditional registration data.
        if config['conditionalRegistrationData']:
            self._sas_admin.PreloadRegistrationData(
                {'registrationData': config['conditionalRegistrationData']})

        # Register CBSDs.
        request = {'registrationRequest': config['registrationRequests']}
        responses = self._sas.Registration(request)['registrationResponse']

        # Check registration responses.
        self.assertEqual(len(responses), len(config['registrationRequests']))
        for i, response in enumerate(responses):
            response = responses[i]
            logging.debug('Looking at response number %d', i)
            self.assertNotEqual(response['response']['responseCode'], 0)
            self.assertFalse('cbsdId' in response)
Exemple #8
0
def prepare():
    parser = argparse.ArgumentParser(
        description='Collect data for the paper to display')

    parser.add_argument('--config',
                        required=True,
                        help="File with the configuration")
    parser.add_argument('--collect', required=True, help="Data to collect")
    parser.add_argument('--target',
                        required=True,
                        help="Target to store the collected data to")

    args = parser.parse_args()

    collect_functions = {
        "base": get_base_data,
        "schemes": get_schemes_data,
        "labels": get_labels_data,
        "models2agg": get_models_agg,
        "labels2score": get_labels_score
    }

    config = util.loadConfig(args.config)
    config["req_collect"] = args.collect
    config["target"] = args.target

    config["collect_function"] = (collect_functions.get(
        args.collect, default_function))

    config["labels"] = util.getLabels(config)
    return config
Exemple #9
0
    def test_WINNF_FT_S_SSS_15(self, config_filename):
        """Certificate with inapplicable fields presented during Full Activity Dump 
    """
        config = loadConfig(config_filename)

        # Reset the SAS UUT
        self.SasReset()

        # Notify SAS UUT about peer SAS
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({'certificateHash': certificate_hash,\
                                         'url': SAS_TEST_HARNESS_URL })
        self.assertTlsHandshakeSucceed(self._sas_admin._base_url,
                                       ['AES128-GCM-SHA256'],
                                       config['sasCert'], config['sasKey'])
        trigger_succeed = False
        # Initiate Full Activity Dump
        try:
            self.TriggerFullActivityDumpAndWaitUntilComplete(
                config['sasCert'], config['sasKey'])
            trigger_succeed = True
        except HTTPError as e:
            # Check if HTTP status is 403
            self.assertEqual(e.error_code, 403)
        self.assertFalse(trigger_succeed,
                         "Full Activity Dump is expected to fail")
Exemple #10
0
    def __init__(self, conf = {}, daoClass = Dao):
        global logger
        if any(conf) == False:
            self.__conf = util.loadConfig(appName = moduleName)
            global webServerRoot
            webServerRoot = self.__conf['outputDir']
        else:
            self.__conf = conf
        logger = logging.getLogger(moduleName)
        
        self.__daoClass = daoClass
        self.__dao = daoClass.getInstance()
        self.openclosDbSessionPlugin = OpenclosDbSessionPlugin(daoClass)
        
        if 'httpServer' in self.__conf and 'ipAddr' in self.__conf['httpServer'] and self.__conf['httpServer']['ipAddr'] is not None:
            self.host = self.__conf['httpServer']['ipAddr']
        else:
            self.host = 'localhost'

        if 'httpServer' in self.__conf and 'port' in self.__conf['httpServer']:
            self.port = self.__conf['httpServer']['port']
        else:
            self.port = 8080
        self.baseUrl = 'http://%s:%d' % (self.host, self.port)

        self.report = ResourceAllocationReport(self.__conf, daoClass)
        # Create a single instance of l2Report as it holds thread-pool
        # for device connection. Don't create l2Report multiple times 
        self.l2Report = L2Report(self.__conf, daoClass)
        # Create a single instance of l3Report as it holds thread-pool
        # for device connection. Don't create l3Report multiple times 
        self.l3Report = L3Report(self.__conf, daoClass)
Exemple #11
0
    def test_WINNF_FT_S_SSS_11(self, config_filename):
        """Blacklisted certificate presented by SAS Test Harness.

    Checks that SAS UUT response with fatal alert message.
    """
        # Reset SAS UUT
        self.SasReset()

        # Read the configuration
        config = loadConfig(config_filename)

        # Read the fingerprint from the certificate
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({
            'certificateHash': certificate_hash,
            'url': SAS_TEST_HARNESS_URL
        })

        # Tls handshake fails or Http 403
        self.assertTlsHandshakeFailureOrHttp403(client_cert=config['sasCert'],
                                                client_key=config['sasKey'],
                                                is_sas=True)

        logging.info(
            "TLS handshake failed as the sas certificate has blacklisted")
Exemple #12
0
    def __init__(self, conf = {}):
        global logger
        if conf is None or any(conf) == False:
            self.__conf = util.loadConfig(appName = moduleName)
        else:
            self.__conf = conf

        logger = logging.getLogger(moduleName)
        # default value
        self.target = DEFAULT_HOST
        self.port = DEFAULT_PORT
        
        # validate required parameter
        if 'snmpTrap' in self.__conf and 'openclos_trap_group' in self.__conf['snmpTrap'] and 'target' in self.__conf['snmpTrap']['openclos_trap_group']:
            self.target = self.__conf['snmpTrap']['openclos_trap_group']['target']
        else:
            logger.info("snmpTrap:openclos_trap_group:target is missing from configuration. using %s" % (self.target))                

        if 'snmpTrap' in self.__conf and 'openclos_trap_group' in self.__conf['snmpTrap'] and 'port' in self.__conf['snmpTrap']['openclos_trap_group']:
            self.port = int(self.__conf['snmpTrap']['openclos_trap_group']['port'])
        else:
            logger.info("snmpTrap:openclos_trap_group:port is missing from configuration. using %d" % (self.port))                
            
        if 'snmpTrap' in self.__conf and 'threadCount' in self.__conf['snmpTrap']:
            self.executor = concurrent.futures.ThreadPoolExecutor(max_workers = self.__conf['snmpTrap']['threadCount'])
        else:
            self.executor = concurrent.futures.ThreadPoolExecutor(max_workers = DEFAULT_MAX_THREADS)

        # event to stop from sleep
        self.stopEvent = Event()
        
        self.twoStageConfigurationCallback = util.getTwoStageConfigurationCallback(self.__conf)
  def __init__(self, configuration_file, database_file='jonnyboards.db'):
      self.config = {}
      self.database = database.Database(database_file)

      (self.api_key, self.sensors) = util.loadConfig(configuration_file)
      self.ipaddress = util.get_ip_address()
      self._configureSensors()
Exemple #14
0
    def __init__(self, conf = {}):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))

        else:
            self.conf = conf
        self.dao = Dao(self.conf)
Exemple #15
0
  def test_WINNF_FT_S_SCS_12(self,config_filename):
    """Expired certificate presented during registration.

    Checks that SAS UUT response with fatal alert message.
    """
    config = loadConfig(config_filename)
    self.assertTlsHandshakeFailureOrHttp403(client_cert=config['clientCert'],
                                            client_key=config['clientKey'])
Exemple #16
0
  def test_WINNF_FT_S_SCS_6(self, config_filename):
    """Unrecognized root of trust certificate presented during registration.

    Checks that SAS UUT response with fatal alert with unknown_ca.
    """
    config = loadConfig(config_filename)
    self.assertTlsHandshakeFailureOrHttp403(client_cert=config['clientCert'],
                                            client_key=config['clientKey'])
Exemple #17
0
    def __init__(self, conf={}):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(
                logging.getLevelName(self.conf['logLevel'][moduleName]))

        else:
            self.conf = conf
        self.dao = Dao(self.conf)
Exemple #18
0
    def test_WINNF_FT_S_SDS_9(self, config_filename):
        """Non-CBRS trust root signed certificate presented during registration.

    Checks that SAS UUT response with fatal alert message.
    """
        config = loadConfig(config_filename)
        self.assertTlsHandshakeFailureOrHttp403(
            client_cert=config['domainProxyCert'],
            client_key=config['domainProxyKey'])
Exemple #19
0
    def __init__(self, conf = {}, daoClass = Dao):
        global logger
        if any(conf) == False:
            self._conf = util.loadConfig(appName = moduleName)
        else:
            self._conf = conf

        logger = logging.getLogger(moduleName)
        self._dao = daoClass.getInstance()
    def __init__(self, conf = {}):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))
        else:
            self.conf = conf

        self.dao = Dao(self.conf)
        self.templateEnv = Environment(loader=PackageLoader('jnpr.openclos', junosTemplateLocation))
        self.templateEnv.keep_trailing_newline = True
Exemple #21
0
    def test_WINNF_FT_S_WDB_1(self, config_filename):
        """PAL Database Update."""

        # Load the configuration file
        config = loadConfig(config_filename)

        # Very light checking of the configuration file.
        self.assertEqual(len(config['registrationRequests']),
                         len(config['palIds']))

        # Step 1: Register device(s) 'C' with conditional registration data
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Step 2: Request creation of PPA(s).
        # Forming of PPA creation request(s)
        ppa_creation_requests = []
        for cbsd_id, pal_ids in zip(cbsd_ids, config['palIds']):
            ppa_creation_requests.append({
                "cbsdIds": [cbsd_id],
                "palIds": pal_ids
            })

        # Trigger PPA creation.
        for ppa_creation_request in ppa_creation_requests:
            self.assertPpaCreationFailure(ppa_creation_request)

        # Step 3: Create PAL database with a PAL record containing the PAL ID 'P'.
        pal_database = DatabaseServer('PAL Database',
                                      config['palDatabaseConfig']['hostName'],
                                      config['palDatabaseConfig']['port'])

        # Start PAL database server.
        pal_database.start()

        # Set file path.
        pal_database.setFileToServe(config['palDatabaseConfig']['fileUrl'],
                                    config['palDatabaseConfig']['filePath'])

        # Inject the PAL database URL into the SAS UUT.
        self._sas_admin.InjectDatabaseUrl({
            'type':
            'PAL',
            'url':
            pal_database.getBaseUrl() + config['palDatabaseConfig']['fileUrl']
        })

        # Step 4: Admin Test Harness triggers CPAS.
        self.TriggerDailyActivitiesImmediatelyAndWaitUntilComplete()

        # Step 5: Request creation of PPA(s) again
        for ppa_creation_request in ppa_creation_requests:
            ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
                ppa_creation_request)
            logging.debug('ppa_id received from SAS UUT:%s', ppa_id)
Exemple #22
0
    def __init__(self, conf = {}, templateEnv = None):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))

        else:
            self.conf = conf
        self.dao = Dao(self.conf)

        if templateEnv is None:
            self.templateEnv = Environment(loader=PackageLoader('jnpr.openclos', ztpTemplateLocation))
    def test_WINNF_FT_S_PCR_7(self, config_filename):
        """Overlapping PPA Boundaries.

    Checks SAS UUT shall doesnt create PPA zone within the service area.
    Checks SAS UUT shall confirm a valid PPA boundary claimed by the PAL holder,
    composed of one or more adjacent Census Tracts was overlapped by another
    PPA zone.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Load the test_WINNF_FT_S_PCR_1 config. All other inputs must be identical
        # to those used in the corresponding configuration of PCR.1.
        pcr_1_test_config = loadConfig(config['configPCR_1'])

        # Inject the PAL records.
        for pal_record in pcr_1_test_config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Inject the overlap ppa zone into SAS UUT.
        zone_id = self._sas_admin.InjectZoneData(
            {'record': config['overlapPpaRecord']})
        self.assertTrue(zone_id)

        # Register devices and check the response.
        cbsd_ids = self.assertRegistered(
            pcr_1_test_config['registrationRequests'],
            pcr_1_test_config['conditionalRegistrationData'])

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [
            record['palId'] for record in pcr_1_test_config['palRecords']
        ]

        # Create PPA creation request with device which is already part of
        # existing PPA zone.
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT and check SAS UUT should not create PPA boundary
        # claimed by PAL holder was overlapped by PPA zone.
        self.assertPpaCreationFailure(ppa_creation_request)
Exemple #24
0
    def __init__(self, deviceId, conf = {}, daoClass = Dao):
        global logger
        if any(conf) == False:
            self._conf = util.loadConfig(appName = moduleName)
        else:
            self._conf = conf
        logger = logging.getLogger(moduleName)

        self.daoClass = daoClass
        self.pod = None
        self.deviceId = deviceId
        self.deviceConnectionHandle = None
Exemple #25
0
  def test_WINNF_FT_S_SCS_16(self, config_filename):
    """Certificate signed by a revoked CA presented during registration.

    Checks that SAS UUT response with fatal alert message.
    """
    # Read the configuration
    config = loadConfig(config_filename)

    # Tls handshake fails since CA is revoked
    self.assertTlsHandshakeFailureOrHttp403(client_cert=config['clientCert'],
                                            client_key=config['clientKey'])
    logging.info("TLS handshake failed as the CA certificate has been revoked")
Exemple #26
0
  def test_WINNF_FT_S_SCS_11(self, config_filename):
    """Blacklisted certificate presented during registration.

    Checks that SAS UUT response with fatal alert message.
    """
    # Read the configuration
    config = loadConfig(config_filename)

    # Tls handshake fails or http 403 response
    self.assertTlsHandshakeFailureOrHttp403(client_cert=config['clientCert'],
                                            client_key=config['clientKey'])
    logging.info("TLS handshake failed as the client certificate has blacklisted")
Exemple #27
0
    def test_WINNF_FT_S_SSS_17(self, config_filename):
        """Unknown SAS attempts to establish a TLS session.
    """
        config = loadConfig(config_filename)

        # Reset the SAS UUT
        self.SasReset()

        # Attempt TLS handshake without injecting peer SAS info and verify it fails
        self.assertTlsHandshakeFailureOrHttp403(client_cert=config['sasCert'],
                                                client_key=config['sasKey'],
                                                is_sas=True)
Exemple #28
0
    def __init__(self, conf = {}, daoClass = Dao):
        global logger
        if any(conf) == False:
            self._conf = util.loadConfig(appName = moduleName)
        else:
            self._conf = conf

        logger = logging.getLogger(moduleName)
        self._dao = daoClass.getInstance()

        self._templateEnv = Environment(loader=PackageLoader('jnpr.openclos', junosTemplateLocation))
        self._templateEnv.keep_trailing_newline = True
        self.isZtpStaged = util.isZtpStaged(self._conf)
Exemple #29
0
    def __init__(self, conf={}, templateEnv=None):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(
                logging.getLevelName(self.conf['logLevel'][moduleName]))

        else:
            self.conf = conf
        self.dao = Dao(self.conf)

        if templateEnv is None:
            self.templateEnv = Environment(
                loader=PackageLoader('jnpr.openclos', ztpTemplateLocation))
Exemple #30
0
    def __init__(self, conf = {}, templateEnv = None, daoClass = Dao):
        global logger
        if any(conf) == False:
            self.__conf = util.loadConfig(appName = moduleName)
        else:
            self.__conf = conf

        logger = logging.getLogger(moduleName)
        self._dao = daoClass.getInstance()

        if templateEnv is None:
            self.templateEnv = Environment(loader=PackageLoader('jnpr.openclos', ztpTemplateLocation))
            self.templateEnv.lstrip_blocks = True
            self.templateEnv.trim_blocks = True
    def test_WINNF_FT_S_PCR_6(self, config_filename):
        """Unsuccessful PPA boundary Claimed by PAL Holder Not contained within Maximum PPA Boundary.

    SAS UUT shall reject a PPA boundary claimed by the PAL holder,
    that is not fully contained within the maximum PPA boundary created by SAS UUT.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Load the test_WINNF_FT_S_PCR_1 config. All other inputs must be identical
        # to those used in the corresponding configuration of PCR.1.
        pcr_1_test_config = loadConfig(config['configPCR_1'])

        # Inject the PAL records.
        for pal_record in pcr_1_test_config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Register devices and  check response.
        cbsd_ids = self.assertRegistered(
            pcr_1_test_config['registrationRequests'],
            pcr_1_test_config['conditionalRegistrationData'])

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [
            record['palId'] for record in pcr_1_test_config['palRecords']
        ]

        # Create PPA creation request with user claimed ppa contour.
        ppa_creation_request = {
            "cbsdIds": cbsd_ids,
            "palIds": pal_ids,
            "providedContour": config['userClaimedPpaContour']
        }

        # Trigger PPA Creation to SAS UUT.
        self.assertPpaCreationFailure(ppa_creation_request)
Exemple #32
0
    def test_WINNF_FT_S_SSS_12(self, config_filename):
        """Expired certificate presented by SAS Test Harness.

    Checks that SAS UUT response with fatal alert message.
    """
        self.SasReset()
        config = loadConfig(config_filename)
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({
            'certificateHash': certificate_hash,
            'url': SAS_TEST_HARNESS_URL
        })
        self.assertTlsHandshakeFailureOrHttp403(client_cert=config['sasCert'],
                                                client_key=config['sasKey'],
                                                is_sas=True)
    def test_WINNF_FT_S_SSS_18(self, config_filename):
        """Security requirement for Full Activity Dump message Request
    """
        config = loadConfig(config_filename)

        # Reset the SAS UUT
        self.SasReset()

        # Notify SAS UUT about peer SAS
        certificate_hash = getCertificateFingerprint(
            config['validCertKeyPair']['cert'])
        self._sas_admin.InjectPeerSas({'certificateHash': certificate_hash,\
                                         'url': SAS_TEST_HARNESS_URL })
        # Load a Device
        device_a = json.load(
            open(os.path.join('testcases', 'testdata', 'device_a.json')))

        # Load grant request
        grant_a = json.load(
            open(os.path.join('testcases', 'testdata', 'grant_0.json')))
        cbsd_ids, grant_ids = self.assertRegisteredAndGranted([device_a],
                                                              [grant_a])

        # Initiate Full Activity Dump with valid cert, key pair
        fadResponse =  self.TriggerFullActivityDumpAndWaitUntilComplete(config['validCertKeyPair']['cert'], \
                                                                        config['validCertKeyPair']['key'])

        self.assertContainsRequiredFields("FullActivityDump.schema.json",
                                          fadResponse)
        url = fadResponse['files'][0]['url']

        # Attempting FAD record download with different invalid cert,key pair
        try:
            # This uses the same base_url as GetFullActivityDump().
            self.assertTlsHandshakeFailure(
                self._sas.sas_sas_active_base_url,
                client_cert=config['invalidCertKeyPair']['cert'],
                client_key=config['invalidCertKeyPair']['key'])
        except AssertionError as e:
            try:
                self._sas.DownloadFile(url,config['invalidCertKeyPair']['cert'], \
                                                        config['invalidCertKeyPair']['key'])
            except HTTPError as e:
                self.assertEqual(e.error_code, 403)
            else:
                self.fail("FAD record file download should have failed")
Exemple #34
0
    def __init__(self, conf = {}):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))
            global webServerRoot
            webServerRoot = self.conf['outputDir']
        else:
            self.conf = conf
        self.dao = Dao(self.conf)

        if 'httpServer' in self.conf and 'ipAddr' in self.conf['httpServer'] and self.conf['httpServer']['ipAddr'] is not None:
            self.host = self.conf['httpServer']['ipAddr']
        else:
            self.host = 'localhost'

        if 'httpServer' in self.conf and 'port' in self.conf['httpServer']:
            self.port = self.conf['httpServer']['port']
        else:
            self.port = 8080
        self.baseUrl = 'http://%s:%d' % (self.host, self.port)
Exemple #35
0
def prepare():
    parser = argparse.ArgumentParser(
        description='Print a config to a given hash and step'
    )
    parser.add_argument('--config',
            required = True,
            help = "Main configuration file")
    parser.add_argument('--hash',
            required = True,
            help = "Hash to be checked")
    parser.add_argument('--step',
            required = True,
            help = "Step to be checked")


    args = parser.parse_args()
    config = loadConfig(args.config)
    config["cHash"] = args.hash
    config["step"] = args.step
    return config
Exemple #36
0
    def test_WINNF_FT_S_SSS_13(self, config_filename):
        """ Disallowed TLS method attempted during registration.

        Checks that SAS UUT response with fatal alert message.
    """
        self.SasReset()

        # Load the configuration
        config = loadConfig(config_filename)

        # Read the fingerprint from the certificate
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({
            'certificateHash': certificate_hash,
            'url': SAS_TEST_HARNESS_URL
        })
        self.assertTlsHandshakeFailureOrHttp403(client_cert=config['sasCert'],
                                                client_key=config['sasKey'],
                                                ssl_method=SSL.TLSv1_1_METHOD,
                                                is_sas=True)
Exemple #37
0
  def test_WINNF_FT_S_REG_13(self, config_filename):
    """[Configurable] Unsupported SAS Protocol version."""

    config = loadConfig(config_filename)
    # Very light checking of the config file.
    self.assertValidConfig(
        config, {
            'fccIds': list,
            'userIds': list,
            'registrationRequests': list,
            'sasVersion': basestring
        })
    self.assertEqual(len(config['fccIds']), len(config['userIds']))
    self.assertEqual(len(config['fccIds']), len(config['registrationRequests']))
    # Use the (higher) SAS version set in the config file.
    self._sas.cbsd_sas_version  = config['sasVersion']

    # Whitelist N1 FCC ID.
    for fcc_id, max_eirp_dbm_per_10_mhz in config['fccIds']:
      self._sas_admin.InjectFccId({
          'fccId': fcc_id,
          'fccMaxEirp': max_eirp_dbm_per_10_mhz
      })

    # Whitelist N1 user ID.
    for user_id in config['userIds']:
      self._sas_admin.InjectUserId({'userId': user_id})

    # Register N1 CBSD.
    request = {'registrationRequest': config['registrationRequests']}
    try:
      responses = self._sas.Registration(request)['registrationResponse']
      # Check registration response.
      self.assertEqual(len(responses), len(config['registrationRequests']))
      for i in range(len(responses)):
        response = responses[i]
        logging.debug('Looking at response number %d', i)
        self.assertEqual(response['response']['responseCode'], 100)
    except HTTPError as e:
      # Allow HTTP status 404
      self.assertEqual(e.error_code, 404)
Exemple #38
0
    def test_WINNF_FT_S_SSS_14(self, config_filename):
        """ Invalid cipher suite presented during registration.

        Checks that SAS UUT response with fatal alert message.
    """
        self.SasReset()

        # Load the configuration
        config = loadConfig(config_filename)

        # Read the fingerprint from the certificate
        certificate_hash = getCertificateFingerprint(config['sasCert'])
        self._sas_admin.InjectPeerSas({
            'certificateHash': certificate_hash,
            'url': SAS_TEST_HARNESS_URL
        })
        self.assertTlsHandshakeFailureOrHttp403(
            client_cert=config['sasCert'],
            client_key=config['sasKey'],
            ciphers='ECDHE-RSA-AES256-GCM-SHA384',
            is_sas=True)
Exemple #39
0
    def __init__(self, conf={}):
        if any(conf) == False:
            self.conf = util.loadConfig()
            logger.setLevel(
                logging.getLevelName(self.conf['logLevel'][moduleName]))
            global webServerRoot
            webServerRoot = self.conf['outputDir']
        else:
            self.conf = conf
        self.dao = Dao(self.conf)

        if 'httpServer' in self.conf and 'ipAddr' in self.conf[
                'httpServer'] and self.conf['httpServer']['ipAddr'] is not None:
            self.host = self.conf['httpServer']['ipAddr']
        else:
            self.host = 'localhost'

        if 'httpServer' in self.conf and 'port' in self.conf['httpServer']:
            self.port = self.conf['httpServer']['port']
        else:
            self.port = 8080
        self.baseUrl = 'http://%s:%d' % (self.host, self.port)
Exemple #40
0
 def __init__(self):
     config = util.loadConfig()
     host = config['mongoDB']['host']
     port = config['mongoDB']['port']
     dbName = config['mongoDB']['dbName']
     objColName = config['mongoDB']['objCol']
     tagColName = config['mongoDB']['tagCol']
     rawColName = config['mongoDB']['rawCol']
     recgColName = config['mongoDB']['recgCol']
     toggleColName = config['mongoDB']['toggleCol']
     path = 'mongodb://' + host + ':' + str(port) + '/'
     self.client = pymongo.MongoClient(path)
     self.db = self.client[dbName]
     self.objCol = self.db[objColName]
     self.tagCol = self.db[tagColName]
     self.togCol = self.db[toggleColName]
     self.rawCol = self.db[rawColName]
     self.recgCol = self.db[recgColName]
     self.updateTag = True
     self.updateObj = True
     self.relatedTags = {}
     self.rawToInsert = []
     self.recgToInsert = []
Exemple #41
0
def main():
    """ Test CCNN. """

    # Load the config settings.
    cfg = util.loadConfig()

    # Total patches in the dataset.
    n_patches  = cfg.IMG_NUM * cfg.PATCH_PER_IMG

    # Build the test graph.
    test_graph = tf.Graph()
    with test_graph.as_default():

        # Determine the testing size.
        test_n_patches = n_patches * cfg.TEST_PCT
        test_n_epoch   = int(test_n_patches / cfg.BATCH_SIZE)

        # Pass through CCNN>
        test_patches, \
        test_densities = ccnn.inputs('test', 0, cfg)
        test_predict   = ccnn.inference(test_patches, is_train=True, cfg=cfg)
        test_loss      = ccnn.miscount(test_predict, test_densities, totals=True)

        # Train on the entire training set.
        test_saver = tf.train.Saver()
        with tf.Session() as test_sess:

            # Load the last training checkpoint.
            ckpt = tf.train.get_checkpoint_state(cfg.TRAIN_CHECKPOINT_DIR)
            if ckpt and ckpt.model_checkpoint_path:
                test_saver.restore(test_sess, ckpt.model_checkpoint_path)
            else:
                print 'No checkpoint found!'

            # SUPER IMPORTANT.
            # Start filename queue runner.
            coord = tf.train.Coordinator()
            threads = tf.train.start_queue_runners(coord=coord)

            print 'Running {} batches ({} patches with batch size {})'.format(
                  test_n_epoch, test_n_patches, cfg.BATCH_SIZE)

            # Run the testing session.
            num = test_n_epoch
            miscount = np.zeros([num * cfg.BATCH_SIZE, 3])
            for step in xrange(num):
                # Slice for batch totals.
                s = slice(step*cfg.BATCH_SIZE, (step+1)*cfg.BATCH_SIZE)
                miscount[s, 0], miscount[s, 1], miscount[s, 2] = \
                    np.squeeze(test_sess.run(test_loss))
                print 'Batch: {} -- True count: {:05.2f} Predict count: {:05.2f}'\
                    ' (err {:04.2f} - {:05.2f}%)'.format(
                        step, 
                        np.mean(miscount[s, 0]),
                        np.mean(miscount[s, 1]), 
                        np.mean(miscount[s, 2]),
                        (100. * np.mean(miscount[s, 2])/np.mean(miscount[s, 0]))
                    )

            # Finish off filename queue coordinator.
            coord.request_stop()
            coord.join(threads)

            # Display histogram.        
            path = os.path.join(cfg.TEST_CHECKPOINT_DIR, 'hist.png')
            dispColorHistogram(miscount, path)
Exemple #42
0
			# reorder tblNms according to tableOrder
			x = [d for d in configDict['applications'] if d['appName'] == app_name][0]
			if x and 'tableOrder' in x.keys():
				tableOrder = x['tableOrder']
				tn_in_db = []
				for tn in tableOrder:
					if tn in tblNms:
						tn_in_db.append(tn)
						tblNms.remove(tn)
				tblNms = tn_in_db + tblNms

			tblTags= ["#%s"%tblNm for tblNm in tblNms]

			# Iterate over individual tables and retrieve the row data for display
			for tblNm in tblNms:
				rowcount = [row for row in c.execute("SELECT count(*) row_count FROM %s"%tblNm)][0][0]
				if rowcount < 500:
					rows = c.execute('select * from %s'%tblNm)
					# force ascii conversion for display
					colnames[tblNm] = [asciiDammit(description[0]) for description in c.description]
					dbTables[tblNm] = [[wpu.renderHtmlTableCell(x) for x in row] for row in rows]
			conn.close()

	return render_template('report.html', dbpaths=databases, run_id=run_id, tableNames=tblTags, filenames=filenames, filepaths=filepaths, imagetags=imagetags, dbTables=dbTables, colnames=colnames, app_name=app_name)

if __name__ == '__main__':
	# read in the configuration file, then run the server
	configDict, appDataDirDict = wpu.loadConfig(configFile = 'appconfig.json')
	app.run(debug=True, host='0.0.0.0', port=5757)
 def __init__(self, configuration_file, database_file='jonnyboards.db'):
   self.config = {}
   self.api_key, self.sensors = util.loadConfig(configuration_file)
   self.database = database.Database(database_file)
   self.ubidotsConfig()
Exemple #44
0
#!/usr/bin/env python3
"""
main loop starter for the ftpusbwatch program
"""
import os,sys,subprocess,time
os.chdir(os.path.dirname(__file__)) # ensure correct working direcory
try:
    import util,usbwait
    util.ntpTimeWait()

    config=util.loadConfig("config.json")
    log=util.initLogger(config)
except KeyboardInterrupt:
    raise
except Exception as e:
    """ if all else fails, do a git pull, hoping that will fix it """
    import traceback
    traceback.print_exc()
    util.waitForNetwork(timeout=None)
    gitlog = subprocess.check_output("git pull -f",shell=True).decode('utf-8').strip()
    subprocess.call("sync")
    print(gitlog)
    if gitlog == "Already up-to-date.":
        print("Could not start. Waiting and git-pulling")
        time.sleep(3600)
    subprocess.Popen("./main.py",shell=True)
    sys.exit(0)

try:
    log.info("boot|Waiting for network and updating")
    util.waitForNetwork(timeout=None)