Switch to oops for error configuration so we can get more info about failures
This commit is contained in:
@@ -4,9 +4,9 @@ package certificate
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
// log "github.com/sirupsen/logrus"
|
||||
@@ -158,7 +158,7 @@ func readCertificate(data []byte) (certificate Certificate, err error) {
|
||||
"certificate_bytes_length": len(data),
|
||||
"reason": "too short (len < CERT_MIN_SIZE)" + fmt.Sprintf("%d", certificate.kind.Int()),
|
||||
}).Error("invalid certificate, empty")
|
||||
err = fmt.Errorf("error parsing certificate: certificate is empty")
|
||||
err = oops.Errorf("error parsing certificate: certificate is empty")
|
||||
return
|
||||
case 1, 2:
|
||||
certificate.kind = Integer(data[0 : len(data)-1])
|
||||
@@ -168,7 +168,7 @@ func readCertificate(data []byte) (certificate Certificate, err error) {
|
||||
"certificate_bytes_length": len(data),
|
||||
"reason": "too short (len < CERT_MIN_SIZE)" + fmt.Sprintf("%d", certificate.kind.Int()),
|
||||
}).Error("invalid certificate, too short")
|
||||
err = fmt.Errorf("error parsing certificate: certificate is too short")
|
||||
err = oops.Errorf("error parsing certificate: certificate is too short")
|
||||
return
|
||||
default:
|
||||
certificate.kind = Integer(data[0:1])
|
||||
@@ -176,7 +176,7 @@ func readCertificate(data []byte) (certificate Certificate, err error) {
|
||||
payloadLength := len(data) - CERT_MIN_SIZE
|
||||
certificate.payload = data[CERT_MIN_SIZE:]
|
||||
if certificate.len.Int() > len(data)-CERT_MIN_SIZE {
|
||||
err = fmt.Errorf("certificate parsing warning: certificate data is shorter than specified by length")
|
||||
err = oops.Errorf("certificate parsing warning: certificate data is shorter than specified by length")
|
||||
log.WithFields(logrus.Fields{
|
||||
"at": "(Certificate) NewCertificate",
|
||||
"certificate_bytes_length": certificate.len.Int(),
|
||||
@@ -222,12 +222,12 @@ func NewCertificate() *Certificate {
|
||||
|
||||
func NewCertificateDeux(certType int, payload []byte) (*Certificate, error) {
|
||||
if certType < 0 || certType > 255 {
|
||||
return nil, fmt.Errorf("invalid certificate type: %d", certType)
|
||||
return nil, oops.Errorf("invalid certificate type: %d", certType)
|
||||
}
|
||||
certTypeByte := byte(certType)
|
||||
|
||||
if len(payload) > 65535 {
|
||||
return nil, fmt.Errorf("payload too long: %d bytes", len(payload))
|
||||
return nil, oops.Errorf("payload too long: %d bytes", len(payload))
|
||||
}
|
||||
|
||||
_len, err := NewIntegerFromInt(len(payload), 2)
|
||||
@@ -255,12 +255,12 @@ func NewCertificateWithType(certType uint8, payload []byte) (*Certificate, error
|
||||
case CERT_NULL, CERT_HASHCASH, CERT_HIDDEN, CERT_SIGNED, CERT_MULTIPLE, CERT_KEY:
|
||||
// Valid type
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid certificate type: %d", certType)
|
||||
return nil, oops.Errorf("invalid certificate type: %d", certType)
|
||||
}
|
||||
|
||||
// For NULL certificates, payload should be empty
|
||||
if certType == CERT_NULL && len(payload) > 0 {
|
||||
return nil, errors.New("NULL certificates must have empty payload")
|
||||
return nil, oops.Errorf("NULL certificates must have empty payload")
|
||||
}
|
||||
length, _ := NewIntegerFromInt(len(payload), 2)
|
||||
|
||||
@@ -280,10 +280,10 @@ func NewCertificateWithType(certType uint8, payload []byte) (*Certificate, error
|
||||
|
||||
func GetSignatureTypeFromCertificate(cert Certificate) (int, error) {
|
||||
if cert.Type() != CERT_KEY {
|
||||
return 0, fmt.Errorf("unexpected certificate type: %d", cert.Type())
|
||||
return 0, oops.Errorf("unexpected certificate type: %d", cert.Type())
|
||||
}
|
||||
if len(cert.payload) < 4 {
|
||||
return 0, fmt.Errorf("certificate payload too short to contain signature type")
|
||||
return 0, oops.Errorf("certificate payload too short to contain signature type")
|
||||
}
|
||||
sigType := int(binary.BigEndian.Uint16(cert.payload[2:4])) // Changed offset to read signing key type
|
||||
return sigType, nil
|
||||
|
@@ -2,10 +2,10 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func ReadDate(data []byte) (date Date, remainder []byte, err error) {
|
||||
log.WithFields(logrus.Fields{
|
||||
"data": data,
|
||||
}).Error("ReadDate: data is too short")
|
||||
err = errors.New("ReadDate: data is too short")
|
||||
err = oops.Errorf("ReadDate: data is too short")
|
||||
return
|
||||
}
|
||||
copy(date[:], data[:8])
|
||||
|
@@ -1,23 +1,24 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrZeroLength = errors.New("error parsing string: zero length")
|
||||
ErrDataTooShort = errors.New("string parsing warning: string data is shorter than specified by length")
|
||||
ErrDataTooLong = errors.New("string parsing warning: string contains data beyond length")
|
||||
ErrLengthMismatch = errors.New("error reading I2P string, length does not match data")
|
||||
ErrMappingLengthMismatch = errors.New("warning parsing mapping: mapping length exceeds provided data")
|
||||
ErrZeroLength = oops.Errorf("error parsing string: zero length")
|
||||
ErrDataTooShort = oops.Errorf("string parsing warning: string data is shorter than specified by length")
|
||||
ErrDataTooLong = oops.Errorf("string parsing warning: string contains data beyond length")
|
||||
ErrLengthMismatch = oops.Errorf("error reading I2P string, length does not match data")
|
||||
ErrMappingLengthMismatch = oops.Errorf("warning parsing mapping: mapping length exceeds provided data")
|
||||
)
|
||||
|
||||
// WrapErrors compiles a slice of errors and returns them wrapped together as a single error.
|
||||
func WrapErrors(errs []error) error {
|
||||
var err error
|
||||
for i, e := range errs {
|
||||
err = fmt.Errorf("%v\n\t%d: %v", err, i, e)
|
||||
err = oops.Errorf("%v\n\t%d: %v", err, i, e)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -164,7 +163,7 @@ func ReadMapping(bytes []byte) (mapping Mapping, remainder []byte, err []error)
|
||||
"at": "ReadMapping",
|
||||
"reason": "zero length",
|
||||
}).Warn("mapping format violation")
|
||||
e := errors.New("zero length")
|
||||
e := oops.Errorf("zero length")
|
||||
err = append(err, e)
|
||||
return
|
||||
}
|
||||
@@ -184,7 +183,7 @@ func ReadMapping(bytes []byte) (mapping Mapping, remainder []byte, err []error)
|
||||
"expected_size": size.Int(),
|
||||
"actual_size": len(remainder),
|
||||
}).Warn("mapping format violation: mapping length exceeds provided data")
|
||||
e := errors.New("warning parsing mapping: mapping length exceeds provided data")
|
||||
e := oops.Errorf("warning parsing mapping: mapping length exceeds provided data")
|
||||
err = append(err, e)
|
||||
|
||||
// Use whatever data is available (recovery)
|
||||
@@ -209,7 +208,7 @@ func ReadMapping(bytes []byte) (mapping Mapping, remainder []byte, err []error)
|
||||
"at": "ReadMapping",
|
||||
"reason": "error parsing mapping values",
|
||||
}).Warn("mapping format violation")
|
||||
e := errors.New("error parsing mapping values")
|
||||
e := oops.Errorf("error parsing mapping values")
|
||||
err = append(err, e)
|
||||
}
|
||||
if len(remainder) > 0 { // Handle extra bytes beyond mapping length
|
||||
@@ -217,7 +216,7 @@ func ReadMapping(bytes []byte) (mapping Mapping, remainder []byte, err []error)
|
||||
"expected_size": size.Int(),
|
||||
"actual_size": len(remainder),
|
||||
}).Error("mapping format violation: data exists beyond length of mapping")
|
||||
e := errors.New("warning parsing mapping: data exists beyond length of mapping")
|
||||
e := oops.Errorf("warning parsing mapping: data exists beyond length of mapping")
|
||||
err = append(err, e)
|
||||
|
||||
// Slice the exact mapping bytes
|
||||
|
@@ -2,9 +2,9 @@ package data
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -154,7 +154,7 @@ func TestFullGoMapToMappingProducesCorrectMapping(t *testing.T) {
|
||||
func TestStopValueReadTrueWhenCorrectErr(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
status := stopValueRead(errors.New("error parsing string: zero length"))
|
||||
status := stopValueRead(oops.Errorf("error parsing string: zero length"))
|
||||
|
||||
assert.Equal(true, status, "stopValueRead() did not return true when String error found")
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func TestStopValueReadTrueWhenCorrectErr(t *testing.T) {
|
||||
func TestStopValueReadFalseWhenWrongErr(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
status := stopValueRead(errors.New("something else"))
|
||||
status := stopValueRead(oops.Errorf("something else"))
|
||||
|
||||
assert.Equal(false, status, "stopValueRead() did not return false when non String error found")
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -90,7 +90,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"at": "(Mapping) Values",
|
||||
"reason": "data shorter than expected",
|
||||
}).Error("mapping contained no data")
|
||||
errs = []error{errors.New("mapping contained no data")}
|
||||
errs = []error{oops.Errorf("mapping contained no data")}
|
||||
return
|
||||
}
|
||||
map_values := make(MappingValues, 0)
|
||||
@@ -103,7 +103,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"mapping_length_field": int_map_length,
|
||||
"reason": "data longer than expected",
|
||||
}).Warn("mapping format warning")
|
||||
errs = append(errs, errors.New("warning parsing mapping: data exists beyond length of mapping"))
|
||||
errs = append(errs, oops.Errorf("warning parsing mapping: data exists beyond length of mapping"))
|
||||
} else if int_map_length > mapping_len {
|
||||
log.WithFields(logrus.Fields{
|
||||
"at": "(Mapping) Values",
|
||||
@@ -111,7 +111,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"mapping_length_field": int_map_length,
|
||||
"reason": "data shorter than expected",
|
||||
}).Warn("mapping format warning")
|
||||
errs = append(errs, errors.New("warning parsing mapping: mapping length exceeds provided data"))
|
||||
errs = append(errs, oops.Errorf("warning parsing mapping: mapping length exceeds provided data"))
|
||||
}
|
||||
|
||||
encounteredKeysMap := map[string]bool{}
|
||||
@@ -158,7 +158,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"key": string(key_str),
|
||||
}).Error("mapping format violation")
|
||||
log.Printf("DUPE: %s", key_str)
|
||||
errs = append(errs, errors.New("mapping format violation, duplicate key in mapping"))
|
||||
errs = append(errs, oops.Errorf("mapping format violation, duplicate key in mapping"))
|
||||
// Based on other implementations this does not seem to happen often?
|
||||
// Java throws an exception in this case, the base object is a Hashmap so the value is overwritten and an exception is thrown.
|
||||
// i2pd as far as I can tell just overwrites the original value
|
||||
@@ -171,7 +171,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"reason": "expected =",
|
||||
"value:": string(remainder),
|
||||
}).Warn("mapping format violation")
|
||||
errs = append(errs, errors.New("mapping format violation, expected ="))
|
||||
errs = append(errs, oops.Errorf("mapping format violation, expected ="))
|
||||
log.Printf("ERRVAL: %s", remainder)
|
||||
break
|
||||
} else {
|
||||
@@ -197,7 +197,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
|
||||
"reason": "expected ;",
|
||||
"value:": string(remainder),
|
||||
}).Warn("mapping format violation")
|
||||
errs = append(errs, errors.New("mapping format violation, expected ;"))
|
||||
errs = append(errs, oops.Errorf("mapping format violation, expected ;"))
|
||||
break
|
||||
} else {
|
||||
remainder = remainder[1:]
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -124,7 +123,7 @@ func ToI2PString(data string) (str I2PString, err error) {
|
||||
"max_len": STRING_MAX_SIZE,
|
||||
"reason": "too much data",
|
||||
}).Error("cannot create I2P string")
|
||||
err = errors.New("cannot store that much data in I2P string")
|
||||
err = oops.Errorf("cannot store that much data in I2P string")
|
||||
return
|
||||
}
|
||||
i2p_string := []byte{byte(data_len)}
|
||||
|
@@ -31,6 +31,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/signature"
|
||||
"github.com/samber/oops"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -148,7 +149,7 @@ func (keyCertificate KeyCertificate) ConstructPublicKey(data []byte) (public_key
|
||||
"required_len": KEYCERT_PUBKEY_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error constructing public key")
|
||||
err = fmt.Errorf("error constructing public key: not enough data")
|
||||
err = oops.Errorf("error constructing public key: not enough data")
|
||||
return
|
||||
}
|
||||
switch key_type {
|
||||
@@ -191,7 +192,7 @@ var SignaturePublicKeySizes = map[uint16]int{
|
||||
func (keyCertificate *KeyCertificate) CryptoPublicKeySize() (int, error) {
|
||||
size, exists := CryptoPublicKeySizes[uint16(keyCertificate.CpkType.Int())]
|
||||
if !exists {
|
||||
return 0, fmt.Errorf("unknown crypto key type: %d", keyCertificate.CpkType.Int())
|
||||
return 0, oops.Errorf("unknown crypto key type: %d", keyCertificate.CpkType.Int())
|
||||
}
|
||||
return size, nil
|
||||
}
|
||||
@@ -240,7 +241,7 @@ func (keyCertificate KeyCertificate) ConstructSigningPublicKey(data []byte) (sig
|
||||
"required_len": KEYCERT_SPK_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error constructing signing public key")
|
||||
err = fmt.Errorf("error constructing signing public key: not enough data")
|
||||
err = oops.Errorf("error constructing signing public key: not enough data")
|
||||
return
|
||||
}
|
||||
switch signing_key_type {
|
||||
@@ -297,7 +298,7 @@ func (keyCertificate KeyCertificate) ConstructSigningPublicKey(data []byte) (sig
|
||||
log.WithFields(logrus.Fields{
|
||||
"signing_key_type": signing_key_type,
|
||||
}).Warn("Unknown signing key type")
|
||||
return nil, fmt.Errorf("unknown signing key type")
|
||||
return nil, oops.Errorf("unknown signing key type")
|
||||
}
|
||||
|
||||
return
|
||||
@@ -365,11 +366,11 @@ func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder
|
||||
}
|
||||
|
||||
if certificate.Type() != CERT_KEY {
|
||||
return nil, remainder, fmt.Errorf("invalid certificate type: %d", certificate.Type())
|
||||
return nil, remainder, oops.Errorf("invalid certificate type: %d", certificate.Type())
|
||||
}
|
||||
|
||||
if len(certificate.Data()) < 4 {
|
||||
return nil, remainder, fmt.Errorf("key certificate data too short")
|
||||
return nil, remainder, oops.Errorf("key certificate data too short")
|
||||
}
|
||||
log.Println("Certificate Data in NewKeyCertificate: ", certificate.Data()[0:2], certificate.Data()[2:4])
|
||||
|
||||
@@ -393,7 +394,7 @@ func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder
|
||||
|
||||
func KeyCertificateFromCertificate(cert Certificate) (*KeyCertificate, error) {
|
||||
if cert.Type() != CERT_KEY {
|
||||
return nil, fmt.Errorf("expected Key Certificate type, got %d", cert.Type())
|
||||
return nil, oops.Errorf("expected Key Certificate type, got %d", cert.Type())
|
||||
}
|
||||
|
||||
data := cert.Data()
|
||||
@@ -401,7 +402,7 @@ func KeyCertificateFromCertificate(cert Certificate) (*KeyCertificate, error) {
|
||||
fmt.Printf("Certificate Data Bytes in KeyCertificateFromCertificate: %v\n", data)
|
||||
|
||||
if len(data) < 4 {
|
||||
return nil, fmt.Errorf("certificate payload too short in KeyCertificateFromCertificate")
|
||||
return nil, oops.Errorf("certificate payload too short in KeyCertificateFromCertificate")
|
||||
}
|
||||
|
||||
cpkTypeBytes := data[0:2]
|
||||
|
@@ -2,10 +2,8 @@
|
||||
package keys_and_cert
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/certificate"
|
||||
. "github.com/go-i2p/go-i2p/lib/common/key_certificate"
|
||||
@@ -154,7 +152,7 @@ func ReadKeysAndCert(data []byte) (keys_and_cert KeysAndCert, remainder []byte,
|
||||
"required_len": KEYS_AND_CERT_MIN_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing keys and cert")
|
||||
err = errors.New("error parsing KeysAndCert: data is smaller than minimum valid size")
|
||||
err = oops.Errorf("error parsing KeysAndCert: data is smaller than minimum valid size")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -217,7 +215,7 @@ func ReadKeysAndCertElgAndEd25519(data []byte) (keysAndCert *KeysAndCert, remain
|
||||
|
||||
dataLen := len(data)
|
||||
if dataLen < minDataLength {
|
||||
err = fmt.Errorf("error parsing KeysAndCert: data is smaller than minimum valid size, got %d bytes", dataLen)
|
||||
err = oops.Errorf("error parsing KeysAndCert: data is smaller than minimum valid size, got %d bytes", dataLen)
|
||||
log.WithError(err).Error("Data is smaller than minimum valid size")
|
||||
return
|
||||
}
|
||||
@@ -228,7 +226,7 @@ func ReadKeysAndCertElgAndEd25519(data []byte) (keysAndCert *KeysAndCert, remain
|
||||
// Extract public key
|
||||
publicKeyData := data[:pubKeySize]
|
||||
if len(publicKeyData) != pubKeySize {
|
||||
err = errors.New("invalid ElGamal public key length")
|
||||
err = oops.Errorf("invalid ElGamal public key length")
|
||||
log.WithError(err).Error("Invalid ElGamal public key length")
|
||||
return
|
||||
}
|
||||
@@ -244,7 +242,7 @@ func ReadKeysAndCertElgAndEd25519(data []byte) (keysAndCert *KeysAndCert, remain
|
||||
// Extract signing public key
|
||||
signingPubKeyData := data[paddingEnd : paddingEnd+sigKeySize]
|
||||
if len(signingPubKeyData) != sigKeySize {
|
||||
err = errors.New("invalid Ed25519 public key length")
|
||||
err = oops.Errorf("invalid Ed25519 public key length")
|
||||
log.WithError(err).Error("Invalid Ed25519 public key length")
|
||||
return
|
||||
}
|
||||
@@ -273,14 +271,14 @@ func constructPublicKey(data []byte, cryptoType uint16) (crypto.RecievingPublicK
|
||||
switch cryptoType {
|
||||
case CRYPTO_KEY_TYPE_ELGAMAL:
|
||||
if len(data) != 256 {
|
||||
return nil, errors.New("invalid ElGamal public key length")
|
||||
return nil, oops.Errorf("invalid ElGamal public key length")
|
||||
}
|
||||
var elgPublicKey crypto.ElgPublicKey
|
||||
copy(elgPublicKey[:], data)
|
||||
return elgPublicKey, nil
|
||||
// Handle other crypto types...
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported crypto key type: %d", cryptoType)
|
||||
return nil, oops.Errorf("unsupported crypto key type: %d", cryptoType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,12 +286,12 @@ func constructSigningPublicKey(data []byte, sigType uint16) (crypto.SigningPubli
|
||||
switch sigType {
|
||||
case SIGNATURE_TYPE_ED25519_SHA512:
|
||||
if len(data) != 32 {
|
||||
return nil, errors.New("invalid Ed25519 public key length")
|
||||
return nil, oops.Errorf("invalid Ed25519 public key length")
|
||||
}
|
||||
return crypto.Ed25519PublicKey(data), nil
|
||||
// Handle other signature types...
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported signature key type: %d", sigType)
|
||||
return nil, oops.Errorf("unsupported signature key type: %d", sigType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +307,7 @@ func NewKeysAndCert(
|
||||
|
||||
if keyCertificate == nil {
|
||||
log.Error("KeyCertificate is nil")
|
||||
return nil, errors.New("KeyCertificate cannot be nil")
|
||||
return nil, oops.Errorf("KeyCertificate cannot be nil")
|
||||
}
|
||||
|
||||
// Get actual key sizes from certificate
|
||||
@@ -323,7 +321,7 @@ func NewKeysAndCert(
|
||||
"expected_size": pubKeySize,
|
||||
"actual_size": publicKey.Len(),
|
||||
}).Error("Invalid publicKey size")
|
||||
return nil, fmt.Errorf("publicKey has invalid size: expected %d, got %d", pubKeySize, publicKey.Len())
|
||||
return nil, oops.Errorf("publicKey has invalid size: expected %d, got %d", pubKeySize, publicKey.Len())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +332,7 @@ func NewKeysAndCert(
|
||||
"expected_size": sigKeySize,
|
||||
"actual_size": signingPublicKey.Len(),
|
||||
}).Error("Invalid signingPublicKey size")
|
||||
return nil, fmt.Errorf("signingPublicKey has invalid size: expected %d, got %d", sigKeySize, signingPublicKey.Len())
|
||||
return nil, oops.Errorf("signingPublicKey has invalid size: expected %d, got %d", sigKeySize, signingPublicKey.Len())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +343,7 @@ func NewKeysAndCert(
|
||||
"expected_size": expectedPaddingSize,
|
||||
"actual_size": len(padding),
|
||||
}).Error("Invalid padding size")
|
||||
return nil, fmt.Errorf("invalid padding size")
|
||||
return nil, oops.Errorf("invalid padding size")
|
||||
}
|
||||
|
||||
keysAndCert := &KeysAndCert{
|
||||
|
@@ -3,11 +3,11 @@ package lease
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -87,7 +87,7 @@ func ReadLease(data []byte) (lease Lease, remainder []byte, err error) {
|
||||
log.WithField("input_length", len(data)).Debug("Reading Lease from bytes")
|
||||
|
||||
if len(data) < LEASE_SIZE {
|
||||
err = errors.New("error parsing lease: not enough data")
|
||||
err = oops.Errorf("error parsing lease: not enough data")
|
||||
log.WithFields(logrus.Fields{
|
||||
"data_length": len(data),
|
||||
"required_length": LEASE_SIZE,
|
||||
|
@@ -2,10 +2,10 @@
|
||||
package lease_set
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/signature"
|
||||
"github.com/samber/oops"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -175,7 +175,7 @@ func ReadDestinationFromLeaseSet(data []byte) (destination Destination, remainde
|
||||
fmt.Printf("Reading Destination from LeaseSet, input_length=%d\n", len(data))
|
||||
|
||||
if len(data) < 387 { // Minimum size of Destination (384 keys + 3 bytes for minimum certificate)
|
||||
err = errors.New("LeaseSet data too short to contain Destination")
|
||||
err = oops.Errorf("LeaseSet data too short to contain Destination")
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func ReadDestinationFromLeaseSet(data []byte) (destination Destination, remainde
|
||||
fmt.Printf(" destinationLength: %d\n", destinationLength)
|
||||
|
||||
if len(data) < destinationLength {
|
||||
err = errors.New("LeaseSet data too short to contain full Destination")
|
||||
err = oops.Errorf("LeaseSet data too short to contain full Destination")
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func (lease_set LeaseSet) PublicKey() (public_key crypto.ElgPublicKey, err error
|
||||
"required_len": LEASE_SET_PUBKEY_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing public key")
|
||||
err = errors.New("error parsing public key: not enough data")
|
||||
err = oops.Errorf("error parsing public key: not enough data")
|
||||
copy(public_key[:], remainder)
|
||||
return
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func (lease_set LeaseSet) SigningKey() (signing_public_key crypto.SigningPublicK
|
||||
"required_len": offset + LEASE_SET_SPK_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing signing public key")
|
||||
err = errors.New("error parsing signing public key: not enough data")
|
||||
err = oops.Errorf("error parsing signing public key: not enough data")
|
||||
return
|
||||
}
|
||||
if cert_len == 0 {
|
||||
@@ -328,7 +328,7 @@ func (lease_set LeaseSet) LeaseCount() (count int, err error) {
|
||||
"required_len": LEASE_SET_PUBKEY_SIZE + LEASE_SET_SPK_SIZE + 1,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing lease count")
|
||||
err = errors.New("error parsing lease count: not enough data")
|
||||
err = oops.Errorf("error parsing lease count: not enough data")
|
||||
return
|
||||
}
|
||||
c := Integer([]byte{remainder[LEASE_SET_PUBKEY_SIZE+LEASE_SET_SPK_SIZE]})
|
||||
@@ -339,7 +339,7 @@ func (lease_set LeaseSet) LeaseCount() (count int, err error) {
|
||||
"lease_count": count,
|
||||
"reason": "more than 16 leases",
|
||||
}).Warn("invalid lease set")
|
||||
err = errors.New("invalid lease set: more than 16 leases")
|
||||
err = oops.Errorf("invalid lease set: more than 16 leases")
|
||||
} else {
|
||||
log.WithField("lease_count", count).Debug("Retrieved LeaseCount from LeaseSet")
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (lease_set LeaseSet) Leases() (leases []Lease, err error) {
|
||||
"required_len": end,
|
||||
"reason": "some leases missing",
|
||||
}).Error("error parsnig lease set")
|
||||
err = errors.New("error parsing lease set: some leases missing")
|
||||
err = oops.Errorf("error parsing lease set: some leases missing")
|
||||
return
|
||||
}
|
||||
var lease Lease
|
||||
@@ -422,7 +422,7 @@ func (lease_set LeaseSet) Signature() (signature signature.Signature, err error)
|
||||
"required_len": end,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing signatre")
|
||||
err = errors.New("error parsing signature: not enough data")
|
||||
err = oops.Errorf("error parsing signature: not enough data")
|
||||
return
|
||||
}
|
||||
signature = []byte(lease_set[start:end])
|
||||
@@ -500,15 +500,15 @@ func NewLeaseSet(
|
||||
log.Debug("Creating new LeaseSet")
|
||||
// Validate destination size
|
||||
if len(destination.KeysAndCert.Bytes()) < 387 {
|
||||
return nil, errors.New("invalid destination: minimum size is 387 bytes")
|
||||
return nil, oops.Errorf("invalid destination: minimum size is 387 bytes")
|
||||
}
|
||||
// Validate encryption key size
|
||||
if len(encryptionKey.Bytes()) != LEASE_SET_PUBKEY_SIZE {
|
||||
return nil, errors.New("invalid encryption key size")
|
||||
return nil, oops.Errorf("invalid encryption key size")
|
||||
}
|
||||
// Validate inputs
|
||||
if len(leases) > 16 {
|
||||
return nil, errors.New("invalid lease set: more than 16 leases")
|
||||
return nil, oops.Errorf("invalid lease set: more than 16 leases")
|
||||
}
|
||||
// Validate signing key size matches certificate
|
||||
cert := destination.Certificate()
|
||||
@@ -520,13 +520,13 @@ func NewLeaseSet(
|
||||
}
|
||||
expectedSize := keyCert.SignatureSize()
|
||||
if len(signingKey.Bytes()) != expectedSize {
|
||||
return nil, fmt.Errorf("invalid signing key size: got %d, expected %d",
|
||||
return nil, oops.Errorf("invalid signing key size: got %d, expected %d",
|
||||
len(signingKey.Bytes()), expectedSize)
|
||||
}
|
||||
} else {
|
||||
// Default DSA size
|
||||
if len(signingKey.Bytes()) != LEASE_SET_SPK_SIZE {
|
||||
return nil, errors.New("invalid signing key size")
|
||||
return nil, oops.Errorf("invalid signing key size")
|
||||
}
|
||||
}
|
||||
// Build LeaseSet data
|
||||
|
@@ -3,7 +3,6 @@ package lease_set
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -12,6 +11,7 @@ import (
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_address"
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/common/signature"
|
||||
"github.com/samber/oops"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
|
||||
@@ -274,7 +274,7 @@ func createTestLeaseSet(t *testing.T, routerInfo *router_info.RouterInfo, leaseC
|
||||
// Generate test Destination and client keys
|
||||
dest, encryptionKey, signingKey, signingPrivKey, err := generateTestDestination(t)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate test destination: %v", err)
|
||||
return nil, oops.Errorf("failed to generate test destination: %v", err)
|
||||
}
|
||||
|
||||
destBytes := dest.KeysAndCert.Bytes()
|
||||
|
@@ -3,14 +3,13 @@ package router_address
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
@@ -251,7 +250,7 @@ func (router_address RouterAddress) Host() (net.Addr, error) {
|
||||
ip := net.ParseIP(hostBytes)
|
||||
if ip == nil {
|
||||
log.Error("Failed to parse IP address")
|
||||
return nil, fmt.Errorf("null host error")
|
||||
return nil, oops.Errorf("null host error")
|
||||
}
|
||||
// return net.ResolveIPAddr("", ip.String())
|
||||
addr, err := net.ResolveIPAddr("", ip.String())
|
||||
@@ -285,7 +284,7 @@ func (router_address RouterAddress) Port() (string, error) {
|
||||
func (router_address RouterAddress) StaticKey() ([32]byte, error) {
|
||||
sk := router_address.StaticKeyString()
|
||||
if len([]byte(sk)) != 32 {
|
||||
return [32]byte{}, fmt.Errorf("error: invalid static key")
|
||||
return [32]byte{}, oops.Errorf("error: invalid static key")
|
||||
}
|
||||
return [32]byte(sk), nil
|
||||
}
|
||||
@@ -293,7 +292,7 @@ func (router_address RouterAddress) StaticKey() ([32]byte, error) {
|
||||
func (router_address RouterAddress) InitializationVector() ([16]byte, error) {
|
||||
iv := router_address.InitializationVectorString()
|
||||
if len([]byte(iv)) != 16 {
|
||||
return [16]byte{}, fmt.Errorf("error: invalid IV")
|
||||
return [16]byte{}, oops.Errorf("error: invalid IV")
|
||||
}
|
||||
return [16]byte(iv), nil
|
||||
}
|
||||
@@ -319,7 +318,7 @@ func ReadRouterAddress(data []byte) (router_address RouterAddress, remainder []b
|
||||
log.WithField("data_length", len(data)).Debug("Reading RouterAddress from data")
|
||||
if len(data) == 0 {
|
||||
log.WithField("at", "(RouterAddress) ReadRouterAddress").Error("error parsing RouterAddress: no data")
|
||||
err = errors.New("error parsing RouterAddress: no data")
|
||||
err = oops.Errorf("error parsing RouterAddress: no data")
|
||||
return
|
||||
}
|
||||
router_address.TransportCost, remainder, err = NewInteger(data, 1)
|
||||
|
@@ -8,18 +8,20 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
func consolidateNetDb(sourcePath string, destPath string) error {
|
||||
// Create destination directory if it doesn't exist
|
||||
if err := os.MkdirAll(destPath, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create destination directory: %v", err)
|
||||
return oops.Errorf("failed to create destination directory: %v", err)
|
||||
}
|
||||
|
||||
// Walk through all subdirectories
|
||||
return filepath.Walk(sourcePath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error accessing path %q: %v", path, err)
|
||||
return oops.Errorf("error accessing path %q: %v", path, err)
|
||||
}
|
||||
|
||||
// Skip if it's a directory
|
||||
@@ -37,7 +39,7 @@ func consolidateNetDb(sourcePath string, destPath string) error {
|
||||
|
||||
// Copy the file
|
||||
if err := copyFile(srcFile, dstFile); err != nil {
|
||||
return fmt.Errorf("failed to copy %s: %v", info.Name(), err)
|
||||
return oops.Errorf("failed to copy %s: %v", info.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +71,7 @@ func consolidateAllNetDbs(tempDir string) error {
|
||||
|
||||
// Create the temp directory
|
||||
if err := os.MkdirAll(tempDir, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create temp directory: %v", err)
|
||||
return oops.Errorf("failed to create temp directory: %v", err)
|
||||
}
|
||||
|
||||
// Try to consolidate I2P netDb
|
||||
@@ -91,7 +93,7 @@ func consolidateAllNetDbs(tempDir string) error {
|
||||
|
||||
func cleanupTempDir(path string) error {
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return fmt.Errorf("failed to cleanup temporary directory %s: %v", path, err)
|
||||
return oops.Errorf("failed to cleanup temporary directory %s: %v", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -110,7 +112,7 @@ func createTempNetDbDir() (string, error) {
|
||||
// Create the directory with appropriate permissions
|
||||
err := os.MkdirAll(tempDir, 0o755)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create temporary directory: %v", err)
|
||||
return "", oops.Errorf("failed to create temporary directory: %v", err)
|
||||
}
|
||||
|
||||
return tempDir, nil
|
||||
|
@@ -3,13 +3,12 @@ package router_info
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/certificate"
|
||||
"github.com/samber/oops"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
|
||||
@@ -306,7 +305,7 @@ func ReadRouterInfo(bytes []byte) (info RouterInfo, remainder []byte, err error)
|
||||
sigType, err := certificate.GetSignatureTypeFromCertificate(cert)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to get signature type from certificate")
|
||||
return RouterInfo{}, remainder, fmt.Errorf("certificate signature type error: %v", err)
|
||||
return RouterInfo{}, remainder, oops.Errorf("certificate signature type error: %v", err)
|
||||
}
|
||||
|
||||
// Enhanced signature type validation
|
||||
@@ -315,7 +314,7 @@ func ReadRouterInfo(bytes []byte) (info RouterInfo, remainder []byte, err error)
|
||||
"sigType": sigType,
|
||||
"cert": cert,
|
||||
}).Error("Invalid signature type detected")
|
||||
return RouterInfo{}, remainder, fmt.Errorf("invalid signature type: %d", sigType)
|
||||
return RouterInfo{}, remainder, oops.Errorf("invalid signature type: %d", sigType)
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
@@ -329,7 +328,7 @@ func ReadRouterInfo(bytes []byte) (info RouterInfo, remainder []byte, err error)
|
||||
//"required_len": MAPPING_SIZE,
|
||||
"reason": "not enough data",
|
||||
}).Error("error parsing router info")
|
||||
err = errors.New("error parsing router info: not enough data to read signature")
|
||||
err = oops.Errorf("error parsing router info: not enough data to read signature")
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
|
@@ -2,9 +2,8 @@
|
||||
package signature
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -88,12 +87,12 @@ func ReadSignature(data []byte, sigType int) (sig Signature, remainder []byte, e
|
||||
case SIGNATURE_TYPE_REDDSA_SHA512_ED25519:
|
||||
sigLength = RedDSA_SHA512_Ed25519_SIZE
|
||||
default:
|
||||
err = fmt.Errorf("unsupported signature type: %d", sigType)
|
||||
err = oops.Errorf("unsupported signature type: %d", sigType)
|
||||
return
|
||||
}
|
||||
|
||||
if len(data) < sigLength {
|
||||
err = fmt.Errorf("insufficient data to read signature: need %d bytes, have %d", sigLength, len(data))
|
||||
err = oops.Errorf("insufficient data to read signature: need %d bytes, have %d", sigLength, len(data))
|
||||
log.WithError(err).Error("Failed to read Signature")
|
||||
return
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (d *AESSymmetricDecrypter) Decrypt(data []byte) ([]byte, error) {
|
||||
|
||||
if len(data)%aes.BlockSize != 0 {
|
||||
log.Error("Ciphertext is not a multiple of the block size")
|
||||
return nil, fmt.Errorf("ciphertext is not a multiple of the block size")
|
||||
return nil, oops.Errorf("ciphertext is not a multiple of the block size")
|
||||
}
|
||||
|
||||
plaintext := make([]byte, len(data))
|
||||
@@ -120,18 +120,18 @@ func pkcs7Unpad(data []byte) ([]byte, error) {
|
||||
length := len(data)
|
||||
if length == 0 {
|
||||
log.Error("Data is empty")
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
return nil, oops.Errorf("data is empty")
|
||||
}
|
||||
padding := int(data[length-1])
|
||||
if padding == 0 || padding > aes.BlockSize {
|
||||
log.WithField("padding", padding).Error("Invalid padding")
|
||||
return nil, fmt.Errorf("invalid padding")
|
||||
return nil, oops.Errorf("invalid padding")
|
||||
}
|
||||
paddingStart := length - padding
|
||||
for i := paddingStart; i < length; i++ {
|
||||
if data[i] != byte(padding) {
|
||||
log.Error("Invalid padding")
|
||||
return nil, fmt.Errorf("invalid padding")
|
||||
return nil, oops.Errorf("invalid padding")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func pkcs7Unpad(data []byte) ([]byte, error) {
|
||||
// EncryptNoPadding encrypts data using AES-CBC without padding
|
||||
func (e *AESSymmetricEncrypter) EncryptNoPadding(data []byte) ([]byte, error) {
|
||||
if len(data)%aes.BlockSize != 0 {
|
||||
return nil, fmt.Errorf("data length must be a multiple of block size")
|
||||
return nil, oops.Errorf("data length must be a multiple of block size")
|
||||
}
|
||||
|
||||
block, err := aes.NewCipher(e.Key)
|
||||
@@ -161,7 +161,7 @@ func (e *AESSymmetricEncrypter) EncryptNoPadding(data []byte) ([]byte, error) {
|
||||
// DecryptNoPadding decrypts data using AES-CBC without padding
|
||||
func (d *AESSymmetricDecrypter) DecryptNoPadding(data []byte) ([]byte, error) {
|
||||
if len(data)%aes.BlockSize != 0 {
|
||||
return nil, fmt.Errorf("data length must be a multiple of block size")
|
||||
return nil, oops.Errorf("data length must be a multiple of block size")
|
||||
}
|
||||
|
||||
block, err := aes.NewCipher(d.Key)
|
||||
|
@@ -4,16 +4,16 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
curve25519 "go.step.sm/crypto/x25519"
|
||||
)
|
||||
|
||||
var Curve25519EncryptTooBig = errors.New("failed to encrypt data, too big for Curve25519")
|
||||
var Curve25519EncryptTooBig = oops.Errorf("failed to encrypt data, too big for Curve25519")
|
||||
|
||||
type Curve25519PublicKey []byte
|
||||
|
||||
@@ -132,14 +132,14 @@ func (v *Curve25519Verifier) VerifyHash(h, sig []byte) (err error) {
|
||||
}
|
||||
if len(v.k) != curve25519.PublicKeySize {
|
||||
log.Error("Invalid Curve25519 public key size")
|
||||
err = errors.New("failed to verify: invalid curve25519 public key size")
|
||||
err = oops.Errorf("failed to verify: invalid curve25519 public key size")
|
||||
return
|
||||
}
|
||||
|
||||
ok := curve25519.Verify(v.k, h, sig)
|
||||
if !ok {
|
||||
log.Error("Invalid signature")
|
||||
err = errors.New("failed to verify: invalid signature")
|
||||
err = oops.Errorf("failed to verify: invalid signature")
|
||||
} else {
|
||||
log.Debug("Hash verified successfully")
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (s *Curve25519Signer) Sign(data []byte) (sig []byte, err error) {
|
||||
|
||||
if len(s.k) != curve25519.PrivateKeySize {
|
||||
log.Error("Invalid Curve25519 private key size")
|
||||
err = errors.New("failed to sign: invalid curve25519 private key size")
|
||||
err = oops.Errorf("failed to sign: invalid curve25519 private key size")
|
||||
return
|
||||
}
|
||||
h := sha512.Sum512(data)
|
||||
|
@@ -6,17 +6,17 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
Ed25519EncryptTooBig = errors.New("failed to encrypt data, too big for Ed25519")
|
||||
ErrInvalidPublicKeySize = errors.New("failed to verify: invalid ed25519 public key size")
|
||||
Ed25519EncryptTooBig = oops.Errorf("failed to encrypt data, too big for Ed25519")
|
||||
ErrInvalidPublicKeySize = oops.Errorf("failed to verify: invalid ed25519 public key size")
|
||||
)
|
||||
|
||||
type Ed25519PublicKey []byte
|
||||
@@ -133,7 +133,7 @@ func (elg Ed25519PublicKey) NewEncrypter() (enc Encrypter, err error) {
|
||||
log.Debug("Creating new Ed25519 encrypter")
|
||||
k := createEd25519PublicKey(elg[:])
|
||||
if k == nil {
|
||||
return nil, errors.New("invalid public key format")
|
||||
return nil, oops.Errorf("invalid public key format")
|
||||
}
|
||||
|
||||
enc, err = createEd25519Encryption(k, rand.Reader)
|
||||
@@ -159,14 +159,14 @@ func (v *Ed25519Verifier) VerifyHash(h, sig []byte) (err error) {
|
||||
}
|
||||
if len(v.k) != ed25519.PublicKeySize {
|
||||
log.Error("Invalid Ed25519 public key size")
|
||||
err = errors.New("failed to verify: invalid ed25519 public key size")
|
||||
err = oops.Errorf("failed to verify: invalid ed25519 public key size")
|
||||
return
|
||||
}
|
||||
|
||||
ok := ed25519.Verify(v.k, h, sig)
|
||||
if !ok {
|
||||
log.Warn("Invalid Ed25519 signature")
|
||||
err = errors.New("failed to verify: invalid signature")
|
||||
err = oops.Errorf("failed to verify: invalid signature")
|
||||
} else {
|
||||
log.Debug("Ed25519 signature verified successfully")
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (k Ed25519PrivateKey) Zero() {
|
||||
|
||||
func (k Ed25519PrivateKey) NewDecrypter() (Decrypter, error) {
|
||||
if len(k) != ed25519.PrivateKeySize {
|
||||
return nil, errors.New("invalid ed25519 private key size")
|
||||
return nil, oops.Errorf("invalid ed25519 private key size")
|
||||
}
|
||||
d := &Ed25519Decrypter{
|
||||
privateKey: k,
|
||||
@@ -216,7 +216,7 @@ func (d *Ed25519Decrypter) Decrypt(data []byte) ([]byte, error) {
|
||||
|
||||
func (d *Ed25519Decrypter) DecryptPadding(data []byte, zeroPadding bool) ([]byte, error) {
|
||||
if len(data) != 514 && len(data) != 512 {
|
||||
return nil, errors.New("invalid ciphertext length")
|
||||
return nil, oops.Errorf("invalid ciphertext length")
|
||||
}
|
||||
|
||||
// Extract components based on padding
|
||||
@@ -239,14 +239,14 @@ func (d *Ed25519Decrypter) DecryptPadding(data []byte, zeroPadding bool) ([]byte
|
||||
// Use private key to decrypt
|
||||
m := new(big.Int).ModInverse(a, p)
|
||||
if m == nil {
|
||||
return nil, errors.New("decryption failed: modular inverse does not exist")
|
||||
return nil, oops.Errorf("decryption failed: modular inverse does not exist")
|
||||
}
|
||||
|
||||
decrypted := new(big.Int).Mod(new(big.Int).Mul(b, m), p).Bytes()
|
||||
|
||||
// Remove padding and validate hash
|
||||
if len(decrypted) < 33 {
|
||||
return nil, errors.New("decryption failed: result too short")
|
||||
return nil, oops.Errorf("decryption failed: result too short")
|
||||
}
|
||||
|
||||
hashBytes := decrypted[1:33]
|
||||
@@ -255,7 +255,7 @@ func (d *Ed25519Decrypter) DecryptPadding(data []byte, zeroPadding bool) ([]byte
|
||||
// Verify hash
|
||||
actualHash := sha256.Sum256(message)
|
||||
if !bytes.Equal(hashBytes, actualHash[:]) {
|
||||
return nil, errors.New("decryption failed: hash verification failed")
|
||||
return nil, oops.Errorf("decryption failed: hash verification failed")
|
||||
}
|
||||
|
||||
return message, nil
|
||||
@@ -263,7 +263,7 @@ func (d *Ed25519Decrypter) DecryptPadding(data []byte, zeroPadding bool) ([]byte
|
||||
|
||||
func (k Ed25519PrivateKey) NewSigner() (Signer, error) {
|
||||
if len(k) != ed25519.PrivateKeySize {
|
||||
return nil, errors.New("invalid ed25519 private key size")
|
||||
return nil, oops.Errorf("invalid ed25519 private key size")
|
||||
}
|
||||
return &Ed25519Signer{k: k}, nil
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func (k Ed25519PrivateKey) Generate() (SigningPrivateKey, error) {
|
||||
func (k Ed25519PrivateKey) Public() (SigningPublicKey, error) {
|
||||
fmt.Printf("Ed25519PrivateKey.Public(): len(k) = %d\n", len(k))
|
||||
if len(k) != ed25519.PrivateKeySize {
|
||||
return nil, fmt.Errorf("invalid ed25519 private key size: expected %d, got %d", ed25519.PrivateKeySize, len(k))
|
||||
return nil, oops.Errorf("invalid ed25519 private key size: expected %d, got %d", ed25519.PrivateKeySize, len(k))
|
||||
}
|
||||
pubKey := k[32:]
|
||||
fmt.Printf("Ed25519PrivateKey.Public(): extracted pubKey length: %d\n", len(pubKey))
|
||||
@@ -302,7 +302,7 @@ func (s *Ed25519Signer) Sign(data []byte) (sig []byte, err error) {
|
||||
|
||||
if len(s.k) != ed25519.PrivateKeySize {
|
||||
log.Error("Invalid Ed25519 private key size")
|
||||
err = errors.New("failed to sign: invalid ed25519 private key size")
|
||||
err = oops.Errorf("failed to sign: invalid ed25519 private key size")
|
||||
return
|
||||
}
|
||||
h := sha512.Sum512(data)
|
||||
|
@@ -4,10 +4,10 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"golang.org/x/crypto/openpgp/elgamal"
|
||||
@@ -38,8 +38,8 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
ElgDecryptFail = errors.New("failed to decrypt elgamal encrypted data")
|
||||
ElgEncryptTooBig = errors.New("failed to encrypt data, too big for elgamal")
|
||||
ElgDecryptFail = oops.Errorf("failed to decrypt elgamal encrypted data")
|
||||
ElgEncryptTooBig = oops.Errorf("failed to encrypt data, too big for elgamal")
|
||||
)
|
||||
|
||||
// generate an elgamal key pair
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
import "github.com/samber/oops"
|
||||
|
||||
var (
|
||||
ErrBadSignatureSize = errors.New("bad signature size")
|
||||
ErrInvalidKeyFormat = errors.New("invalid key format")
|
||||
ErrInvalidSignature = errors.New("invalid signature")
|
||||
ErrBadSignatureSize = oops.Errorf("bad signature size")
|
||||
ErrInvalidKeyFormat = oops.Errorf("invalid key format")
|
||||
ErrInvalidSignature = oops.Errorf("invalid signature")
|
||||
)
|
||||
|
||||
// type for verifying signatures
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package i2np
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
common "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
@@ -173,7 +173,7 @@ type BuildRequestRecord struct {
|
||||
Padding [29]byte
|
||||
}
|
||||
|
||||
var ERR_BUILD_REQUEST_RECORD_NOT_ENOUGH_DATA = errors.New("not enough i2np build request record data")
|
||||
var ERR_BUILD_REQUEST_RECORD_NOT_ENOUGH_DATA = oops.Errorf("not enough i2np build request record data")
|
||||
|
||||
func ReadBuildRequestRecord(data []byte) (BuildRequestRecord, error) {
|
||||
log.Debug("Reading BuildRequestRecord")
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package i2np
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
datalib "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
@@ -90,7 +90,7 @@ type I2NPSSUHeader struct {
|
||||
Expiration time.Time
|
||||
}
|
||||
|
||||
var ERR_I2NP_NOT_ENOUGH_DATA = errors.New("not enough i2np header data")
|
||||
var ERR_I2NP_NOT_ENOUGH_DATA = oops.Errorf("not enough i2np header data")
|
||||
|
||||
// Read an entire I2NP message and return the parsed header
|
||||
// with embedded encrypted data
|
||||
|
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -19,6 +17,7 @@ import (
|
||||
"github.com/go-i2p/go-i2p/lib/common/signature"
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
"github.com/go-i2p/go-i2p/lib/util/time/sntp"
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
// RouterInfoKeystore is an implementation of KeyStore for storing and retrieving RouterInfo private keys and exporting RouterInfos
|
||||
@@ -82,7 +81,7 @@ func generateNewKey() (crypto.Ed25519PrivateKey, error) {
|
||||
func loadExistingKey(keyData []byte) (crypto.Ed25519PrivateKey, error) {
|
||||
// Validate key length
|
||||
if len(keyData) != ed25519.PrivateKeySize {
|
||||
return nil, errors.New("invalid key length")
|
||||
return nil, oops.Errorf("invalid key length")
|
||||
}
|
||||
|
||||
// Convert to our type
|
||||
@@ -127,31 +126,31 @@ func (ks *RouterInfoKeystore) ConstructRouterInfo(addresses []*router_address.Ro
|
||||
// Get signing keys
|
||||
publicKey, privateKey, err := ks.GetKeys()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get keys: %w", err)
|
||||
return nil, oops.Errorf("failed to get keys: %w", err)
|
||||
}
|
||||
|
||||
// Create certificate with Ed25519 key type
|
||||
payload := new(bytes.Buffer)
|
||||
cryptoKeyType, err := data.NewIntegerFromInt(7, 2) // Ed25519
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create crypto key type: %w", err)
|
||||
return nil, oops.Errorf("failed to create crypto key type: %w", err)
|
||||
}
|
||||
signingKeyType, err := data.NewIntegerFromInt(7, 2) // Ed25519
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create signing key type: %w", err)
|
||||
return nil, oops.Errorf("failed to create signing key type: %w", err)
|
||||
}
|
||||
payload.Write(*cryptoKeyType)
|
||||
payload.Write(*signingKeyType)
|
||||
|
||||
cert, err := certificate.NewCertificateWithType(certificate.CERT_KEY, payload.Bytes())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create certificate: %w", err)
|
||||
return nil, oops.Errorf("failed to create certificate: %w", err)
|
||||
}
|
||||
|
||||
// Create padding
|
||||
keyCert, err := key_certificate.KeyCertificateFromCertificate(*cert)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create key certificate: %w", err)
|
||||
return nil, oops.Errorf("failed to create key certificate: %w", err)
|
||||
}
|
||||
|
||||
pubKeySize := keyCert.CryptoSize()
|
||||
@@ -160,7 +159,7 @@ func (ks *RouterInfoKeystore) ConstructRouterInfo(addresses []*router_address.Ro
|
||||
padding := make([]byte, paddingSize)
|
||||
_, err = rand.Read(padding)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate padding: %w", err)
|
||||
return nil, oops.Errorf("failed to generate padding: %w", err)
|
||||
}
|
||||
|
||||
// Create RouterIdentity
|
||||
@@ -171,7 +170,7 @@ func (ks *RouterInfoKeystore) ConstructRouterInfo(addresses []*router_address.Ro
|
||||
padding,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create router identity: %w", err)
|
||||
return nil, oops.Errorf("failed to create router identity: %w", err)
|
||||
}
|
||||
|
||||
// Get timestamp
|
||||
@@ -192,7 +191,7 @@ func (ks *RouterInfoKeystore) ConstructRouterInfo(addresses []*router_address.Ro
|
||||
signature.SIGNATURE_TYPE_EDDSA_SHA512_ED25519,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create router info: %w", err)
|
||||
return nil, oops.Errorf("failed to create router info: %w", err)
|
||||
}
|
||||
|
||||
return ri, nil
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package reseed
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -10,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/eyedeekay/go-unzip/pkg/unzip"
|
||||
@@ -93,7 +93,7 @@ func (r Reseed) SingleReseed(uri string) ([]router_info.RouterInfo, error) {
|
||||
}
|
||||
if len(files) <= 0 {
|
||||
log.Error("Reseed appears to have no content")
|
||||
return nil, fmt.Errorf("error: reseed appears to have no content")
|
||||
return nil, oops.Errorf("error: reseed appears to have no content")
|
||||
}
|
||||
|
||||
log.WithField("file_count", len(files)).Debug("Successfully extracted reseed files")
|
||||
@@ -121,5 +121,5 @@ func (r Reseed) SingleReseed(uri string) ([]router_info.RouterInfo, error) {
|
||||
}
|
||||
}
|
||||
log.Error("Undefined reseed error")
|
||||
return nil, fmt.Errorf("error: undefined reseed error")
|
||||
return nil, oops.Errorf("error: undefined reseed error")
|
||||
}
|
||||
|
@@ -72,7 +72,6 @@ import (
|
||||
"crypto/sha512"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -80,6 +79,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -152,29 +152,29 @@ var contentTypes = map[byte]ContentType{
|
||||
}
|
||||
|
||||
var (
|
||||
ErrMissingMagicBytes = errors.New("missing magic bytes")
|
||||
ErrMissingUnusedByte6 = errors.New("missing unused byte 6")
|
||||
ErrMissingFileFormatVersion = errors.New("missing or incorrect file format version")
|
||||
ErrMissingSignatureType = errors.New("missing or invalid signature type")
|
||||
ErrUnsupportedSignatureType = errors.New("unsupported signature type")
|
||||
ErrMissingSignatureLength = errors.New("missing signature length")
|
||||
ErrMissingUnusedByte12 = errors.New("missing unused byte 12")
|
||||
ErrMissingVersionLength = errors.New("missing version length")
|
||||
ErrVersionTooShort = errors.New("version length too short")
|
||||
ErrMissingUnusedByte14 = errors.New("missing unused byte 14")
|
||||
ErrMissingSignerIDLength = errors.New("missing signer ID length")
|
||||
ErrMissingContentLength = errors.New("missing content length")
|
||||
ErrMissingUnusedByte24 = errors.New("missing unused byte 24")
|
||||
ErrMissingFileType = errors.New("missing or invalid file type")
|
||||
ErrMissingUnusedByte26 = errors.New("missing unused byte 26")
|
||||
ErrMissingContentType = errors.New("missing or invalid content type")
|
||||
ErrMissingUnusedBytes28To39 = errors.New("missing unused bytes 28-39")
|
||||
ErrMissingVersion = errors.New("missing version")
|
||||
ErrMissingSignerID = errors.New("missing signer ID")
|
||||
ErrMissingContent = errors.New("missing content")
|
||||
ErrMissingSignature = errors.New("missing signature")
|
||||
ErrInvalidPublicKey = errors.New("invalid public key")
|
||||
ErrInvalidSignature = errors.New("invalid signature")
|
||||
ErrMissingMagicBytes = oops.Errorf("missing magic bytes")
|
||||
ErrMissingUnusedByte6 = oops.Errorf("missing unused byte 6")
|
||||
ErrMissingFileFormatVersion = oops.Errorf("missing or incorrect file format version")
|
||||
ErrMissingSignatureType = oops.Errorf("missing or invalid signature type")
|
||||
ErrUnsupportedSignatureType = oops.Errorf("unsupported signature type")
|
||||
ErrMissingSignatureLength = oops.Errorf("missing signature length")
|
||||
ErrMissingUnusedByte12 = oops.Errorf("missing unused byte 12")
|
||||
ErrMissingVersionLength = oops.Errorf("missing version length")
|
||||
ErrVersionTooShort = oops.Errorf("version length too short")
|
||||
ErrMissingUnusedByte14 = oops.Errorf("missing unused byte 14")
|
||||
ErrMissingSignerIDLength = oops.Errorf("missing signer ID length")
|
||||
ErrMissingContentLength = oops.Errorf("missing content length")
|
||||
ErrMissingUnusedByte24 = oops.Errorf("missing unused byte 24")
|
||||
ErrMissingFileType = oops.Errorf("missing or invalid file type")
|
||||
ErrMissingUnusedByte26 = oops.Errorf("missing unused byte 26")
|
||||
ErrMissingContentType = oops.Errorf("missing or invalid content type")
|
||||
ErrMissingUnusedBytes28To39 = oops.Errorf("missing unused bytes 28-39")
|
||||
ErrMissingVersion = oops.Errorf("missing version")
|
||||
ErrMissingSignerID = oops.Errorf("missing signer ID")
|
||||
ErrMissingContent = oops.Errorf("missing content")
|
||||
ErrMissingSignature = oops.Errorf("missing signature")
|
||||
ErrInvalidPublicKey = oops.Errorf("invalid public key")
|
||||
ErrInvalidSignature = oops.Errorf("invalid signature")
|
||||
)
|
||||
|
||||
const magicBytes = "I2Psu3"
|
||||
@@ -217,7 +217,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err := reader.Read(mbytes)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read magic bytes")
|
||||
return nil, fmt.Errorf("reading magic bytes: %w", err)
|
||||
return nil, oops.Errorf("reading magic bytes: %w", err)
|
||||
}
|
||||
if l != len(mbytes) {
|
||||
log.Error("Missing magic bytes")
|
||||
@@ -235,7 +235,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused byte 6")
|
||||
return nil, fmt.Errorf("reading unused byte 6: %w", err)
|
||||
return nil, oops.Errorf("reading unused byte 6: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing unused byte 6")
|
||||
@@ -248,7 +248,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read SU3 file format version")
|
||||
return nil, fmt.Errorf("reading SU3 file format version: %w", err)
|
||||
return nil, oops.Errorf("reading SU3 file format version: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing SU3 file format version")
|
||||
@@ -271,7 +271,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(sigTypeBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read signature type")
|
||||
return nil, fmt.Errorf("reading signature type: %w", err)
|
||||
return nil, oops.Errorf("reading signature type: %w", err)
|
||||
}
|
||||
if l != 2 {
|
||||
log.Error("Missing signature type")
|
||||
@@ -291,7 +291,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(sigLengthBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read signature length")
|
||||
return nil, fmt.Errorf("reading signature length: %w", err)
|
||||
return nil, oops.Errorf("reading signature length: %w", err)
|
||||
}
|
||||
if l != 2 {
|
||||
log.Error("Missing signature length")
|
||||
@@ -307,7 +307,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused byte 12")
|
||||
return nil, fmt.Errorf("reading unused byte 12: %w", err)
|
||||
return nil, oops.Errorf("reading unused byte 12: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing unused byte 12")
|
||||
@@ -321,7 +321,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(verLengthBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read version length")
|
||||
return nil, fmt.Errorf("reading version length: %w", err)
|
||||
return nil, oops.Errorf("reading version length: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing version length")
|
||||
@@ -339,7 +339,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused byte 14")
|
||||
return nil, fmt.Errorf("reading unused byte 14: %w", err)
|
||||
return nil, oops.Errorf("reading unused byte 14: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing unused byte 14")
|
||||
@@ -353,7 +353,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(sigIDLengthBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read signer ID length")
|
||||
return nil, fmt.Errorf("reading signer id length: %w", err)
|
||||
return nil, oops.Errorf("reading signer id length: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing signer ID length")
|
||||
@@ -368,7 +368,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(contentLengthBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read content length")
|
||||
return nil, fmt.Errorf("reading content length: %w", err)
|
||||
return nil, oops.Errorf("reading content length: %w", err)
|
||||
}
|
||||
if l != 8 {
|
||||
log.Error("Missing content length")
|
||||
@@ -383,7 +383,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused byte 24")
|
||||
return nil, fmt.Errorf("reading unused byte 24: %w", err)
|
||||
return nil, oops.Errorf("reading unused byte 24: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing unused byte 24")
|
||||
@@ -397,7 +397,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(fileTypeBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read file type")
|
||||
return nil, fmt.Errorf("reading file type: %w", err)
|
||||
return nil, oops.Errorf("reading file type: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing file type")
|
||||
@@ -416,7 +416,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused byte 26")
|
||||
return nil, fmt.Errorf("reading unused byte 26: %w", err)
|
||||
return nil, oops.Errorf("reading unused byte 26: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing unused byte 26")
|
||||
@@ -430,7 +430,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(contentTypeBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read content type")
|
||||
return nil, fmt.Errorf("reading content type: %w", err)
|
||||
return nil, oops.Errorf("reading content type: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.Error("Missing content type")
|
||||
@@ -450,7 +450,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(unused[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read unused bytes 28-39")
|
||||
return nil, fmt.Errorf("reading unused bytes 28-39: %w", err)
|
||||
return nil, oops.Errorf("reading unused bytes 28-39: %w", err)
|
||||
}
|
||||
if l != 1 {
|
||||
log.WithField("byte_number", 28+i).Error("Missing unused byte")
|
||||
@@ -465,7 +465,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(versionBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.Debug("Read unused bytes 28-39")
|
||||
return nil, fmt.Errorf("reading version: %w", err)
|
||||
return nil, oops.Errorf("reading version: %w", err)
|
||||
}
|
||||
if l != int(verLen) {
|
||||
log.Error("Missing version")
|
||||
@@ -481,7 +481,7 @@ func Read(reader io.Reader) (su3 *SU3, err error) {
|
||||
l, err = reader.Read(signerIDBytes[:])
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Failed to read signer ID")
|
||||
return nil, fmt.Errorf("reading signer id: %w", err)
|
||||
return nil, oops.Errorf("reading signer id: %w", err)
|
||||
}
|
||||
if l != int(signIDLen) {
|
||||
log.Error("Missing signer ID")
|
||||
@@ -562,7 +562,7 @@ func (r *contentReader) Read(p []byte) (n int, err error) {
|
||||
|
||||
if r.finished {
|
||||
log.Warn("Attempt to read content after finishing")
|
||||
return 0, errors.New("out of bytes, maybe you read the signature before you read the content")
|
||||
return 0, oops.Errorf("out of bytes, maybe you read the signature before you read the content")
|
||||
}
|
||||
|
||||
if r.reader == nil {
|
||||
@@ -578,7 +578,7 @@ func (r *contentReader) Read(p []byte) (n int, err error) {
|
||||
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
log.WithError(err).Error("Error reading content")
|
||||
return l, fmt.Errorf("reading content: %w", err)
|
||||
return l, oops.Errorf("reading content: %w", err)
|
||||
} else if errors.Is(err, io.EOF) && r.reader.readSoFar != r.su3.ContentLength {
|
||||
log.Error("Content shorter than expected")
|
||||
return l, ErrMissingContent
|
||||
@@ -656,7 +656,7 @@ func (r *signatureReader) getBytes() {
|
||||
_, err := ioutil.ReadAll(r.su3.contentReader)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to read remaining content")
|
||||
r.err = fmt.Errorf("reading content: %w", err)
|
||||
r.err = oops.Errorf("reading content: %w", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -671,7 +671,7 @@ func (r *signatureReader) getBytes() {
|
||||
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to read signature")
|
||||
r.err = fmt.Errorf("reading signature: %w", err)
|
||||
r.err = oops.Errorf("reading signature: %w", err)
|
||||
} else if reader.readSoFar != uint64(r.su3.SignatureLength) {
|
||||
log.Error("Signature shorter than expected")
|
||||
r.err = ErrMissingSignature
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
import "github.com/samber/oops"
|
||||
|
||||
// error for when we have no transports available to use
|
||||
var ErrNoTransportAvailable = errors.New("no transports available")
|
||||
var ErrNoTransportAvailable = oops.Errorf("no transports available")
|
||||
|
@@ -5,19 +5,19 @@ import (
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
"github.com/go-i2p/go-i2p/lib/transport/obfs"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
"github.com/samber/oops"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func (ns *NoiseSession) testEncryptPacket(plaintext []byte) (int, []byte, error) {
|
||||
if ns.CipherState == nil {
|
||||
return 0, nil, fmt.Errorf("CipherState is nil")
|
||||
return 0, nil, oops.Errorf("CipherState is nil")
|
||||
}
|
||||
|
||||
// Encrypt the data
|
||||
@@ -37,18 +37,18 @@ func (ns *NoiseSession) testEncryptPacket(plaintext []byte) (int, []byte, error)
|
||||
|
||||
func (ns *NoiseSession) testPacketDeux(packet []byte) (int, []byte, error) {
|
||||
if ns.CipherState == nil {
|
||||
return 0, nil, fmt.Errorf("CipherState is nil")
|
||||
return 0, nil, oops.Errorf("CipherState is nil")
|
||||
}
|
||||
|
||||
if len(packet) < 2 {
|
||||
return 0, nil, fmt.Errorf("Packet too short to contain length prefix")
|
||||
return 0, nil, oops.Errorf("Packet too short to contain length prefix")
|
||||
}
|
||||
|
||||
// Extract the length prefix
|
||||
packetLength := binary.BigEndian.Uint16(packet[:2])
|
||||
|
||||
if len(packet[2:]) < int(packetLength) {
|
||||
return 0, nil, fmt.Errorf("Packet data is shorter than indicated length")
|
||||
return 0, nil, oops.Errorf("Packet data is shorter than indicated length")
|
||||
}
|
||||
|
||||
ciphertext := packet[2 : 2+packetLength]
|
||||
|
@@ -3,10 +3,10 @@ package noise
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ func (c *NoiseSession) ComposeReceiverHandshakeMessage(localStatic noise.DHKey,
|
||||
|
||||
if len(remoteStatic) != 0 && len(remoteStatic) != noise.DH25519.DHLen() {
|
||||
log.WithField("rs_length", len(remoteStatic)).Error("Invalid remote static key length")
|
||||
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
||||
return nil, nil, nil, oops.Errorf("only 32 byte curve25519 public keys are supported")
|
||||
}
|
||||
|
||||
negData = make([]byte, 6)
|
||||
@@ -84,7 +84,7 @@ func (c *NoiseSession) ComposeReceiverHandshakeMessage(localStatic noise.DHKey,
|
||||
|
||||
// Verify no CipherStates are returned yet
|
||||
if cs0 != nil || cs1 != nil {
|
||||
return nil, nil, nil, errors.New("unexpected cipher states in message 2")
|
||||
return nil, nil, nil, oops.Errorf("unexpected cipher states in message 2")
|
||||
}
|
||||
|
||||
return negData, msg, state, nil
|
||||
|
@@ -3,13 +3,12 @@ package noise
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
func (c *NoiseSession) RunOutgoingHandshake() error {
|
||||
@@ -59,12 +58,12 @@ func (c *NoiseSession) ComposeInitiatorHandshakeMessage(
|
||||
|
||||
remoteStatic, err := c.peerStaticKey()
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("Peer static key retrieval error: %s", err)
|
||||
return nil, nil, nil, oops.Errorf("Peer static key retrieval error: %s", err)
|
||||
}
|
||||
|
||||
/*localStatic, err := c.localStaticKey()
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("Local static key retrieval error: %s", err)
|
||||
return nil, nil, nil, oops.Errorf("Local static key retrieval error: %s", err)
|
||||
}
|
||||
localStaticDH := noise.DHKey{
|
||||
Public: localStatic[:],
|
||||
@@ -73,7 +72,7 @@ func (c *NoiseSession) ComposeInitiatorHandshakeMessage(
|
||||
localStaticDH := *c.HandshakeKey()
|
||||
|
||||
if len(remoteStatic) != 0 && len(remoteStatic) != noise.DH25519.DHLen() {
|
||||
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
||||
return nil, nil, nil, oops.Errorf("only 32 byte curve25519 public keys are supported")
|
||||
}
|
||||
|
||||
negotiationData = make([]byte, 6)
|
||||
@@ -109,7 +108,7 @@ func (c *NoiseSession) ComposeInitiatorHandshakeMessage(
|
||||
|
||||
// Verify no CipherStates are returned yet
|
||||
if cs0 != nil || cs1 != nil {
|
||||
return nil, nil, nil, errors.New("unexpected cipher states in message 1")
|
||||
return nil, nil, nil, oops.Errorf("unexpected cipher states in message 1")
|
||||
}
|
||||
|
||||
return negotiationData, handshakeMessage, handshakeState, nil
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package noise
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ func (c *NoiseSession) Read(b []byte) (int, error) {
|
||||
"at": "(NoiseSession) Read",
|
||||
"reason": "session is closed",
|
||||
}).Error("session is closed")
|
||||
return 0, errors.New("session is closed")
|
||||
return 0, oops.Errorf("session is closed")
|
||||
}
|
||||
if atomic.CompareAndSwapInt32(&c.activeCall, x, x+2) {
|
||||
defer atomic.AddInt32(&c.activeCall, -2)
|
||||
@@ -36,7 +36,7 @@ func (c *NoiseSession) Read(b []byte) (int, error) {
|
||||
defer c.Mutex.Unlock()
|
||||
if !c.handshakeComplete {
|
||||
log.Error("NoiseSession Read: internal error - handshake still not complete after running")
|
||||
return 0, errors.New("internal error")
|
||||
return 0, oops.Errorf("internal error")
|
||||
}
|
||||
n, err := c.readPacketLocked(b)
|
||||
if err != nil {
|
||||
@@ -52,7 +52,7 @@ func (c *NoiseSession) decryptPacket(data []byte) (int, []byte, error) {
|
||||
|
||||
if c.CipherState == nil {
|
||||
log.Error("Packet decryption: CipherState is nil")
|
||||
return 0, nil, errors.New("CipherState is nil")
|
||||
return 0, nil, oops.Errorf("CipherState is nil")
|
||||
}
|
||||
// Decrypt
|
||||
decryptedData, err := c.CipherState.Decrypt(nil, nil, data)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package noise
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -10,6 +9,7 @@ import (
|
||||
|
||||
cb "github.com/emirpasic/gods/queues/circularbuffer"
|
||||
"github.com/flynn/noise"
|
||||
"github.com/samber/oops"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/transport"
|
||||
@@ -101,7 +101,7 @@ func (s *NoiseSession) peerStaticKey() ([32]byte, error) {
|
||||
return addr.StaticKey()
|
||||
}
|
||||
}
|
||||
return [32]byte{}, fmt.Errorf("Remote static key error")
|
||||
return [32]byte{}, oops.Errorf("Remote static key error")
|
||||
}
|
||||
|
||||
func (s *NoiseSession) peerStaticIV() ([16]byte, error) {
|
||||
@@ -114,7 +114,7 @@ func (s *NoiseSession) peerStaticIV() ([16]byte, error) {
|
||||
return addr.InitializationVector()
|
||||
}
|
||||
}
|
||||
return [16]byte{}, fmt.Errorf("Remote static IV error")
|
||||
return [16]byte{}, oops.Errorf("Remote static IV error")
|
||||
}
|
||||
|
||||
// newBlock allocates a new packet, from hc's free list if possible.
|
||||
@@ -147,7 +147,7 @@ func NewNoiseTransportSession(ri router_info.RouterInfo) (transport.TransportSes
|
||||
return session, nil
|
||||
}
|
||||
log.Error("Failed to create NoiseTransportSession, all addresses failed")
|
||||
return nil, fmt.Errorf("Transport constructor error")
|
||||
return nil, oops.Errorf("Transport constructor error")
|
||||
}
|
||||
|
||||
func NewNoiseSession(ri router_info.RouterInfo) (*NoiseSession, error) {
|
||||
|
@@ -7,12 +7,11 @@ package noise
|
||||
**/
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/data"
|
||||
@@ -27,7 +26,7 @@ type NoiseTransport struct {
|
||||
router_info.RouterInfo
|
||||
transportStyle string
|
||||
Listener net.Listener
|
||||
//peerConnections map[data.Hash]transport.TransportSession
|
||||
// peerConnections map[data.Hash]transport.TransportSession
|
||||
peerConnections map[data.Hash]*NoiseSession
|
||||
}
|
||||
|
||||
@@ -84,7 +83,7 @@ func (noopt *NoiseTransport) SetIdentity(ident router_info.RouterInfo) (err erro
|
||||
"at": "(NoiseTransport) SetIdentity",
|
||||
"reason": "network socket is null",
|
||||
}).Error("network socket is null")
|
||||
err = errors.New("network socket is null")
|
||||
err = oops.Errorf("network socket is null")
|
||||
return
|
||||
}
|
||||
log.Debug("NoiseTransport: Identity set successfully")
|
||||
@@ -100,7 +99,7 @@ func (noopt *NoiseTransport) GetSession(routerInfo router_info.RouterInfo) (tran
|
||||
log.WithField("hash", hash).Debug("NoiseTransport: Getting session")
|
||||
if len(hash) == 0 {
|
||||
log.Error("NoiseTransport: RouterInfo has no IdentityHash")
|
||||
return nil, errors.New("NoiseTransport: GetSession: RouterInfo has no IdentityHash")
|
||||
return nil, oops.Errorf("NoiseTransport: GetSession: RouterInfo has no IdentityHash")
|
||||
}
|
||||
if t, ok := noopt.peerConnections[hash]; ok {
|
||||
log.Debug("NoiseTransport: Existing session found")
|
||||
@@ -194,7 +193,7 @@ func (s *NoiseTransport) localStaticKey() ([32]byte, error) {
|
||||
return addr.StaticKey()
|
||||
}
|
||||
}
|
||||
return [32]byte{}, fmt.Errorf("Remote static key error")
|
||||
return [32]byte{}, oops.Errorf("Remote static key error")
|
||||
}
|
||||
|
||||
func (s *NoiseTransport) localStaticIV() ([16]byte, error) {
|
||||
@@ -207,7 +206,7 @@ func (s *NoiseTransport) localStaticIV() ([16]byte, error) {
|
||||
return addr.InitializationVector()
|
||||
}
|
||||
}
|
||||
return [16]byte{}, fmt.Errorf("Remote static IV error")
|
||||
return [16]byte{}, oops.Errorf("Remote static IV error")
|
||||
}
|
||||
|
||||
func (h *NoiseTransport) HandshakeKey() *noise.DHKey {
|
||||
|
@@ -2,10 +2,9 @@ package noise
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -19,7 +18,7 @@ func (c *NoiseSession) Write(b []byte) (int, error) {
|
||||
"at": "(NoiseSession) Write",
|
||||
"reason": "session is closed",
|
||||
}).Error("session is closed")
|
||||
return 0, errors.New("session is closed")
|
||||
return 0, oops.Errorf("session is closed")
|
||||
}
|
||||
if atomic.CompareAndSwapInt32(&c.activeCall, x, x+2) {
|
||||
defer atomic.AddInt32(&c.activeCall, -2)
|
||||
@@ -38,7 +37,7 @@ func (c *NoiseSession) Write(b []byte) (int, error) {
|
||||
defer c.Mutex.Unlock()
|
||||
if !c.handshakeComplete {
|
||||
log.Error("NoiseSession: Write - internal error, handshake still not complete")
|
||||
return 0, errors.New("internal error")
|
||||
return 0, oops.Errorf("internal error")
|
||||
}
|
||||
n, err := c.writePacketLocked(b)
|
||||
if err != nil {
|
||||
@@ -55,14 +54,14 @@ func (c *NoiseSession) encryptPacket(data []byte) (int, []byte, error) {
|
||||
m := len(data)
|
||||
if c.CipherState == nil {
|
||||
log.Error("NoiseSession: encryptPacket - CipherState is nil")
|
||||
return 0, nil, errors.New("CipherState is nil")
|
||||
return 0, nil, oops.Errorf("CipherState is nil")
|
||||
}
|
||||
|
||||
// Encrypt the data
|
||||
encryptedData, err := c.CipherState.Encrypt(nil, nil, data)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("NoiseSession: encryptPacket - failed to encrypt data")
|
||||
return 0, nil, fmt.Errorf("failed to encrypt: '%w'", err)
|
||||
return 0, nil, oops.Errorf("failed to encrypt: '%w'", err)
|
||||
}
|
||||
// m := len(encryptedData)
|
||||
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package ntcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
"github.com/go-i2p/go-i2p/lib/transport/noise"
|
||||
"github.com/go-i2p/go-i2p/lib/transport/obfs"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"golang.org/x/exp/rand"
|
||||
)
|
||||
|
||||
@@ -97,7 +98,7 @@ func (s *NTCP2Session) peerStaticKey() ([32]byte, error) {
|
||||
return addr.StaticKey()
|
||||
}
|
||||
}
|
||||
return [32]byte{}, fmt.Errorf("Remote static key error")
|
||||
return [32]byte{}, oops.Errorf("Remote static key error")
|
||||
}
|
||||
|
||||
func (s *NTCP2Session) peerStaticIV() ([16]byte, error) {
|
||||
@@ -110,7 +111,7 @@ func (s *NTCP2Session) peerStaticIV() ([16]byte, error) {
|
||||
return addr.InitializationVector()
|
||||
}
|
||||
}
|
||||
return [16]byte{}, fmt.Errorf("Remote static IV error")
|
||||
return [16]byte{}, oops.Errorf("Remote static IV error")
|
||||
}
|
||||
|
||||
// ObfuscateEphemeral implements NTCP2's key obfuscation using AES-256-CBC
|
||||
|
@@ -5,13 +5,14 @@ package ntcp
|
||||
**/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/transport"
|
||||
"github.com/go-i2p/go-i2p/lib/transport/noise"
|
||||
"github.com/go-i2p/go-i2p/lib/util/time/sntp"
|
||||
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,11 +75,11 @@ func (t *NTCP2Transport) Accept() (net.Conn, error) {
|
||||
// then check if it's a router address
|
||||
routerAddr, ok := remoteAddr.(*router_info.RouterInfo)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("remote address is not a router address")
|
||||
return nil, oops.Errorf("remote address is not a router address")
|
||||
}
|
||||
// then check if it's compatible
|
||||
if !t.Compatible(*routerAddr) {
|
||||
return nil, fmt.Errorf("remote router address is not compatible with NTCP2")
|
||||
return nil, oops.Errorf("remote router address is not compatible with NTCP2")
|
||||
}
|
||||
// Wrap connection with NTCP2 session
|
||||
session, err := NewNTCP2Session(remoteAddr.(router_info.RouterInfo)) // nil for incoming connections
|
||||
@@ -102,7 +103,7 @@ func (s *NTCP2Transport) localStaticKey() ([32]byte, error) {
|
||||
return addr.StaticKey()
|
||||
}
|
||||
}
|
||||
return [32]byte{}, fmt.Errorf("Remote static key error")
|
||||
return [32]byte{}, oops.Errorf("Remote static key error")
|
||||
}
|
||||
|
||||
func (s *NTCP2Transport) localStaticIV() ([16]byte, error) {
|
||||
@@ -115,5 +116,5 @@ func (s *NTCP2Transport) localStaticIV() ([16]byte, error) {
|
||||
return addr.InitializationVector()
|
||||
}
|
||||
}
|
||||
return [16]byte{}, fmt.Errorf("Remote static IV error")
|
||||
return [16]byte{}, oops.Errorf("Remote static IV error")
|
||||
}
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package obfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
// ObfuscateEphemeralKey encrypts the ephemeral public key in the message using AES-256-CBC without padding
|
||||
func ObfuscateEphemeralKey(message []byte, aesKey *crypto.AESSymmetricKey) ([]byte, error) {
|
||||
if len(message) < 32 {
|
||||
return nil, fmt.Errorf("message is too short to contain ephemeral public key")
|
||||
return nil, oops.Errorf("message is too short to contain ephemeral public key")
|
||||
}
|
||||
|
||||
// Extract the ephemeral public key (first 32 bytes)
|
||||
@@ -36,7 +35,7 @@ func ObfuscateEphemeralKey(message []byte, aesKey *crypto.AESSymmetricKey) ([]by
|
||||
// DeobfuscateEphemeralKey decrypts the ephemeral public key in the message using AES-256-CBC without padding
|
||||
func DeobfuscateEphemeralKey(message []byte, aesKey *crypto.AESSymmetricKey) ([]byte, error) {
|
||||
if len(message) < 32 {
|
||||
return nil, fmt.Errorf("message is too short to contain ephemeral public key")
|
||||
return nil, oops.Errorf("message is too short to contain ephemeral public key")
|
||||
}
|
||||
|
||||
// Extract the encrypted ephemeral public key (first 32 bytes)
|
||||
|
@@ -2,10 +2,10 @@ package tunnel
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
|
||||
common "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/samber/oops"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -180,7 +180,7 @@ func (delivery_instructions DeliveryInstructions) Type() (int, error) {
|
||||
return FIRST_FRAGMENT, nil
|
||||
}
|
||||
log.Error("DeliveryInstructions contains no data")
|
||||
return 0, errors.New("DeliveryInstructions contains no data")
|
||||
return 0, oops.Errorf("DeliveryInstructions contains no data")
|
||||
}
|
||||
|
||||
// Read the integer stored in the 6-1 bits of a FOLLOW_ON_FRAGMENT's flag, indicating
|
||||
@@ -212,7 +212,7 @@ func (delivery_instructions DeliveryInstructions) FragmentNumber() (int, error)
|
||||
return fragNum, nil
|
||||
}
|
||||
log.Error("Fragment Number only exists on FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
return 0, errors.New("Fragment Number only exists on FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
return 0, oops.Errorf("Fragment Number only exists on FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
}
|
||||
|
||||
// Read the value of the 0 bit of a FOLLOW_ON_FRAGMENT, which is set to 1 to indicate the
|
||||
@@ -246,7 +246,7 @@ func (delivery_instructions DeliveryInstructions) LastFollowOnFragment() (bool,
|
||||
return isLast, nil
|
||||
}
|
||||
log.Error("Last Fragment only exists for FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
return false, errors.New("Last Fragment only exists for FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
return false, oops.Errorf("Last Fragment only exists for FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||
}
|
||||
|
||||
// Return the delivery type for these DeliveryInstructions, can be of type
|
||||
@@ -270,7 +270,7 @@ func (delivery_instructions DeliveryInstructions) DeliveryType() (byte, error) {
|
||||
return deliveryType, nil
|
||||
}
|
||||
log.Error("DeliveryInstructions contains no data")
|
||||
return 0, errors.New("DeliveryInstructions contains no data")
|
||||
return 0, oops.Errorf("DeliveryInstructions contains no data")
|
||||
}
|
||||
|
||||
// Check if the delay bit is set. This feature in unimplemented in the Java router.
|
||||
@@ -304,7 +304,7 @@ func (delivery_instructions DeliveryInstructions) HasDelay() (bool, error) {
|
||||
return delay, nil
|
||||
}
|
||||
log.Error("DeliveryInstructions contains no data")
|
||||
return false, errors.New("DeliveryInstructions contains no data")
|
||||
return false, oops.Errorf("DeliveryInstructions contains no data")
|
||||
}
|
||||
|
||||
// Returns true if the Delivery Instructions are fragmented or false
|
||||
@@ -333,7 +333,7 @@ func (delivery_instructions DeliveryInstructions) Fragmented() (bool, error) {
|
||||
// return ((delivery_instructions[0] & 0x08) == 0x08), nil
|
||||
}
|
||||
log.Error("DeliveryInstructions contains no data")
|
||||
return false, errors.New("DeliveryInstructions contains no data")
|
||||
return false, oops.Errorf("DeliveryInstructions contains no data")
|
||||
}
|
||||
|
||||
// Check if the extended options bit is set. This feature in unimplemented in the Java router.
|
||||
@@ -368,7 +368,7 @@ func (delivery_instructions DeliveryInstructions) HasExtendedOptions() (bool, er
|
||||
return extended_options, nil
|
||||
}
|
||||
log.Error("DeliveryInstructions contains no data")
|
||||
return false, errors.New("DeliveryInstructions contains no data")
|
||||
return false, oops.Errorf("DeliveryInstructions contains no data")
|
||||
}
|
||||
|
||||
// Check if the DeliveryInstructions is of type DT_TUNNEL.
|
||||
@@ -399,7 +399,7 @@ func (delivery_instructions DeliveryInstructions) HasHash() (bool, error) {
|
||||
}
|
||||
if len(delivery_instructions) < min_size {
|
||||
log.Error("Delivery Instructions indicates hash present but has too little data")
|
||||
return false, errors.New("Delivery Instructions indicates hash present but has too little data")
|
||||
return false, oops.Errorf("Delivery Instructions indicates hash present but has too little data")
|
||||
}
|
||||
log.Debug("DeliveryInstructions has Hash")
|
||||
} else {
|
||||
@@ -425,11 +425,11 @@ func (delivery_instructions DeliveryInstructions) TunnelID() (tunnel_id uint32,
|
||||
log.WithField("tunnel_id", tunnel_id).Debug("TunnelID retrieved")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are invalid, too little data for Tunnel ID")
|
||||
err = errors.New("DeliveryInstructions are invalid, too little data for Tunnel ID")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, too little data for Tunnel ID")
|
||||
}
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are not of type DT_TUNNEL")
|
||||
err = errors.New("DeliveryInstructions are not of type DT_TUNNEL")
|
||||
err = oops.Errorf("DeliveryInstructions are not of type DT_TUNNEL")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -455,7 +455,7 @@ func (delivery_instructions DeliveryInstructions) Hash() (hash common.Hash, err
|
||||
log.WithField("hash", hash).Debug("Hash retrieved for DT_TUNNEL")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions is invalid, not contain enough data for hash given type DT_TUNNEL")
|
||||
err = errors.New("DeliveryInstructions is invalid, not contain enough data for hash given type DT_TUNNEL")
|
||||
err = oops.Errorf("DeliveryInstructions is invalid, not contain enough data for hash given type DT_TUNNEL")
|
||||
}
|
||||
} else if delivery_type == DT_ROUTER {
|
||||
if len(delivery_instructions) >= hash_end {
|
||||
@@ -463,11 +463,11 @@ func (delivery_instructions DeliveryInstructions) Hash() (hash common.Hash, err
|
||||
log.WithField("hash", hash).Debug("Hash retrieved for DT_ROUTER")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions is invalid, not contain enough data for hash given type DT_ROUTER")
|
||||
err = errors.New("DeliveryInstructions is invalid, not contain enough data for hash given type DT_ROUTER")
|
||||
err = oops.Errorf("DeliveryInstructions is invalid, not contain enough data for hash given type DT_ROUTER")
|
||||
}
|
||||
} else {
|
||||
log.Error("No Hash on DeliveryInstructions not of type DT_TUNNEL or DT_ROUTER")
|
||||
err = errors.New("No Hash on DeliveryInstructions not of type DT_TUNNEL or DT_ROUTER")
|
||||
err = oops.Errorf("No Hash on DeliveryInstructions not of type DT_TUNNEL or DT_ROUTER")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (delivery_instructions DeliveryInstructions) Delay() (delay_factor DelayFac
|
||||
log.WithField("delay_factor", delay_factor).Debug("Delay factor retrieved for DT_TUNNEL")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
err = errors.New("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
err = oops.Errorf("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
return
|
||||
}
|
||||
} else if di_type == DT_ROUTER {
|
||||
@@ -502,7 +502,7 @@ func (delivery_instructions DeliveryInstructions) Delay() (delay_factor DelayFac
|
||||
log.WithField("delay_factor", delay_factor).Debug("Delay factor retrieved for DT_ROUTER")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
err = errors.New("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
err = oops.Errorf("DeliveryInstructions is invalid, does not contain enough data for DelayFactor")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
@@ -529,7 +529,7 @@ func (delivery_instructions DeliveryInstructions) MessageID() (msgid uint32, err
|
||||
log.WithField("message_id", msgid).Debug("MessageID retrieved for FOLLOW_ON_FRAGMENT")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
err = errors.New("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
}
|
||||
} else if di_type == FIRST_FRAGMENT {
|
||||
var message_id_index int
|
||||
@@ -543,11 +543,11 @@ func (delivery_instructions DeliveryInstructions) MessageID() (msgid uint32, err
|
||||
log.WithField("message_id", msgid).Debug("MessageID retrieved for FIRST_FRAGMENT")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
err = errors.New("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, not enough data for Message ID")
|
||||
}
|
||||
} else {
|
||||
log.Error("No Message ID for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
err = errors.New("No Message ID for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
err = oops.Errorf("No Message ID for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -570,13 +570,13 @@ func (delivery_instructions DeliveryInstructions) ExtendedOptions() (data []byte
|
||||
}
|
||||
if len(delivery_instructions) < extended_options_index+2 {
|
||||
log.Error("DeliveryInstructions are invalid, length is shorter than required for Extended Options")
|
||||
err = errors.New("DeliveryInstructions are invalid, length is shorter than required for Extended Options")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, length is shorter than required for Extended Options")
|
||||
return
|
||||
} else {
|
||||
extended_options_size := common.Integer([]byte{delivery_instructions[extended_options_index]})
|
||||
if len(delivery_instructions) < extended_options_index+1+extended_options_size.Int() {
|
||||
log.Error("DeliveryInstructions are invalid, length is shorter than specified in Extended Options")
|
||||
err = errors.New("DeliveryInstructions are invalid, length is shorter than specified in Extended Options")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, length is shorter than specified in Extended Options")
|
||||
return
|
||||
} else {
|
||||
data = delivery_instructions[extended_options_index+1 : extended_options_size.Int()]
|
||||
@@ -587,7 +587,7 @@ func (delivery_instructions DeliveryInstructions) ExtendedOptions() (data []byte
|
||||
}
|
||||
} else {
|
||||
log.Error("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
err = errors.New("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
err = oops.Errorf("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -606,7 +606,7 @@ func (delivery_instructions DeliveryInstructions) FragmentSize() (frag_size uint
|
||||
log.WithField("fragment_size", frag_size).Debug("FragmentSize retrieved for FOLLOW_ON_FRAGMENT")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
err = errors.New("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
}
|
||||
} else if di_type == FIRST_FRAGMENT {
|
||||
var fragment_size_index int
|
||||
@@ -620,11 +620,11 @@ func (delivery_instructions DeliveryInstructions) FragmentSize() (frag_size uint
|
||||
log.WithField("fragment_size", frag_size).Debug("FragmentSize retrieved for FIRST_FRAGMENT")
|
||||
} else {
|
||||
log.Error("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
err = errors.New("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
err = oops.Errorf("DeliveryInstructions are invalid, not enough data for Fragment Size")
|
||||
}
|
||||
} else {
|
||||
log.Error("No Fragment Size for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
err = errors.New("No Fragment Size for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
err = oops.Errorf("No Fragment Size for DeliveryInstructions not of type FIRST_FRAGMENT or FOLLOW_ON_FRAGMENT")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -668,7 +668,7 @@ func (delivery_instructions DeliveryInstructions) message_id_index() (message_id
|
||||
return message_id, nil
|
||||
} else {
|
||||
log.Error("DeliveryInstruction must be fragmented to have a Message ID")
|
||||
return 0, errors.New("DeliveryInstruction must be fragmented to have a Message ID")
|
||||
return 0, oops.Errorf("DeliveryInstruction must be fragmented to have a Message ID")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ func (delivery_instructions DeliveryInstructions) extended_options_index() (exte
|
||||
|
||||
} else {
|
||||
log.Error("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
err = errors.New("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
err = oops.Errorf("DeliveryInstruction does not have the ExtendedOptions flag set")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -845,7 +845,7 @@ func maybeAppendMessageID(di_flag DeliveryInstructions, di_type int, data, curre
|
||||
}
|
||||
if len(data) < message_id_index+4 {
|
||||
log.Error("Data is too short to contain message ID in FIRST_FRAGMENT")
|
||||
err = errors.New("data is too short to contain message ID in FIRST_FRAGMENT")
|
||||
err = oops.Errorf("data is too short to contain message ID in FIRST_FRAGMENT")
|
||||
} else {
|
||||
now = append(current, data[message_id_index:message_id_index+4]...)
|
||||
log.Debug("MessageID appended for FIRST_FRAGMENT")
|
||||
@@ -854,7 +854,7 @@ func maybeAppendMessageID(di_flag DeliveryInstructions, di_type int, data, curre
|
||||
} else if di_type == FOLLOW_ON_FRAGMENT {
|
||||
if len(data) < 5 {
|
||||
log.Error("Data is too short to contain message ID in FOLLOW_ON_FRAGMENT")
|
||||
err = errors.New("data is too short to contain message ID in FOLLOW_ON_FRAGMENT")
|
||||
err = oops.Errorf("data is too short to contain message ID in FOLLOW_ON_FRAGMENT")
|
||||
} else {
|
||||
now = append(current, data[1:5]...)
|
||||
log.Debug("MessageID appended for FOLLOW_ON_FRAGMENT")
|
||||
@@ -886,7 +886,7 @@ func maybeAppendSize(di_flag DeliveryInstructions, di_type int, data, current []
|
||||
} else if di_type == FOLLOW_ON_FRAGMENT {
|
||||
if len(data) < 7 {
|
||||
log.Error("Data is too short to contain size data")
|
||||
err = errors.New("data is too short to contain size data")
|
||||
err = oops.Errorf("data is too short to contain size data")
|
||||
} else {
|
||||
now = append(now, data[5:7]...)
|
||||
log.Debug("Size appended for FOLLOW_ON_FRAGMENT")
|
||||
@@ -899,7 +899,7 @@ func readDeliveryInstructions(data []byte) (instructions DeliveryInstructions, r
|
||||
log.Debug("Reading DeliveryInstructions")
|
||||
if len(data) < 1 {
|
||||
log.Error("No data provided")
|
||||
err = errors.New("no data provided")
|
||||
err = oops.Errorf("no data provided")
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user