Skip to content

Commit 2abe3bc

Browse files
Okapi 419 oberon_verify_token language wrappers (#420)
1 parent e03eb8a commit 2abe3bc

File tree

98 files changed

+2916
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2916
-260
lines changed

dart/lib/okapi.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class Oberon {
7474
static final _oberonUnBlindToken = OkapiNative.library
7575
.lookupFunction<OkapiFunctionNative, OkapiFunction>(
7676
'oberon_unblind_token');
77+
static final _oberonVerifyToken = OkapiNative.library
78+
.lookupFunction<OkapiFunctionNative, OkapiFunction>(
79+
'oberon_verify_token');
7780
static final _oberonVerifyProof = OkapiNative.library
7881
.lookupFunction<OkapiFunctionNative, OkapiFunction>(
7982
'oberon_verify_proof');
@@ -97,6 +100,10 @@ class Oberon {
97100
UnBlindOberonTokenRequest request) =>
98101
OkapiNative.nativeCall(
99102
_oberonUnBlindToken, request, UnBlindOberonTokenResponse());
103+
static VerifyOberonTokenResponse VerifyToken(
104+
VerifyOberonTokenRequest request) =>
105+
OkapiNative.nativeCall(
106+
_oberonVerifyToken, request, VerifyOberonTokenResponse());
100107
static VerifyOberonProofResponse VerifyProof(
101108
VerifyOberonProofRequest request) =>
102109
OkapiNative.nativeCall(

dart/lib/proto/okapi/security/v1/security.pb.dart

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/proto/okapi/security/v1/security.pbjson.dart

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/test/test-okapi.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ void main() {
4141
var result = Oberon.VerifyProof(verifyProofRequest);
4242
assert(result.valid);
4343
});
44+
test('VerifyToken', () {
45+
var rightKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1,2,3]));
46+
var wrongKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [0,1,2]));
47+
var data = Uint8List.fromList(utf8.encode('4113'));
48+
49+
var token = Oberon.CreateToken(CreateOberonTokenRequest(sk: rightKey.sk, data: data));
50+
51+
var verifyRight = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: rightKey.pk, data: data));
52+
var verifyWrong = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: wrongKey.pk, data: data));
53+
54+
assert(verifyRight.valid);
55+
assert(!verifyWrong.valid);
56+
});
4457
test('Demo With Blinding', () {
4558
var key = Oberon.CreateKey(CreateOberonKeyRequest());
4659
var data = Uint8List.fromList(utf8.encode("alice"));

docs/reference/proto/index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
- [UnBlindOberonTokenResponse](#okapi-security-v1-UnBlindOberonTokenResponse)
4949
- [VerifyOberonProofRequest](#okapi-security-v1-VerifyOberonProofRequest)
5050
- [VerifyOberonProofResponse](#okapi-security-v1-VerifyOberonProofResponse)
51+
- [VerifyOberonTokenRequest](#okapi-security-v1-VerifyOberonTokenRequest)
52+
- [VerifyOberonTokenResponse](#okapi-security-v1-VerifyOberonTokenResponse)
5153

5254
- [okapi/transport/v1/transport.proto](#okapi_transport_v1_transport-proto)
5355
- [CoreMessage](#okapi-transport-v1-CoreMessage)
@@ -648,6 +650,38 @@ Contains the status of the proof validation
648650

649651

650652

653+
654+
<a name="okapi-security-v1-VerifyOberonTokenRequest"></a>
655+
656+
### VerifyOberonTokenRequest
657+
Verify that an oberon token comes from the desired issuer
658+
659+
660+
| Field | Type | Label | Description |
661+
| ----- | ---- | ----- | ----------- |
662+
| token | [bytes](#bytes) | | raw token bytes |
663+
| pk | [bytes](#bytes) | | token is valid to this public key? |
664+
| data | [bytes](#bytes) | | public part of oberon protocol - can be any data |
665+
666+
667+
668+
669+
670+
671+
<a name="okapi-security-v1-VerifyOberonTokenResponse"></a>
672+
673+
### VerifyOberonTokenResponse
674+
Contains the verification result for the oberon token
675+
676+
677+
| Field | Type | Label | Description |
678+
| ----- | ---- | ----- | ----------- |
679+
| valid | [bool](#bool) | | token is valid to the public key |
680+
681+
682+
683+
684+
651685

652686

653687

dotnet/Library/Okapi/Native.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ internal static extern int
116116

117117
[DllImport(LibraryName, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
118118
internal static extern int oberon_unblind_token(ByteBuffer request, out ByteBuffer response, out ExternError error);
119+
120+
[DllImport(LibraryName, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
121+
internal static extern int oberon_verify_token(ByteBuffer request, out ByteBuffer response, out ExternError error);
119122

120123
#endregion
121124
}

dotnet/Library/Okapi/Oberon.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public static UnBlindOberonTokenResponse UnblindToken(UnBlindOberonTokenRequest
3333
{
3434
return Native.Call<UnBlindOberonTokenRequest, UnBlindOberonTokenResponse>(request, Native.oberon_unblind_token);
3535
}
36+
37+
public static VerifyOberonTokenResponse VerifyToken(VerifyOberonTokenRequest request)
38+
{
39+
return Native.Call<VerifyOberonTokenRequest, VerifyOberonTokenResponse>(request, Native.oberon_verify_token);
40+
}
3641
}

dotnet/Library/Okapi/Okapi.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<Protobuf Include="..\..\..\proto\okapi\keys\v1\keys.proto" Link="Protobuf/keys.proto" ProtoRoot="..\..\..\proto"/>
25-
<Protobuf Include="..\..\..\proto\okapi\transport\v1\transport.proto" Link="Protobuf/transport.proto" ProtoRoot="..\..\..\proto"/>
26-
<Protobuf Include="..\..\..\proto\okapi\proofs\v1\proofs.proto" Link="Protobuf/proofs.proto" ProtoRoot="..\..\..\proto"/>
27-
<Protobuf Include="..\..\..\proto\okapi\security\v1\security.proto" Link="Protobuf/security.proto" ProtoRoot="..\..\..\proto"/>
28-
<Protobuf Include="..\..\..\proto\pbmse\v1\pbmse.proto" Link="Protobuf/pbmse/pbmse.proto" ProtoRoot="..\..\..\proto"/>
29-
<Protobuf Include="..\..\..\proto\okapi\examples\v1\examples.proto" Link="Protobuf/examples.proto" ProtoRoot="..\..\..\proto"/>
30-
<Protobuf Include="..\..\..\proto\okapi\hashing\v1\hashing.proto" Link="Protobuf/hashing.proto" ProtoRoot="..\..\..\proto"/>
24+
<Protobuf Include="..\..\..\proto\**\*.proto" Link="Protobuf/keys.proto" ProtoRoot="..\..\..\proto"/>
3125
</ItemGroup>
3226

3327
<ItemGroup>

dotnet/Tests/Okapi.Tests/OberonTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,39 @@ public void TestDemo()
3939

4040
Assert.True(result.Valid);
4141
}
42+
43+
[Fact]
44+
public void TestVerifyToken()
45+
{
46+
var data = ByteString.CopyFromUtf8("4113");
47+
var seed = ByteString.CopyFromUtf8("123");
48+
var otherSeed = ByteString.CopyFromUtf8("012");
49+
50+
var rightKey = Oberon.CreateKey(new() {Seed = seed});
51+
var wrongKey = Oberon.CreateKey(new() {Seed = otherSeed});
52+
53+
var token = Oberon.CreateToken(new CreateOberonTokenRequest
54+
{
55+
Data = data,
56+
Sk = rightKey.Sk
57+
});
58+
59+
var rightResult = Oberon.VerifyToken(new ()
60+
{
61+
Data = data,
62+
Pk = rightKey.Pk,
63+
Token = token.Token
64+
});
65+
Assert.True(rightResult.Valid);
66+
67+
var wrongResult = Oberon.VerifyToken(new ()
68+
{
69+
Data = data,
70+
Pk = wrongKey.Pk,
71+
Token = token.Token
72+
});
73+
Assert.False(wrongResult.Valid);
74+
}
4275

4376
[Fact]
4477
public void TestDemoWithBlinding()

go/okapi/native.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func getLibraryName() string {
4444
case "windows":
4545
return "okapi.dll"
4646
case "darwin":
47-
return "/Users/scott/Documents/GitHub/okapi/libs/macos/libokapi.dylib"
47+
return "libokapi.dylib"
4848
case "linux":
4949
return "libokapi.so"
5050
default:

0 commit comments

Comments
 (0)