enable SSL via Java property (#21)
This commit is contained in:
parent
8341407cbe
commit
4607016910
4 changed files with 48 additions and 45 deletions
|
|
@ -38,10 +38,10 @@ jobs:
|
||||||
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
||||||
tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
||||||
fi
|
fi
|
||||||
- run:
|
# - run:
|
||||||
name: Install GraalVM SSL libs
|
# name: Install GraalVM SSL libs
|
||||||
command: |
|
# command: |
|
||||||
.circleci/script/graalvm_ssl
|
# .circleci/script/graalvm_ssl
|
||||||
- run:
|
- run:
|
||||||
name: Run JVM tests
|
name: Run JVM tests
|
||||||
command: |
|
command: |
|
||||||
|
|
@ -96,10 +96,10 @@ jobs:
|
||||||
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
||||||
tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz
|
||||||
fi
|
fi
|
||||||
- run:
|
# - run:
|
||||||
name: Install GraalVM SSL libs
|
# name: Install GraalVM SSL libs
|
||||||
command: |
|
# command: |
|
||||||
.circleci/script/graalvm_ssl
|
# .circleci/script/graalvm_ssl
|
||||||
- run:
|
- run:
|
||||||
name: Build binary
|
name: Build binary
|
||||||
command: |
|
command: |
|
||||||
|
|
@ -159,10 +159,10 @@ jobs:
|
||||||
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz
|
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz
|
||||||
tar xzf graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz
|
tar xzf graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz
|
||||||
fi
|
fi
|
||||||
- run:
|
# - run:
|
||||||
name: Install GraalVM SSL libs
|
# name: Install GraalVM SSL libs
|
||||||
command: |
|
# command: |
|
||||||
.circleci/script/graalvm_ssl
|
# .circleci/script/graalvm_ssl
|
||||||
- run:
|
- run:
|
||||||
name: Build binary
|
name: Build binary
|
||||||
command: |
|
command: |
|
||||||
|
|
|
||||||
45
README.md
45
README.md
|
|
@ -99,7 +99,7 @@ through the aliases:
|
||||||
|
|
||||||
From Java the following is available:
|
From Java the following is available:
|
||||||
|
|
||||||
- `System`: `exit`, `getProperty`, `getProperties`, `getenv`
|
- `System`: `exit`, `getProperty`, `setProperty`, `getProperties`, `getenv`
|
||||||
|
|
||||||
Special vars:
|
Special vars:
|
||||||
|
|
||||||
|
|
@ -185,39 +185,30 @@ Writing file: /tmp/clojure.org.html
|
||||||
|
|
||||||
## Enabling SSL
|
## Enabling SSL
|
||||||
|
|
||||||
If you want to be able to use SSL to e.g. `(slurp "https://www.clojure.org")`
|
If you want to be able to use SSL to e.g. run `(slurp
|
||||||
you will need install a runtime dependency called `libsunec.so`. Because I don't
|
"https://www.clojure.org")` you will need to add the location where
|
||||||
know if I'm allowed to ship this library with babashka, I have chosen to let the
|
`libsunec.so` or `libsunec.dylib` is located to the `java.library.path` Java
|
||||||
user take care of these and put them in a known location. This also allows you
|
property. This library comes with most JVM installations, so you might already
|
||||||
to include a different `cacerts`.
|
have it on your machine. It is usually located in `<JAVA_HOME>/jre/lib` or
|
||||||
|
`<JAVA_HOME>/jre/<platform>/lib`. It is also bundled with GraalVM.
|
||||||
|
|
||||||
To enable SSL, create a `~/.babashka/lib` directory and copy the`libsunec.so`
|
Example:
|
||||||
(Linux) or `libsunec.dylib` (Mac) to it. This library comes with GraalVM and is
|
|
||||||
located in `<GRAALVM_HOME>/jre/lib/<platform>` inside the distribution. Also create a and
|
|
||||||
`~/.babashka/lib/security` directory and copy `cacerts` to it which comes
|
|
||||||
bundled with GraalVM and is located in
|
|
||||||
`<GRAALVM_HOME>/jre/lib/security`.
|
|
||||||
|
|
||||||
As a shell script:
|
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
mkdir -p ~/.babashka/lib/security
|
$ cat /tmp/https_get.clj
|
||||||
|
#!/usr/bin/env bb -f
|
||||||
|
|
||||||
# Linux:
|
(System/setProperty
|
||||||
cp $GRAALVM_HOME/jre/lib/amd64/libsunec.so ~/.babashka/lib
|
"java.library.path"
|
||||||
|
"/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib")
|
||||||
|
|
||||||
# Mac:
|
(slurp (first *command-line-args*))
|
||||||
cp $GRAALVM_HOME/jre/lib/libsunec.dylib ~/.babashka/lib
|
|
||||||
|
|
||||||
cp $GRAALVM_HOME/jre/lib/security/cacerts ~/.babashka/lib/security
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can download a distribution of GraalVM for your platform on
|
``` shellsession
|
||||||
[Github](https://github.com/oracle/graal/releases).
|
$ /tmp/https_get.clj https://www.google.com | bb '(subs *in* 0 50)'
|
||||||
|
"<!doctype html><html itemscope=\"\" itemtype=\"http:/"
|
||||||
More information about GraalVM and SSL can be found
|
```
|
||||||
[here](https://blog.taylorwood.io/2018/10/04/graalvm-https.html) and
|
|
||||||
[here](https://quarkus.io/guides/native-and-ssl-guide).
|
|
||||||
|
|
||||||
## Test
|
## Test
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,9 @@
|
||||||
([s d]
|
([s d]
|
||||||
(System/getProperty s d)))
|
(System/getProperty s d)))
|
||||||
|
|
||||||
|
(defn set-property [k v]
|
||||||
|
(System/setProperty k v))
|
||||||
|
|
||||||
(defn get-properties []
|
(defn get-properties []
|
||||||
(System/getProperties))
|
(System/getProperties))
|
||||||
|
|
||||||
|
|
@ -117,6 +120,7 @@
|
||||||
'edn/read-string edn/read-string
|
'edn/read-string edn/read-string
|
||||||
'System/getenv get-env
|
'System/getenv get-env
|
||||||
'System/getProperty get-property
|
'System/getProperty get-property
|
||||||
|
'System/setProperty set-property
|
||||||
'System/getProperties get-properties
|
'System/getProperties get-properties
|
||||||
'System/exit exit})
|
'System/exit exit})
|
||||||
|
|
||||||
|
|
@ -124,10 +128,7 @@
|
||||||
(edn/read {;;:readers *data-readers*
|
(edn/read {;;:readers *data-readers*
|
||||||
:eof ::EOF} *in*))
|
:eof ::EOF} *in*))
|
||||||
|
|
||||||
(defn main
|
#_(defn set-ssl []
|
||||||
[& args]
|
|
||||||
#_(binding [*out* *err*]
|
|
||||||
(prn ">> args" args))
|
|
||||||
(let [home (System/getProperty "user.home")
|
(let [home (System/getProperty "user.home")
|
||||||
bb-lib-dir (io/file home ".babashka" "lib")
|
bb-lib-dir (io/file home ".babashka" "lib")
|
||||||
lib-path (System/getProperty "java.library.path")
|
lib-path (System/getProperty "java.library.path")
|
||||||
|
|
@ -135,7 +136,12 @@
|
||||||
ca-certs (.getPath (io/file ca-certs-dir "cacerts"))]
|
ca-certs (.getPath (io/file ca-certs-dir "cacerts"))]
|
||||||
(System/setProperty "java.library.path" (str (.getPath bb-lib-dir) ":" lib-path))
|
(System/setProperty "java.library.path" (str (.getPath bb-lib-dir) ":" lib-path))
|
||||||
(System/setProperty "javax.net.ssl.trustStore" ca-certs)
|
(System/setProperty "javax.net.ssl.trustStore" ca-certs)
|
||||||
(System/setProperty "javax.net.ssl.trustAnchors" ca-certs))
|
(System/setProperty "javax.net.ssl.tru stAnchors" ca-certs)))
|
||||||
|
|
||||||
|
(defn main
|
||||||
|
[& args]
|
||||||
|
#_(binding [*out* *err*]
|
||||||
|
(prn ">> args" args))
|
||||||
(let [t0 (System/currentTimeMillis)
|
(let [t0 (System/currentTimeMillis)
|
||||||
{:keys [:version :raw-in :raw-out :println?
|
{:keys [:version :raw-in :raw-out :println?
|
||||||
:help? :file :command-line-args
|
:help? :file :command-line-args
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,13 @@
|
||||||
(bb nil))))
|
(bb nil))))
|
||||||
|
|
||||||
(deftest ssl-test
|
(deftest ssl-test
|
||||||
(is (re-find #"doctype html" (bb nil "(slurp \"https://www.google.com\")"))))
|
(let [graalvm-home (System/getenv "GRAALVM_HOME")
|
||||||
|
lib-path (format "%1$s/jre/lib:%1$s/jre/lib/amd64" graalvm-home)
|
||||||
|
_ (prn "lib-path" lib-path)
|
||||||
|
resp (bb nil (format "(System/setProperty \"java.library.path\" \"%s\")
|
||||||
|
(slurp \"https://www.google.com\")"
|
||||||
|
lib-path))]
|
||||||
|
(is (re-find #"doctype html" resp))))
|
||||||
|
|
||||||
(deftest stream-test
|
(deftest stream-test
|
||||||
(is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc *in*)")))
|
(is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc *in*)")))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue