@@ -188,19 +188,6 @@ def abs_connection_file(self):
188188 """ ,
189189 ).tag (config = True )
190190
191- enable_curve = Bool (
192- bool (int (os .environ .get ("JUPYTER_ENABLE_CURVE" , "0" ))),
193- help = "Enable CurveZMQ transport encryption and authentication. "
194- "When True, a keypair is generated at startup and stored in the "
195- "connection file so that clients can authenticate and encrypt "
196- "all ZMQ channels." ,
197- ).tag (config = True )
198-
199- # Internal CurveZMQ keypair (Z85-encoded bytes); populated in init_sockets
200- # when enable_curve is True.
201- _curve_publickey : bytes | None = None
202- _curve_secretkey : bytes | None = None
203-
204191 # polling
205192 parent_handle = Integer (
206193 int (os .environ .get ("JPY_PARENT_PID" ) or 0 ),
@@ -227,12 +214,12 @@ def excepthook(self, etype, evalue, tb):
227214 def _apply_curve_server_options (self , socket : zmq .Socket [t .Any ]) -> None :
228215 """Set CurveZMQ server-side options on *socket* before it is bound.
229216
230- This is a no-op when enable_curve is False or keys have not been
231- generated yet, so it is safe to call unconditionally.
217+ This is a no-op when Curve keys are not available yet, so it is safe
218+ to call unconditionally.
232219 """
233- if self .enable_curve and self . _curve_secretkey is not None :
234- socket .curve_secretkey = self ._curve_secretkey
235- socket .curve_publickey = self ._curve_publickey
220+ if self .curve_secretkey is not None :
221+ socket .curve_secretkey = self .curve_secretkey
222+ socket .curve_publickey = self .curve_publickey
236223 socket .curve_server = True
237224
238225 def init_poller (self ):
@@ -298,10 +285,9 @@ def write_connection_file(self, **kwargs: Any) -> None:
298285 iopub_port = self .iopub_port ,
299286 control_port = self .control_port ,
300287 )
301- if self .enable_curve and self ._curve_publickey is not None :
302- # write_connection_file() in jupyter-client handles JSON-safe key serialization
303- connection_info ["curve_publickey" ] = self ._curve_publickey
304- connection_info ["curve_secretkey" ] = self ._curve_secretkey
288+ if self .curve_publickey is not None :
289+ connection_info ["curve_publickey" ] = self .curve_publickey
290+ connection_info ["curve_secretkey" ] = self .curve_secretkey
305291 if Path (cf ).exists ():
306292 # If the file exists, merge our info into it. For example, if the
307293 # original file had port number 0, we update with the actual port
@@ -356,16 +342,15 @@ def init_sockets(self):
356342 self .context = context = zmq .Context ()
357343 atexit .register (self .close )
358344
359- if self .enable_curve :
360- self ._curve_publickey , self ._curve_secretkey = zmq .curve_keypair ()
361- self .log .debug ("CurveZMQ enabled; generated server keypair" )
345+ if self .curve_secretkey is not None :
346+ self .log .debug ("Detected CurveZMQ secret key; using transport encryption" )
362347 elif self .transport == "tcp" :
363348 self .log .warning (
364349 "Kernel is running over TCP without encryption."
365350 " All communication (including code and outputs) is sent in plain text"
366351 " and is susceptible to eavesdropping."
367- " Use IPC transport or set IPKernelApp.enable_curve=True to enable "
368- " CurveZMQ encryption."
352+ " Use IPC transport or launch with kernel manager-provisioned "
353+ " CurveZMQ keys to enable transport encryption."
369354 )
370355
371356 self .shell_socket = context .socket (zmq .ROUTER )
@@ -439,8 +424,8 @@ def init_heartbeat(self):
439424 self .heartbeat = Heartbeat (
440425 hb_ctx ,
441426 (self .transport , self .ip , self .hb_port ),
442- curve_publickey = self ._curve_publickey if self . enable_curve else None ,
443- curve_secretkey = self ._curve_secretkey if self . enable_curve else None ,
427+ curve_publickey = self .curve_publickey ,
428+ curve_secretkey = self .curve_secretkey ,
444429 )
445430 self .hb_port = self .heartbeat .port
446431 self .log .debug ("Heartbeat REP Channel on port: %i" , self .hb_port )
0 commit comments