Пример #1
0
def get_username_from_cert(cert_string):
    try:
        gid = GID(string=cert_string)
        
        # extract the URN in the subjectAltName
        urn_str = gid.get_urn()
        
        logger.debug("URN: %s" % urn_str)
        
    except:
        logger.warn("Failed to get certificate from string.")
        logger.warn(traceback.format_exc())
        return cert_string
    
    try:
        urn = URN(urn=str(urn_str))
    except ValueError:
        return cert_string
    
    # check if this user is one of ours
    home_urn = get_user_urn(urn.getName())
    if home_urn == urn.urn_string():
        username = urn.getName()
    else:
        username = urn_to_username(urn.urn_string())
        
    logger.debug("Returning username %s" % username)
    
    return username
Пример #2
0
    def setUp(self):
        """
        Update settings, create DummyOMs and test models and login.
        """
        # add the test application
        self.settings_manager.set(
            OPENFLOW_OTHER_RESOURCES=(
                ("expedient.clearinghouse.resources", "Resource"),
            ),
            DEBUG_PROPAGATE_EXCEPTIONS=True,
        )
        self.su = User.objects.create_superuser(
            "superuser", "*****@*****.**", "password")
        self.test_user_password = "******"
        self.test_user = User.objects.create_user(
            "test_user", "*****@*****.**", self.test_user_password)
        give_permission_to("can_add_aggregate", Aggregate, self.test_user)
        give_permission_to("can_create_project", Project, self.test_user)
        
        for i in range(NUM_DUMMY_OMS):
            om = DummyOM.objects.create()
            om.populate_links(NUM_SWITCHES_PER_AGG, 
                              NUM_LINKS_PER_AGG/2)
            username = "******" % i
            password = "******"
            u = User.objects.create_user(username, "*****@*****.**", password)
    
            # Add the aggregate to the CH
            url = SCHEME + "://%s/dummyom/%s/xmlrpc/" % (HOST, om.id)
            
            proxy = PasswordXMLRPCServerProxy.objects.create(
                username=username, password=password,
                url=url, verify_certs=False,
            )
    
            # test availability
            if not proxy.is_available():
                raise Exception("Problem: Proxy not available")

            proxy.delete()
            
        # create user cert/keys
        self.user_urn = get_user_urn(self.test_user.username)
        self.user_cert, self.user_key = create_x509_cert(self.user_urn)
        
        # get slice creds
        self.slice_cred = geni_clearinghouse.CreateSlice(
            self.user_cert.save_to_string())
        self.slice_gid = credential.Credential(
            string=self.slice_cred).get_gid_object()
        
        # xmlrpc client
        self.rpc = xmlrpclib.ServerProxy(
            "http://testserver" + reverse("openflow_gapi"),
            transport=TestClientTransport(
                defaults={
                    "REMOTE_USER": self.user_cert.save_to_string(),
                    "SSL_CLIENT_CERT": self.user_cert.save_to_string(),
                },
            ),
        )
Пример #3
0
    def setUp(self):
        """
        Update settings, create DummyOMs and test models and login.
        """
        # add the test application
        self.settings_manager.set(
            OPENFLOW_OTHER_RESOURCES=(("expedient.clearinghouse.resources",
                                       "Resource"), ),
            DEBUG_PROPAGATE_EXCEPTIONS=True,
        )
        self.su = User.objects.create_superuser("superuser", "*****@*****.**",
                                                "password")
        self.test_user_password = "******"
        self.test_user = User.objects.create_user("test_user", "*****@*****.**",
                                                  self.test_user_password)
        give_permission_to("can_add_aggregate", Aggregate, self.test_user)
        give_permission_to("can_create_project", Project, self.test_user)

        for i in range(NUM_DUMMY_OMS):
            om = DummyOM.objects.create()
            om.populate_links(NUM_SWITCHES_PER_AGG, NUM_LINKS_PER_AGG / 2)
            username = "******" % i
            password = "******"
            u = User.objects.create_user(username, "*****@*****.**", password)

            # Add the aggregate to the CH
            url = SCHEME + "://%s/dummyom/%s/xmlrpc/" % (HOST, om.id)

            proxy = PasswordXMLRPCServerProxy.objects.create(
                username=username,
                password=password,
                url=url,
                verify_certs=False,
            )

            # test availability
            if not proxy.is_available():
                raise Exception("Problem: Proxy not available")

            proxy.delete()

        # create user cert/keys
        self.user_urn = get_user_urn(self.test_user.username)
        self.user_cert, self.user_key = create_x509_cert(self.user_urn)

        # get slice creds
        self.slice_cred = geni_clearinghouse.CreateSlice(
            self.user_cert.save_to_string())
        self.slice_gid = credential.Credential(
            string=self.slice_cred).get_gid_object()

        # xmlrpc client
        self.rpc = xmlrpclib.ServerProxy(
            "http://testserver" + reverse("openflow_gapi"),
            transport=TestClientTransport(defaults={
                "REMOTE_USER":
                self.user_cert.save_to_string(),
                "SSL_CLIENT_CERT":
                self.user_cert.save_to_string(),
            }, ),
        )