GithubHelp home page GithubHelp logo

jolm's People

Contributors

brevilo avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

laurent-treeb

jolm's Issues

io.github.brevilo.jolm.Utils$OlmException: BAD_MESSAGE_FORMAT

Hey jolm Team,

Thank you guys for the wonderful work. we now use Olm to encrypt&decrypt our API in java, the encrypt session is working fine, but we have an error that happens on the decrypt method call:

This is our test code:

/**
     * Basic test:
     * - alice creates an account
     * - bob creates an account
     * - alice creates an outbound session with bob (bobIdentityKey & bobOneTimeKey)
     * - alice encrypts a message with its session
     * - bob creates an inbound session based on alice's encrypted message
     * - bob decrypts the encrypted message with its session
     */
    @Test
    public void test01AliceToBob() {
        String plainMessage = "Hello Bob, this is message from Alice.";
        LOGGER.info("plain message: {}", plainMessage);
        String decryptedMessage = "";

        String bobIdentityKey = null;
        String bobOneTimeKey = null;

        Account aliceAccount = null;
        Account bobAccount = null;

        Session aliceSession = null;
        Session bobSession = null;

        try {
            // ALICE & BOB ACCOUNTS CREATION
            aliceAccount = new Account();
            bobAccount = new Account();

            bobIdentityKey = bobAccount.identityKeys().getCurve25519();   // generate  identityKey

            /**
             * generate oneTimeKey
             */
            bobAccount.generateOneTimeKeys(5);
            Map<String, String> bobOneTimeKeys = bobAccount.oneTimeKeys().getCurve25519();
            for (String key : bobOneTimeKeys.keySet()) {
                bobOneTimeKey = bobOneTimeKeys.get(key);
                LOGGER.info("OneTimeKeys: {} = {}", key, bobOneTimeKey);
            }
            LOGGER.info("identityKey = {}, oneTimeKey = {}", bobIdentityKey, bobOneTimeKey);

            // create OutboundSession to Bob
            aliceSession = Session.createOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);

            Message encryptedMessage = aliceSession.encrypt(plainMessage);
            LOGGER.info("encrypted message: {}", JSONUtils.toJSONString(encryptedMessage));
            LOGGER.info("encrypted message type: {}", encryptedMessage.type());


            bobSession = Session.createInboundSession(bobAccount, encryptedMessage.getCipherText());

            decryptedMessage = bobSession.decrypt(encryptedMessage);

            LOGGER.info("decrypted message: {}", decryptedMessage);

            aliceAccount.clear();
            bobAccount.clear();

            aliceSession.clear();
            bobSession.clear();

        } catch (Exception e) {
            LOGGER.error("Olm session test error: ", e);
        }
        Assert.assertEquals(plainMessage, decryptedMessage);
    }

This is our output log:

2021-11-11 16:34:38.772 [main] INFO  net.metachain.server.utils.TestOlmSession - plain message: Hello Bob, this is message from Alice.
2021-11-11 16:34:39.517 [main] INFO  net.metachain.server.utils.TestOlmSession - OneTimeKeys: AAAABQ = +MkagVTW7bGjgM1Os9WC7r8VaQHNiPS643Tt1VOPM0A
2021-11-11 16:34:39.518 [main] INFO  net.metachain.server.utils.TestOlmSession - OneTimeKeys: AAAABA = yOhxoS8gxy9M4SeoB77GfUyR17RIEE8/zHd6Ysfv4yA
2021-11-11 16:34:39.518 [main] INFO  net.metachain.server.utils.TestOlmSession - OneTimeKeys: AAAAAw = 4sXwydQ8rNknUubMavJj4zIOhxEuLHetd1DtcZRn3no
2021-11-11 16:34:39.518 [main] INFO  net.metachain.server.utils.TestOlmSession - OneTimeKeys: AAAAAg = UdlPlxp07nNdvd39bD202NTy899Ehn6RE/yGY27/0X8
2021-11-11 16:34:39.518 [main] INFO  net.metachain.server.utils.TestOlmSession - OneTimeKeys: AAAAAQ = A7Gjemi/vAdTyWq8HARzRyQsSkOQYag9dMpmraUS5SE
2021-11-11 16:34:39.519 [main] INFO  net.metachain.server.utils.TestOlmSession - identityKey = NOC83AGZLQI8K1YySs0iZgTS1Y4bXee4ISuD23DmJis, oneTimeKey = A7Gjemi/vAdTyWq8HARzRyQsSkOQYag9dMpmraUS5SE
2021-11-11 16:34:39.616 [main] INFO  net.metachain.server.utils.TestOlmSession - encrypted message: {"cipherText":"AwogA7Gjemi/vAdTyWq8HARzRyQsSkOQYag9dMpmraUS5SESIGJEyhTLzbn/dktZgrQiFexgE5JoYhkrugBEkeqHwnI4GiD/XW0taj3ihcNuvnqrKzPIgVMO6MLBSGyUpdgCPPs8ESJfAwogPgA6/b48L+Z0kqS94BD5GuZM5vhen/b75Z9/J7MRo1IQACIw1uuyj9I+gRI6SUvLuojfC4JIxjFiD1936FdFfsvQy1DGE9wn1+Yl75OaKy5ZX4EGlY3zJ+8dKWw"}
2021-11-11 16:34:39.617 [main] INFO  net.metachain.server.utils.TestOlmSession - encrypted message type: 0
2021-11-11 16:34:39.621 [main] ERROR net.metachain.server.utils.TestOlmSession - Olm session test error: 
io.github.brevilo.jolm.Utils$OlmException: BAD_MESSAGE_FORMAT
	at io.github.brevilo.jolm.Session.checkOlmResult(Session.java:268)
	at io.github.brevilo.jolm.Session.checkOlmResult(Session.java:254)
	at io.github.brevilo.jolm.Session.decrypt(Session.java:219)
	at net.metachain.server.utils.TestOlmSession.test01AliceToBob(TestOlmSession.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

org.junit.ComparisonFailure: 
Expected :Hello Bob, this is message from Alice.

How to fix it or can you provide the full unit test code? @brevilo

Fatal error: Problematic frame: V [libjvm.dylib+0x6d20a6] SymbolTable::lookup_dynamic(int, char const*, int, unsigned int)+0x1c

Hey @brevilo , sometimes, It has an fatal error on unit test, it will disappear after many runs.

there is log message on Mac OS 11.5

/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58487:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Users/Wendell/.m2/repository/org/junit/platform/junit-platform-launcher/1.7.2/junit-platform-launcher-1.7.2.jar:/Users/Wendell/.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar:/Users/Wendell/.m2/repository/org/junit/platform/junit-platform-engine/1.7.2/junit-platform-engine-1.7.2.jar:/Users/Wendell/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/Wendell/.m2/repository/org/junit/platform/junit-platform-commons/1.7.2/junit-platform-commons-1.7.2.jar:/Users/Wendell/workspace/jolm/target/test-classes:/Users/Wendell/workspace/jolm/target/classes:/Users/Wendell/.m2/repository/net/java/dev/jna/jna/5.8.0/jna-5.8.0.jar:/Users/Wendell/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.1/jackson-databind-2.11.1.jar:/Users/Wendell/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.11.1/jackson-annotations-2.11.1.jar:/Users/Wendell/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.1/jackson-core-2.11.1.jar:/Users/Wendell/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.7.2/junit-jupiter-engine-5.7.2.jar:/Users/Wendell/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.7.2/junit-jupiter-api-5.7.2.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 io.github.brevilo.jolm.SessionTest,testAliceToBob
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000010e6d20a6, pid=15556, tid=6147
#
# JRE version: OpenJDK Runtime Environment (11.0.1+13) (build 11.0.1+13)
# Java VM: OpenJDK 64-Bit Server VM (11.0.1+13, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# V  [libjvm.dylib+0x6d20a6]  SymbolTable::lookup_dynamic(int, char const*, int, unsigned int)+0x1c
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/Wendell/workspace/jolm/hs_err_pid15556.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

[hs_err_pid15556.log](https://github.com/brevilo/jolm/files/7524446/hs_err_pid15556.log)

java.lang.IllegalArgumentException: Allocation size must be greater than zero

Hey @brevilo ,

I'm back again, we got a new error, could you check and fix it?

Describe the bug

java.lang.IllegalArgumentException: Allocation size must be greater than zero
        at com.sun.jna.Memory.<init>(Memory.java:239)
        at io.github.brevilo.jolm.Utils.toNative(Utils.java:86)
        at io.github.brevilo.jolm.Session.createInboundSession(Session.java:341)
        at net.metachain.server.utils.OlmCryptoUtils.decrypt(OlmCryptoUtils.java:69)
        at net.metachain.server.service.impl.NetworkServiceImpl.findCachedNodes(NetworkServiceImpl.java:402)
        at net.metachain.server.service.impl.PCClientServiceImpl.syncNodesV2(PCClientServiceImpl.java:361)
        at net.metachain.server.service.impl.PCClientServiceImpl$$FastClassBySpringCGLIB$$7cb9ffc5.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at net.metachain.server.service.impl.PCClientServiceImpl$$EnhancerBySpringCGLIB$$87212b8.syncNodesV2(<generated>)
        at net.metachain.server.controller.PCClientController.syncNodes(PCClientController.java:45)
        at sun.reflect.GeneratedMethodAccessor283.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
                                                                                                                                                                                              2512,1-8       7%
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at net.metachain.server.common.filter.OlmResponseFilter.doFilterInternal(OlmResponseFilter.java:34)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at net.metachain.server.common.filter.HttpRequestFilter.doFilterInternal(HttpRequestFilter.java:48)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
                                                                                                                                                                                              2551,2-9       8%
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

Expected behavior
Should not happen this error.

To Reproduce
With many request, some times, it will reproduce.

Environment (please complete the following information):

  • OS: Linux
  • Java version: openjdk version "1.8.0_292"
  • libolm version 3.2.6
  • jOlm version 1.0.4

Fatal error: Problematic frame: # C [jna8893831892584865540.tmp+0x9220]

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f8a5f99c220, pid=11858, tid=0x00007f8a624f4700
#
# JRE version: OpenJDK Runtime Environment (8.0_292-b10) (build 1.8.0_292-8u292-b10-0ubuntu1~16.04.1-b10)
# Java VM: OpenJDK 64-Bit Server VM (25.292-b10 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [jna8893831892584865540.tmp+0x9220]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
...

Hey @brevilo, we deployed our service to the Linux product environment, The terrible thing is that our service has been down two times in one day, I think it is due to the jOlm framework. this may be the same problem as #4.

I recommend that you deploy an API and then simulate concurrent testing, you will reproduce this error.

Could you quickly find the problem and fix it? that's important for us. Thanks!

Support JDK 1.8 in maven repository

Hey @brevilo , thanks for your bug fix!

Could you support jdk 1.8 in Maven repository? jdk 11 is a high version, many projects running on jdk 1.8, So we have to re-build jar on jdk 1.8.

thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.