Still Alive

My work life has been very distracting these past few months. I’m not quite out of the woods yet, but things should calm down a bit over the next few weeks, which should give me a chance to have some fun here again.

My apologies to folks reporting bugs or asking for advice. Your pleas are not lost on me, and I’ll make a point to fix the known bugs, and generally try to be a wee bit more helpful.

As much as it itches me, I’ll try hard not to start some new project yet, at least not until I feel better about the state of the existing stuff.

Anyway, here’s my tentative TODO list for now:

  • isSigned() chokes on a certificate served for www.openssl.org. That’s probably a clue my ASN-1 parsing sucks. I have an incomplete but potentially much better parsing method for ASN-1 (based on *gasp* actually reading a spec), so that might be the way to go there.
  • There’s something rotten in my BigInteger implementation, which seems to result in RSA key lengths being occasionally off.
  • Fix some TLS bugs (Andy’s parsing bugs, at least)
  • Implement some missing bits of TLS (to at least get https://api.del.icio.us/v1/tags/get to load.)
  • Check RSAKeyTest::testPem2(), since it might be broken.
  • Update the Eval library with a recent tamarin dump, and fix the newline problem in the test app.

If I’m missing something in that list, feel free to remind me.

Explore posts in the same categories: sadness

11 Comments on “Still Alive”

  1. Gabe Says:

    In order to handle wild cards in certificate names need the following patch below. This makes it so *.s3.amazonaws.com cert works.

    TLSEngine: line 691, instead of ==, do regex.

    var escaped:String = regexEscape(firstCert.getCommonName());
    var reg:String = escaped.replace(/\\\*/g, “[^.]+”)
    if (new RegExp(reg).exec(_otherIdentity)) {

    The function to escape regular expression characters:

    // Regexp.escape(’\\*?{}.’) #=> \\\\\*\?\{\}\.
    private function regexEscape(s:String):String {
    return s.replace(/([\\*?{}.])/g, “\\$1″);
    }

    And the *.s3.amazonaws.com becomes: [^.]+\.s3\.amazonaws\.com

  2. Remi Frenay Says:

    Hi Henri,

    I’ve been using your PDML code and I think it’s a very useful project.
    At this moment the your project has not been updated for 4 years, so I
    guess your busy with other things.
    If you want I can help you with putting new life into this project. I
    can help you with : php code, documentation, forum.

    ps: Sorry that I’m using your blog to post you about this but the email adres on sourceforge doesn’t work anymore.

    Regards,
    Remi Frenay

  3. Sergejack Says:

    The zip file supposed to contain the SWC file actually contain a XML and a SWF file.
    I’m quite new to Flex so pardon my ignorance if those files are usable as a library, but isn’t it a mishandling?

  4. Jarosia Says:

    in eval is it possible to import classes, i.e Dictionary?

  5. Thijs Triemstra Says:

    Hi, I see the downloads page doesn’t provide any MD5 sigs for the released packages. Any reason? Or does it not make sense to provide those and am I just being paranoid? ;)

    Thanks for the great library!

  6. dachev Says:

    Didn’t find your email anywhere, so thought that as you moderate your comments it would be ok to post this here.

    I just spent the afternoon breaking appart your rsa key generation proceedure for real life usage. With this I managed to generate 2048 bit rsa keys real time in flash.

    To run this needs two of the protected methods of BigInteger to be declared public + some way to handle enterframe events.

    package system.math.rsa {

    import system.utils.StageEvents;

    import flash.events.Event;
    import flash.utils.ByteArray;
    import flash.utils.getTimer;

    import com.hurlant.crypto.prng.Random;
    import com.hurlant.math.BigInteger;
    import com.hurlant.crypto.rsa.RSAKey;

    import com.hurlant.math.bi_internal;

    // A class aimed at spreading the calculation effort
    // for generating an rsa key over multiple frames.

    public class RSAKeyGenerator {

    private const MAXTIME : int = 25; // doesn’t work all that well though; will slow down the framerate quite a little.
    private const T : int = 20; // 1-.5^T certainty of numbers tested being prime.

    // callback - call to provide generated key.
    // B - bit length of the key.
    // E - public exponent. hex WITHOUT innitial ‘0x’.

    public static function beginGeneration (B:uint, E:String, callback : Function) : void {
    new RSAKeyGenerator (B, E, callback);
    }

    private var callback : Function;

    public function RSAKeyGenerator (_B:uint, _E:String, _callback : Function) {
    B = _B;
    E = _E;
    callback = _callback;

    /////////////////////

    rng = new Random ();
    qs = B>>1;
    key = new RSAKey(null,0,null);
    key.e = parseInt(E, 16);
    ee = new BigInteger(E, 16);

    /////////////////////

    StageEvents.addWeakListener (this, Event.ENTER_FRAME, advance);
    advance ();
    }

    public function ready () : void {

    callback (key);

    E = null;
    callback = null;
    rng = null;
    key = null;
    ee = null;
    }

    ////

    private var time : int;

    ////

    private var B : int;
    private var E : String;

    ////

    private var step : int = 0;

    ////

    private var rng : Random;
    private var qs : uint;
    private var key : RSAKey;
    private var ee : BigInteger;

    ////

    private var pmode : Boolean = false;
    private var pobj : BigInteger;
    private var bits : int;

    public function advance (enterframe : Event = null) : void {

    time = getTimer ();

    if (!key) {
    StageEvents.removeWeakListener (this, Event.ENTER_FRAME);
    return;
    }
    if (pmode) {
    advancePrimify ();
    return;
    }

    for (;;) {

    if (step MAXTIME)
    return;
    }
    }
    step = 10;
    break;
    }

    if (getTimer () - time > MAXTIME)
    return;

    if (step MAXTIME)
    return;
    }
    }
    step = 20;
    break;
    }

    if (getTimer () - time > MAXTIME)
    return;

    trace (”++ p :\n” + key.p);
    trace (”++ q :\n” + key.q);

    if (key.p.compareTo(key.q) MAXTIME)
    return;
    }
    trace (”Success !”);
    ready ();
    }

    public function bigRandom(_bits:int) : Boolean {
    pobj = null;
    bits = _bits;

    if (bits>3));
    x.position = 0;
    pobj = new BigInteger(x);

    pmode = true;
    primify ();

    return !pmode;
    }

    public function primify () :void {

    if (!pobj.testBit(bits-1)) { // force MSB set
    pobj.bitwiseTo(BigInteger.ONE.shiftLeft(bits-1), op_or, pobj);
    }
    if (pobj.bi_internal::isEven()) {
    pobj.bi_internal::dAddOffset(1,0); // force odd
    }
    advancePrimify ();
    }

    public function advancePrimify () : void {

    var probablePrime : Boolean = isProbablePrime (T);
    if (ppprogress) return;

    while (!probablePrime) { // t = 1;
    pobj.bi_internal::dAddOffset (2, 0);

    while (pobj.bitLength () > bits)
    pobj.bi_internal::subTo (BigInteger.ONE.shiftLeft (bits-1), pobj);

    if (getTimer () - time > MAXTIME)
    return;

    probablePrime = isProbablePrime (T);
    if (ppprogress) return;
    }
    pmode = false;
    }

    private function op_or(x:int, y:int):int {return x|y;}

    ////////////////////////

    public const lowprimes:Array = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509];
    public const lplim:int = (1= 1-.5^t
    *
    */

    var ppprogress : Boolean = false;

    public function isProbablePrime(t:int):Boolean {

    if (ppprogress) //////////////////////////////////////////////////////
    return advanceMillerRabin ();

    var i:int;
    x = pobj.abs();

    if (x.t == 1 && x.bi_internal::a[0]>1;
    if (t>lowprimes.length) {
    t = lowprimes.length;
    }
    a = new BigInteger ();

    return advanceMillerRabin ();
    }

    private function advanceMillerRabin () : Boolean {

    for (i=i;i MAXTIME) {
    ++i;
    return false;
    }
    }

    endMillerRabin ();
    return true;
    }

    private function endMillerRabin () : void {
    n1 = null;
    a = null;
    r = null;
    x = null;
    ppprogress = false; ////////////////////////////////////////////////////
    }

    //*/
    }
    }

  7. Stephen Says:

    I’m trying to use dispose and in IVMode.as line 63, there is a reference to iv and not lastIV, which I suspect is a bug. That should probably be fixed in the next release.

  8. Ben Says:

    I’m looking into a way to generate a dynamic proxy of an arbitrary interface definition in AS3. Because it is not possible to dynamically type cast a dynamically constructed object to an interface in AS3, I though it may be possible to use the Eval library to compile generated code at runtime and load it into the interpreter. Looking through the source it seems that the “implements INTERFACE” tokens get lexed but the parsing of this is not yet implemented. I see you have some mild plans to update the library sometime soon. Would this update encompass being able to generate dynamic instances of interfaces?

  9. ken larkin Says:

    Shouldn’t the verify function return a bool to say whether the signature is valid. How do I use the verify function to check using a public key wheather a string was actually signed by a particular private key.

    Please help,
    Thanks,
    Ken

  10. Ben Says:

    I’m trying the TLSEngine out against a local installation of Stunnel (4.24) with a self-signed cert.

    The handshake breaks down in the loadCertificates function because the firstCert is the parent cert from the store, so a “Cannot verify certificate” error is thrown.

    When I run the TLSTest against the 5 publicly available servers listed there, everything is fine.

    The main difference seems to be that the cert chains are longer in the TLSTest example than when I run it against the Stunnel socket.

    It is possible that my Stunnel cert is wrong?

    Ben

  11. Anonymous Says:

Comment: