Skip to content

Commit

Permalink
Move temporary key ID to request body
Browse files Browse the repository at this point in the history
  • Loading branch information
petrdvorak committed Aug 5, 2024
1 parent 65bbe7a commit 3c634c4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public EncryptedRequest encryptRequest(byte[] data) throws EncryptorException {
}

return new EncryptedRequest(
encryptorParameters.getTemporaryKeyId(),
base64Encoder.encodeToString(eciesCryptogram.getEphemeralPublicKey()),
base64Encoder.encodeToString(eciesCryptogram.getEncryptedData()),
base64Encoder.encodeToString(eciesCryptogram.getMac()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@Data
@AllArgsConstructor
public class EncryptedRequest {
private String temporaryKeyId;
private String ephemeralPublicKey;
private String encryptedData;
private String mac;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ private EncryptedResponse copyResponse(EncryptedResponse response) {
* Make new instance of encrypted request object with identical values copied from the provided object.
* @param request Request object to copy.
* @return Copy of provided request object.
*/ private EncryptedRequest copyRequest(EncryptedRequest request) {
return new EncryptedRequest(request.getEphemeralPublicKey(), request.getEncryptedData(), request.getMac(), request.getNonce(), request.getTimestamp());
*/
private EncryptedRequest copyRequest(EncryptedRequest request) {
return new EncryptedRequest(request.getTemporaryKeyId(), request.getEphemeralPublicKey(), request.getEncryptedData(), request.getMac(), request.getNonce(), request.getTimestamp());
}

/**
Expand Down Expand Up @@ -658,111 +659,127 @@ public void testVectors_3_2() throws Exception {
// Requests
final EncryptedRequest[] encryptedRequest = {
new EncryptedRequest(
null,
"Avlav7hfDwCA1zJq6gyczWtUn+MhNCebikIH7rkUkoHB",
"jZ1y4ZkJpvRTDHFXQ+J9jsWaFuV0AvqpUXFDCi3bH90YCutTufSamKXpEIhFfqBmhzYak2g6LBUfgmTJ7c74D+eOqGRn1EwZOcgVHKbaFjgthwSUnD8E7maEK9u5qmVdi52drt9vQ1Cye5jWn0vSTKmvSkfcQcmK42o/0r/8LXs=",
"ovJWPbaRr/+9nDLwHhej1u9iNVg0OVVNNO2zI88AM9g=",
"BKIsGcbgqAqEKhuEJFX25Q==",
1691762307382L
),
new EncryptedRequest(
null,
"A97NlW0JPLJfpG0AUvaRHRGSHh+quZu+u0c+yxsK7Xji",
"qYLONkDWFpXefTKPbaKTA/PWdRYH5pk9uvGjUqSYbeK7Q0aOohK2MknTyviyNuSp",
"DNlZdsM1wgH8v2mAROjj3vmQu4DI4ZJnuTBzQMrHsew=",
"ZQxUjy/hSRyJ3xBtqyXBeQ==",
1691762307384L
),
new EncryptedRequest(
null,
"AtSsPjiwbh3GnWYjCOejGIGg0LEbl1X6SY4f1F77PG2I",
"px6h9Hu+wyH38YySO6istbinaF3ALyrBraad0qhTCJZrYrVlTv1bEnfvElBupQzGUx3SikSqaOjR+UKzj9TVfa2rw36LkSIVFZYk1gG6xW3U852ZvJpuTtw6h7WhFYks",
"bySXBDU/9mDx9T8i9DFWX7Xn4O6HZK2EMLpA+ogv3eM=",
"6p2OQ20Ezjd+RcCAr2w34w==",
1691762307384L
),
new EncryptedRequest(
null,
"AnjhcBNyzpyUs8TnvW164zfwVk6UQjof8zueumjUADlB",
"rQDj9EseF9GvJY6a0YCExA==",
"Mpu0lek/SXf7JvxnlEngv/Bx8nFhxi54vHVrBr0f7H8=",
"0qdMsQVKjhE8gwRm8It2Vg==",
1691762307385L
),
new EncryptedRequest(
null,
"Aqa/2aW4VuZTXaFoc0rcc67RotG0rbiqpvontLsdoLIe",
"ic3LxIfwgK9XbckAxivYvMdwuAL9nOC/Kdry4w/1xRw=",
"OyQcPCU8opsBN88vCE/9Km53a8sNqamIMIwxNfOOyto=",
"6YzESLD7x6ANSxeirDAXZQ==",
1691762307385L
),
new EncryptedRequest(
null,
"Aomhgt+8zAMsuRYgsVJMioFFPLP6eK+4omcLfftS/PHK",
"xNdtHsq28x+cFGxLGJbW6l7SscETdLRHejmXYETzU8670YyaqpiGOO5276vb3XDnxM6GjKHEztXruz8YBQzWKYqc6YVU4WqKMNHBu1A/9yKY8KGE+XsSxyrkZxoIM4oZuUp7p1ui+H87PPY8Vs/c9dMM5YUMYVUFZA1kBnzskKs=",
"z05w9DN9CKWtURAr0g7D5Kya8Jvp+CQFLNz2Fy1inaI=",
"fWn7lYWXckz72X4elEU+3g==",
1691762307385L
),
new EncryptedRequest(
null,
"AoCXG9cbmKBSPP2zi3pOuJQV6dENZ751dUhEGoDqLWVB",
"fqsJXWuIt2rwwsWLu8TbPnCxwha6PTGTpzmsLq/Tdynt5YcrEBk9wlRaQIXzWi0KbES20BjJbgL7JIaY2qj/XlFU+vxB+vybUnHrtpe2NaDthaYgdEecX3W1uzpyd745ogDSGe19gOqwXCFCRFLF+w==",
"T/tx0z+61zPosCa2Y0oJBepFOOfn0O1lrMKkr9RSVNY=",
"YQwJfuPmImzyBhGqZ7QMNw==",
1691762307386L
),
new EncryptedRequest(
null,
"A/5KJP3Cb8DhNjo8Cs2juYLwpswsUBJe6XXdwowIelP7",
"wUXXg0vgkZjqvqIfJm7YPgk+7bwgWSttizi+uSKAE4z8dOY8zUp0uvsvsUqDIvnhisnc82IyS/kGhSg1QWyzjAdfr5rWehl+aS+e8GPIu3Ok8n0qNG9TJ1n/UxuD6Ok/WTCHsRW2QoU2I8vB6BAMUw==",
"J88D9JrcVVmVlUNe5g6IzEHd3m+PqfSzBNyCfEb+UXg=",
"vr95iaeHXK4W0o0WU3MAkQ==",
1691762307386L
),
new EncryptedRequest(
null,
"A3TP+jPFrRgQd563V8goh2wJgvRS9eMpwjo9tOivLboN",
"8MjZ4+3cUC7IkwyNK09WSDMOrMpNwfHrXUM3A/19sjyOVZJIAl9HYJySlN8h9A2qrG7l0Eu6nFUwjDH8+NHfqBHCdOAnpncwgANE5GetzgA=",
"pmWeeMSroONdztB05rb6932llfAJJo6+uqLvwYq01dw=",
"ecQuWdjhJB90a0vxXJCHDA==",
1691762307386L
),
new EncryptedRequest(
null,
"A0w7WTl0Q3vhxlyKJWV1hM1YC484mysCqhjay9uFSmvG",
"K0Ep8dWNhD99yZm/mShFy53DYbTCntm582rlWwskPfcKTE7b/7gBFbXaGly1o9cmQ9Wv9RjBx8Ai4rda/KKbyMq3ZaX6ljAWFpOmqUIgMUQ=",
"Zr7vEn6WBYkFFZRAvq3UdRR/OWF2uOK0ABik9fytOUo=",
"20zLGrzcBPr6aPWQTOESuQ==",
1691762307387L
),
new EncryptedRequest(
null,
"A4o3ZVufjyXvJnc98rvHxTbQgCpY1dwMkJs4mKkT78up",
"8hYJGXgHLD8tH9sFrRlU6fxGWU/JdlSBpPkL178OFRdORMXTY/ReMRbajQD3bXKzXjmhdYR5X13fHsmiuvHIQVPRFB0ZyS43HT/uEDpWh8SWByKjNB5je6ftEySsmpKGp0KvmjXgiIRX7TiRzwJ03g==",
"VX9TB4hPM7/6U/NQvBNR6VaP1loyq2ZhcmEu4NWCU7g=",
"Z5XV6HOqZ3ftaxEkdgjIwQ==",
1691762307387L
),
new EncryptedRequest(
null,
"AhVR4QxfHA5resv8ppMANxzZwkaWphsmtA/EENi8Swjp",
"ASC8xiBSyjx8wGwf71U9Zk4nZT9w//8AafiZaT+9RtObUmb1HjguWv3Xpqejnf5kml3Z7sXDYgFemFYLklhL5A==",
"8wlb+Pz3UulREpbcBV4GfiY4bePugBPV6ywgaycvrpU=",
"Y6DDsiZb40xV1lhNNWloiw==",
1691762307387L
),
new EncryptedRequest(
null,
"A9ok7XXLWWWtQAxERdvFv3I31D+pgZuY3cVSbjpJHLda",
"+b0Ki6WcoaoGJhBrGR28zeMqS91XMmCCtO/HU3xaKNg=",
"jmkaGcZ+qnrMXtD1R7YhRmJJU+d3y6/nATjNno7DA0A=",
"MrgNNwmotGQZspWUFNMuRw==",
1691762307388L
),
new EncryptedRequest(
null,
"A24fQipKuaW7sOmXbpZDW+QetW/aBmS+2fkrkSdNDlQe",
"GaXg6TBM+H4ru/E25gvV0g==",
"xV19DEuOG+SGpT22GU55mVQqU4I7/+vgWNFKDq6tK5k=",
"mXHJkh/NUVzxLAXRH2r+9g==",
1691762307388L
),
new EncryptedRequest(
null,
"ArzfJWjDZrjndvQg3aFxZme6w/Z5P4uV4mBClCbURJuv",
"cbG2zh4dp5Ig65/Gdz97ZLm1vWeLfSUbIIoLWQXQm5pUVLkHJ55Mrl4TwdK6kTG0",
"lawZCFwh0NTpNafMwC92/ndMnkryG4yxfAvp/4q1F3Y=",
"C48N0ekaenicTtsb6LEf1g==",
1691762307388L
),
new EncryptedRequest(
null,
"At3TEHVJmtO+VPUtJ/ijXYhx1BAnjcDnQRk9AbhukeWa",
"4RPt1tswWfapZNWU7gFkuMyUADjsykdAQHQsMXHmghDE3l7dVYiMctKuj8RHFLAIsgI09toZelMAPRE1PLJz6g==",
"JgkwHwwwoDb14zokbecDQeqmOrJxRO0Lddv1sQp0bnQ=",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public static class Key {
*/
private static final String ACTIVATION_ID = "activation_id";

/**
* Key representing the "temporary_key_id" in the PowerAuth encryption header.
*/
private static final String TEMPORARY_KEY_ID = "temporary_key_id";

/**
* Key representing the "version" in the PowerAuth encryption header.
*/
Expand All @@ -63,11 +58,6 @@ public static class Key {
*/
private String activationId;

/**
* Temporary Key ID.
*/
private String temporaryKeyId;

/**
* PowerAuth protocol version.
*/
Expand All @@ -89,12 +79,10 @@ public PowerAuthEncryptionHttpHeader() {
*
* @param applicationKey Application key.
* @param version Version.
* @param temporaryKeyId Temporary key ID.
*/
public PowerAuthEncryptionHttpHeader(String applicationKey, String version, String temporaryKeyId) {
public PowerAuthEncryptionHttpHeader(String applicationKey, String version) {
this.applicationKey = applicationKey;
this.version = version;
this.temporaryKeyId = temporaryKeyId;
}

/**
Expand All @@ -103,13 +91,11 @@ public PowerAuthEncryptionHttpHeader(String applicationKey, String version, Stri
* @param applicationKey Application key.
* @param activationId Activation ID
* @param version Version.
* @param temporaryKeyId Temporary key ID.
*/
public PowerAuthEncryptionHttpHeader(String applicationKey, String activationId, String version, String temporaryKeyId) {
public PowerAuthEncryptionHttpHeader(String applicationKey, String activationId, String version) {
this.applicationKey = applicationKey;
this.activationId = activationId;
this.version = version;
this.temporaryKeyId = temporaryKeyId;
}

/**
Expand All @@ -123,7 +109,6 @@ public PowerAuthEncryptionHttpHeader fromValue(String headerValue) {
Map<String, String> map = parseHttpHeader(headerValue);
this.applicationKey = map.get(Key.APPLICATION_KEY);
this.activationId = map.get(Key.ACTIVATION_ID);
this.temporaryKeyId = map.get(Key.TEMPORARY_KEY_ID);
this.version = map.get(Key.VERSION);
return this;
}
Expand All @@ -137,7 +122,6 @@ public String buildHttpHeader() {
return POWERAUTH_PREFIX
+ headerField(Key.APPLICATION_KEY, this.applicationKey) + ", "
+ (this.activationId == null ? "" : headerField(Key.ACTIVATION_ID, this.activationId) + ", ")
+ (this.temporaryKeyId == null ? "" : headerField(Key.TEMPORARY_KEY_ID, this.temporaryKeyId) + ", ")
+ headerField(Key.VERSION, this.version);
}

Expand Down Expand Up @@ -165,11 +149,4 @@ public String getVersion() {
return version;
}

/**
* Get temporary key ID.
* @return Temporary key ID.
*/
public String getTemporaryKeyId() {
return temporaryKeyId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public static class Key {
*/
private static final String SIGNATURE_TYPE = "pa_signature_type";

/**
* Key representing the "pa_temporary_key_id" in the PowerAuth authorization header.
*/
private static final String TEMPORARY_KEY_ID = "pa_temporary_key_id";

/**
* Key representing the "pa_nonce" in the PowerAuth authorization header.
*/
Expand Down Expand Up @@ -88,11 +83,6 @@ public static class Key {
*/
private String signatureType;

/**
* Field representing temporary key ID value.
*/
private String temporaryKeyId;

/**
* Field representing nonce value.
*/
Expand Down Expand Up @@ -145,7 +135,6 @@ public PowerAuthSignatureHttpHeader fromValue(String headerValue) {
this.nonce = map.get(Key.NONCE);
this.signatureType = map.get(Key.SIGNATURE_TYPE);
this.signature = map.get(Key.SIGNATURE);
this.temporaryKeyId = map.get(Key.TEMPORARY_KEY_ID);
this.version = map.get(Key.VERSION);
return this;
}
Expand All @@ -161,7 +150,6 @@ public String buildHttpHeader() {
+ headerField(Key.NONCE, this.nonce) + ", "
+ headerField(Key.SIGNATURE_TYPE, this.signatureType) + ", "
+ headerField(Key.SIGNATURE, this.signature) + ", "
+ ((temporaryKeyId != null) ? headerField(Key.TEMPORARY_KEY_ID, temporaryKeyId) + ", " : "")
+ headerField(Key.VERSION, this.version);
}

Expand Down Expand Up @@ -207,14 +195,6 @@ public String getNonce() {
return nonce;
}

/**
* Get temporary key ID.
* @return Temporary key ID.
*/
public String getTemporaryKeyId() {
return temporaryKeyId;
}

/**
* Get version.
* @return Version.
Expand Down

0 comments on commit 3c634c4

Please sign in to comment.