Skip to content

Commit

Permalink
Add from_user_id
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Aug 21, 2024
1 parent 50da09f commit 91f440a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LiftLog.Ui/Models/UserEvent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message InboxMessageDao {
FollowResponseDao follow_response = 3;
UnFollowNotification unfollow_notification = 4;
}
// The signature of the [message + the to_user_id], signed with the private key of the from_user_id
// The signature of the [message +from_user_id+ the to_user_id], signed with the private key of the from_user_id
bytes signature = 5;
}

Expand Down
18 changes: 15 additions & 3 deletions LiftLog.Ui/Services/FeedFollowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public async Task<ApiResult> RequestToFollowAUserAsync(FeedIdentity identity, Fe
};
inboxMessage.Signature = ByteString.CopyFrom(
await encryptionService.SignRsaPssSha256Async(
[.. inboxMessage.GetPayloadBytes(), .. toFollow.Id.ToByteArray()],
[
.. inboxMessage.GetPayloadBytes(),
.. identity.Id.ToByteArray(),
.. toFollow.Id.ToByteArray(),
],
identity.RsaKeyPair.PrivateKey
)
);
Expand Down Expand Up @@ -73,7 +77,11 @@ RsaPublicKey userPublicKey
};
inboxMessage.Signature = ByteString.CopyFrom(
await encryptionService.SignRsaPssSha256Async(
[.. inboxMessage.GetPayloadBytes(), .. request.UserId.ToByteArray()],
[
.. inboxMessage.GetPayloadBytes(),
.. identity.Id.ToByteArray(),
.. request.UserId.ToByteArray(),
],
identity.RsaKeyPair.PrivateKey
)
);
Expand Down Expand Up @@ -109,7 +117,11 @@ RsaPublicKey userPublicKey
};
inboxMessage.Signature = ByteString.CopyFrom(
await encryptionService.SignRsaPssSha256Async(
[.. inboxMessage.GetPayloadBytes(), .. request.UserId.ToByteArray()],
[
.. inboxMessage.GetPayloadBytes(),
.. identity.Id.ToByteArray(),
.. request.UserId.ToByteArray(),
],
identity.RsaKeyPair.PrivateKey
)
);
Expand Down
14 changes: 13 additions & 1 deletion LiftLog.Ui/Store/Feed/FeedEffects.Following.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ public async Task UnfollowFeedUser(UnfollowFeedUserAction action, IDispatcher di
FollowSecret = action.FeedUser.FollowSecret,
},
};
inboxMessage.Signature = ByteString.CopyFrom(
await encryptionService.SignRsaPssSha256Async(
[
.. inboxMessage.GetPayloadBytes(),
.. identity.Id.ToByteArray(),
.. action.FeedUser.Id.ToByteArray(),
],
identity.RsaKeyPair.PrivateKey
)
);
var encryptedInboxMessage = await encryptionService.EncryptRsaOaepSha256Async(
inboxMessage.ToByteArray(),
action.FeedUser.PublicKey
Expand Down Expand Up @@ -315,7 +325,9 @@ unverifiedInboxMessage.Signature is null

var payloadBytes = unverifiedInboxMessage.GetPayloadBytes();
var myUserIdBytes = state.Value.Identity!.Id.ToByteArray();
byte[] signedPayload = [.. payloadBytes, .. myUserIdBytes];
var subjectUserIdBytes = unverifiedInboxMessage.FromUserId.ToByteArray();

byte[] signedPayload = [.. payloadBytes, .. subjectUserIdBytes, .. myUserIdBytes];
var publicKey = await GetUserPublicKey(unverifiedInboxMessage.FromUserId);

var verified = await encryptionService.VerifyRsaPssSha256Async(
Expand Down

0 comments on commit 91f440a

Please sign in to comment.