diff --git a/LICENSE b/LICENSE index dd5dcca..ffc9c30 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 bounce-chat +Copyright (c) 2015 Hayden Parker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2e126bf..aa22613 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ # go-i2p -An I2P router and library implemented in Go -work in progress check back later +A pure go implementation of the I2P router + +## Status + +go-i2p is in early development. The common data structures are starting to get + +## Contributing + + + +## License + +This project is licensed under the MIT license, see LICENSE for more information. diff --git a/lib/common/certificate.go b/lib/common/certificate.go index cecc84b..ccece32 100644 --- a/lib/common/certificate.go +++ b/lib/common/certificate.go @@ -2,7 +2,7 @@ package common /* I2P Certificate -https://geti2p.net/en/docs/spec/common-structures#type_Certificate +https://geti2p.net/spec/common-structures#type-certificate Accurate for version 0.9.24 +----+----+----+----+----+-// diff --git a/lib/common/keys_and_cert.go b/lib/common/keys_and_cert.go index 7e5ebc1..646c156 100644 --- a/lib/common/keys_and_cert.go +++ b/lib/common/keys_and_cert.go @@ -2,7 +2,7 @@ package common /* I2P KeysAndCert -https://geti2p.net/en/docs/spec/common-structures#struct_KeysAndCert +https://geti2p.net/spec/common-structures#keysandcert Accurate for version 0.9.24 +----+----+----+----+----+----+----+----+ @@ -55,6 +55,7 @@ const ( KEYS_AND_CERT_PUBKEY_SIZE = 256 KEYS_AND_CERT_SPK_SIZE = 128 KEYS_AND_CERT_MIN_SIZE = 387 + KEYS_AND_CERT_DATA_SIZE = 384 ) type KeysAndCert []byte @@ -155,7 +156,7 @@ func (keys_and_cert KeysAndCert) Certificate() (cert Certificate, err error) { err = errors.New("error parsing KeysAndCert: data is smaller than minimum valid size") return } - cert, _, err = ReadCertificate(keys_and_cert[KEYS_AND_CERT_PUBKEY_SIZE+KEYS_AND_CERT_SPK_SIZE:]) + cert, _, err = ReadCertificate(keys_and_cert[KEYS_AND_CERT_DATA_SIZE:]) return } @@ -174,14 +175,14 @@ func ReadKeysAndCert(data []byte) (keys_and_cert KeysAndCert, remainder []byte, err = errors.New("error parsing KeysAndCert: data is smaller than minimum valid size") return } - copy(data[:KEYS_AND_CERT_MIN_SIZE], keys_and_cert) + keys_and_cert = KeysAndCert(data[:KEYS_AND_CERT_MIN_SIZE]) cert, _ := keys_and_cert.Certificate() - n, err := cert.Length() - if err != nil { + cert_len, _ := cert.Length() + if cert_len == 0 { remainder = data[KEYS_AND_CERT_MIN_SIZE:] return } - keys_and_cert = append(keys_and_cert, data[KEYS_AND_CERT_MIN_SIZE:n+3]...) - remainder = data[KEYS_AND_CERT_MIN_SIZE+n+3:] + keys_and_cert = append(keys_and_cert, data[KEYS_AND_CERT_MIN_SIZE:KEYS_AND_CERT_MIN_SIZE+cert_len]...) + remainder = data[KEYS_AND_CERT_MIN_SIZE+cert_len:] return } diff --git a/lib/common/keys_and_cert_test.go b/lib/common/keys_and_cert_test.go index fa09229..2640fdf 100644 --- a/lib/common/keys_and_cert_test.go +++ b/lib/common/keys_and_cert_test.go @@ -1,7 +1,7 @@ package common import ( - //"github.com/stretchr/testify/assert" + "github.com/stretchr/testify/assert" "testing" ) @@ -48,9 +48,37 @@ func TestReadKeysAndCertWithMissingCertData(t *testing.T) { } func TestReadKeysAndCertWithValidDataWithCertificate(t *testing.T) { + assert := assert.New(t) + + cert_data := make([]byte, 128+256) + cert_data = append(cert_data, []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}...) + keys_and_cert, remainder, err := ReadKeysAndCert(cert_data) + assert.Equal(0, len(remainder)) + assert.Nil(err) + + _, err = keys_and_cert.PublicKey() + assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data containing certificate") + _, err = keys_and_cert.SigningPublicKey() + assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data containing certificate") + _, err = keys_and_cert.Certificate() + assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data containing certificate") } func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) { + assert := assert.New(t) + + cert_data := make([]byte, 128+256) + cert_data = append(cert_data, []byte{0x00, 0x00, 0x00}...) + keys_and_cert, remainder, err := ReadKeysAndCert(cert_data) + assert.Equal(0, len(remainder)) + assert.Nil(err) + + _, err = keys_and_cert.PublicKey() + assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data not containing certificate") + _, err = keys_and_cert.SigningPublicKey() + assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data not containing certificate") + _, err = keys_and_cert.Certificate() + assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data not containing certificate") } func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) { diff --git a/lib/common/lease_set_test.go b/lib/common/lease_set_test.go index 805d0c7..d0214af 100644 --- a/lib/common/lease_set_test.go +++ b/lib/common/lease_set_test.go @@ -1 +1,7 @@ package common + +import ( + //"github.com/stretchr/testify/assert" + //"testing" +) +