Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 90d68be3 authored by deuce's avatar deuce

Pass the TLS session CRYPT_CONTEXT value along with the client socket in

the constructor things.  This allows TLS-enabled services to work correctly,
and removes an ugly hack from the web server.

There's still an odd issue with the NNTP service when using TLS though.
parent 76c34660
......@@ -2688,7 +2688,7 @@ static void ctrl_thread(void* arg)
if(js_CreateUserObject(js_cx, js_glob, &scfg, "user", user.number, &client)==NULL)
lprintf(LOG_ERR,"%04d !JavaScript ERROR creating user object",sock);
if(js_CreateClientObject(js_cx, js_glob, "client", &client, sock)==NULL)
if(js_CreateClientObject(js_cx, js_glob, "client", &client, sock, -1)==NULL)
lprintf(LOG_ERR,"%04d !JavaScript ERROR creating client object",sock);
if(js_CreateFileAreaObject(js_cx, js_glob, &scfg, &user
......@@ -4058,7 +4058,7 @@ static void ctrl_thread(void* arg)
if(js_CreateUserObject(js_cx, js_glob, &scfg, "user", &user, &client, /* global_user: */TRUE)==NULL)
lprintf(LOG_ERR,"%04d !JavaScript ERROR creating user object",sock);
if(js_CreateClientObject(js_cx, js_glob, "client", &client, sock)==NULL)
if(js_CreateClientObject(js_cx, js_glob, "client", &client, sock, -1)==NULL)
lprintf(LOG_ERR,"%04d !JavaScript ERROR creating client object",sock);
if(js_CreateFileAreaObject(js_cx, js_glob, &scfg, &user, &client
......
......@@ -170,7 +170,7 @@ static JSClass js_client_class = {
};
JSObject* DLLCALL js_CreateClientObject(JSContext* cx, JSObject* parent
,const char* name, client_t* client, SOCKET sock)
,const char* name, client_t* client, SOCKET sock, CRYPT_CONTEXT session)
{
JSObject* obj;
......@@ -182,7 +182,7 @@ JSObject* DLLCALL js_CreateClientObject(JSContext* cx, JSObject* parent
JS_SetPrivate(cx, obj, client); /* Store a pointer to client_t */
js_CreateSocketObject(cx, obj, "socket", sock);
js_CreateSocketObject(cx, obj, "socket", sock, session);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,obj,"Represents a TCP/IP client session",310);
......
......@@ -331,6 +331,7 @@ js_load(JSContext *cx, uintN argc, jsval *arglist)
,p->startup /* js */
,NULL /* client */
,INVALID_SOCKET /* client_socket */
,-1 /* client TLS session */
,NULL /* server props */
,&bg->obj
)) {
......
......@@ -562,7 +562,7 @@ js_accept(JSContext *cx, uintN argc, jsval *arglist)
}
}
if((sockobj=js_CreateSocketObject(cx, obj, "new_socket", new_socket))==NULL) {
if((sockobj=js_CreateSocketObject(cx, obj, "new_socket", new_socket, -1))==NULL) {
closesocket(new_socket);
JS_RESUMEREQUEST(cx, rc);
JS_ReportError(cx,"Error creating new socket object");
......@@ -2044,7 +2044,7 @@ static BOOL js_DefineSocketOptionsArray(JSContext *cx, JSObject *obj, int type)
/* Socket Constructor (creates socket descriptor) */
JSObject* DLLCALL js_CreateSocketObjectWithoutParent(JSContext* cx, SOCKET sock)
JSObject* DLLCALL js_CreateSocketObjectWithoutParent(JSContext* cx, SOCKET sock, CRYPT_CONTEXT session)
{
JSObject* obj;
js_socket_private_t* p;
......@@ -2069,7 +2069,7 @@ JSObject* DLLCALL js_CreateSocketObjectWithoutParent(JSContext* cx, SOCKET sock)
p->sock = sock;
p->external = TRUE;
p->network_byte_order = TRUE;
p->session=-1;
p->session=session;
if (p->sock != INVALID_SOCKET) {
len=sizeof(p->remote_addr);
......@@ -2107,7 +2107,7 @@ js_socket_constructor(JSContext *cx, uintN argc, jsval *arglist)
#else
JS_ValueToInt32(cx,argv[i],&sock);
#endif
obj = js_CreateSocketObjectWithoutParent(cx, sock);
obj = js_CreateSocketObjectWithoutParent(cx, sock, -1);
if (obj == NULL) {
JS_ReportError(cx, "Failed to create external socket object");
return JS_FALSE;
......@@ -2189,11 +2189,11 @@ JSObject* DLLCALL js_CreateSocketClass(JSContext* cx, JSObject* parent)
return(sockobj);
}
JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *name, SOCKET sock)
JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *name, SOCKET sock, CRYPT_CONTEXT session)
{
JSObject* obj;
obj = js_CreateSocketObjectWithoutParent(cx, sock);
obj = js_CreateSocketObjectWithoutParent(cx, sock, session);
if(obj==NULL)
return(NULL);
JS_DefineProperty(cx, parent, name, OBJECT_TO_JSVAL(obj), NULL, NULL, JSPROP_ENUMERATE|JSPROP_READONLY);
......
......@@ -203,6 +203,7 @@ BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
,js_startup_t* js_startup /* js */
,client_t* client /* client */
,SOCKET client_socket /* client */
,CRYPT_CONTEXT session /* client */
,js_server_props_t* props /* server */
,JSObject** glob
)
......@@ -225,7 +226,7 @@ BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
/* Client Object */
if(client!=NULL
&& js_CreateClientObject(js_cx, *glob, "client", client, client_socket)==NULL)
&& js_CreateClientObject(js_cx, *glob, "client", client, client_socket, session)==NULL)
break;
/* Server */
......
......@@ -782,7 +782,7 @@ static BOOL js_init(char** environ)
if(!js_CreateCommonObjects(js_cx, &scfg, NULL, js_global_functions
,time(NULL), host_name, SOCKLIB_DESC /* system */
,&cb,&startup /* js */
,NULL,INVALID_SOCKET /* client */
,NULL,INVALID_SOCKET,-1 /* client */
,NULL /* server */
,&js_glob
)) {
......
......@@ -1923,9 +1923,9 @@ js_mailproc(SOCKET sock, client_t* client, user_t* user, struct mailproc* mailpr
/* Global Objects (including system, js, client, Socket, MsgBase, File, User, etc. */
if(!js_CreateCommonObjects(*js_cx, &scfg, &scfg, NULL
,uptime, startup->host_name, SOCKLIB_DESC /* system */
,&js_callback /* js */
,&js_callback /* js */
,&startup->js
,client, sock /* client */
,client, sock, -1 /* client */
,&js_server_props /* server */
,js_glob
))
......
......@@ -1181,7 +1181,7 @@ bool sbbs_t::js_init(ulong* stack_frame)
,uptime, startup->host_name, SOCKLIB_DESC /* system */
,&js_callback /* js */
,&startup->js
,&client, client_socket /* client */
,&client, client_socket, -1 /* client */
,&js_server_props /* server */
,&js_glob
))
......@@ -1260,6 +1260,7 @@ extern "C" BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
,js_startup_t* js_startup /* js */
,client_t* client /* client */
,SOCKET client_socket /* client */
,CRYPT_CONTEXT session /* client */
,js_server_props_t* props /* server */
,JSObject** glob
)
......@@ -1285,7 +1286,7 @@ extern "C" BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
/* Client Object */
if(client!=NULL
&& js_CreateClientObject(js_cx, *glob, "client", client, client_socket)==NULL)
&& js_CreateClientObject(js_cx, *glob, "client", client, client_socket, session)==NULL)
break;
/* Server */
......
......@@ -1167,6 +1167,7 @@ extern "C" {
DLLEXPORT JSBool DLLCALL js_DefineConstIntegers(JSContext* cx, JSObject* obj, jsConstIntSpec*, int flags);
DLLEXPORT JSBool DLLCALL js_CreateArrayOfStrings(JSContext* cx, JSObject* parent
,const char* name, char* str[], unsigned flags);
#ifdef USE_CRYPTLIB
DLLEXPORT BOOL DLLCALL js_CreateCommonObjects(JSContext* cx
,scfg_t* cfg /* common */
,scfg_t* node_cfg /* node-specific */
......@@ -1178,9 +1179,11 @@ extern "C" {
,js_startup_t* /* js */
,client_t* client /* client */
,SOCKET client_socket /* client */
,CRYPT_CONTEXT session /* client */
,js_server_props_t* props /* server */
,JSObject** glob
);
#endif
/* js_server.c */
DLLEXPORT JSObject* DLLCALL js_CreateServerObject(JSContext* cx, JSObject* parent
......@@ -1212,8 +1215,10 @@ extern "C" {
,char* socklib_desc);
/* js_client.c */
#ifdef USE_CRYPTLIB
DLLEXPORT JSObject* DLLCALL js_CreateClientObject(JSContext* cx, JSObject* parent
,const char* name, client_t* client, SOCKET sock);
,const char* name, client_t* client, SOCKET sock, CRYPT_CONTEXT session);
#endif
/* js_user.c */
DLLEXPORT JSObject* DLLCALL js_CreateUserClass(JSContext* cx, JSObject* parent, scfg_t* cfg);
DLLEXPORT JSObject* DLLCALL js_CreateUserObject(JSContext* cx, JSObject* parent, scfg_t* cfg
......@@ -1241,8 +1246,10 @@ extern "C" {
/* js_socket.c */
DLLEXPORT JSObject* DLLCALL js_CreateSocketClass(JSContext* cx, JSObject* parent);
#ifdef USE_CRYPTLIB
DLLEXPORT JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent
,char *name, SOCKET sock);
,char *name, SOCKET sock, CRYPT_CONTEXT session);
#endif
DLLEXPORT JSObject* DLLCALL js_CreateSocketObjectFromSet(JSContext* cx, JSObject* parent
,char *name, struct xpms_set *set);
......
......@@ -772,7 +772,7 @@ js_initcx(JSRuntime* js_runtime, SOCKET sock, service_client_t* service_client,
/* Client Object */
if(service_client->client!=NULL) {
if(js_CreateClientObject(js_cx, *glob, "client", service_client->client, sock)==NULL)
if(js_CreateClientObject(js_cx, *glob, "client", service_client->client, sock, service_client->tls_sess)==NULL)
break;
}
......
......@@ -5523,9 +5523,6 @@ static JSContext*
js_initcx(http_session_t *session)
{
JSContext* js_cx;
jsval val;
JSObject* obj;
js_socket_private_t* p;
lprintf(LOG_DEBUG,"%04d JavaScript: Initializing context (stack: %lu bytes)"
,session->socket,startup->js.cx_stack);
......@@ -5550,6 +5547,7 @@ js_initcx(http_session_t *session)
,&startup->js /* js */
,&session->client /* client */
,session->socket /* client */
,session->tls_sess /* client */
,&js_server_props /* server */
,&session->js_glob
)
......@@ -5559,14 +5557,6 @@ js_initcx(http_session_t *session)
JS_DestroyContext(js_cx);
return(NULL);
}
if (session->is_tls) {
JS_GetProperty(js_cx, session->js_glob, "client", &val);
obj=JSVAL_TO_OBJECT(val);
JS_GetProperty(js_cx, obj, "socket", &val);
obj=JSVAL_TO_OBJECT(val);
p=(js_socket_private_t*)JS_GetPrivate(js_cx,obj);
p->session=session->tls_sess;
}
return(js_cx);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment