stef / libopaque

c implementation of the OPAQUE protocol with bindings for python, php, ruby, lua, zig, java, erlang, golang, js and SASL.
GNU Lesser General Public License v3.0
69 stars 10 forks source link

fix: add java package #39

Closed cipriansofronia closed 1 week ago

cipriansofronia commented 2 weeks ago

While working with the java jni implementation we discovered that it is quite difficult to work with the current default package layout, so this PR aims to introduce a small change that will allow projects to easily import Opaque dependencies.

$ make test
javac -d build test.java io/opaque/Opaque.java io/opaque/OpaqueCredReq.java io/opaque/OpaqueCredResp.java io/opaque/OpaqueCreds.java io/opaque/OpaqueIds.java io/opaque/OpaquePreRecExpKey.java io/opaque/OpaqueRecExpKey.java io/opaque/OpaqueRegReq.java io/opaque/OpaqueRegResp.java
jar -cvfe opaque.jar Main build
added manifest
adding: build/(in = 0) (out= 0)(stored 0%)
adding: build/io/(in = 0) (out= 0)(stored 0%)
adding: build/io/opaque/(in = 0) (out= 0)(stored 0%)
adding: build/io/opaque/OpaqueCredReq.class(in = 243) (out= 189)(deflated 22%)
adding: build/io/opaque/OpaqueRegReq.class(in = 239) (out= 187)(deflated 21%)
adding: build/io/opaque/OpaqueCredResp.class(in = 258) (out= 203)(deflated 21%)
adding: build/io/opaque/OpaqueIds.class(in = 330) (out= 247)(deflated 25%)
adding: build/io/opaque/Opaque.class(in = 2053) (out= 759)(deflated 63%)
adding: build/io/opaque/OpaqueCreds.class(in = 261) (out= 209)(deflated 19%)
adding: build/io/opaque/OpaqueRecExpKey.class(in = 254) (out= 204)(deflated 19%)
adding: build/io/opaque/OpaquePreRecExpKey.class(in = 260) (out= 207)(deflated 20%)
adding: build/io/opaque/OpaqueRegResp.class(in = 243) (out= 189)(deflated 22%)
adding: build/Main.class(in = 4824) (out= 2472)(deflated 48%)
gcc jni.c -shared -fPIC -o libopaquejni.so -I/opt/java/openjdk/include -I/opt/java/openjdk/include/linux -lopaque
java -enableassertions -Djava.library.path=. -classpath build:opaque.jar Main
rec=[B@4e0e2f2a, ek=[B@73d16e93
sec=[B@2a139a55, pub=[B@15db9742
sec=[B@7852e922, pub=[B@4e25154f
rec=[B@5c647e05, ek=[B@33909752
sec=[B@55f96302, pub=[B@3d4eac69
sec=[B@42a57993, pub=[B@75b84c92
rec: 890487a63a748ed2f45170c3a43b7906b1563f3c14157cdc0947c731d31baa07db0297f95d3eb92c42f3ccc8f713527806f5d8d9f508c9541d3511e21a9052e00ad697e67ab11dba2ce2e7bafa556583cbf12c52ca1228eca6ba95fd2f94ce7cc75b7f0f8b9d3a29284bf61508239c931d0bd131ae7b5c2ada3c491e09b29213114cdefb029d75d136ab43ff2722ef36c97dea4425ea206f7304c5aa4811c60600010a44996e5b756d06a37cac089647a476418a66f528e33ae27b8d9ed9a223010b59e867f7ba9892bcc1fb765082ccbe76ad3116aab26cd06fd3205af952772f94dad1279f3d3c3191862a73a0e5eb13f0873989642aff506d3b7816d7d2a5

sec=[B@677327b6, pub=[B@14ae5a5
sec=[B@7f31245a, pub=[B@6d6f6e28
rec: eb91874d9a43517a638d0442f763674df38f18e86a43b2e7ce1ed77ccd06a30b000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f80c901ed7e030c6a288490e3a689d447d27771fd5d9b37890c5f1164dd32654d2e4c12a1e8ea1a3e28f98f999bcc8b8c0ad5ed132ef51c8788d8e8fc4a859f8c17ea9df94c42446e94c521ed4c6ff8b338dc73a685138d024ee7fb9cf3cbaa1e97a6612ad8a7cd944f04f3719bc6f4a189ad5e7ecc944e9a48a8296f0e59d428d1fcb7325efb91c733faeaf345fc290052c2e85f7a797b09eb5f347c0a465e1754976b7dbe3566bd9e7dc083f9023854538e7216056cff7dcac18900e7ccf86c

sec=[B@135fbaa4, pub=[B@45ee12a7
sec=[B@330bedb4, pub=[B@2503dbd3
everything ok
stef commented 2 weeks ago

awesome. thank you. will have a look!

can you tell me what you mean with

it is quite difficult to work with the current default package layout

how so? what does that mean? i'm not a java guy, so understanding this helps me to not mess this up in the future.

cipriansofronia commented 2 weeks ago

Thank you, @stef, for picking it up so fast 🙏🏻! While setting up the JNI implementation, we noticed that Opaque.java had to be placed in our project under src/main/java. If we were to place it in a different package directory (smth like src/main/java/io/opaque), System.loadLibrary would not be able to properly bind the native implementation at runtime. However, we encountered another issue: we could not import the Opaque classes because java cannot load classes from the default package when there is a package hierarchy. Therefore, by specifying the package path in jni.c, we were able to import the Opaque classes properly wherever needed. Hope this makes sense!

stef commented 2 weeks ago

ok. makes sense. one last question why io? is there other options like "auth" or "crypto"? or can i choose my own? like "ctrlc"? i have zero clue about these things, so excuse my naiveté.

cipriansofronia commented 2 weeks ago

it can be whatever you think is better.. so, should I rename it to ctrlc? any other ideas? it would just be a package location for .java files

stef commented 2 weeks ago

ah, good to know. thanks for the answer. i dunno, io doesn't tell me anything, ctrlc is what i would use if i had to use an org. would you?

stef commented 2 weeks ago

btw you might want to pull/merge https://github.com/stef/libopaque/commit/a34fc5f207db86adabefc3d7da1f53f9fdb64eb9 which should fix the CI/CD tests. i've been working hard on liboprf (a dependency of libopaque) and thus there is a bit of fixing to be done for the codeql tests...

cipriansofronia commented 1 week ago

sure, I can go with ctrlc, io is commonly used in java/scala world for projects, but we can set it up as u suggested so, should I go with ctrlc or smth like ctrlc/opaque ?

cipriansofronia commented 1 week ago
$ make clean test
rm -rf build
rm -f opaque.jar
rm -f libopaquejni.so
javac -d build test.java ctrlc/Opaque.java ctrlc/OpaqueCredReq.java ctrlc/OpaqueCredResp.java ctrlc/OpaqueCreds.java ctrlc/OpaqueIds.java ctrlc/OpaquePreRecExpKey.java ctrlc/OpaqueRecExpKey.java ctrlc/OpaqueRegReq.java ctrlc/OpaqueRegResp.java
jar -cvfe opaque.jar Main build
added manifest
adding: build/(in = 0) (out= 0)(stored 0%)
adding: build/ctrlc/(in = 0) (out= 0)(stored 0%)
adding: build/ctrlc/OpaqueCreds.class(in = 257) (out= 208)(deflated 19%)
adding: build/ctrlc/OpaqueRecExpKey.class(in = 250) (out= 203)(deflated 18%)
adding: build/ctrlc/OpaquePreRecExpKey.class(in = 256) (out= 206)(deflated 19%)
adding: build/ctrlc/OpaqueCredResp.class(in = 254) (out= 201)(deflated 20%)
adding: build/ctrlc/Opaque.class(in = 1985) (out= 757)(deflated 61%)
adding: build/ctrlc/OpaqueCredReq.class(in = 239) (out= 188)(deflated 21%)
adding: build/ctrlc/OpaqueRegReq.class(in = 235) (out= 185)(deflated 21%)
adding: build/ctrlc/OpaqueIds.class(in = 326) (out= 247)(deflated 24%)
adding: build/ctrlc/OpaqueRegResp.class(in = 239) (out= 188)(deflated 21%)
adding: build/Main.class(in = 4732) (out= 2472)(deflated 47%)
gcc jni.c -shared -fPIC -o libopaquejni.so -I/opt/java/openjdk/include -I/opt/java/openjdk/include/linux -lopaque
java -enableassertions -Djava.library.path=. -classpath build:opaque.jar Main
rec=[B@4e0e2f2a, ek=[B@73d16e93
sec=[B@2a139a55, pub=[B@15db9742
sec=[B@7852e922, pub=[B@4e25154f
rec=[B@5c647e05, ek=[B@33909752
sec=[B@55f96302, pub=[B@3d4eac69
sec=[B@42a57993, pub=[B@75b84c92
rec: 2d914c0d6339a791f9dfdf5bb58d065bac6b8c9fb1cbdbd0d8bf8e9b735a1f052abaf3b0cb7554f23756de405cd72f85d834c98425328c4db6cd4a24531b1f3bc870ccc084c954e6c31a07bf32e175c29a5b622409fa0e96f365f550043dff15d3e405ff09d0ac829a982dec5f05953f7c5cc1a535684f6b43b0ac82be99c8e26240cedd6af05f86a53161cf219b0b4bd4d918b33561c449949907d43e8a8a201321743072f6d4c52c5280f143eb67a5e01ab6b78521b7a4eae028296f77c673713aee79e40235d1de41c6999d7ae7757f1af0932aabe1428942795b441496db719ce1f65d4eff52a1ea2e0efbf86672f0e705a1f30859ad585cbfe88237e760

sec=[B@677327b6, pub=[B@14ae5a5
sec=[B@7f31245a, pub=[B@6d6f6e28
rec: cd1a190ec8e0fe20583c175eed0fd8d0ca0e5f6f2a1ce366362f05f0aeb5d907000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fd82ae6e9ed34099ab306734abb26402bf445efed12fe250e712f68200e8aee6fcc1497c44954248d189ad025349913e37b2fa818be700c22f4f6f49f1fa42b482be02d58a3fbe6522e08de262496518ac1a081d31a049bf0235f4a288c9c818cdac0065b8874ca1702944361476e42bf93d50c847b0b91eff8b7f168c98f73c1382c08fbe4fd37b4202cab1df8ff1e527a4486fdb577345531d3a009880839e699b78e68fc646baebaefb6ca15dfa35d9909777c66657e555f2bf9b09b29a591

sec=[B@135fbaa4, pub=[B@45ee12a7
sec=[B@330bedb4, pub=[B@2503dbd3
everything ok
stef commented 1 week ago

sure, I can go with ctrlc, io is commonly used in java/scala world for projects

if that is the custom, then sure let's keep it that way.

stef commented 1 week ago

ah fuck, i just saw you already renamed, it. i'll handle it from here. thx. will be merged today.

cipriansofronia commented 1 week ago

no worries, u can merge it with ctrlc package name as well, no problem

stef commented 1 week ago

much <3 and thanks for putting up with my ignorance!

stef commented 1 week ago

btw if you are able to disclose where and how you're using libopaque, it would be very interesting to know.

cipriansofronia commented 1 week ago

I can only share the name of the company where this will be used, which is InvestSuite 😄

cipriansofronia commented 1 week ago

may I ask you to release a new tag with these changes, please? thank you 🙏🏻

stef commented 1 week ago

https://github.com/stef/libopaque/releases/tag/v0.99.4