mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-10 07:00:08 +00:00
Knut Ahlers
a1df72edc5
commitf0db1ff1f8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:19:56 2017 +0100 Mark option as deprecated Signed-off-by: Knut Ahlers <knut@ahlers.me> commit9891df2a16
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:11:56 2017 +0100 Fix: Typo Signed-off-by: Knut Ahlers <knut@ahlers.me> commit836006de64
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:04:20 2017 +0100 Add new dependencies Signed-off-by: Knut Ahlers <knut@ahlers.me> commitd64fee60c8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 11:55:52 2017 +0100 Replace insecure password hashing Prior this commit passwords were hashed with a static salt and using the SHA1 hashing function. This could lead to passwords being attackable in case someone gets access to the raw data stored inside the database. This commit introduces password hashing using bcrypt hashing function which addresses this issue. Old passwords are not automatically re-hashed as they are unknown. Replacing the old password scheme is not that easy and needs #10 to be solved. Therefore the old hashing scheme is kept for compatibility reason. Signed-off-by: Knut Ahlers <knut@ahlers.me> Signed-off-by: Knut Ahlers <knut@ahlers.me> closes #14 closes #15
122 lines
2.2 KiB
Go
122 lines
2.2 KiB
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ssh
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
type server struct {
|
|
*ServerConn
|
|
chans <-chan NewChannel
|
|
}
|
|
|
|
func newServer(c net.Conn, conf *ServerConfig) (*server, error) {
|
|
sconn, chans, reqs, err := NewServerConn(c, conf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
go DiscardRequests(reqs)
|
|
return &server{sconn, chans}, nil
|
|
}
|
|
|
|
func (s *server) Accept() (NewChannel, error) {
|
|
n, ok := <-s.chans
|
|
if !ok {
|
|
return nil, io.EOF
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
func sshPipe() (Conn, *server, error) {
|
|
c1, c2, err := netPipe()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
clientConf := ClientConfig{
|
|
User: "user",
|
|
}
|
|
serverConf := ServerConfig{
|
|
NoClientAuth: true,
|
|
}
|
|
serverConf.AddHostKey(testSigners["ecdsa"])
|
|
done := make(chan *server, 1)
|
|
go func() {
|
|
server, err := newServer(c2, &serverConf)
|
|
if err != nil {
|
|
done <- nil
|
|
}
|
|
done <- server
|
|
}()
|
|
|
|
client, _, reqs, err := NewClientConn(c1, "", &clientConf)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
server := <-done
|
|
if server == nil {
|
|
return nil, nil, errors.New("server handshake failed.")
|
|
}
|
|
go DiscardRequests(reqs)
|
|
|
|
return client, server, nil
|
|
}
|
|
|
|
func BenchmarkEndToEnd(b *testing.B) {
|
|
b.StopTimer()
|
|
|
|
client, server, err := sshPipe()
|
|
if err != nil {
|
|
b.Fatalf("sshPipe: %v", err)
|
|
}
|
|
|
|
defer client.Close()
|
|
defer server.Close()
|
|
|
|
size := (1 << 20)
|
|
input := make([]byte, size)
|
|
output := make([]byte, size)
|
|
b.SetBytes(int64(size))
|
|
done := make(chan int, 1)
|
|
|
|
go func() {
|
|
newCh, err := server.Accept()
|
|
if err != nil {
|
|
b.Fatalf("Client: %v", err)
|
|
}
|
|
ch, incoming, err := newCh.Accept()
|
|
go DiscardRequests(incoming)
|
|
for i := 0; i < b.N; i++ {
|
|
if _, err := io.ReadFull(ch, output); err != nil {
|
|
b.Fatalf("ReadFull: %v", err)
|
|
}
|
|
}
|
|
ch.Close()
|
|
done <- 1
|
|
}()
|
|
|
|
ch, in, err := client.OpenChannel("speed", nil)
|
|
if err != nil {
|
|
b.Fatalf("OpenChannel: %v", err)
|
|
}
|
|
go DiscardRequests(in)
|
|
|
|
b.ResetTimer()
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
if _, err := ch.Write(input); err != nil {
|
|
b.Fatalf("WriteFull: %v", err)
|
|
}
|
|
}
|
|
ch.Close()
|
|
b.StopTimer()
|
|
|
|
<-done
|
|
}
|