Spaces:
Running
Running
File size: 4,630 Bytes
8f3f8db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
/*
* This is a fake SSL plugin, actual authentication and crypto
* is handled by browser and SocketPlugin
*/
function SqueakSSL() {
"use strict";
return {
getModuleName: function() { return 'SqueakSSL (fake)'; },
interpreterProxy: null,
primHandler: null,
handleCounter: 0,
// Return codes from the core SSL functions
SQSSL_OK: 0,
SQSSL_NEED_MORE_DATA: -1,
SQSSL_INVALID_STATE: -2,
SQSSL_BUFFER_TOO_SMALL: -3,
SQSSL_INPUT_TOO_LARGE: -4,
SQSSL_GENERIC_ERROR: -5,
SQSSL_OUT_OF_MEMORY: -6,
// SqueakSSL getInt/setInt property IDs
SQSSL_PROP_VERSION: 0,
SQSSL_PROP_LOGLEVEL: 1,
SQSSL_PROP_SSLSTATE: 2,
SQSSL_PROP_CERTSTATE: 3,
// SqueakSSL getString/setString property IDs
SQSSL_PROP_PEERNAME: 0,
SQSSL_PROP_CERTNAME: 1,
SQSSL_PROP_SERVERNAME: 2,
setInterpreter: function(anInterpreter) {
this.interpreterProxy = anInterpreter;
this.primHandler = this.interpreterProxy.vm.primHandler;
return true;
},
primitiveCreate: function(argCount) {
var name = '{SqueakJS SSL #' + (++this.handleCounter) + '}';
var sqHandle = this.primHandler.makeStString(name);
sqHandle.handle = true;
this.interpreterProxy.popthenPush(argCount + 1, sqHandle);
return true;
},
primitiveConnect: function(argCount) {
if (argCount !== 5) return false;
this.interpreterProxy.popthenPush(argCount + 1, 0);
return true;
},
primitiveDestroy: function(argCount) {
if (argCount !== 1) return false;
this.interpreterProxy.popthenPush(argCount + 1, 1); // Non-zero if successful
return true;
},
primitiveGetIntProperty: function(argCount) {
if (argCount !== 2) return false;
var handle = this.interpreterProxy.stackObjectValue(1).handle;
if (handle === undefined) return false;
var propID = this.interpreterProxy.stackIntegerValue(0);
var res;
if (propID === this.SQSSL_PROP_CERTSTATE) {
res = this.SQSSL_OK; // Always valid
} else {
res = 0;
}
this.interpreterProxy.popthenPush(argCount + 1, res);
return true;
},
primitiveSetStringProperty: function(argCount) {
if (argCount !== 3) return false;
var handle = this.interpreterProxy.stackObjectValue(2).handle;
if (handle === undefined) return false;
// We don't actually care
// var propID = this.interpreterProxy.stackIntegerValue(1);
// var value = this.interpreterProxy.stackObjectValue(0);
this.interpreterProxy.pop(argCount);
return true;
},
primitiveGetStringProperty: function(argCount) {
if (argCount !== 2) return false;
var handle = this.interpreterProxy.stackObjectValue(1).handle;
if (handle === undefined) return false;
var propID = this.interpreterProxy.stackIntegerValue(0);
var res;
if (propID === this.SQSSL_PROP_PEERNAME) {
res = this.primHandler.makeStString('*'); // Match all
} else {
res = this.interpreterProxy.nilObject();
}
this.interpreterProxy.popthenPush(argCount + 1, res);
return true;
},
primitiveEncrypt: function(argCount) {
if (argCount !== 5) return false;
var handle = this.interpreterProxy.stackObjectValue(4).handle;
if (handle === undefined) return false;
var srcBuf = this.interpreterProxy.stackObjectValue(3);
var start = this.interpreterProxy.stackIntegerValue(2) - 1;
var length = this.interpreterProxy.stackIntegerValue(1);
var dstBuf = this.interpreterProxy.stackObjectValue(0);
dstBuf.bytes = srcBuf.bytes; // Just copy all there is
this.interpreterProxy.popthenPush(argCount + 1, length);
return true;
},
primitiveDecrypt: function(argCount) {
if (argCount !== 5) return false;
var handle = this.interpreterProxy.stackObjectValue(4).handle;
if (handle === undefined) return false;
var srcBuf = this.interpreterProxy.stackObjectValue(3);
var start = this.interpreterProxy.stackIntegerValue(2) - 1;
var length = this.interpreterProxy.stackIntegerValue(1);
var dstBuf = this.interpreterProxy.stackObjectValue(0);
dstBuf.bytes = srcBuf.bytes; // Just copy all there is
this.interpreterProxy.popthenPush(argCount + 1, length);
return true;
}
};
}
function registerSqueakSSL() {
if (typeof Squeak === "object" && Squeak.registerExternalModule) {
Squeak.registerExternalModule('SqueakSSL', SqueakSSL());
} else self.setTimeout(registerSqueakSSL, 100);
};
registerSqueakSSL();
|