Giter VIP home page Giter VIP logo

paseto4j's Introduction

Java implementation of PASETO: Platform-Agnostic Security Tokens

License Quality Gate Status GitHub release java-jdk Build

Implementation of PASETO library written in Java. This library is focused on taking part of the encryption/decryption part of the tokens it has a little dependencies as possible. How you construct the tokens with which JSON library is up to you. According to the specification the payload should always be a JSON object.

Contents

What is Paseto?

Paseto is everything you love about JOSE (JWT, JWE, JWS) without any of the many design deficits that plague the JOSE standards. Paseto (Platform-Agnostic SEcurity TOkens) is a specification and reference implementation for secure stateless tokens.

Key Differences between Paseto and JWT

Unlike JSON Web Tokens (JWT), which gives developers more than enough rope with which to hang themselves, Paseto only allows secure operations. JWT gives you "algorithm agility", Paseto gives you "versioned protocols". It's incredibly unlikely that you'll be able to use Paseto in an insecure way.

Caution: Neither JWT nor Paseto were designed for stateless session management. Paseto is suitable for tamper-proof cookies, but cannot prevent replay attacks by itself

Installation

There are three version available in Maven Central.

Version 3

Version 3 is composed of NIST-approved algorithms, and will operate on tokens with the v3 version header.

Add the following dependency to your project:

<!-- https://mvnrepository.com/artifact/io.github.nbaars/paseto4j-version3 -->
<dependency>
    <groupId>io.github.nbaars</groupId>
    <artifactId>paseto4j-version3</artifactId>
    <version>${paseto4j.version}</version>
</dependency>

Version 2

Version 2 (the recommended version by the specification) is supported, this version depends on Libsodium see here on how to install this library. The Dockerfile contains an example how to install it on a Linux based system.

Add the following dependency to your project:

<!-- https://mvnrepository.com/artifact/io.github.nbaars/paseto4j-version2 -->
<dependency>
    <groupId>io.github.nbaars</groupId>
    <artifactId>paseto4j-version2</artifactId>
    <version>${paseto4j.version}</version>
</dependency>

Version 1

Add the following dependency to your project:

<!-- https://mvnrepository.com/artifact/io.github.nbaars/paseto4j-version1 -->
<dependency>
    <groupId>io.github.nbaars</groupId>
    <artifactId>paseto4j-version1</artifactId>
    <version>${paseto4j.version}</version>
</dependency>

Usage

For usage see the examples project which shows how to use Paseto4j in action.

Differences with other Java Paseto implementations

Why use this library over the other Java implementations?

  • No dependency on any JSON library. It is a lightweight library supporting the basic Paseto operations. The rest is up-to-you.
  • Easy to use API.
  • Available on Maven Central

Example usages

Development

paseto-version2 needs Libsodium to be present, to avoid installing it on your local machine, you can use the following command to build it locally:

docker build -t paseto4j .
docker run -v "${HOME}"/.m2:/root/.m2 -v "${PWD}":/workspace paseto4j ./mvnw verify     

The first command is only necessary ones, for building the Maven image.

Release

We use Calendar Versioning as version numbers. Creating a new tag and pushing it to GitHub will start the release process.

paseto4j's People

Contributors

dependabot[bot] avatar nbaars avatar paragonie-security avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

paseto4j's Issues

Add V3

We need to support V3 & V4 as well

Support BouncyCastle FIPS

Where we use BC we should support BCFIPS as a security provider.

We should be strict in the provider, if someone really wants to use BC as security provider they should be able to. It should not depend on our choice in the source code.

Update Tuweni version

New version is available which solves the SonaType report about old Guava dependency:

+- org.apache.tuweni:tuweni-crypto:jar:2.2.0:compile
[INFO] |  +- org.apache.tuweni:tuweni-io:jar:2.2.0:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.14:compile
[INFO] |  +- org.apache.tuweni:tuweni-units:jar:2.2.0:compile
[INFO] |  +- com.google.guava:guava:jar:31.0.1-jre:compile

PasetoPublicTest fails when running (say 1000) times with - The length of the signature **MUST** be 96 bytes long

Describe the bug
PasetoPublicTest fails when running (say 1000) times with the following exception being thrown


org.paseto4j.commons.PasetoException: The length of the signature **MUST** be 96 bytes long

	at org.paseto4j.commons.Conditions.verify(Conditions.java:9)
	at org.paseto4j.version3.PasetoPublic.sign(PasetoPublic.java:80)
	at org.paseto4j.version3.Paseto.sign(Paseto.java:85)
	at org.paseto4j.version3.Paseto.sign(Paseto.java:77)
	at org.paseto4j.version3.Paseto.sign(Paseto.java:70)
	at org.paseto4j.version3.PasetoPublicTest.normalUsage(PasetoPublicTest.java:114)
	at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:18)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

To Reproduce
Steps to reproduce the behavior:

  1. Go to the PasetoPublicTest
  2. Set "repeat count" of test to 1000
  3. Run the test
  4. Observe the failure

Expected behavior
No error

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • IntelliJ IDEA 2022.3.3 (Ultimate Edition)

Additional context
We are planning to use this library at Sky but with this issue, it's a showstopper

cant make token if i run my project as a jar

its like issue that people have here
spring-projects/spring-boot#28837
problem is with version 3
if u didnt undrestand what is wrong then read this:
i am making a spring boot app...there is this line in my app that work good if i run my app in intelij " Security.addProvider(new BouncyCastleProvider()); Cipher aes = Cipher.getInstance("AES/CTR/NoPadding", "BC");" but if i make a jar from my app and then try to run it then it throw this exception "Caused by: java.lang.SecurityException: JCE cannot authenticate the provider BC at java.base/javax.crypto.Cipher.getInstance(Cipher.java:723) ~[na:na] at java.base/javax.crypto.Cipher.getInstance(Cipher.java:643) ~[na:na] " how to make my code work fine when it is a jar?
by the way i am using springboot 3.0.6 and jdk 19 ... u used BouncyCastleProvider in your lib in CryptoFunction.class encryptDecrypt method line 66
and i kinda tried all dependency that i colud find here: https://mvnrepository.com/artifact/org.bouncycastle
with "provider" scope in pom.xml
and i tried this link too: https://stackoverflow.com/questions/13721579/jce-cannot-authenticate-the-provider-bc-in-java-swing-application like put security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider in java.security file
or set crypto.policy to unlimited

Use javax.security.PrivateKey and PublicKey as argument to the PrivateKey and PublicKey class wrappers

At the moment the moment both classes take a byte[] as argument:

 public PublicKey(byte[] keyMaterial, Version version) {
        super(keyMaterial, version);
    }

It is easier from a user perspective to change this to:

 public PublicKey(javax.security.PublicKey, Version version) {
        super(keyMaterial, version);
    }

this way the API is not responsible for translations, we take a valid key which the user needs to obtain from a byte[], PEM encoded string etc.

V1 Public Signed Token by paseto.js not able be verified by JAVA Public V1 verify

Hi, I am new to paseto. I recently using the paseto (javascript) and was able to sign and verify with my own private and public keys but when other people who use JAVA paseto4j to verify the signed token and it will prompts invalid signature error.
The strange thing is, I was able to verify the signed token by JAVA paseto4j with the same Javascript paseto codes.

Bind Keys to Version and Purpose

static String decrypt(byte[] key, String token, String footer) {

static String parse(byte[] publicKey, String signedMessage, String footer) throws SignatureException {

See https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/03-Algorithm-Lucidity.md

Right now, byte arrays are accepted by this API. There's no mechanism to prevent a user from using a v2 public key as a v2 local key.

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.