Example #1
0
    def loadObject(self, obj):
        # expect object to be a Sequence containing a certificate, 
        # but will accept a plain certificate too (for now)
        issuer, subject = getIssuerAndSubject(obj, 1)
        if issuer is None or subject is None:
            print "Warning: Unexpected SPKI object. Skipping."
            print sexp.pprint(obj.sexp())
            return

        sexp = obj.sexp().encode_canonical()
        if self.identity.has_key(sexp):
            print "Warning: Duplicate certificate ignored."
            return

        issuer = issuer.getPrincipal()
        subject = subject.getPrincipal()

        l = self.byIssuer.get(issuer, [])
        l.append(obj)
        self.byIssuer[issuer] = l

        # if the issuer is a name, then we will enter the certificate
        # in multiple slots. one for the full name, and one for the
        # base issuer.
        if isinstance(issuer, spki.FullyQualifiedName):
            prin = issuer.principal
            l = self.byIssuer.get(prin, [])
            l.append(obj)
            self.byIssuer[prin] = l

        l = self.bySubject.get(subject, [])
        l.append(obj)
        self.bySubject[subject] = l

        self.identity[sexp] = sexp
Example #2
0
    def delete(self, obj):
        sexp = obj.sexp().encode_canonical()
        if not self.identity.has_key(sexp):
            raise KeyError, "object not in database: %s" % str(obj)
        del self.identity[sexp]

        issuer, subject = getIssuerAndSubject(obj, 1)
        issuer = issuer.getPrincipal()
        subject = subject.getPrincipal()

        # these shouldn't raise exceptions if the identity dictionary
        # test succeeded 
        self.byIssuer[issuer].remove(obj)
        self.bySubject[subject].remove(obj)
Example #3
0
def getCertSubjectHash(cert, keystore):
    """Gets the hash of a certificate subject

    Args:
        cert: spki.Sequence

        keystore: KeyStore object

    Returns:
        spki.Hash
    """

    issuer, subject = spki.getIssuerAndSubject(cert)
    if subject.isName():
        names = subject.getPrincipal().names
        for name in names:
            try:
                #  Gets hash object for name then converts to base 64 string
                return parseKeyIdInput(name, keystore)
            except (ValueError, NameError):
                continue
        raise ValueError("Unbound spki name: %s" % name)
    else:
        return subject.getPrincipal()
Example #4
0
 def writeStorageHint(self, obj, io):
     issuer, subject = getIssuerAndSubject(obj)
     # XXX need to get rid of newlines in issuer and subject
     io.write("# %s\n# %s\n" % (stripNewlines(issuer.sexp()),
                                stripNewlines(subject.sexp())))