Skip to content

Commit

Permalink
Add type to KBS json.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed Jan 27, 2020
1 parent 1d9fff3 commit ba6e1ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static KeyBackupRequest createKeyBackupRequest(byte[] kbsAccessKey,

Request requestData = Request.newBuilder().setBackup(backupRequest).build();

return createKeyBackupRequest(requestData, remoteAttestation);
return createKeyBackupRequest(requestData, remoteAttestation, "backup");
}

public static KeyBackupRequest createKeyRestoreRequest(byte[] kbsAccessKey,
Expand All @@ -66,7 +66,7 @@ public static KeyBackupRequest createKeyRestoreRequest(byte[] kbsAccessKey,

Request request = Request.newBuilder().setRestore(restoreRequest).build();

return createKeyBackupRequest(request, remoteAttestation);
return createKeyBackupRequest(request, remoteAttestation, "restore");
}

public static KeyBackupRequest createKeyDeleteRequest(TokenResponse token,
Expand All @@ -80,7 +80,7 @@ public static KeyBackupRequest createKeyDeleteRequest(TokenResponse token,

Request request = Request.newBuilder().setDelete(deleteRequest).build();

return createKeyBackupRequest(request, remoteAttestation);
return createKeyBackupRequest(request, remoteAttestation, "delete");
}

public static BackupResponse getKeyBackupResponse(KeyBackupResponse response, RemoteAttestation remoteAttestation)
Expand Down Expand Up @@ -109,13 +109,13 @@ public static DeleteResponse getKeyDeleteResponseStatus(KeyBackupResponse respon
return DeleteResponse.parseFrom(data);
}

private static KeyBackupRequest createKeyBackupRequest(Request requestData, RemoteAttestation remoteAttestation) {
private static KeyBackupRequest createKeyBackupRequest(Request requestData, RemoteAttestation remoteAttestation, String type) {
byte[] clientKey = remoteAttestation.getKeys().getClientKey();
byte[] aad = remoteAttestation.getRequestId();

AESCipher.AESEncryptedResult aesEncryptedResult = AESCipher.encrypt(clientKey, aad, requestData.toByteArray());

return new KeyBackupRequest(aesEncryptedResult.aad, aesEncryptedResult.iv, aesEncryptedResult.data, aesEncryptedResult.mac);
return new KeyBackupRequest(aesEncryptedResult.aad, aesEncryptedResult.iv, aesEncryptedResult.data, aesEncryptedResult.mac, type);
}

private static byte[] decryptData(KeyBackupResponse response, RemoteAttestation remoteAttestation) throws InvalidCiphertextException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ public class KeyBackupRequest {
@JsonProperty
private byte[] mac;

@JsonProperty
private String type;

public KeyBackupRequest() {
}

public KeyBackupRequest(byte[] requestId, byte[] iv, byte[] data, byte[] mac) {
this.requestId = requestId;
this.iv = iv;
this.data = data;
this.mac = mac;
public KeyBackupRequest(byte[] requestId, byte[] iv, byte[] data, byte[] mac, String type) {
this.requestId = requestId;
this.iv = iv;
this.data = data;
this.mac = mac;
this.type = type;
}

public byte[] getRequestId() {
Expand All @@ -44,8 +48,12 @@ public byte[] getMac() {
return mac;
}

public String getType() {
return type;
}

public String toString() {
return "{ requestId: " + Hex.toString(requestId) + ", iv: " + Hex.toString(iv) + ", data: " + Hex.toString(data) + ", mac: " + Hex.toString(mac) + "}";
return "{ type:" + type + ", requestId: " + Hex.toString(requestId) + ", iv: " + Hex.toString(iv) + ", data: " + Hex.toString(data) + ", mac: " + Hex.toString(mac) + "}";
}

}

0 comments on commit ba6e1ab

Please sign in to comment.