Skip to content
Snippets Groups Projects
Commit bd530a3f authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Move precan out into it's own file

parent dfc8b3a0
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
///////////////////////////////////////////////////////////////////////////////
// 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
}
...@@ -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 = createDhKeys(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 createDhKeys(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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment