예제 #1
0
func TestSignProof(t *testing.T) {
	pubkeyRec, privKeyRec, _ := ed25519.GenerateKey(rand.Reader)
	pubkeySend, privkeySend, _ := ed25519.GenerateKey(rand.Reader)
	now := time.Now().UnixNano()
	proof := SignProofToken(now, pubkeyRec, pubkeySend, privkeySend)
	ok, nowDec, senderPub := VerifyProofToken(proof, pubkeyRec)
	if !ok {
		t.Error("Siganture did not verify")
	}
	if *senderPub != *pubkeySend {
		t.Error("Sender Pubkey decode failed")
	}
	if now != nowDec {
		t.Error("Time decode failed")
	}
	ok, signedProofToken := CounterSignToken(proof, pubkeyRec, privKeyRec)
	if !ok {
		t.Error("CounterSignToken did not verify")
	}
	ok, nowDec2 := VerifyCounterSig(signedProofToken, pubkeySend)
	if !ok {
		t.Error("VerifyCounterSig did not verify")
	}
	if now != nowDec2 {
		t.Error("Time decode failed")
	}
}
예제 #2
0
func TestGenerateIDKeys(t *testing.T) {
	var err error
	clientPK, clientSK, err = ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatalf("%v", err)
	}

	serverPK, serverSK, err = ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatalf("%v", err)
	}
}
예제 #3
0
func GenerateKeys(random io.Reader) (*[64]byte, *[32]byte) {
	pub, priv, err := ed25519.GenerateKey(random)
	if err != nil {
		lg.Fatal(err)
	}
	return priv, pub
}
예제 #4
0
파일: main.go 프로젝트: rakoo/challengeauth
func getSigningKey() (*[ed25519.PublicKeySize]byte, *[ed25519.PrivateKeySize]byte) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		log.Fatal(err)
	}
	return pub, priv
}
예제 #5
0
func init() {
	var err error
	testKeyPub, testKeyPriv, err = ed25519.GenerateKey(rand.Reader)
	if err != nil {
		panic(err)
	}
}
예제 #6
0
func TestCheckToken(t *testing.T) {
	now := uint64(times.Now()) / SkewWindow
	pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatalf("Key generation failed: %s", err)
	}
	authtoken := CreateToken(pubkey, privkey, 1)
	pubkey2, ltime, lcounter, err := authtoken.CheckToken()
	if err != nil {
		t.Errorf("Token verification failed: %s", err)
	}
	if *pubkey2 != *pubkey {
		t.Errorf("Token decode failed, pubkey does not match: %x!=%x", *pubkey2, *pubkey)
	}
	if lcounter != 1 {
		t.Errorf("Token decode failed. Counter %d!=1", lcounter)
	}
	if uint64(math.Abs(float64(ltime-now))) > 1 {
		t.Errorf("Token decode failed. Time: %d!=%d", now, ltime)
	}
	authtoken[0] = 0x00
	_, _, _, err = authtoken.CheckToken()
	if err == nil {
		t.Error("Token verification MUST fail")
	}
}
예제 #7
0
func TestConv(t *testing.T) {
	pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatalf("Keygen failed: %s", err)
	}
	sm := make(StringMap)
	sm["alpha"] = "first"
	sm["beta"] = "second"
	sm["gamma"] = "third"
	sm["delta"] = "fourth"
	ss := sm.Sort()
	if ss[0].K != "alpha" || ss[0].V != "first" {
		t.Error("Bad first")
	}
	if ss[3].K != "gamma" || ss[3].V != "third" {
		t.Error("Bad last")
	}
	sig := ss.Sign(10, privkey)
	if !ss.Verify(10, pubkey[:], sig) {
		t.Error("Signature verify failed")
	}
	if ss.Verify(11, pubkey[:], sig) {
		t.Error("Signature verification MUST fail on bad date")
	}
	sig[3] = ^sig[3]
	if ss.Verify(10, pubkey[:], sig) {
		t.Error("Signature verification MUST fail on bad signature")
	}
}
예제 #8
0
파일: client.go 프로젝트: jackyyf/isreversi
func main() {
	user = new(common.User)
	game = new(common.Game)
	var err error
	pubkey, privkey, err = ed25519.GenerateKey(rand.Reader)
	if err != nil {
		panic(err)
	}
	socket, err := utp.Dial("localhost:5428")
	if err != nil {
		panic(err)
	}
	if !handshake(socket) {
		panic("Handshake to server failed!")
	}
	rl, err = readline.NewEx(&readline.Config{
		Prompt: "> ",
		// HistoryFile: "./readline.history",
		InterruptPrompt: "Ctrl-C received, exiting ...",
		EOFPrompt:       "\n",
		AutoComplete:    completer,
	})
	stderr = rl.Stderr()
	go downstream()
	upstream()
}
예제 #9
0
func main() {
	showHelp := flag.Bool("h", false, "display a short usage message and exit")
	flag.Parse()

	if *showHelp {
		usage()
		os.Exit(0)
	}

	if flag.NArg() == 0 {
		usage()
		os.Exit(1)
	}

	for _, baseName := range flag.Args() {
		pubFileName := fmt.Sprintf("%s.pub", baseName)
		privFileName := fmt.Sprintf("%s.key", baseName)

		pub, priv, err := ed25519.GenerateKey(rand.Reader)
		die.If(err)

		err = ioutil.WriteFile(pubFileName, pub[:], 0644)
		die.If(err)

		err = ioutil.WriteFile(privFileName, priv[:], 0600)
		die.If(err)
	}
}
예제 #10
0
// Ed25519Generate generates a new Ed25519 key pair.
func Ed25519Generate(rand io.Reader) (*Ed25519Key, error) {
	publicKey, privateKey, err := ed25519.GenerateKey(rand)
	if err != nil {
		return nil, err
	}
	return &Ed25519Key{publicKey, privateKey}, nil
}
예제 #11
0
파일: server.go 프로젝트: RoPe93/repbin
// New returns a MessageServer.
func New(driver, url, path string, pubKey, privKey []byte) (*MessageServer, error) {
	var err error
	ms := new(MessageServer)
	ms.DB = messagestore.New(driver, url, path, Workers)
	if err != nil {
		return nil, err
	}
	ms.path = path
	ms.PeerFile = path + "peers.config"
	ms.AddToPeer = DefaultAddToPeer
	ms.MaxTimeSkew = DefaultMaxTimeSkew
	ms.MinPostSize = MinPostSize
	ms.MaxPostSize = MaxPostSize
	ms.MinHashCashBits = MinHashCashBits
	ms.MaxSleep = DefaultMaxSleep
	ms.MaxIndexGlobal = DefaultIndexGlobal
	ms.MaxIndexKey = DefaultIndexKey
	ms.TimeGrace = DefaultTimeGrace
	ms.MaxAuthTokenAge = DefaultAuthTokenAge
	ms.NotifyDuration = DefaultNotifyDuration
	ms.FetchDuration = DefaultFetchDuration
	ms.FetchMax = DefaultFetchMax
	ms.ExpireDuration = DefaultExpireDuration
	ms.ExpireFSDuration = DefaultExpireFSDuration
	ms.StepLimit = DefaultStepLimit
	ms.ListenPort = DefaultListenPort
	ms.MinStoreTime = DefaultMinStoreTime
	ms.MaxStoreTime = DefaultMaxStoreTime
	ms.MaxAgeSigners = DefaultMaxAgeSigners
	ms.MaxAgeRecipients = DefaultMaxAgeRecipients
	messagestore.MaxAgeRecipients = DefaultMaxAgeRecipients
	messagestore.MaxAgeSigners = DefaultMaxAgeSigners
	ms.EnablePeerHandler = true

	ms.authPrivKey, err = message.GenLongTermKey(true, false)
	if err != nil {
		return nil, err
	}
	ms.AuthPubKey = message.GenPubKey(ms.authPrivKey)
	if pubKey != nil && privKey != nil {
		ms.TokenPubKey = new([ed25519.PublicKeySize]byte)
		ms.TokenPrivKey = new([ed25519.PrivateKeySize]byte)
		copy(ms.TokenPubKey[:], pubKey)
		copy(ms.TokenPrivKey[:], privKey)
	} else {
		ms.TokenPubKey, ms.TokenPrivKey, err = ed25519.GenerateKey(rand.Reader)
		log.Printf("Peer authentication public key: %s\n", utils.B58encode(ms.TokenPubKey[:]))
		log.Printf("Peer authentication private key: %s\n", utils.B58encode(ms.TokenPrivKey[:]))
		if err != nil {
			return nil, err
		}
	}
	ms.InfoStruct = new(ServerInfo)
	ms.InfoStruct.MinHashCashBits = ms.MinHashCashBits
	ms.InfoStruct.MinPostSize = ms.MinPostSize
	ms.InfoStruct.MaxPostSize = ms.MaxPostSize
	ms.InfoStruct.AuthPubKey = utils.B58encode(ms.AuthPubKey[:])
	return ms, nil
}
예제 #12
0
파일: sign.go 프로젝트: pylls/balloon
// GenerateSigningKeyPair attempts to generate a signature key-pair.
func GenerateSigningKeyPair() (sk, vk []byte, err error) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, nil, errors.New("failed to generate secret signing key: " + err.Error())
	}

	return priv[:], pub[:], nil
}
예제 #13
0
// GenerateSigningKey generates a signing key and import it into the keyring.
func (k *Keyring) GenerateSigningKey() (*SigningSecretKey, error) {
	pub, sec, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, err
	}
	ret := NewSigningSecretKey(pub, sec)
	return &ret, nil
}
예제 #14
0
func (kp *Full) keys() (*[32]byte, *[64]byte) {
	reader := bytes.NewReader(kp.rawSeed())
	pub, priv, err := ed25519.GenerateKey(reader)
	if err != nil {
		panic(err)
	}
	return pub, priv
}
예제 #15
0
파일: signatures.go 프로젝트: mm3/Sia
// GenerateKeyPair creates a public-secret keypair that can be used to sign and
// verify messages.
func GenerateSignatureKeys() (sk SecretKey, pk PublicKey, err error) {
	pkPointer, skPointer, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return
	}
	sk = *skPointer
	pk = *pkPointer
	return
}
예제 #16
0
func TestSPKI(t *testing.T) {
	pk, sk, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		panic(err)
	}

	outs, err := sx.SXCanonical.String(spki.FormEd25519PrivateKey(sk))
	if err != nil {
		panic(err)
	}

	v, err := sx.SX.Parse([]byte(outs))
	if err != nil {
		panic(fmt.Sprintf("failed to parse: %v: %#v", err, outs))
	}

	var sk2 [64]byte
	isPrivate, err := spki.LoadEd25519Key(v, &sk2)
	if err != nil {
		panic(fmt.Sprintf("failed to load: %v: %#v", err, v))
	}

	if !isPrivate {
		panic("should be private")
	}

	if !bytes.Equal(sk[:], sk2[:]) {
		panic("should be equal")
	}

	// public key

	outs, err = sx.SXCanonical.String(spki.FormEd25519PublicKeyFromPrivateKey(sk))
	if err != nil {
		panic(err)
	}

	v, err = sx.SX.Parse([]byte(outs))
	if err != nil {
		panic(err)
	}

	var sk3 [64]byte
	isPrivate, err = spki.LoadEd25519Key(v, &sk3)
	if err != nil {
		panic(err)
	}

	if isPrivate {
		panic("should be public")
	}

	if !bytes.Equal(pk[:], sk3[32:]) {
		panic("should be equal")
	}
}
예제 #17
0
// NewIdentity generates a new identity.
func NewIdentity() (*Identity, error) {
	var err error
	id := &Identity{}
	id.public, id.private, err = ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, err
	}

	return id, nil
}
예제 #18
0
func TestSplitKey(t *testing.T) {
	pubkey, privkey, _ := ed25519.GenerateKey(rand.Reader)
	pubkey2, privkey2 := splitKey(privkey)
	if *pubkey != *pubkey2 {
		t.Error("Split: Public key wrong")
	}
	if *privkey != *privkey2 {
		t.Error("Split: Private key wrong")
	}
}
예제 #19
0
func makeNaclSigningKeyPair(reader io.Reader) (NaclSigningKeyPair, error) {
	pub, priv, err := ed25519.GenerateKey(reader)
	if err != nil {
		return NaclSigningKeyPair{}, err
	}
	return NaclSigningKeyPair{
		Public:  *pub,
		Private: (*NaclSigningKeyPrivate)(priv),
	}, nil
}
예제 #20
0
func (trust *Ed25519) Create(role string) (*data.PublicKey, error) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, err
	}
	public := data.NewPublicKey("ed25519", pub[:])
	private := data.NewPrivateKey("ed25519", pub[:], priv[:])
	trust.addKey(private)
	return public, nil
}
예제 #21
0
func TestKeys(t *testing.T) {
	var cpriv, cpub, cpub2 [32]byte
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if assert.NoError(t, err) {
		assert.True(t, extra25519.PublicKeyToCurve25519(&cpub, pub), "Calling PublicKeyToCurve25519 failed")
		extra25519.PrivateKeyToCurve25519(&cpriv, priv)
		curve25519.ScalarBaseMult(&cpub2, &cpriv)
		assert.Equal(t, cpub, cpub2)
	}
}
예제 #22
0
파일: config.go 프로젝트: mewbak/repbin
// showConfig shows current (default) config
func showConfig() {
	if defaultSettings.PeeringPrivateKey == "" {
		pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
		if err == nil {
			defaultSettings.PeeringPrivateKey = utils.B58encode(privkey[:])
			defaultSettings.PeeringPublicKey = utils.B58encode(pubkey[:])
		}
	}
	config, _ := json.MarshalIndent(defaultSettings, "", "    ")
	fmt.Println(string(config))
}
예제 #23
0
파일: fuzz.go 프로젝트: mark-adams/client
func newSigPrivKey() (*sigPrivKey, error) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, err
	}
	k := &sigPrivKey{
		public:  newSigPubKey(*pub),
		private: *priv,
	}
	return k, nil
}
예제 #24
0
파일: ed25519.go 프로젝트: askk/ripple
func NewEd25519Key(seed []byte) (*ed25519key, error) {
	r := rand.Reader
	if seed != nil {
		r = bytes.NewReader(Sha512Half(seed))
	}
	_, priv, err := ed25519.GenerateKey(r)
	if err != nil {
		return nil, err
	}
	return &ed25519key{*priv}, nil
}
예제 #25
0
파일: ed25519.go 프로젝트: smitterson/hc
// ED25519GenerateKey return a public and private ED25519 key pair from a string.
func ED25519GenerateKey(str string) ([]byte /* public */, []byte /* private */, error) {
	b := bytes.NewBuffer([]byte(str))
	if len(str) < 32 {
		zeros := make([]byte, 32-len(str))
		b.Write(zeros)
	}

	public, private, err := ed25519.GenerateKey(bytes.NewReader(b.Bytes()))

	return public[:], private[:], err
}
예제 #26
0
func newSigPrivKey(t *testing.T) *sigPrivKey {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}
	k := &sigPrivKey{
		public:  newSigPubKey(*pub),
		private: *priv,
	}
	kr.insertSigningKey(k)
	return k
}
예제 #27
0
파일: ed25519.go 프로젝트: gitter-badger/ac
//
// TODO: need to implement type Signer interface
//       which mean we need Public() and Sign()
func GenKeysED25519(r io.Reader) (*Ed25519PrivateKey, error) {
	var err error

	k := new(Ed25519PrivateKey)
	pub, priv, err := ed25519.GenerateKey(r)
	if err != nil {
		return nil, err
	}
	k.Pub = pub
	k.Priv = priv
	return k, nil
}
예제 #28
0
// NewJudge makes a new judge
func NewJudge(name string) (*Judge, error) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		return nil, err
	}

	return &Judge{
		Name:    name,
		Pubkey:  pub[:],
		Privkey: priv[:],
	}, nil
}
예제 #29
0
파일: signing.go 프로젝트: lackac/horizon
func GenerateKeyFromRawSeed(rawSeed RawSeed) (publicKey PublicKey, privateKey PrivateKey, err error) {
	reader := bytes.NewReader(rawSeed[:])
	pub, priv, err := ed25519.GenerateKey(reader)

	if err != nil {
		return
	}

	privateKey = PrivateKey{rawSeed, *priv}
	publicKey = PublicKey{*pub}
	return
}
예제 #30
0
func TestVouch(t *testing.T) {
	signPub, signPriv, err := ed25519.GenerateKey(fakeRand{})
	if err != nil {
		t.Fatalf("unexpected error from ed25519.GenerateKey: %v", err)
	}
	tlsPriv, err := ecdsa.GenerateKey(elliptic.P256(), fakeRand{})
	if err != nil {
		t.Fatalf("unexpected error from ecdsa.GenerateKey: %v", err)
	}
	cert := x509.Certificate{
		// most fields don't matter

		NotAfter: time.Date(2014, 12, 13, 14, 15, 16, 17, time.UTC),
		ExtraExtensions: []pkix.Extension{
			{Id: asn1.ObjectIdentifier{42}, Value: []byte("filler")},
		},
	}
	if err := edtls.Vouch(signPub, signPriv, &cert, &tlsPriv.PublicKey); err != nil {
		t.Fatalf("unexpected error from Vouch: %v", err)
	}
	if ext := cert.ExtraExtensions; len(ext) != 2 {
		t.Fatalf("unexpected ExtraExtensions: %#v", ext)
	}
	vouch := cert.ExtraExtensions[1]
	if g, e := vouch.Id.String(), "1.2.840.113556.1.8000.2554.31830.5190.18203.20240.41147.7688498.2373901"; g != e {
		t.Errorf("unexpected oid for vouch: %q != %q", g, e)
	}
	if g, e := vouch.Critical, false; g != e {
		t.Errorf("unexpected critical flag: %v != %v", g, e)
	}
	if g, e := len(vouch.Value), ed25519.PublicKeySize+ed25519.SignatureSize; g != e {
		t.Errorf("unexpected signature length: %v != %v", g, e)
	}
	if g, e := vouch.Value, []byte{
		// pubkey
		0x21, 0x52, 0xf8, 0xd1, 0x9b, 0x79, 0x1d, 0x24,
		0x45, 0x32, 0x42, 0xe1, 0x5f, 0x2e, 0xab, 0x6c,
		0xb7, 0xcf, 0xfa, 0x7b, 0x6a, 0x5e, 0xd3, 0x00,
		0x97, 0x96, 0x0e, 0x06, 0x98, 0x81, 0xdb, 0x12,
		// sig
		0x81, 0x1b, 0xf8, 0xef, 0x30, 0xf3, 0x2b, 0x6d,
		0x5f, 0x41, 0xa2, 0x04, 0xff, 0x5a, 0xb5, 0xd0,
		0xb1, 0xfc, 0x60, 0xf0, 0x79, 0x10, 0x57, 0xa8,
		0x42, 0x0f, 0x16, 0xe4, 0x57, 0xc3, 0xe4, 0x60,
		0x28, 0x29, 0xf2, 0xfd, 0x06, 0x67, 0x7c, 0x3a,
		0xc0, 0xcd, 0x85, 0xda, 0x0e, 0xf4, 0x8c, 0x1b,
		0xc0, 0xed, 0xf8, 0xd3, 0x10, 0xa7, 0xa0, 0x4e,
		0x34, 0xed, 0x83, 0x57, 0x41, 0x49, 0xbe, 0x06,
	}; !bytes.Equal(g, e) {
		t.Errorf("unexpected signature packet: %x != %x", g, e)
	}
}