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
bd530a3f
Commit
bd530a3f
authored
3 years ago
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Move precan out into it's own file
parent
dfc8b3a0
No related branches found
No related tags found
3 merge requests
!510
Release
,
!207
WIP: Client Restructure
,
!203
Symmetric broadcast
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/precan.go
+96
-0
96 additions, 0 deletions
api/precan.go
api/user.go
+2
-42
2 additions, 42 deletions
api/user.go
with
98 additions
and
42 deletions
api/precan.go
0 → 100644
+
96
−
0
View file @
bd530a3f
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package
api
import
(
"encoding/binary"
"math/rand"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage/user"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
)
// creates a precanned user
func
createPrecannedUser
(
precannedID
uint
,
rng
csprng
.
Source
,
cmix
,
e2e
*
cyclic
.
Group
)
user
.
Info
{
// DH Keygen
prng
:=
rand
.
New
(
rand
.
NewSource
(
int64
(
precannedID
)))
prime
:=
e2e
.
GetPBytes
()
keyLen
:=
len
(
prime
)
e2eKeyBytes
,
err
:=
csprng
.
GenerateInGroup
(
prime
,
keyLen
,
prng
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
err
.
Error
())
}
// Salt, UID, etc gen
salt
:=
make
([]
byte
,
SaltSize
)
userID
:=
id
.
ID
{}
binary
.
BigEndian
.
PutUint64
(
userID
[
:
],
uint64
(
precannedID
))
userID
.
SetType
(
id
.
User
)
// NOTE: not used... RSA Keygen (4096 bit defaults)
rsaKey
,
err
:=
rsa
.
GenerateKey
(
rng
,
rsa
.
DefaultRSABitLen
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
err
.
Error
())
}
return
user
.
Info
{
TransmissionID
:
&
userID
,
TransmissionSalt
:
salt
,
ReceptionID
:
&
userID
,
ReceptionSalt
:
salt
,
Precanned
:
true
,
E2eDhPrivateKey
:
e2e
.
NewIntFromBytes
(
e2eKeyBytes
),
TransmissionRSA
:
rsaKey
,
ReceptionRSA
:
rsaKey
,
}
}
// NewPrecannedClient creates an insecure user with predetermined keys
// with nodes It creates client storage, generates keys, connects, and
// registers with the network. Note that this does not register a
// username/identity, but merely creates a new cryptographic identity
// for adding such information at a later date.
func
NewPrecannedClient
(
precannedID
uint
,
defJSON
,
storageDir
string
,
password
[]
byte
)
error
{
jww
.
INFO
.
Printf
(
"NewPrecannedClient()"
)
rngStreamGen
:=
fastRNG
.
NewStreamGenerator
(
12
,
1024
,
csprng
.
NewSystemRNG
)
rngStream
:=
rngStreamGen
.
GetStream
()
def
,
err
:=
parseNDF
(
defJSON
)
if
err
!=
nil
{
return
err
}
cmixGrp
,
e2eGrp
:=
decodeGroups
(
def
)
protoUser
:=
createPrecannedUser
(
precannedID
,
rngStream
,
cmixGrp
,
e2eGrp
)
store
,
err
:=
checkVersionAndSetupStorage
(
def
,
storageDir
,
password
,
protoUser
,
cmixGrp
,
e2eGrp
,
rngStreamGen
,
""
)
if
err
!=
nil
{
return
err
}
// Mark the precanned user as finished with permissioning and registered
// with the network.
err
=
store
.
ForwardRegistrationStatus
(
storage
.
PermissioningComplete
)
if
err
!=
nil
{
return
err
}
return
nil
}
This diff is collapsed.
Click to expand it.
api/user.go
+
2
−
42
View file @
bd530a3f
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
package
api
package
api
import
(
import
(
"encoding/binary"
"math/rand"
"regexp"
"regexp"
"runtime"
"runtime"
"strings"
"strings"
...
@@ -39,7 +37,7 @@ func createNewUser(rng *fastRNG.StreamGenerator, cmix,
...
@@ -39,7 +37,7 @@ func createNewUser(rng *fastRNG.StreamGenerator, cmix,
var
e2eKeyBytes
,
transmissionSalt
,
receptionSalt
[]
byte
var
e2eKeyBytes
,
transmissionSalt
,
receptionSalt
[]
byte
e2eKeyBytes
,
transmissionSalt
,
receptionSalt
,
e2eKeyBytes
,
transmissionSalt
,
receptionSalt
,
transmissionRsaKey
,
receptionRsaKey
=
create
Dh
Keys
(
rng
,
e2e
)
transmissionRsaKey
,
receptionRsaKey
=
createKeys
(
rng
,
e2e
)
// Salt, UID, etc gen
// Salt, UID, etc gen
stream
:=
rng
.
GetStream
()
stream
:=
rng
.
GetStream
()
...
@@ -91,7 +89,7 @@ func createNewUser(rng *fastRNG.StreamGenerator, cmix,
...
@@ -91,7 +89,7 @@ func createNewUser(rng *fastRNG.StreamGenerator, cmix,
}
}
}
}
func
create
Dh
Keys
(
rng
*
fastRNG
.
StreamGenerator
,
func
createKeys
(
rng
*
fastRNG
.
StreamGenerator
,
e2e
*
cyclic
.
Group
)
(
e2eKeyBytes
,
e2e
*
cyclic
.
Group
)
(
e2eKeyBytes
,
transmissionSalt
,
receptionSalt
[]
byte
,
transmissionSalt
,
receptionSalt
[]
byte
,
transmissionRsaKey
,
receptionRsaKey
*
rsa
.
PrivateKey
)
{
transmissionRsaKey
,
receptionRsaKey
*
rsa
.
PrivateKey
)
{
...
@@ -143,44 +141,6 @@ func createDhKeys(rng *fastRNG.StreamGenerator,
...
@@ -143,44 +141,6 @@ func createDhKeys(rng *fastRNG.StreamGenerator,
}
}
// TODO: Add precanned user code structures here.
// creates a precanned user
func
createPrecannedUser
(
precannedID
uint
,
rng
csprng
.
Source
,
cmix
,
e2e
*
cyclic
.
Group
)
user
.
Info
{
// DH Keygen
prng
:=
rand
.
New
(
rand
.
NewSource
(
int64
(
precannedID
)))
prime
:=
e2e
.
GetPBytes
()
keyLen
:=
len
(
prime
)
e2eKeyBytes
,
err
:=
csprng
.
GenerateInGroup
(
prime
,
keyLen
,
prng
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
err
.
Error
())
}
// Salt, UID, etc gen
salt
:=
make
([]
byte
,
SaltSize
)
userID
:=
id
.
ID
{}
binary
.
BigEndian
.
PutUint64
(
userID
[
:
],
uint64
(
precannedID
))
userID
.
SetType
(
id
.
User
)
// NOTE: not used... RSA Keygen (4096 bit defaults)
rsaKey
,
err
:=
rsa
.
GenerateKey
(
rng
,
rsa
.
DefaultRSABitLen
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
err
.
Error
())
}
return
user
.
Info
{
TransmissionID
:
&
userID
,
TransmissionSalt
:
salt
,
ReceptionID
:
&
userID
,
ReceptionSalt
:
salt
,
Precanned
:
true
,
E2eDhPrivateKey
:
e2e
.
NewIntFromBytes
(
e2eKeyBytes
),
TransmissionRSA
:
rsaKey
,
ReceptionRSA
:
rsaKey
,
}
}
// createNewVanityUser generates an identity for cMix
// createNewVanityUser generates an identity for cMix
// The identity's ReceptionID is not random but starts with the supplied prefix
// The identity's ReceptionID is not random but starts with the supplied prefix
func
createNewVanityUser
(
rng
csprng
.
Source
,
cmix
,
func
createNewVanityUser
(
rng
csprng
.
Source
,
cmix
,
...
...
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