def METHOD_NAME(self, rule):
    if os.path.exists(rule["key"]) and os.path.exists(rule["crt"]):
        return RET_OK
    for k in ("key", "crt"):
        d = os.path.dirname(rule[k])
        if not os.path.isdir(d):
            if os.path.exists(d):
                perror("%s exists but is not a directory" % d)
                return RET_ERR
            else:
                pinfo("mkdir -p %s" %d)
                os.makedirs(d)
    l = [""]
    for k in ["C", "ST", "L", "O", "OU", "CN", "emailAddress"]:
        l.append(k+"="+rule[k])
    if "alt_names" in rule and len(rule["alt_names"]) > 0:
        dns = []
        for i, d in enumerate(rule["alt_names"]):
            dns.append("DNS.%d=%s" % (i+1, d["DNS"]))
        l.append("subjectAltName="+",".join(dns))
    l.append("")
    cmd = ["openssl", "req", "-x509", "-nodes",
           "-newkey", "rsa:%d" % rule["bits"],
           "-keyout", rule["key"],
           "-out", rule["crt"],
           "-days", "XXX",
           "-subj", "%s" % "/".join(l)]
    pinfo(" ".join(cmd))
    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()
    if p.returncode != 0:
        if len(out) > 0:
            pinfo(out)
        if len(err) > 0:
            perror(err) 
        return RET_ERR
    return RET_OK