pike.git / lib / modules / Standards.pmod / X509.pmod

version» Context lines:

pike.git/lib/modules/Standards.pmod/X509.pmod:268:   }      class Verifier {    constant type = "none";    int(0..1) verify(object,string,string);    this_program init(string key);       optional Crypto.RSA rsa; // Ugly   }    - protected class rsa_verifier + protected class RSAVerifier   {    inherit Verifier;    Crypto.RSA rsa;       constant type = "rsa";       //! -  this_program init(string key) { +  protected void create(string key) {    rsa = RSA.parse_public_key(key); -  return rsa && this; +     }       //!    int(0..1) verify(Sequence algorithm, string msg, string signature)    {    if (algorithm->get_der() == rsa_md5_algorithm->get_der())    return rsa_verify_digest(rsa, Identifiers.md5_id,    Crypto.MD5.hash(msg),    signature);    if (algorithm->get_der() == rsa_sha1_algorithm->get_der())
pike.git/lib/modules/Standards.pmod/X509.pmod:340:    return 0;    Sequence seq = [object(Sequence)]keyinfo[0];    String str = [object(String)]keyinfo[1];       if (seq[0]->get_der() == Identifiers.rsa_id->get_der())    {    if ( (sizeof(seq) != 2)    || (seq[1]->get_der() != Null()->get_der()) )    return 0;    -  return rsa_verifier()->init(str->value); +  return RSAVerifier(str->value);    }       if(seq[0]->get_der() == Identifiers.dsa_sha_id->get_der())    {    /* FIXME: Not implemented */    return 0;    }   }      //! Represents a TBSCertificate.
pike.git/lib/modules/Standards.pmod/X509.pmod:411:    "issuer" : issuer,    "subject" : subject,    ]);    break;    default:    error("Can't case %O to %O\n", this_program, to);    break;    }    }    +  protected string get_id(object asn) +  { +  foreach(.PKCS.Identifiers.name_ids; string name; object id) +  if( asn==id ) return name; +  return (array(string))asn->id*"."; +  } +  +  protected array fmt_asn1(object asn) +  { +  array i = ({}); +  mapping m = ([]); +  +  foreach(asn->elements;; object o) +  { +  o = o[0]; +  string id = get_id(o[0]); +  i += ({ ([ id : o[1]->value]) }); +  if( m ) +  { +  if(m[id]) +  { +  m = 0; +  continue; +  } +  m[id] = o[1]->value; +  } +  } +  +  return m || i; +  } +     protected string _sprintf(int t)    { -  return t=='O' && sprintf("%O(%O)", this_program, cast("mapping")); +  if( t!='O' ) return UNDEFINED; +  mapping m = cast("mapping"); +  catch { +  m->issuer = fmt_asn1(m->issuer); +  m->subject = fmt_asn1(m->subject); +  }; +  return sprintf("%O(%O)", this_program, m);    }       //! Populates the object from a certificate decoded into an ASN.1    //! Object. Returns the object on success, otherwise @expr{0@}. You    //! probably want to call @[decode_certificate] or even    //! @[verify_certificate].    this_program init(Object asn1)    {    der = asn1->get_der();    if (asn1->type_name != "SEQUENCE")