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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
0ede66dd
Commit
0ede66dd
authored
Feb 26, 2021
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Jono/ud contact debug prints
parent
ebdbe03b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/ud.go
+15
-6
15 additions, 6 deletions
cmd/ud.go
interfaces/contact/contact.go
+16
-16
16 additions, 16 deletions
interfaces/contact/contact.go
interfaces/contact/contact_test.go
+45
-76
45 additions, 76 deletions
interfaces/contact/contact_test.go
with
76 additions
and
98 deletions
cmd/ud.go
+
15
−
6
View file @
0ede66dd
...
@@ -138,8 +138,7 @@ var udCmd = &cobra.Command{
...
@@ -138,8 +138,7 @@ var udCmd = &cobra.Command{
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
cBytes
:=
newContact
.
Marshal
()
printContact
(
newContact
)
fmt
.
Printf
(
string
(
cBytes
))
},
90
*
time
.
Second
)
},
90
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -189,10 +188,8 @@ var udCmd = &cobra.Command{
...
@@ -189,10 +188,8 @@ var udCmd = &cobra.Command{
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
for
i
:=
0
;
i
<
len
(
contacts
);
i
++
{
for
_
,
c
:=
range
contacts
{
cBytes
:=
contacts
[
i
]
.
Marshal
()
printContact
(
c
)
jww
.
INFO
.
Printf
(
"Size Printed: %d"
,
len
(
cBytes
))
fmt
.
Printf
(
"%s"
,
cBytes
)
}
}
},
90
*
time
.
Second
)
},
90
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -241,3 +238,15 @@ func init() {
...
@@ -241,3 +238,15 @@ func init() {
rootCmd
.
AddCommand
(
udCmd
)
rootCmd
.
AddCommand
(
udCmd
)
}
}
func
printContact
(
c
contact
.
Contact
)
{
jww
.
DEBUG
.
Printf
(
"Printing client: %+v"
,
c
)
cBytes
:=
c
.
Marshal
()
if
len
(
cBytes
)
==
0
{
jww
.
ERROR
.
Print
(
"Marshaled client has a size of 0."
)
}
else
{
jww
.
DEBUG
.
Printf
(
"Printing marshaled contact of size %d."
,
len
(
cBytes
))
}
fmt
.
Print
(
string
(
cBytes
))
}
This diff is collapsed.
Click to expand it.
interfaces/contact/contact.go
+
16
−
16
View file @
0ede66dd
...
@@ -80,22 +80,6 @@ func (c Contact) Marshal() []byte {
...
@@ -80,22 +80,6 @@ func (c Contact) Marshal() []byte {
return
buff
.
Bytes
()
return
buff
.
Bytes
()
}
}
// Creates a 15 character long fingerprint of contact
// off of the ID and DH public key
func
(
c
Contact
)
GetFingerprint
()
string
{
// Generate hash
sha
:=
crypto
.
SHA256
h
:=
sha
.
New
()
// Hash Id and public key
h
.
Write
(
c
.
ID
.
Bytes
())
h
.
Write
(
c
.
DhPubKey
.
Bytes
())
data
:=
h
.
Sum
(
nil
)
// Encode hash and truncate
return
base64
.
StdEncoding
.
EncodeToString
(
data
[
:
])[
:
fingerprintLength
]
}
// Unmarshal decodes the byte slice produced by Contact.Marshal into a Contact.
// Unmarshal decodes the byte slice produced by Contact.Marshal into a Contact.
func
Unmarshal
(
b
[]
byte
)
(
Contact
,
error
)
{
func
Unmarshal
(
b
[]
byte
)
(
Contact
,
error
)
{
if
len
(
b
)
<
sizeByteLength
*
3
+
id
.
ArrIDLen
{
if
len
(
b
)
<
sizeByteLength
*
3
+
id
.
ArrIDLen
{
...
@@ -151,6 +135,22 @@ func Unmarshal(b []byte) (Contact, error) {
...
@@ -151,6 +135,22 @@ func Unmarshal(b []byte) (Contact, error) {
return
c
,
nil
return
c
,
nil
}
}
// GetFingerprint creates a 15 character long fingerprint of the contact off of
// the ID and DH public key.
func
(
c
Contact
)
GetFingerprint
()
string
{
// Generate hash
sha
:=
crypto
.
SHA256
h
:=
sha
.
New
()
// Hash ID and DH public key
h
.
Write
(
c
.
ID
.
Bytes
())
h
.
Write
(
c
.
DhPubKey
.
Bytes
())
data
:=
h
.
Sum
(
nil
)
// Base64 encode hash and truncate it
return
base64
.
StdEncoding
.
EncodeToString
(
data
)[
:
fingerprintLength
]
}
// Equal determines if the two contacts have the same values.
// Equal determines if the two contacts have the same values.
func
Equal
(
a
,
b
Contact
)
bool
{
func
Equal
(
a
,
b
Contact
)
bool
{
return
a
.
ID
.
Cmp
(
b
.
ID
)
&&
return
a
.
ID
.
Cmp
(
b
.
ID
)
&&
...
...
This diff is collapsed.
Click to expand it.
interfaces/contact/contact_test.go
+
45
−
76
View file @
0ede66dd
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"crypto"
"crypto"
"encoding/base64"
"encoding/base64"
"encoding/json"
"encoding/json"
"fmt"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/csprng"
...
@@ -38,8 +37,6 @@ func TestContact_Marshal_Unmarshal(t *testing.T) {
...
@@ -38,8 +37,6 @@ func TestContact_Marshal_Unmarshal(t *testing.T) {
buff
:=
expectedContact
.
Marshal
()
buff
:=
expectedContact
.
Marshal
()
fmt
.
Println
(
string
(
buff
))
testContact
,
err
:=
Unmarshal
(
buff
)
testContact
,
err
:=
Unmarshal
(
buff
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unmarshal() produced an error: %+v"
,
err
)
t
.
Errorf
(
"Unmarshal() produced an error: %+v"
,
err
)
...
@@ -101,78 +98,54 @@ func TestContact_Marshal_Size(t *testing.T) {
...
@@ -101,78 +98,54 @@ func TestContact_Marshal_Size(t *testing.T) {
}
}
}
}
// Unit test of
g
etFingerprint
// Unit test of
G
etFingerprint
.
func
TestContact_GetFingerprint
(
t
*
testing
.
T
)
{
func
TestContact_GetFingerprint
(
t
*
testing
.
T
)
{
c
:=
Contact
{
c
:=
Contact
{
ID
:
id
.
NewIdFromString
(
"Samwise"
,
id
.
User
,
t
),
ID
:
id
.
NewIdFromString
(
"Samwise"
,
id
.
User
,
t
),
DhPubKey
:
getCycInt
(
512
),
DhPubKey
:
getCycInt
(
512
),
}
}
contactString
:=
c
.
GetFingerprint
()
testFP
:=
c
.
GetFingerprint
()
if
len
(
contactString
)
!=
fingerprintLength
{
if
len
(
testFP
)
!=
fingerprintLength
{
t
.
Errorf
(
"
Unexpected length for fingerprint
."
+
t
.
Errorf
(
"
GetFingerprint() returned fingerprint with unexpected length
."
+
"
\n
\t
E
xpected length: %d
"
+
"
\n
e
xpected length: %d
\n
received length: %d"
,
"
\n\t
Received length: %d"
,
len
(
contactString
),
fingerprintLength
)
fingerprintLength
,
len
(
testFP
)
)
}
}
// Generate hash
// Generate expected fingerprint
sha
:=
crypto
.
SHA256
h
:=
crypto
.
SHA256
.
New
()
h
:=
sha
.
New
()
// Hash Id and public key
h
.
Write
(
c
.
ID
.
Bytes
())
h
.
Write
(
c
.
ID
.
Bytes
())
h
.
Write
(
c
.
DhPubKey
.
Bytes
())
h
.
Write
(
c
.
DhPubKey
.
Bytes
())
data
:=
h
.
Sum
(
nil
)
expectedFP
:=
base64
.
StdEncoding
.
EncodeToString
(
h
.
Sum
(
nil
))[
:
fingerprintLength
]
expectedFP
:=
base64
.
StdEncoding
.
EncodeToString
(
data
[
:
])[
:
fingerprintLength
]
if
strings
.
Compare
(
expectedFP
,
testFP
)
!=
0
{
t
.
Errorf
(
"GetFingerprint() returned expected fingerprint."
+
if
strings
.
Compare
(
contactString
,
expectedFP
)
!=
0
{
"
\n
expected: %s
\n
received: %s"
,
expectedFP
,
testFP
)
t
.
Errorf
(
"Fingerprint outputted is not expected."
+
"
\n\t
Expected: %s"
+
"
\n\t
Received: %s"
,
contactString
,
expectedFP
)
}
}
}
}
// Consistency test for changes in underlying dependencies
// Consistency test for changes in underlying dependencies
.
func
TestContact_GetFingerprint_Consistency
(
t
*
testing
.
T
)
{
func
TestContact_GetFingerprint_Consistency
(
t
*
testing
.
T
)
{
expected
:=
[]
string
{
expected
:=
[]
string
{
"rBUw1n4jtH4uEYq"
,
"rBUw1n4jtH4uEYq"
,
"Z/Jm1OUwDaql5cd"
,
"+vHLzY+yH96zAiy"
,
"Z/Jm1OUwDaql5cd"
,
"cZm5Iz78ViOIlnh"
,
"9LqrcbFEIV4C4LX"
,
"ll4eykGpMWYlxw+"
,
"+vHLzY+yH96zAiy"
,
"6YQshWJhdPL6ajx"
,
"Y6gTPVEzow4IHOm"
,
"6f/rT2vWxDC9tdt"
,
"cZm5Iz78ViOIlnh"
,
"rwqbDT+PoeA6Iww"
,
"YN4IFijP/GZ172O"
,
"ScbHVQc2T9SXQ2m"
,
"9LqrcbFEIV4C4LX"
,
"50mfbCXQ+LIqiZn"
,
"cyRYdMKXByiFdtC"
,
"7g6ujy7iIbJVl4F"
,
"ll4eykGpMWYlxw+"
,
"6YQshWJhdPL6ajx"
,
"Y6gTPVEzow4IHOm"
,
"6f/rT2vWxDC9tdt"
,
"rwqbDT+PoeA6Iww"
,
"YN4IFijP/GZ172O"
,
"ScbHVQc2T9SXQ2m"
,
"50mfbCXQ+LIqiZn"
,
"cyRYdMKXByiFdtC"
,
"7g6ujy7iIbJVl4F"
,
}
}
numTest
:=
15
for
i
:=
range
expected
{
output
:=
make
([]
string
,
0
)
for
i
:=
0
;
i
<
numTest
;
i
++
{
c
:=
Contact
{
c
:=
Contact
{
ID
:
id
.
NewIdFromUInt
(
uint64
(
i
),
id
.
User
,
t
),
ID
:
id
.
NewIdFromUInt
(
uint64
(
i
),
id
.
User
,
t
),
DhPubKey
:
getGroup
()
.
NewInt
(
25
),
DhPubKey
:
getGroup
()
.
NewInt
(
25
),
}
}
contactString
:=
c
.
GetFingerprint
()
fp
:=
c
.
GetFingerprint
()
output
=
append
(
output
,
contactString
)
if
expected
[
i
]
!=
fp
{
t
.
Errorf
(
"GetFingerprint() did not output the expected fingerprint (%d)."
+
"
\n
expected: %s
\n
received: %s"
,
i
,
expected
[
i
],
fp
)
}
}
for
i
:=
0
;
i
<
numTest
;
i
++
{
if
strings
.
Compare
(
output
[
i
],
expected
[
i
])
!=
0
{
t
.
Errorf
(
"Fingerprint outputted is not expected."
+
"
\n\t
Received: %s"
+
"
\n\t
Expected: %s"
,
output
[
i
],
expected
[
i
])
}
}
}
}
}
...
@@ -183,9 +156,8 @@ func TestEqual(t *testing.T) {
...
@@ -183,9 +156,8 @@ func TestEqual(t *testing.T) {
DhPubKey
:
getCycInt
(
512
),
DhPubKey
:
getCycInt
(
512
),
OwnershipProof
:
make
([]
byte
,
1024
),
OwnershipProof
:
make
([]
byte
,
1024
),
Facts
:
fact
.
FactList
{
Facts
:
fact
.
FactList
{
{
Fact
:
"myVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongUsername"
,
T
:
fact
.
Username
},
{
Fact
:
"myUsername"
,
T
:
fact
.
Username
},
{
Fact
:
"myVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongEmail@elixxir.io"
,
T
:
fact
.
Email
},
{
Fact
:
"devinputvalidation@elixxir.io"
,
T
:
fact
.
Email
},
{
Fact
:
"6502530000US"
,
T
:
fact
.
Phone
},
},
},
}
}
rand
.
Read
(
a
.
OwnershipProof
)
rand
.
Read
(
a
.
OwnershipProof
)
...
@@ -213,34 +185,31 @@ func TestEqual(t *testing.T) {
...
@@ -213,34 +185,31 @@ func TestEqual(t *testing.T) {
}
}
func
getCycInt
(
size
int
)
*
cyclic
.
Int
{
func
getCycInt
(
size
int
)
*
cyclic
.
Int
{
var
primeString
=
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+
var
primeString
=
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E0"
+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+
"88A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F"
+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+
"14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDE"
+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+
"E386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48"
+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
+
"361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED52907709"
+
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
+
"6966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E8603"
+
"83655D23DCA3AD961C62F356208552BB9ED529077096966D"
+
"9B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D22"
+
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
+
"61898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458"
+
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
+
"DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619"
+
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
+
"DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE1"
+
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
+
"17577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A"
+
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
+
"92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150B"
+
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
+
"DA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B"
+
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
+
"2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127"
+
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
+
"D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFF"
+
"43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7"
+
"FFF"
"88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA"
+
"2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6"
+
"287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED"
+
"1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9"
+
"93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199"
+
"FFFFFFFFFFFFFFFF"
buff
,
err
:=
csprng
.
GenerateInGroup
([]
byte
(
primeString
),
size
,
csprng
.
NewSystemRNG
())
buff
,
err
:=
csprng
.
GenerateInGroup
([]
byte
(
primeString
),
size
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
grp
:=
cyclic
.
NewGroup
(
large
.
NewIntFromString
(
primeString
,
16
),
large
.
NewInt
(
2
))
.
NewIntFromBytes
(
buff
)
grp
:=
cyclic
.
NewGroup
(
large
.
NewIntFromString
(
primeString
,
16
),
large
.
NewInt
(
2
))
.
NewIntFromBytes
(
buff
)
return
grp
return
grp
}
}
...
...
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