Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a few system properties the process can read to make life a bit easier for folks working behind proxy #182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions cli/src/main/scala/jupyter/scala/JupyterScala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package jupyter
package scala

import java.io.{ ByteArrayOutputStream, InputStream }
import java.net.{ Authenticator, PasswordAuthentication }
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.{ X509TrustManager, TrustManager, SSLContext, HttpsURLConnection }

import jupyter.kernel.interpreter.InterpreterKernel
import jupyter.kernel.server.{ ServerApp, ServerAppOptions }
Expand All @@ -21,6 +25,36 @@ case class JupyterScalaApp(
@Recurse
options: ServerAppOptions
) extends App with LazyLogging {

Authenticator.setDefault(
new Authenticator {
override protected def getPasswordAuthentication: PasswordAuthentication =
if (getRequestorType eq Authenticator.RequestorType.PROXY) {
val user = Option(System.getProperty("http.proxyUser")) orElse Option(System.getProperty("https.proxyUser"))
val passwd = Option(System.getProperty("http.proxyPassword")) orElse Option(System.getProperty("https.proxyPassword"))
(user, passwd) match {
case (Some(u), Some(p)) => new PasswordAuthentication(u, p.toCharArray)
case _ => null
}
}
else null
}
)

private val sslVerify = System.getProperty("ssl.verify")
if (sslVerify == "no" || sslVerify == "false" || sslVerify == "off") {
val trustedAllCerts : Array[TrustManager] = Array(
new X509TrustManager {
override def checkServerTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = ()
override def checkClientTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = ()
override def getAcceptedIssuers: Array[X509Certificate] = null
}
)
val sc = SSLContext.getInstance("TLS")
sc.init(null, trustedAllCerts, new SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory)
}

def readFully(is: InputStream) = {
val buffer = new ByteArrayOutputStream()

Expand Down