14
14
import java .io .IOException ;
15
15
import java .net .*;
16
16
import java .net .http .HttpResponse ;
17
+ import java .nio .ByteBuffer ;
17
18
import java .nio .charset .StandardCharsets ;
18
19
import java .security .*;
19
20
import java .time .Instant ;
20
- import java .util .Base64 ;
21
- import java .util .HashMap ;
22
- import java .util .Map ;
23
- import java .util .Objects ;
21
+ import java .util .*;
24
22
import java .util .concurrent .atomic .AtomicBoolean ;
25
23
import java .util .concurrent .atomic .AtomicReference ;
26
24
import java .util .concurrent .locks .Lock ;
@@ -37,6 +35,7 @@ public class AttestationTokenRetriever {
37
35
private final AtomicReference <String > coreJwt ;
38
36
private final Handler <Pair <Integer , String >> responseWatcher ;
39
37
private final String attestationEndpoint ;
38
+ private final byte [] encodedAttestationEndpoint ;
40
39
private final IClock clock ;
41
40
private final Vertx vertx ;
42
41
private final URLConnectionHttpClient httpClient ;
@@ -71,6 +70,7 @@ public AttestationTokenRetriever(Vertx vertx,
71
70
int attestCheckMilliseconds ) {
72
71
this .vertx = vertx ;
73
72
this .attestationEndpoint = attestationEndpoint ;
73
+ this .encodedAttestationEndpoint = this .encodeStringUnicodeAttestationEndpoint (attestationEndpoint );
74
74
this .clientApiToken = clientApiToken ;
75
75
this .appVersion = appVersion ;
76
76
this .attestationProvider = attestationProvider ;
@@ -153,7 +153,7 @@ public void attest() throws IOException, AttestationTokenRetrieverException {
153
153
KeyPair keyPair = generateKeyPair ();
154
154
byte [] publicKey = keyPair .getPublic ().getEncoded ();
155
155
JsonObject requestJson = JsonObject .of (
156
- "attestation_request" , Base64 .getEncoder ().encodeToString (attestationProvider .getAttestationRequest (publicKey )),
156
+ "attestation_request" , Base64 .getEncoder ().encodeToString (attestationProvider .getAttestationRequest (publicKey , this . encodedAttestationEndpoint )),
157
157
"public_key" , Base64 .getEncoder ().encodeToString (publicKey ),
158
158
"application_name" , appVersion .getAppName (),
159
159
"application_version" , appVersion .getAppVersion ()
@@ -289,4 +289,10 @@ private void notifyResponseWatcher(int statusCode, String responseBody) {
289
289
public boolean attested () {
290
290
return this .attestationToken .get () != null && this .clock .now ().isBefore (this .attestationTokenExpiresAt );
291
291
}
292
+
293
+ private byte [] encodeStringUnicodeAttestationEndpoint (String data ) {
294
+ // buffer.array() may include extra empty bytes at the end. This returns only the bytes that have data
295
+ ByteBuffer buffer = StandardCharsets .UTF_8 .encode (data );
296
+ return Arrays .copyOf (buffer .array (), buffer .limit ());
297
+ }
292
298
}
0 commit comments