pike.git / lib / modules / Standards.pmod / PKCS.pmod / Certificate.pmod

version» Context lines:

pike.git/lib/modules/Standards.pmod/PKCS.pmod/Certificate.pmod:119:    exponent2 INTEGER, -- d mod (q-1)    coefficient INTEGER -- (inverse of q) mod p }      Version ::= INTEGER      */      import Standards.ASN1.Types;   import .Identifiers;    + protected object X509 = master()->resolv("Standards.X509"); +    class AttributeValueAssertion   {    inherit Sequence;    void create(mapping(string:object) types,    string type,    object value)    {    if (!objectp(types[type]))    error("Unknown attribute type '%s':%O\n", type, types[type]);    ::create( ({ types[type], value }) );
pike.git/lib/modules/Standards.pmod/PKCS.pmod/Certificate.pmod:147:    void create(mapping(string:object) types, mapping(string:object) pairs)    {    ::create(map(indices(pairs),    lambda(string s, mapping m, mapping t) {    return AttributeValueAssertion(t, s, m[s]);    },    pairs, types));    }   }    + //!   variant Sequence build_distinguished_name(mapping args)   {    // Turn mapping into array of pairs    array a = ({});    foreach(sort(indices(args)), string name)    a += ({ ([name : args[name]]) });       return build_distinguished_name(a);   }   
pike.git/lib/modules/Standards.pmod/PKCS.pmod/Certificate.pmod:200:    break;    }    }       return Sequence(map(args, lambda(mapping rdn) {    return attribute_set(    .Identifiers.at_ids, rdn);    } ));   }    - Sequence decode_pem_certificate(string cert) - { -  - } -  - //! Return the certificate issuer RDN from a certificate string. + //! Perform the reverse operation of @[build_distinguished_name()].   //! - //! @param cert - //! A string containing an X509 certificate. - //! - //! Note that the certificate normally must be decoded using - //! @[MIME.decode_base64]. - //! - //! @returns - //! An Standards.ASN1.Sequence object containing the certificate issuer - //! Distinguished Name (DN). - Sequence get_certificate_issuer(string cert) + //! @seealso + //! @[build_distinguished_name()] + array(mapping(string(7bit):string)) decode_distinguished_name(Sequence dn)   { -  return Standards.ASN1.Decode.simple_der_decode(cert)[0][3]; +  array(mapping(string(7bit):string)) ret = +  allocate(sizeof(dn->elements), aggregate_mapping)(); +  foreach(dn->elements; int i; Set attr) { +  foreach(attr->elements, Sequence val) { +  string(7bit) name = reverse_at_ids[val[0]]; +  if (!name) { +  // Unknown identifier. +  name = ((array(string))val[0]->id) * ".";    } -  +  ret[i][name] = val[1]->value; +  } +  } +  return ret; + }      //! Converts an RDN (relative distinguished name) Seqeunce object to a   //! human readable string in X500 format.   //! - //! @param cert - //! A string containing an X509 certificate. - //! - //! Note that the certificate normally must be decoded using - //! @[MIME.decode_base64]. - //! +    //! @returns   //! A string containing the certificate issuer   //! Distinguished Name (DN) in human readable X500 format.   //!   //! @note   //! We don't currently handle attributes with multiple values, not   //! all attribute types are understood.   string get_dn_string(Sequence dnsequence)   {    string dn="";
pike.git/lib/modules/Standards.pmod/PKCS.pmod/Certificate.pmod:271:    v=v[0..(sizeof(v)-2)] + "\\ ";       rdns += ({ (t + "=" + v) });    }    }       dn = rdns * ",";    return dn;   }    - //! Return the certificate subject RDN from a certificate string. - //! - //! @param cert - //! A string containing an X509 certificate. - //! - //! Note that the certificate normally must be decoded using - //! @[MIME.decode_base64]. - //! - //! @returns - //! An Standards.ASN1.Sequence object containing the certificate subject - //! Distinguished Name (DN). - Sequence get_certificate_subject(string cert) - { -  return Standards.ASN1.Decode.simple_der_decode(cert)[0][5]; - } -  +    class Attribute   {    inherit Sequence;    -  void create(mapping(string:object) types, string type, +  protected void create(mapping(string:object) types, string type,    array(object) v)    {    if (!types[type])    error( "Unknown attribute type '%s'\n", type);    ::create( ({ types[type], Set(v) }) );    } -  +  protected variant void create(array(Object) elements) +  { +  if (sizeof(elements) != 2) +  error("Invalid attribute encoding.\n"); +  ::create(elements);    } -  + }      class Attributes   {    inherit Set;    -  void create(mapping(string:object) types, mapping(string:array(object)) m) +  protected void create(mapping(string:object) types, +  mapping(string:array(object)) m)    {    ::create(map(indices(m),    lambda(string field, mapping m, mapping t) {    return Attribute(t, field, m[field]);    }, m, types));    } -  +  protected variant void create(array(Object) elements) +  { +  ::create(map(elements, +  lambda(object e) { +  return Attribute(e->elements); +  }));    } -  + }