socrates_gui/static/js/spice-html5.js
/*----------------------------------------------------------------------------
**  Extract an RSA key from a memory buffer
**--------------------------------------------------------------------------*/
Extract an RSA key from a memory buffer
Extract an RSA key from a memory buffer
function create_rsa_from_mb(mb, at)
{
    var u8 = new Uint8Array(mb);
    var lenblock;
    var seq;
    var ba;
    var i;
    var ret;
    seq = find_sequence(u8, at);
    if (! seq)
        return null;
    at = seq[0];
    seq = find_sequence(u8, at);
    if (! seq)
        return null;
    at = seq[0] + seq[1];
    if (u8[at++] != 0x3)
    {
        console.log("Error: expecting bit string next.");
        return null;
    }
    lenblock = asn_get_length(u8, at);
    if (! lenblock)
        return null;
    at = lenblock[0];
    if (u8[at] != 0 && u8[at + 1] != 0x30)
    {
        console.log("Error: unexpected values in bit string.");
        return null;
    }
    seq = find_sequence(u8, at + 1);
    if (! seq)
        return null;
    at = seq[0];
    if (u8[at++] != 0x02)
    {
        console.log("Error: expecting integer n next.");
        return null;
    }
    lenblock = asn_get_length(u8, at);
    if (! lenblock)
        return null;
    at = lenblock[0];
    ba = new Array(lenblock[1]);
    for (i = 0; i < lenblock[1]; i++)
        ba[i] = u8[at + i];
    ret = new RSAKey();
    ret.n = new BigInteger(ba);
    at += lenblock[1];
    if (u8[at++] != 0x02)
    {
        console.log("Error: expecting integer e next.");
        return null;
    }
    lenblock = asn_get_length(u8, at);
    if (! lenblock)
        return null;
    at = lenblock[0];
    ret.e = u8[at++];
    for (i = 1; i < lenblock[1]; i++)
    {
        ret.e <<= 8;
        ret.e |= u8[at++];
    }
    return ret;
}
function create_rsa_from_mb ( mb , at ) { var u8 = new Uint8Array ( mb ) ; var lenblock ; var seq ; var ba ; var i ; var ret ; seq = find_sequence ( u8 , at ) ; if ( ! seq ) return null ; at = seq [ 0 ] ; seq = find_sequence ( u8 , at ) ; if ( ! seq ) return null ; at = seq [ 0 ] + seq [ 1 ] ; if ( u8 [ at ++ ] != 0x3 ) { console . log ( "Error: expecting bit string next." ) ; return null ; } lenblock = asn_get_length ( u8 , at ) ; if ( ! lenblock ) return null ; at = lenblock [ 0 ] ; if ( u8 [ at ] != 0 && u8 [ at + 1 ] != 0x30 ) { console . log ( "Error: unexpected values in bit string." ) ; return null ; } seq = find_sequence ( u8 , at + 1 ) ; if ( ! seq ) return null ; at = seq [ 0 ] ; if ( u8 [ at ++ ] != 0x02 ) { console . log ( "Error: expecting integer n next." ) ; return null ; } lenblock = asn_get_length ( u8 , at ) ; if ( ! lenblock ) return null ; at = lenblock [ 0 ] ; ba = new Array ( lenblock [ 1 ] ) ; for ( i = 0 ; i < lenblock [ 1 ] ; i ++ ) ba [ i ] = u8 [ at + i ] ; ret = new RSAKey ( ) ; ret . n = new BigInteger ( ba ) ; at += lenblock [ 1 ] ; if ( u8 [ at ++ ] != 0x02 ) { console . log ( "Error: expecting integer e next." ) ; return null ; } lenblock = asn_get_length ( u8 , at ) ; if ( ! lenblock ) return null ; at = lenblock [ 0 ] ; ret . e = u8 [ at ++ ] ; for ( i = 1 ; i < lenblock [ 1 ] ; i ++ ) { ret . e <<= 8 ; ret . e |= u8 [ at ++ ] ; } return ret ; }
Extract an RSA key from a memory buffer
Extract an RSA key from a memory buffer
/* We have a sequence which contains a sequence followed by a bit string */ /* Skip over the contained sequence */ /* Get the bit string, which is *itself* a sequence.  Having fun yet? */ /* Okay, now we have a sequence of two binary values, we hope. */