8 Commits

Author SHA1 Message Date
idk
529cdd6063 update deb changelog 2020-10-18 01:03:01 -04:00
idk
33f3caa3f9 Add fmt make target, incorporate address length fix from qiwenmin, add a shortcut for saving your keys 2020-10-18 00:58:45 -04:00
idk
5a43ad260d Merge pull request #3 from qiwenmin/fix-wrong-addr
Fix wrong address.
2020-10-18 04:34:41 +00:00
Qi Wenmin
cd744bfe49 Fix wrong address.
With some addresses, ToBytes() calculates the wrong buffer lenngth
and returns the larger buffer for next step (sha256). So the b32
address will wrong.

For example, when the b64 key is the following:

tr2kQArAdxb7rt3Hr6itisY1Pi7ncWVUYDan2rjB45F1lIFvDPJih5dBa~WfWTvfyt
QKdtFoGHLuZdC8X71R5GXGvh8N0ECBtjhYPG8chFSEO2Cab2SZKYskEqGeOrlOvAQ-
yYaH0xCkarxFdvEbXoV~cfDhHDJcZI3Uc522sLWlB72-uOH9nlzyt-41byGc5GWn5c
CxJZx8UfszUIG9B2QoptrN0xquWvkLxescZ~0JYePTEJTeQFWlfPAiHcuAloAq3yKt
DCY4xcSracQr9ieCmnFJoUsLtzsjSrn7L~WwlI4pYYXxkm2dtzR8cPHJCBUBNMbK~K
TIxLtH0Tt9wI3edHgRMdxNm3EoozpPMXA05Ouni~ehWMhaywiJKTDZcGKDRqXJVm~y
xJGcXiXT2UzdwM~D20KTTUlLmeRqsU5hqpk2kgBIWKFfb8Gunx2hr0wEHsJypUwDQ-
FSGT0Fw0MRGq0QWvwXxroPbJdjsNnYOKCEogHxC4VrmzaLhHlEBQAEAAcAAA==

the right raw key length is 391, but ToBytes() returns a 393 bytes
raw key.

Using DecodeString() can fix this issue.
2020-09-27 08:33:52 +08:00
idk
1ef2d90f46 fix some debian stuff 2020-06-22 18:15:05 -04:00
idk
f90e3b2755 remove it from go mod 2020-06-22 14:09:44 -04:00
idk
a959ac58ba Merge pull request #2 from eyedeekay/fancy-config
Fancy config
2019-12-08 03:14:32 +00:00
idk
0a2d58418f Merge pull request #1 from eyedeekay/desthash44
add 44-char dest hashes
2019-12-07 22:31:43 +00:00
10 changed files with 85 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
USER_GH=eyedeekay
VERSION=0.32.2
VERSION=0.32.31
packagename=sam3
echo:
@@ -17,3 +17,11 @@ tar:
--exclude .go \
--exclude bin \
-cJvf ../$(packagename)_$(VERSION).orig.tar.xz .
copier:
echo '#! /usr/bin/env sh' > deb/copy.sh
echo 'for f in $$(ls); do scp $$f/*.deb user@192.168.99.106:~/DEBIAN_PKGS/$$f/main/; done' >> deb/copy.sh
fmt:
find . -name '*.go' -exec gofmt -w -s {} \;

View File

@@ -108,6 +108,10 @@ func (s *DatagramSession) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
}
}
func (s *DatagramSession) Accept() (net.Conn, error) {
return s, nil
}
func (s *DatagramSession) Read(b []byte) (n int, err error) {
rint, _, rerr := s.ReadFrom(b)
return rint, rerr
@@ -147,6 +151,10 @@ func (s *DatagramSession) LocalAddr() net.Addr {
return s.LocalI2PAddr()
}
func (s *DatagramSession) Addr() net.Addr {
return s.LocalI2PAddr()
}
func (s *DatagramSession) Lookup(name string) (a net.Addr, err error) {
var sam *SAM
sam, err = NewSAM(s.samAddr)

15
debian/changelog vendored
View File

@@ -1,3 +1,18 @@
golang-github-eyedeekay-sam3 (0.3.2.31) unreleased; urgency=medium
[ idk ]
* Incorporate address fix from qiwenmin
* Shortcut for saving keys to text file
-- idk <hankhill19580@gmail.com> Sun, 18 Oct 2020 1:01:03 -0500
golang-github-eyedeekay-sam3 (0.3.2.3) unreleased; urgency=medium
[ idk ]
* Purge ramp, re-release
-- idk <hankhill19580@gmail.com> Mon, 22 Jun 2020 17:55:03 -0500
golang-github-eyedeekay-sam3 (0.3.2.2) bionic; urgency=medium
[ idk ]

3
debian/control vendored
View File

@@ -5,7 +5,8 @@ Maintainer: Debian Go Packaging Team <team+pkg-go@tracker.debian.org>
Uploaders: idk <hankhill19580@gmail.com>
Build-Depends: debhelper (>= 11),
dh-golang,
golang-any
git,
golang-any | golang-go,
Standards-Version: 4.2.1
Homepage: https://github.com/eyedeekay/sam3
Vcs-Browser: https://github.com/eyedeekay/sam3

View File

@@ -22,7 +22,7 @@ func SetType(s string) func(*SAMEmit) error {
c.Style = s
return nil
}
return fmt.Errorf("Invalid session STYLE=%s, must be STREAM, DATAGRAM, or RAW")
return fmt.Errorf("Invalid session STYLE=%s, must be STREAM, DATAGRAM, or RAW", s)
}
}

View File

@@ -76,7 +76,7 @@ func (e *SAMEmit) ConnectBytes(dest string) []byte {
func (e *SAMEmit) Accept() string {
return fmt.Sprintf(
"STREAM ACCEPT ID=%s",
"STREAM ACCEPT ID=%s %s %s",
e.I2PConfig.ID(),
e.I2PConfig.FromPort(),
e.I2PConfig.ToPort(),

1
go.mod
View File

@@ -2,4 +2,3 @@ module github.com/eyedeekay/sam3
go 1.12
require github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab

2
go.sum
View File

@@ -1,2 +0,0 @@
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab h1:EfTRHxGSbiaEyxNzvKRBWVIDw3mD8xXGxj4gvwFzY7Q=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc=

View File

@@ -7,6 +7,7 @@ import (
"encoding/base64"
"errors"
"io"
"os"
"strings"
)
@@ -31,6 +32,18 @@ func NewKeys(addr I2PAddr, both string) I2PKeys {
return I2PKeys{addr, both}
}
// fileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func fileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, err
}
return !info.IsDir(), nil
}
// load keys from non standard format
func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) {
var buff bytes.Buffer
@@ -42,12 +55,40 @@ func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) {
return
}
// load keys from non-standard format by specifying a text file.
// If the file does not exist, generate keys, otherwise, fail
// closed.
func LoadKeys(r string) (I2PKeys, error) {
exists, err := fileExists(r)
if err != nil {
return I2PKeys{}, err
}
if exists {
fi, err := os.Open(r)
if err != nil {
return I2PKeys{}, err
}
defer fi.Close()
return LoadKeysIncompat(fi)
}
return I2PKeys{}, err
}
// store keys in non standard format
func StoreKeysIncompat(k I2PKeys, w io.Writer) (err error) {
_, err = io.WriteString(w, k.Address.Base64()+"\n"+k.Both)
return
}
func StoreKeys(k I2PKeys, r string) error {
fi, err := os.Open(r)
if err != nil {
return err
}
defer fi.Close()
return StoreKeysIncompat(k, fi)
}
// Returns the public keys of the I2PKeys.
func (k I2PKeys) Addr() I2PAddr {
return k.Address
@@ -160,11 +201,7 @@ func NewI2PAddrFromBytes(addr []byte) (I2PAddr, error) {
// Turns an I2P address to a byte array. The inverse of NewI2PAddrFromBytes().
func (addr I2PAddr) ToBytes() ([]byte, error) {
buf := make([]byte, i2pB64enc.DecodedLen(len(addr)))
if _, err := i2pB64enc.Decode(buf, []byte(addr)); err != nil {
return buf, errors.New("Address is not base64-encoded")
}
return buf, nil
return i2pB64enc.DecodeString(string(addr))
}
func (addr I2PAddr) Bytes() []byte {

View File

@@ -150,7 +150,7 @@ func Test_StreamingServerClient(t *testing.T) {
}
func ExampleStreamSession() {
// Creates a new StreamingSession, dials to zzz.i2p and gets a SAMConn
// Creates a new StreamingSession, dials to idk.i2p and gets a SAMConn
// which behaves just like a normal net.Conn.
const samBridge = "127.0.0.1:7656"
@@ -172,7 +172,7 @@ func ExampleStreamSession() {
fmt.Println(err.Error())
return
}
someone, err := sam.Lookup("zzz.i2p")
someone, err := sam.Lookup("idk.i2p")
if err != nil {
fmt.Println(err.Error())
return
@@ -192,17 +192,17 @@ func ExampleStreamSession() {
buf := make([]byte, 4096)
n, err := conn.Read(buf)
if !strings.Contains(strings.ToLower(string(buf[:n])), "http") && !strings.Contains(strings.ToLower(string(buf[:n])), "html") {
fmt.Printf("Probably failed to StreamSession.DialI2P(zzz.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
log.Printf("Probably failed to StreamSession.DialI2P(zzz.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
fmt.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
log.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
} else {
fmt.Println("Read HTTP/HTML from zzz.i2p")
log.Println("Read HTTP/HTML from zzz.i2p")
fmt.Println("Read HTTP/HTML from idk.i2p")
log.Println("Read HTTP/HTML from idk.i2p")
}
return
// Output:
//Sending HTTP GET /
//Read HTTP/HTML from zzz.i2p
//Read HTTP/HTML from idk.i2p
}
func ExampleStreamListener() {