Roxen.git / server / config_interface / actions / make_selfsigned_dsa.pike

version» Context lines:

Roxen.git/server/config_interface/actions/make_selfsigned_dsa.pike:1:   /* -  * $Id: make_selfsigned_dsa.pike,v 1.11 2008/08/15 12:33:54 mast Exp $ +  * $Id$    */      #if constant (Nettle)      inherit "ssl_common.pike";   inherit "wizard";   #include <roxen.h>   //<locale-token project="admin_tasks"> LOCALE </locale-token>   #define LOCALE(X,Y) _STR_LOCALE("admin_tasks",X,Y)   
Roxen.git/server/config_interface/actions/make_selfsigned_dsa.pike:32:    "<b>" + LOCALE(94, "Key size") + "</b><br />"    "<var name='key_size' type='select' default='1024' "    "choices='512,576,640,704,768,832,896,960,1024'/><br />\n"    "<blockquote><p>"+generic_key_size_string+"</p></blockquote>"    + key_file_form("my_dsa_key.pem");   }      mixed verify_0(object id, object mc)   {    int key_size = (int) id->variables->key_size; -  if ( (key_size < 512) || (key_size > 1024) || (key_size % 64)) +  if ( !(<512, 576, 640, 704, 768, 832, 896, 960, 1024 >)[key_size])    {    id->variables->_error =    LOCALE(135, "Invalid key size.");    return 1;    }    object file;    object privs = Privs("Storing private DSA key.");    if (!(file = lopen(id->variables->key_file, "wct", 0600)))    {    id->variables->_error =    "Could not open file: "    + (strerror(errno()) || (string) errno())    + ".";    privs = 0;    return 1;    }       privs = 0;       Crypto.DSA dsa = Crypto.DSA(); -  dsa->use_random(Crypto.Random.random_string); -  dsa->generate_parameters(key_size); -  dsa->generate_key(); +  dsa->set_random(Crypto.Random.random_string); +  dsa->generate_key(key_size, 160);       string key = Tools.PEM.simple_build_pem    ("DSA PRIVATE KEY",    Standards.PKCS.DSA.private_key(dsa));    WERROR(key);       if (strlen(key) != file->write(key))    {    id->variables->_error =    "Write failed: "
Roxen.git/server/config_interface/actions/make_selfsigned_dsa.pike:131:    object part = msg->parts["DSA PRIVATE KEY"];       if (!part)    return "<font color='red'>Key file not formatted properly.\n</font>";       object dsa = DSA.parse_private_key(part->decoded_body());       if (!dsa)    return "<font color='red'>Invalid key.\n</font>";    -  dsa->use_random(Crypto.Random.random_string); +  dsa->set_random(Crypto.Random.random_string);       mapping attrs = ([]);    string attr;       /* Remove initial and trailing whitespace, and ignore    * empty attributes. */    foreach( ({ "countryName", "stateOrProvinceName",    "localityName", "organizationName",    "organizationUnitName", "commonName" }), attr)    {    if (id->variables[attr]) {    attrs[attr] = global.String.trim_whites (id->variables[attr]);    if (attrs[attr] == "") m_delete (attrs, attr);    }    }       array name = ({ });    if (attrs->countryName) -  name += ({(["countryName": asn1_printable_string (attrs->countryName)])}); +  name += ({([ "countryName": PrintableString(attrs->countryName) ])});    foreach( ({ "stateOrProvinceName",    "localityName", "organizationName",    "organizationUnitName", "commonName" }), attr)    {    if (attrs[attr]) -  /* UTF8String is the recommended type. But it seems that -  * netscape can't handle that. So when PrintableString doesn't -  * suffice, we use latin1 but call it TeletexString (since at -  * least netscape expects things that way). */ -  name += ({ ([ attr : (asn1_printable_valid (attrs[attr]) ? -  asn1_printable_string : -  asn1_broken_teletex_string) (attrs[attr]) ]) }); +  name += ({ ([ attr : UTF8String(attrs[attr]) ]) });    }       /* Create a plain X.509 v1 certificate, without any extensions */    string cert = Tools.X509.make_selfsigned_dsa_certificate    (dsa, 24 * 3600 * (int) id->variables->ttl, name);       string res=("<font size='+2'>"+LOCALE(133,"This is your Certificate.")+    "</font>"    "<textarea name='certificate' cols='80' rows='12'>");   
Roxen.git/server/config_interface/actions/make_selfsigned_dsa.pike:212:    + (strerror(file->errno()) || (string) file->errno())    + ".";    return 1;    }    }    return 0;   }      mixed wizard_done(object id, object mc)   { +  roxen.background_run(0, roxen.scan_certs);    return http_string_answer( sprintf("<p>"+LOCALE(131,"Wrote %d bytes to %s.")+    "</p>\n<p><cf-ok/></p>\n",    strlen(id->variables->certificate),    combine_path(getcwd(), "../local",    id->variables->cert_file)) );   }         mixed parse( RequestID id ) { return wizard_for(id,0); }         #endif /* constant (Nettle) */