Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
362 commits
Select commit Hold shift + click to select a range
777e230
Move constructors to conventional location
ghubstan Sep 17, 2024
cb4cfec
Suppress 'unchecked assignment' warnings
ghubstan Sep 17, 2024
23dee6c
Optimize imports, suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 17, 2024
7a88757
Make class level fields 'final' (immutable)
ghubstan Sep 17, 2024
6bcefbb
Annotate 'unused' param, and suppress warning
ghubstan Sep 17, 2024
4eb9d96
Apply auto-formatting
ghubstan Sep 17, 2024
59a6c80
Add TODO comment about all-caps enum defs
ghubstan Sep 17, 2024
198cfcc
Make class level fields 'final' (immutable)
ghubstan Sep 17, 2024
fcb2309
Apply auto-formatting
ghubstan Sep 17, 2024
912f256
Be consistent about placement of static modifier
ghubstan Sep 17, 2024
8bb181c
Suppress StringBufferReplaceableByString warning
ghubstan Sep 17, 2024
cfac8cb
Follow camelCase method name convention in SymbolTable.java
ghubstan Sep 17, 2024
d3ef35c
Fix syntax and field/method/constructor ordering problems
ghubstan Sep 17, 2024
00c46f7
Use ALL_CAPS naming convention for static final fields
ghubstan Sep 17, 2024
e8400b0
Adjust placement of 'final' modifier
ghubstan Sep 17, 2024
ac9915a
Adjust comment
ghubstan Sep 17, 2024
c68938e
Make immutable class level fields 'final', remove redundant cast
ghubstan Sep 17, 2024
da204ae
Follow camelCase method name convention in TemporarySymbolTable.java
ghubstan Sep 17, 2024
0ee654a
Use camelCase method name in Term.java
ghubstan Sep 17, 2024
cea0eca
Apply auto-formatting
ghubstan Sep 17, 2024
c343534
Suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 17, 2024
4e5d7e9
Use camelCase method names in World.java
ghubstan Sep 17, 2024
9874f2f
Move constuctors to appropiate location, apply auto-formatting
ghubstan Sep 17, 2024
fc7dfed
Remove extra blank line
ghubstan Sep 17, 2024
22c7209
Use chained str-buffer 'append' calls
ghubstan Sep 17, 2024
99cb9d5
Use chained str-buffer 'append' calls
ghubstan Sep 17, 2024
ea1e6e7
Suppress unchecked assignment warnings
ghubstan Sep 17, 2024
f521e56
Use camelCase method name in Error.java, adjust affecte TestCase
ghubstan Sep 18, 2024
d27762d
Apply auto-formatting
ghubstan Sep 18, 2024
56d603e
Make immutable class level fields 'final'
ghubstan Sep 18, 2024
bfd9870
Delete unnecessary hashCode() impl
ghubstan Sep 18, 2024
a564147
Auto-rearrange inner classes
ghubstan Sep 18, 2024
b329c85
Use camelCase field and param names in FailedCheck.java
ghubstan Sep 18, 2024
75267bd
Apply auto-formatting
ghubstan Sep 18, 2024
3c99cd1
Use camelCase field and param names in FailedCheck.java
ghubstan Sep 18, 2024
b3410fd
Make immutable class level fields 'final'
ghubstan Sep 18, 2024
79b66c5
Use 'equals()' for Java string comparisons
ghubstan Sep 18, 2024
4e81cf5
Remove redundant comparison
ghubstan Sep 18, 2024
de254e4
Rearrange (normalize) placement of hashCode() implementations
ghubstan Sep 18, 2024
39d3d2a
Use camelCase field and param names
ghubstan Sep 18, 2024
757d32f
Delete unnecesary method
ghubstan Sep 18, 2024
4bcad81
Remove blank line
ghubstan Sep 18, 2024
07ceebf
Add TODO comment about probable bug
ghubstan Sep 18, 2024
32ff42f
Apply auto-formatting
ghubstan Sep 18, 2024
bfe3e7d
Rearrange methods via default IDE code style settings
ghubstan Sep 18, 2024
88edb36
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
9d3b940
Auto-arrange method placement
ghubstan Sep 19, 2024
62be498
Add braces to if statements (as per convention), let Objects.equals(a…
ghubstan Sep 19, 2024
cf09b64
Use camelCase method names in ExpressionParser.java
ghubstan Sep 19, 2024
e7e77c9
Replace 's.length() == 0' with s.isEmpt()
ghubstan Sep 19, 2024
ca3bafb
Apply auto-formatting
ghubstan Sep 19, 2024
760d9a4
Auto-arrange methods (by name, alphanumerically)
ghubstan Sep 19, 2024
e390047
Suppress 'unused' method warning
ghubstan Sep 19, 2024
ef51c1f
Remove unused import, local variables
ghubstan Sep 19, 2024
d56cf18
Remove redundant boolean initializer
ghubstan Sep 19, 2024
82f9fca
Remove unused local variable
ghubstan Sep 19, 2024
80a8acf
Remove unecessary explicit type arguments
ghubstan Sep 19, 2024
d588b2b
Remove unecessary explicit type arguments
ghubstan Sep 19, 2024
81e374e
Remove unecessary explicit type arguments
ghubstan Sep 19, 2024
ed887bc
Use camelCase method names in Parser.java
ghubstan Sep 19, 2024
19e00f5
Use s.isEmpty()
ghubstan Sep 19, 2024
5ae845c
Suppress 'unused' param warning
ghubstan Sep 19, 2024
cdeef08
Remove unused local variable
ghubstan Sep 19, 2024
d75279b
Simplify boolean statement; s already guaranteed notEmpty
ghubstan Sep 19, 2024
b277d6d
Remove unecessary explicit type arguments
ghubstan Sep 19, 2024
ef12fb6
Apply auto-formatting
ghubstan Sep 19, 2024
25a29e6
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
2955358
Remove blank line
ghubstan Sep 19, 2024
a999380
Use camelCase method & variable names in Biscuit.java
ghubstan Sep 19, 2024
a745e0d
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
e4c2a89
Change param name
ghubstan Sep 19, 2024
3666608
Suppress 'unused' method warnings
ghubstan Sep 19, 2024
ba350b0
Apply auto-formatting
ghubstan Sep 19, 2024
e656d54
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
ae60a91
Use camelCase variable name
ghubstan Sep 19, 2024
9f922af
Use camelCase method & variable names in Block.java
ghubstan Sep 19, 2024
49ba035
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
76d2515
Suppress 'unused' method warnings; can be a reminder for new unit tests
ghubstan Sep 19, 2024
5d27e50
Use List.of(for-only-one-arg) -- a list init perf optimization
ghubstan Sep 19, 2024
d63d157
Simplify boolean exp; empty array lists are never null
ghubstan Sep 19, 2024
de950d1
Use camelCase variable name
ghubstan Sep 19, 2024
922e713
Apply auto-formatter
ghubstan Sep 19, 2024
cfd775e
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
0b5f0a2
Use camelCase method name
ghubstan Sep 19, 2024
865d0df
Make immutable class level field 'final'
ghubstan Sep 19, 2024
360a4e6
Replace lambda with method ref
ghubstan Sep 19, 2024
b4c9004
Use static import
ghubstan Sep 19, 2024
1f05101
Remove unused import
ghubstan Sep 19, 2024
0082c4f
Let Objects.equals() take care of null checks
ghubstan Sep 19, 2024
b336a5f
Apply auto-formatter
ghubstan Sep 19, 2024
e83ac0f
Apply auto-arrange (methods)
ghubstan Sep 19, 2024
57ab8d2
Use static import
ghubstan Sep 19, 2024
8e37b3c
Remove unecessary explicit type argument
ghubstan Sep 19, 2024
b948045
Let Objects.equals() take care of null checks
ghubstan Sep 19, 2024
0c0a4b8
Remove unused local variable
ghubstan Sep 19, 2024
f6544e1
Use camelCase method name
ghubstan Sep 19, 2024
4365873
Add TODO comment about java/protobuf enum naming convention
ghubstan Sep 19, 2024
9177fd0
Apply auto-formatting
ghubstan Sep 19, 2024
e2b52fe
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
05c7d82
Use conventional java variable names (no underscore)
ghubstan Sep 19, 2024
25f8d5d
Use static import
ghubstan Sep 19, 2024
608a57a
Suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 19, 2024
9ed7ee4
Use conventional java variable names (no underscore)
ghubstan Sep 19, 2024
a4f0d02
Let Objects.equals() take care of null checks
ghubstan Sep 19, 2024
057c51a
Remove unnecessary explicit type argument
ghubstan Sep 19, 2024
5fcb563
Optimize HashMap constructor call
ghubstan Sep 19, 2024
ab4ac89
Delete unused import
ghubstan Sep 19, 2024
cd06fbb
Replace lambda with method ref
ghubstan Sep 19, 2024
db95745
Replace statement lambda with expression lambda
ghubstan Sep 19, 2024
8aa6c06
Suppress unused method warnings
ghubstan Sep 19, 2024
80ae911
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
f147bd6
Get rid of redundant variable 'm'
ghubstan Sep 19, 2024
fe3a18c
Replace lambda with method ref
ghubstan Sep 19, 2024
272a77f
Use camelCase method name
ghubstan Sep 19, 2024
bf9774a
Apply auto-formatting
ghubstan Sep 19, 2024
0a49258
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
c2fa42d
Use static import
ghubstan Sep 19, 2024
cef208b
Use camelCase method name
ghubstan Sep 19, 2024
cfd34cb
Let Objects.equals() take care of null checks
ghubstan Sep 19, 2024
f4324a6
Make immutable class level field 'final'
ghubstan Sep 19, 2024
8b63656
Suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 19, 2024
11c83ff
Remove empty string concatenation
ghubstan Sep 19, 2024
b87b638
Use static import
ghubstan Sep 19, 2024
7eb5be9
Replace lambda with method ref
ghubstan Sep 19, 2024
e515ffb
Remove unnecessary explicit type argument
ghubstan Sep 19, 2024
34f139c
Suppress 'unused' method warnings
ghubstan Sep 19, 2024
f11df0e
Apply auto-formatting
ghubstan Sep 19, 2024
db61ac3
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
1bc7bd5
Use camelCase method & variable, remove underscores from var names
ghubstan Sep 19, 2024
7062894
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
b4155c7
Suppress 'unused' method warning
ghubstan Sep 19, 2024
f0fdee9
Suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 19, 2024
fbcf89c
Replace lambdas with method refs
ghubstan Sep 19, 2024
28669dc
Use static imports
ghubstan Sep 19, 2024
85c3495
Replace addAll() with parameterized constructor call
ghubstan Sep 19, 2024
1ab1217
Let Objects.equals() take care of null checks
ghubstan Sep 19, 2024
b2e1a1e
Apply auto-formatting
ghubstan Sep 19, 2024
3fa3e74
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
b7cc5b3
Add TODO comment regarding Java & Protobuf enum naming convention
ghubstan Sep 19, 2024
baa8c78
Use camelCase method name
ghubstan Sep 19, 2024
19aeedf
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
afc8423
Add null check to @Nullable publicKey
ghubstan Sep 19, 2024
3ae1f9a
Inline value Kind when is always same value
ghubstan Sep 19, 2024
90db873
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
cba8b15
Normalize placement of 'abstract' modifier
ghubstan Sep 19, 2024
21f4a98
Use camelCase method name
ghubstan Sep 19, 2024
2b750b6
Suppress unused method warnings
ghubstan Sep 19, 2024
46bbd01
Apply auto-formatting
ghubstan Sep 19, 2024
b70cf59
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
0eb2321
Use camelCase method & param names in Utils, adjust affected classes
ghubstan Sep 19, 2024
041c289
Apply auto-formatter
ghubstan Sep 19, 2024
46be3d7
Remove unnecessary throws declaration
ghubstan Sep 19, 2024
cb98d0c
Delete unused import
ghubstan Sep 19, 2024
f430714
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
b6bff34
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
14e08fa
Apply auto-formatting; reorganize imports
ghubstan Sep 19, 2024
296516b
Move SerBiscuit constructors to top, use camelCase method & var names
ghubstan Sep 19, 2024
755a787
Use camelCase variable name
ghubstan Sep 19, 2024
578afc1
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
2a923e1
Suppress 'unused' method warnings
ghubstan Sep 19, 2024
91cc8b7
Suppress MismatchedQueryAndUpdateOfCollection warning
ghubstan Sep 19, 2024
4e15aee
Make list population less verbose
ghubstan Sep 19, 2024
46b9da5
Suppress multiple Javadoc warnings
ghubstan Sep 19, 2024
f67f57c
Remove unnecessary boxing
ghubstan Sep 19, 2024
5e91612
Apply auto-formatting
ghubstan Sep 19, 2024
a010086
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 19, 2024
8432a2e
Put params on separate lines
ghubstan Sep 19, 2024
c7b3a12
Use static import
ghubstan Sep 19, 2024
bf17e18
Use static import
ghubstan Sep 19, 2024
4eb8c3c
Reduce line length
ghubstan Sep 19, 2024
a974622
Remove extra blank lines
ghubstan Sep 19, 2024
6f0adb6
Remove unused import
ghubstan Sep 19, 2024
94d3c09
Normalized placement of 'static' modifier
ghubstan Sep 19, 2024
776ed75
Make immutable class level fields 'final'
ghubstan Sep 19, 2024
134cff5
Apply auto-formatting; rearrange imports
ghubstan Sep 19, 2024
45bf5be
Use camelCase method & variable names in Authorizer.java
ghubstan Sep 20, 2024
c744215
Make immutable class level fields 'final'
ghubstan Sep 20, 2024
402bd8a
Remove redundant toString() call
ghubstan Sep 20, 2024
a7b50eb
Remove unnecessary throws declaration
ghubstan Sep 20, 2024
795cd6f
Suppress MethodDoesntCallSuperMethod warning
ghubstan Sep 20, 2024
1ad44fd
Use chained 'append()' calls
ghubstan Sep 20, 2024
edd624b
Remove redundant cast
ghubstan Sep 20, 2024
8960c52
Suppress Javadoc warnings
ghubstan Sep 20, 2024
89a81f4
Replace stream().forEach() with forEach()
ghubstan Sep 20, 2024
94f6588
Replace lambda with method ref
ghubstan Sep 20, 2024
81f85d3
Delete unused import
ghubstan Sep 20, 2024
9c0a118
Replace statement lambda with expression lambda
ghubstan Sep 20, 2024
869785e
Suppress unused method warnings
ghubstan Sep 20, 2024
1673520
Apply auto-formatter
ghubstan Sep 20, 2024
2b16514
Auto-arrange methods by visibility, then name (alphanumerically)
ghubstan Sep 20, 2024
5a219d5
Normalize placement of 'static' modifier
ghubstan Sep 20, 2024
5da9aa9
Reduce line length(s)
ghubstan Sep 20, 2024
45d2a71
Use more descriptive (idiomatic) datalog & builder type variable names
ghubstan Sep 20, 2024
48db41d
Merge pull request #5 from biscuit-auth/master
ghubstan Dec 23, 2024
f324f5e
Merge branch 'biscuit-auth:master' into in-the-idiom
ghubstan Dec 23, 2024
1114320
Use idiomatic Java variable names, shorten some line lengths
ghubstan Dec 31, 2024
9e4365b
Use idiomatic method names
ghubstan Dec 31, 2024
b36f47a
Remove unnecessary exceptions from throws list
ghubstan Dec 31, 2024
5ac3609
Refactor out some duplicated code blocks
ghubstan Dec 31, 2024
bd0d75d
Normalize placement of 'static' modifier
ghubstan Dec 31, 2024
98c75db
Apply auto-formatting; rearrange imports
ghubstan Dec 31, 2024
cce3e15
Suppress javadoc warnings
ghubstan Dec 31, 2024
0a050ab
Fix grammar
ghubstan Dec 31, 2024
5a13930
Replace iteration with Collection 'addAll()' call
ghubstan Dec 31, 2024
606c0b2
Improve performance with parameterized constructor
ghubstan Dec 31, 2024
c5324ff
Remove unused variable 'c'
ghubstan Dec 31, 2024
924f961
Remove duplicated serialize() method in subclass
ghubstan Dec 31, 2024
a4b45d7
Remove duplicated serializeB64Url() method from superclass
ghubstan Dec 31, 2024
c7630b1
Disambiguate identically named private and public method names
ghubstan Dec 31, 2024
3ffd934
Suppress javadoc warnings
ghubstan Dec 31, 2024
126eba3
Use Collection 'addAll()' instead of iteration
ghubstan Dec 31, 2024
28ec242
Remove unnecessary boxing
ghubstan Dec 31, 2024
5fcd1b4
Delete unnecessary clone() method, add comments about deprecating met…
ghubstan Dec 31, 2024
7f245d2
Add comment about deprecating unused variable
ghubstan Dec 31, 2024
a5d5cbf
Use idiomatic variable & method names, and
ghubstan Jan 1, 2025
eb1c534
Apply auto-formatting, optimize imports
ghubstan Jan 1, 2025
72934d9
Supress javadoc warnings
ghubstan Jan 1, 2025
741ae80
Use enhanced for loop
ghubstan Jan 1, 2025
2bc0007
Suppress 'unused' warnings
ghubstan Jan 1, 2025
ca3b747
Use chained 'append' calls
ghubstan Jan 1, 2025
1a84a63
Suppress unused param warning
ghubstan Jan 1, 2025
0d9163b
Replace lambda with method reference
ghubstan Jan 1, 2025
c5449c8
Make Kind field 'final'
ghubstan Jan 1, 2025
8c8091c
Suppress unused constructor warning
ghubstan Jan 1, 2025
1d7f1c6
Use static import
ghubstan Jan 1, 2025
3b84dca
Use java ALL_CAPS convention for enums
ghubstan Jan 1, 2025
b645402
Use camelCase variable & method names
ghubstan Jan 1, 2025
cc7d55e
Suppress unused method warnings
ghubstan Jan 1, 2025
37a0481
Auto-format java doc comments
ghubstan Jan 1, 2025
c1c152c
Rename ByteArrayOutputStream var (there are so many stream types)
ghubstan Jan 7, 2025
79fe050
Remove unused imports
ghubstan Jan 7, 2025
7379da4
Remove unnecessary throws declaration
ghubstan Jan 7, 2025
17f3d1e
Remove unnecessary throws declaration
ghubstan Jan 7, 2025
ce4a04e
Use final modifier on immutable class fields
ghubstan Jan 7, 2025
97e96e8
Normalize java variable names, dismabiguate SymbolTable from Symbol
ghubstan Jan 7, 2025
a226f07
Apply auto-formatting
ghubstan Jan 7, 2025
0f1051f
Remove unnecessary throws declaration
ghubstan Jan 7, 2025
ad45fa5
Remove unnecessary throws declaration
ghubstan Jan 7, 2025
785018e
Use final modifier on immutable class field
ghubstan Jan 7, 2025
f5f69b9
Remove unnecessary boxing
ghubstan Jan 7, 2025
2fa6bae
Shorten method signature line length
ghubstan Jan 7, 2025
677baae
Add 'unused' method annotations
ghubstan Jan 7, 2025
6745d7f
Disambiguate SymbolTable(s) from Symbol(s)
ghubstan Jan 7, 2025
eb47d61
Change method name symbols() to symbolTable()
ghubstan Jan 7, 2025
569382b
Normalize (camelCase) method name: toBytes()
ghubstan Jan 7, 2025
acd961b
Adjust method name change in prev commit
ghubstan Jan 7, 2025
338e75b
Formatting
ghubstan Jan 7, 2025
18a208d
Adjust to method name change to_bytes() -> toBytes()
ghubstan Jan 7, 2025
f332b8a
Normalize (camelCase) some variable names
ghubstan Jan 7, 2025
a502ba6
Merge pull request #6 from ghubstan/in-the-idiom
ghubstan Jan 7, 2025
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This API implements [Biscuit 2.0](https://www.biscuitsec.org/blog/biscuit-2-0/).

## Usage

```java
```xml
<!-- https://mvnrepository.com/artifact/org.biscuitsec/biscuit -->
<dependency>
<groupId>org.biscuitsec</groupId>
Expand All @@ -25,7 +25,7 @@ This API implements [Biscuit 2.0](https://www.biscuitsec.org/blog/biscuit-2-0/).
### Requirements

* JDK v11
* the Protobuf compiler command `protoc` v3+ is required in `$PATH`.
* The Protobuf compiler binary `protoc` v3+ is required in `$PATH`.

### Build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
* Tokens can carry a root key id, that can be used to indicate which key will verify it.
*/
public interface KeyDelegate {
public Option<PublicKey> root_key(Option<Integer> key_id);
Option<PublicKey> rootKey(Option<Integer> keyId);
}
32 changes: 16 additions & 16 deletions src/main/java/org/biscuitsec/biscuit/crypto/KeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import biscuit.format.schema.Schema;
import biscuit.format.schema.Schema.PublicKey.Algorithm;
import net.i2p.crypto.eddsa.EdDSAEngine;
import org.biscuitsec.biscuit.token.builder.Utils;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
import net.i2p.crypto.eddsa.spec.*;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;
import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;
import org.biscuitsec.biscuit.token.builder.Utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -18,12 +21,9 @@
* Private and public key
*/
public final class KeyPair {
public final EdDSAPrivateKey private_key;
public final EdDSAPublicKey public_key;
public final EdDSAPrivateKey privateKey;
public final EdDSAPublicKey publicKey;

private static final int ED25519_PUBLIC_KEYSIZE = 32;
private static final int ED25519_PRIVATE_KEYSIZE = 64;
private static final int ED25519_SEED_SIZE = 32;
public static final EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);

public KeyPair() {
Expand All @@ -40,8 +40,8 @@ public KeyPair(final SecureRandom rng) {
EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKey.getA(), ed25519);
EdDSAPublicKey pubKey = new EdDSAPublicKey(pubKeySpec);

this.private_key = privKey;
this.public_key = pubKey;
this.privateKey = privKey;
this.publicKey = pubKey;
}

public static KeyPair generate(Algorithm algorithm) {
Expand All @@ -65,7 +65,7 @@ public static Signature generateSignature(Algorithm algorithm) throws NoSuchAlgo
}

public byte[] toBytes() {
return this.private_key.getSeed();
return this.privateKey.getSeed();
}

public KeyPair(byte[] b) {
Expand All @@ -75,8 +75,8 @@ public KeyPair(byte[] b) {
EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKey.getA(), ed25519);
EdDSAPublicKey pubKey = new EdDSAPublicKey(pubKeySpec);

this.private_key = privKey;
this.public_key = pubKey;
this.privateKey = privKey;
this.publicKey = pubKey;
}

public String toHex() {
Expand All @@ -92,15 +92,15 @@ public KeyPair(String hex) {
EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKey.getA(), ed25519);
EdDSAPublicKey pubKey = new EdDSAPublicKey(pubKeySpec);

this.private_key = privKey;
this.public_key = pubKey;
this.privateKey = privKey;
this.publicKey = pubKey;
}

public static Signature getSignature() throws NoSuchAlgorithmException {
return new EdDSAEngine(MessageDigest.getInstance(ed25519.getHashAlgorithm()));
}

public PublicKey public_key() {
return new PublicKey(Schema.PublicKey.Algorithm.Ed25519, this.public_key);
public PublicKey publicKey() {
return new PublicKey(Schema.PublicKey.Algorithm.Ed25519, this.publicKey);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/biscuitsec/biscuit/crypto/PublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class PublicKey {
public final EdDSAPublicKey key;
public final Algorithm algorithm;

public PublicKey(Algorithm algorithm, EdDSAPublicKey public_key) {
this.key = public_key;
public PublicKey(Algorithm algorithm, EdDSAPublicKey publicKey) {
this.key = publicKey;
this.algorithm = algorithm;
}

Expand Down
74 changes: 40 additions & 34 deletions src/main/java/org/biscuitsec/biscuit/crypto/Token.java
Original file line number Diff line number Diff line change
@@ -1,100 +1,106 @@
package org.biscuitsec.biscuit.crypto;

import org.biscuitsec.biscuit.error.Error;
import io.vavr.control.Either;
import net.i2p.crypto.eddsa.EdDSAEngine;
import org.biscuitsec.biscuit.error.Error;
import org.biscuitsec.biscuit.error.Error.FormatError.Signature.InvalidSignature;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.*;
import java.util.ArrayList;

import static io.vavr.API.Left;
import static io.vavr.API.Right;
import static java.nio.ByteOrder.LITTLE_ENDIAN;

class Token {
final class Token {
public final ArrayList<byte[]> blocks;
public final ArrayList<PublicKey> keys;
public final ArrayList<byte[]> signatures;
public final KeyPair next;

public Token(KeyPair rootKeyPair, byte[] message, KeyPair next) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
public Token(KeyPair rootKeyPair, byte[] message, KeyPair next)
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
Signature sgr = new EdDSAEngine(MessageDigest.getInstance(KeyPair.ed25519.getHashAlgorithm()));
ByteBuffer algo_buf = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
algo_buf.putInt(Integer.valueOf(next.public_key().algorithm.getNumber()));
algo_buf.flip();
sgr.initSign(rootKeyPair.private_key);
ByteBuffer algoBuf = ByteBuffer.allocate(4).order(LITTLE_ENDIAN);
algoBuf.putInt(next.publicKey().algorithm.getNumber());
algoBuf.flip();
sgr.initSign(rootKeyPair.privateKey);
sgr.update(message);
sgr.update(algo_buf);
sgr.update(next.public_key().toBytes());
sgr.update(algoBuf);
sgr.update(next.publicKey().toBytes());

byte[] signature = sgr.sign();

this.blocks = new ArrayList<>();
this.blocks.add(message);
this.keys = new ArrayList<>();
this.keys.add(next.public_key());
this.keys.add(next.publicKey());
this.signatures = new ArrayList<>();
this.signatures.add(signature);
this.next = next;
}

public Token(final ArrayList<byte[]> blocks, final ArrayList<PublicKey> keys, final ArrayList<byte[]> signatures,
public Token(final ArrayList<byte[]> blocks,
final ArrayList<PublicKey> keys,
final ArrayList<byte[]> signatures,
final KeyPair next) {
this.signatures = signatures;
this.blocks = blocks;
this.keys = keys;
this.next = next;
}

public Token append(KeyPair keyPair, byte[] message) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException {
public Token append(KeyPair keyPair, byte[] message)
throws NoSuchAlgorithmException, SignatureException, InvalidKeyException {
Signature sgr = new EdDSAEngine(MessageDigest.getInstance(KeyPair.ed25519.getHashAlgorithm()));
sgr.initSign(this.next.private_key);
ByteBuffer algo_buf = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
algo_buf.putInt(Integer.valueOf(next.public_key().algorithm.getNumber()));
algo_buf.flip();
sgr.initSign(this.next.privateKey);
ByteBuffer algoBuf = ByteBuffer.allocate(4).order(LITTLE_ENDIAN);
algoBuf.putInt(next.publicKey().algorithm.getNumber());
algoBuf.flip();
sgr.update(message);
sgr.update(algo_buf);
sgr.update(keyPair.public_key().toBytes());
sgr.update(algoBuf);
sgr.update(keyPair.publicKey().toBytes());

byte[] signature = sgr.sign();

Token token = new Token(this.blocks, this.keys, this.signatures, keyPair);
token.blocks.add(message);
token.signatures.add(signature);
token.keys.add(keyPair.public_key());
token.keys.add(keyPair.publicKey());

return token;
}

// FIXME: rust version returns a Result<(), error::Signature>
public Either<Error, Void> verify(PublicKey root) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
PublicKey current_key = root;
for(int i = 0; i < this.blocks.size(); i++) {
public Either<Error, Void> verify(PublicKey root)
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
PublicKey currentKey = root;
for (int i = 0; i < this.blocks.size(); i++) {
byte[] block = this.blocks.get(i);
PublicKey next_key = this.keys.get(i);
PublicKey nextKey = this.keys.get(i);
byte[] signature = this.signatures.get(i);

Signature sgr = new EdDSAEngine(MessageDigest.getInstance(KeyPair.ed25519.getHashAlgorithm()));
ByteBuffer algo_buf = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
algo_buf.putInt(Integer.valueOf(next.public_key().algorithm.getNumber()));
algo_buf.flip();
sgr.initVerify(current_key.key);
ByteBuffer algoBuf = ByteBuffer.allocate(4).order(LITTLE_ENDIAN);
algoBuf.putInt(next.publicKey().algorithm.getNumber());
algoBuf.flip();
sgr.initVerify(currentKey.key);
sgr.update(block);
sgr.update(algo_buf);
sgr.update(next_key.toBytes());
sgr.update(algoBuf);
sgr.update(nextKey.toBytes());

if (sgr.verify(signature)) {
current_key = next_key;
currentKey = nextKey;
} else {
return Left(new Error.FormatError.Signature.InvalidSignature("signature error: Verification equation was not satisfied"));
return Left(new InvalidSignature("signature error: Verification equation was not satisfied"));
}
}

if(this.next.public_key == current_key.key) {
if (this.next.publicKey == currentKey.key) {
return Right(null);
} else {
return Left(new Error.FormatError.Signature.InvalidSignature("signature error: Verification equation was not satisfied"));
return Left(new InvalidSignature("signature error: Verification equation was not satisfied"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TokenSignature(final SecureRandom rng, KeyPair keypair, byte[] message) {
ArrayList<RistrettoElement> l = new ArrayList<>();
l.add(A);
Scalar d = hash_points(l);
Scalar e = hash_message(keypair.public_key, message);
Scalar e = hash_message(keypair.publicKey, message);

Scalar z = r.multiply(d).subtract(e.multiply(keypair.private_key));

Expand All @@ -43,7 +43,7 @@ public TokenSignature sign(final SecureRandom rng, KeyPair keypair, byte[] messa
ArrayList<RistrettoElement> l = new ArrayList<>();
l.add(A);
Scalar d = hash_points(l);
Scalar e = hash_message(keypair.public_key, message);
Scalar e = hash_message(keypair.publicKey, message);

Scalar z = r.multiply(d).subtract(e.multiply(keypair.private_key));

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/biscuitsec/biscuit/datalog/Check.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.biscuitsec.biscuit.datalog;

import biscuit.format.schema.Schema;
import org.biscuitsec.biscuit.error.Error;
import io.vavr.control.Either;
import org.biscuitsec.biscuit.error.Error;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -45,8 +45,8 @@ public Schema.CheckV2 serialize() {
break;
}

for(int i = 0; i < this.queries.size(); i++) {
b.addQueries(this.queries.get(i).serialize());
for (Rule query : this.queries) {
b.addQueries(query.serialize());
}

return b.build();
Expand All @@ -57,20 +57,18 @@ static public Either<Error.FormatError, Check> deserializeV2(Schema.CheckV2 chec

Kind kind;
switch (check.getKind()) {
case One:
kind = Kind.One;
break;
case All:
kind = Kind.All;
break;
case One:
default:
kind = Kind.One;
break;
}

for (Schema.RuleV2 query: check.getQueriesList()) {
for (Schema.RuleV2 query : check.getQueriesList()) {
Either<Error.FormatError, Rule> res = Rule.deserializeV2(query);
if(res.isLeft()) {
if (res.isLeft()) {
Error.FormatError e = res.getLeft();
return Left(e);
} else {
Expand Down
Loading