Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.10
- image: circleci/golang:1.15

working_directory: /go/src/layeh.com/radius
steps:
Expand Down
14 changes: 11 additions & 3 deletions attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,32 @@ func NewUserPassword(plaintext, secret, requestAuthenticator []byte) (Attribute,
chunks = 1
}

pt2 := plaintext
// fill plaintext pt2 with 0s if needed
remainder := len(pt2) % 16
if remainder != 0 || len(pt2) == 0 {
fill := make([]byte, (16 - remainder))
pt2 = append(pt2, fill...)
}

enc := make([]byte, 0, chunks*16)

hash := md5.New()
hash.Write(secret)
hash.Write(requestAuthenticator)
enc = hash.Sum(enc)

for i, b := range plaintext[:16] {
for i, b := range pt2[:16] {
enc[i] ^= b
}

for i := 16; i < len(plaintext); i += 16 {
for i := 16; i < len(pt2); i += 16 {
hash.Reset()
hash.Write(secret)
hash.Write(enc[i-16 : i])
enc = hash.Sum(enc)

for j, b := range plaintext[i : i+16] {
for j, b := range pt2[i : i+16] {
enc[i+j] ^= b
}
}
Expand Down
27 changes: 27 additions & 0 deletions attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ func TestNewUserPassword_length(t *testing.T) {
}
}

func TestNewUserPassword_byteLength(t *testing.T) {
tbl := []struct {
Password []byte
EncodedLength int
}{
{[]byte(""), 16},
{[]byte("abc"), 16},
{[]byte("0123456789abcde"), 16},
{[]byte("0123456789abcdef"), 16},
{[]byte("0123456789abcdef0"), 16 * 2},
{[]byte("0123456789abcdef0123456789abcdef0123456789abcdef"), 16 * 3},
}

secret := []byte(`12345`)
ra := []byte(`0123456789abcdef`)

for _, x := range tbl {
attr, err := NewUserPassword(x.Password, secret, ra)
if err != nil {
t.Fatal(err)
}
if len(attr) != x.EncodedLength {
t.Fatalf("expected encoded length of %#v = %d, got %d", x.Password, x.EncodedLength, len(attr))
}
}
}

func TestTunnelPassword(t *testing.T) {
roundtrip := []string{
"",
Expand Down
4 changes: 2 additions & 2 deletions client-example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"log"

"layeh.com/radius"
"layeh.com/radius/rfc2865"
"github.com/holgermetschulat/radius"
"github.com/holgermetschulat/radius/rfc2865"
)

var (
Expand Down
7 changes: 5 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func (c *Client) Exchange(ctx context.Context, packet *Packet, addr string) (*Pa
}
defer conn.Close()

conn.Write(wire)
_, err = conn.Write(wire)
if err != nil {
return nil, err
}

var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
Expand Down Expand Up @@ -108,7 +111,7 @@ func (c *Client) Exchange(ctx context.Context, packet *Packet, addr string) (*Pa
return nil, err
}

received, err := Parse(incoming[:n], packet.Secret)
received, err := Parse(incoming[:n], packet.CryptoAuthenticator[:], packet.Secret)
if err != nil {
packetErrorCount++
if c.MaxPacketErrors > 0 && packetErrorCount >= c.MaxPacketErrors {
Expand Down
4 changes: 2 additions & 2 deletions cmd/radius-dict-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sort"
"strings"

"layeh.com/radius/dictionary"
"layeh.com/radius/dictionarygen"
"github.com/holgermetschulat/radius/dictionary"
"github.com/holgermetschulat/radius/dictionarygen"
)

type Refs map[string]string
Expand Down
4 changes: 2 additions & 2 deletions cmd/radserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"os/exec"

"layeh.com/radius"
"layeh.com/radius/rfc2865"
"github.com/holgermetschulat/radius"
"github.com/holgermetschulat/radius/rfc2865"
)

var secret = flag.String("secret", "", "shared RADIUS secret between clients and server")
Expand Down
4 changes: 2 additions & 2 deletions cmd/radtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strconv"
"time"

"layeh.com/radius"
"layeh.com/radius/rfc2865"
"github.com/holgermetschulat/radius"
"github.com/holgermetschulat/radius/rfc2865"
)

const usage = `
Expand Down
3 changes: 3 additions & 0 deletions cryptotest/dictionary.cryptotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ATTRIBUTE CT-Int 11 integer encrypt=2
ATTRIBUTE CT-Octects 12 octets encrypt=2
ATTRIBUTE CT-IPADDR 13 ipaddr encrypt=2
3 changes: 3 additions & 0 deletions cryptotest/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:generate go run ../cmd/radius-dict-gen/main.go -package cryptotest -output generated_cryptotest_test.go dictionary.cryptotest

package cryptotest
Loading