Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
24f70007
Commit
24f70007
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Fix payload size, comments from review
parent
c0843194
No related branches found
No related tags found
2 merge requests
!510
Release
,
!240
Integration update, allow client to use both broadcast methods
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
broadcast/asymmetric.go
+14
-4
14 additions, 4 deletions
broadcast/asymmetric.go
broadcast/broadcastClient.go
+4
-0
4 additions, 0 deletions
broadcast/broadcastClient.go
broadcast/processor.go
+8
-6
8 additions, 6 deletions
broadcast/processor.go
broadcast/symmetric.go
+1
-1
1 addition, 1 deletion
broadcast/symmetric.go
with
27 additions
and
11 deletions
broadcast/asymmetric.go
+
14
−
4
View file @
24f70007
...
...
@@ -8,6 +8,7 @@
package
broadcast
import
(
"encoding/binary"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/message"
...
...
@@ -19,6 +20,7 @@ import (
const
(
asymmetricBroadcastServiceTag
=
"AsymmBcast"
asymmCMixSendTag
=
"AsymmetricBroadcast"
internalPayloadSizeLength
=
2
)
// MaxAsymmetricPayloadSize returns the maximum size for an asymmetric broadcast payload
...
...
@@ -28,20 +30,26 @@ func (bc *broadcastClient) maxAsymmetricPayload() int {
// BroadcastAsymmetric broadcasts the payload to the channel. Requires a healthy network state to send
// Payload must be equal to bc.MaxAsymmetricPayloadSize, and the channel PrivateKey must be passed in
// When a payload is sent, it is split into partitons of size bc.channel.MaxAsymmetricPayloadSize
// which are each encrypted using multicastRSA
func
(
bc
*
broadcastClient
)
BroadcastAsymmetric
(
pk
multicastRSA
.
PrivateKey
,
payload
[]
byte
,
cMixParams
cmix
.
CMIXParams
)
(
id
.
Round
,
ephemeral
.
Id
,
error
)
{
// Confirm network health
if
!
bc
.
net
.
IsHealthy
()
{
return
0
,
ephemeral
.
Id
{},
errors
.
New
(
errNetworkHealth
)
}
if
len
(
payload
)
!=
bc
.
MaxAsymmetricPayloadSize
()
{
// Check payload size
if
len
(
payload
)
>
bc
.
MaxAsymmetricPayloadSize
()
{
return
0
,
ephemeral
.
Id
{},
errors
.
Errorf
(
errPayloadSize
,
len
(
payload
),
bc
.
maxAsymmetricPayload
())
}
payloadLength
:=
uint16
(
len
(
payload
))
encryptedPayload
,
mac
,
fp
,
err
:=
bc
.
channel
.
EncryptAsymmetric
(
payload
,
pk
,
bc
.
rng
.
GetStream
())
finalPayload
:=
make
([]
byte
,
bc
.
maxAsymmetricPayloadSizeRaw
())
binary
.
BigEndian
.
PutUint16
(
finalPayload
[
:
internalPayloadSizeLength
],
payloadLength
)
copy
(
finalPayload
[
internalPayloadSizeLength
:
],
payload
)
// Encrypt payload
encryptedPayload
,
mac
,
fp
,
err
:=
bc
.
channel
.
EncryptAsymmetric
(
finalPayload
,
pk
,
bc
.
rng
.
GetStream
())
if
err
!=
nil
{
return
0
,
ephemeral
.
Id
{},
errors
.
WithMessage
(
err
,
"Failed to encrypt asymmetric broadcast message"
)
}
...
...
@@ -56,7 +64,9 @@ func (bc *broadcastClient) BroadcastAsymmetric(pk multicastRSA.PrivateKey, paylo
cMixParams
.
DebugTag
=
asymmCMixSendTag
}
// Create payload sized for sending over cmix
sizedPayload
:=
make
([]
byte
,
bc
.
net
.
GetMaxMessageLength
())
// Read random data into sized payload
_
,
err
=
bc
.
rng
.
GetStream
()
.
Read
(
sizedPayload
)
if
err
!=
nil
{
return
0
,
ephemeral
.
Id
{},
errors
.
WithMessage
(
err
,
"Failed to add random data to sized broadcast"
)
...
...
This diff is collapsed.
Click to expand it.
broadcast/broadcastClient.go
+
4
−
0
View file @
24f70007
...
...
@@ -102,5 +102,9 @@ func (bc *broadcastClient) MaxPayloadSize() int {
}
func
(
bc
*
broadcastClient
)
MaxAsymmetricPayloadSize
()
int
{
return
bc
.
maxAsymmetricPayloadSizeRaw
()
-
internalPayloadSizeLength
}
func
(
bc
*
broadcastClient
)
maxAsymmetricPayloadSizeRaw
()
int
{
return
bc
.
channel
.
MaxAsymmetricPayloadSize
()
}
This diff is collapsed.
Click to expand it.
broadcast/processor.go
+
8
−
6
View file @
24f70007
...
...
@@ -8,6 +8,7 @@
package
broadcast
import
(
"encoding/binary"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
...
...
@@ -35,14 +36,15 @@ func (p *processor) Process(msg format.Message,
var
err
error
switch
p
.
method
{
case
Asymmetric
:
// We use sized broadcast to fill any remaining bytes in the cmix payload, decode it here
encPartSize
:=
p
.
c
.
RsaPubKey
.
Size
()
// Size of each chunk returned by multicast RSA encryption
encodedMessage
:=
msg
.
GetContents
()[
:
encPartSize
]
payload
,
err
=
p
.
c
.
DecryptAsymmetric
(
encodedMessage
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
errDecrypt
,
p
.
c
.
ReceptionID
,
p
.
c
.
Name
,
err
)
encPartSize
:=
p
.
c
.
RsaPubKey
.
Size
()
// Size returned by multicast RSA encryption
encodedMessage
:=
msg
.
GetContents
()[
:
encPartSize
]
// Only one message is encoded, rest of it is random data
decodedMessage
,
decryptErr
:=
p
.
c
.
DecryptAsymmetric
(
encodedMessage
)
if
decryptErr
!=
nil
{
jww
.
ERROR
.
Printf
(
errDecrypt
,
p
.
c
.
ReceptionID
,
p
.
c
.
Name
,
decryptErr
)
return
}
size
:=
binary
.
BigEndian
.
Uint16
(
decodedMessage
[
:
internalPayloadSizeLength
])
payload
=
decodedMessage
[
internalPayloadSizeLength
:
size
+
internalPayloadSizeLength
]
case
Symmetric
:
payload
,
err
=
p
.
c
.
DecryptSymmetric
(
msg
.
GetContents
(),
msg
.
GetMac
(),
msg
.
GetKeyFP
())
...
...
This diff is collapsed.
Click to expand it.
broadcast/symmetric.go
+
1
−
1
View file @
24f70007
...
...
@@ -19,7 +19,7 @@ import (
const
(
// symmetricClient.Broadcast
errNetworkHealth
=
"cannot send broadcast when the network is not healthy"
errPayloadSize
=
"size of payload %d must be %d"
errPayloadSize
=
"size of payload %d must be
less than
%d"
errBroadcastMethodType
=
"cannot call %s broadcast using %s channel"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment