Ejemplo n.º 1
0
    def __init__(self, userProfileDir):
        """
        CertificateManager constructor.

        userProfileDir - directory in which this user's profile information is
        kept. The CM uses this directory to store the certificate repository.
        """

        self.userProfileDir = userProfileDir
        self.certRepoPath = os.path.join(userProfileDir, "certRepo")
        self.caDir = os.path.join(userProfileDir, "trustedCACerts")
        self.defaultIdentity = None

        self.useDefaultDN = None
        self.useCertFile = None
        self.useKeyFile = None
        
        self.proxyPath = self.GetProxyPath()

        # Do some initial sanity checking.
        # user profile directory needs to exist and be writable
        # system ca cert dir needs to exist and be readable
        #
        # TODO: these could vector a message through the user interface
        # to let the user know of the errors.

        if not os.path.isdir(self.userProfileDir) or \
           not os.access(self.userProfileDir, os.R_OK | os.W_OK):
            raise Exception("User profile directory %s does not exist or is not writable" \
                            % (self.userProfileDir))


        if not os.path.isdir(self.caDir):
            os.mkdir(self.caDir)

        # Configure the certificate mgr.

        # Attempt to initialize the certificate repository. First try
        # to initialize one without specifying the create option.

        try:
            self.certRepo = CertificateRepository.CertificateRepository(self.certRepoPath,
                                                                        create = 0)
            log.debug("Opened repository %s", self.certRepoPath)
        except CertificateRepository.RepoDoesNotExist:
            # We don't have a cert repo.
            # Initialize ourselves.

            self.InitializeRepository()
Ejemplo n.º 2
0
    def InitializeRepository(self):
        """
        Initiailize the cert repository as we don't already have one.

        We need to first create a new repository (by passing create=1
        to the constructor).

        """

        log.debug("initializing repository")

        try:
            self.certRepo = CertificateRepository.CertificateRepository(self.certRepoPath,
                                                                        create = 1)
        except CertificateRepository.RepoAlreadyExists:
            # We really shouldn't be here. Raise an exception.
            log.exception("repo already exists")
            raise Exception, "Received RepoAlreadyExists exception after we determined that it didn't actually exist"

        self.ImportCACertificates()