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
bef3cfeb
Commit
bef3cfeb
authored
4 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
undid debugging statement
parent
18f43638
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
network/message/handler.go
+2
-78
2 additions, 78 deletions
network/message/handler.go
with
2 additions
and
78 deletions
network/message/handler.go
+
2
−
78
View file @
bef3cfeb
package
message
package
message
import
(
import
(
"bytes"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/crypto/
hash
"
"gitlab.com/elixxir/crypto/
e2e
"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"time"
"time"
...
@@ -41,7 +40,6 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
...
@@ -41,7 +40,6 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
// try to get the key fingerprint, process as e2e encryption if
// try to get the key fingerprint, process as e2e encryption if
// the fingerprint is found
// the fingerprint is found
if
key
,
isE2E
:=
e2eKv
.
PopKey
(
fingerprint
);
isE2E
{
if
key
,
isE2E
:=
e2eKv
.
PopKey
(
fingerprint
);
isE2E
{
jww
.
INFO
.
Printf
(
"is e2e message"
)
// Decrypt encrypted message
// Decrypt encrypted message
msg
,
err
=
key
.
Decrypt
(
ecrMsg
)
msg
,
err
=
key
.
Decrypt
(
ecrMsg
)
// get the sender
// get the sender
...
@@ -57,15 +55,13 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
...
@@ -57,15 +55,13 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
}
}
//set the type as E2E encrypted
//set the type as E2E encrypted
encTy
=
message
.
E2E
encTy
=
message
.
E2E
}
else
if
isUnencrypted
,
uSender
:=
IsUnencrypted
(
ecrMsg
);
isUnencrypted
{
}
else
if
isUnencrypted
,
uSender
:=
e2e
.
IsUnencrypted
(
ecrMsg
);
isUnencrypted
{
jww
.
INFO
.
Printf
(
"is unencrypted"
)
// if the key fingerprint does not match, try to treat it as an
// if the key fingerprint does not match, try to treat it as an
// unencrypted message
// unencrypted message
sender
=
uSender
sender
=
uSender
msg
=
ecrMsg
msg
=
ecrMsg
encTy
=
message
.
None
encTy
=
message
.
None
}
else
{
}
else
{
jww
.
INFO
.
Printf
(
"is raw"
)
// if it doesnt match any form of encrypted, hear it as a raw message
// if it doesnt match any form of encrypted, hear it as a raw message
// and add it to garbled messages to be handled later
// and add it to garbled messages to be handled later
msg
=
ecrMsg
msg
=
ecrMsg
...
@@ -97,75 +93,3 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
...
@@ -97,75 +93,3 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
}
}
}
}
}
}
\ No newline at end of file
const
macMask
=
0
b00111111
// IsUnencrypted determines if the message is unencrypted by comparing the hash
// of the message payload to the MAC. Returns true if the message is unencrypted
// and false otherwise.
// the highest bit of the recpient ID is stored in the highest bit of the MAC
// field. This is accounted for and the id is reassembled, with a presumed user
// type
func
IsUnencrypted
(
m
format
.
Message
)
(
bool
,
*
id
.
ID
)
{
expectedMac
:=
makeUnencryptedMAC
(
m
.
GetContents
())
receivedMac
:=
m
.
GetMac
()
idHighBit
:=
(
receivedMac
[
0
]
&
0
b01000000
)
<<
1
receivedMac
[
0
]
&=
macMask
//return false if the message is not unencrypted
if
!
bytes
.
Equal
(
expectedMac
,
receivedMac
)
{
jww
.
INFO
.
Printf
(
"Failed isUnencrypted! Expected: %v; "
+
" Received: %v"
,
expectedMac
,
receivedMac
)
return
false
,
nil
}
//extract the user ID
idBytes
:=
m
.
GetKeyFP
()
idBytes
[
0
]
|=
idHighBit
uid
:=
id
.
ID
{}
copy
(
uid
[
:
],
idBytes
[
:
])
uid
.
SetType
(
id
.
User
)
// Return true if the byte slices are equal
return
true
,
&
uid
}
// SetUnencrypted sets up the condition where the message would be determined to
// be unencrypted by setting the MAC to the hash of the message payload.
func
SetUnencrypted
(
m
format
.
Message
,
uid
*
id
.
ID
)
{
mac
:=
makeUnencryptedMAC
(
m
.
GetContents
())
//copy in the high bit of the userID for storage
mac
[
0
]
|=
(
uid
[
0
]
&
0
b10000000
)
>>
1
// Set the MAC
m
.
SetMac
(
mac
)
//remove the type byte off of the userID and clear the highest bit so
//it can be stored in the fingerprint
fp
:=
format
.
Fingerprint
{}
copy
(
fp
[
:
],
uid
[
:
format
.
KeyFPLen
])
fp
[
0
]
&=
0
b01111111
m
.
SetKeyFP
(
fp
)
}
// returns the mac, fingerprint, and the highest byte
func
makeUnencryptedMAC
(
payload
[]
byte
)[]
byte
{
// Create new hash
h
,
err
:=
hash
.
NewCMixHash
()
if
err
!=
nil
{
jww
.
ERROR
.
Panicf
(
"Failed to create hash: %v"
,
err
)
}
// Hash the message payload
h
.
Write
(
payload
)
payloadHash
:=
h
.
Sum
(
nil
)
//set the first bit as zero to ensure everything stays in the group
payloadHash
[
0
]
&=
macMask
return
payloadHash
}
\ No newline at end of file
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