add signature type support

This commit is contained in:
idk
2019-02-24 23:08:01 -05:00
parent 6ea277fc47
commit a537690baa
4 changed files with 89 additions and 41 deletions

View File

@ -16,6 +16,8 @@ type Client struct {
SamConn net.Conn
rd *bufio.Reader
sigType string
inLength uint
inVariance int
inQuantity uint
@ -36,11 +38,19 @@ type Client struct {
closeIdle bool
closeIdleTime uint
compression bool
compression bool
debug bool
}
var SAMsigTypes = []string{
"SIGNATURE_TYPE=DSA_SHA1",
"SIGNATURE_TYPE=ECDSA_SHA256_P256",
"SIGNATURE_TYPE=ECDSA_SHA384_P384",
"SIGNATURE_TYPE=ECDSA_SHA512_P521",
"SIGNATURE_TYPE=EdDSA_SHA512_Ed25519",
}
// NewDefaultClient creates a new client, connecting to the default host:port at localhost:7656
func NewDefaultClient() (*Client, error) {
return NewClient("localhost:7656")
@ -72,6 +82,7 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
c.closeIdle = true
c.closeIdleTime = 600000
c.debug = false
c.sigType = ""
for _, o := range opts {
if err := o(&c); err != nil {
return nil, err
@ -96,7 +107,7 @@ func (c *Client) samaddr() string {
// send the initial handshake command and check that the reply is ok
func (c *Client) hello() error {
r, err := c.sendCmd("HELLO VERSION MIN=3.0 MAX=3.2\n")
r, err := c.sendCmd("HELLO VERSION MIN=3.0 MAX=3.1\n")
if err != nil {
return err
}

2
debian/changelog vendored
View File

@ -3,4 +3,4 @@ golang-github-eyedeekay-gosam (0.1.0+git20190221.2896c83-1) unstable; urgency=me
[ idk ]
* Initial release (Closes: TODO)
-- lair repo key <problemsolver@openmailbox.org> Sat, 23 Feb 2019 11:43:05 -0500
-- idk <hankhill19580@gmail.com> Sat, 23 Feb 2019 11:43:05 -0500

View File

@ -257,109 +257,140 @@ func SetCompression(b bool) func(*Client) error {
}
}
/* SAM v 3.1 Options*/
//SetSignatureType tells gosam to pass SAM a signature_type parameter with one
// of the following values:
// "SIGNATURE_TYPE=DSA_SHA1",
// "SIGNATURE_TYPE=ECDSA_SHA256_P256",
// "SIGNATURE_TYPE=ECDSA_SHA384_P384",
// "SIGNATURE_TYPE=ECDSA_SHA512_P521",
// "SIGNATURE_TYPE=EdDSA_SHA512_Ed25519",
// or an empty string
func SetSignatureType(s string) func(*Client) error {
return func(c *Client) error {
if s == "" {
c.sigType = ""
return nil
}
for _, valid := range SAMsigTypes {
if s == valid {
c.sigType = valid
return nil
}
}
return fmt.Errorf("Invalid signature type specified at construction time")
}
}
//return the signature type as a string.
func (c *Client) sigtype() string {
return fmt.Sprintf(" %s ", c.sigType)
}
//return the inbound length as a string.
func (c *Client) inlength() string {
return fmt.Sprintf("inbound.length=%d", c.inLength)
return fmt.Sprintf(" inbound.length=%d ", c.inLength)
}
//return the outbound length as a string.
func (c *Client) outlength() string {
return fmt.Sprintf("outbound.length=%d", c.outLength)
return fmt.Sprintf(" outbound.length=%d ", c.outLength)
}
//return the inbound length variance as a string.
func (c *Client) invariance() string {
return fmt.Sprintf("inbound.lengthVariance=%d", c.inVariance)
return fmt.Sprintf(" inbound.lengthVariance=%d ", c.inVariance)
}
//return the outbound length variance as a string.
func (c *Client) outvariance() string {
return fmt.Sprintf("outbound.lengthVariance=%d", c.outVariance)
return fmt.Sprintf(" outbound.lengthVariance=%d ", c.outVariance)
}
//return the inbound tunnel quantity as a string.
func (c *Client) inquantity() string {
return fmt.Sprintf("inbound.quantity=%d", c.inQuantity)
return fmt.Sprintf(" inbound.quantity=%d ", c.inQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *Client) outquantity() string {
return fmt.Sprintf("outbound.quantity=%d", c.outQuantity)
return fmt.Sprintf(" outbound.quantity=%d ", c.outQuantity)
}
//return the inbound tunnel quantity as a string.
func (c *Client) inbackups() string {
return fmt.Sprintf("inbound.backupQuantity=%d", c.inQuantity)
return fmt.Sprintf(" inbound.backupQuantity=%d ", c.inQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *Client) outbackups() string {
return fmt.Sprintf("outbound.backupQuantity=%d", c.outQuantity)
return fmt.Sprintf(" outbound.backupQuantity=%d ", c.outQuantity)
}
func (c *Client) encryptlease() string {
if c.encryptLease {
return "i2cp.encryptLeaseSet=true"
return " i2cp.encryptLeaseSet=true "
}
return "i2cp.encryptLeaseSet=false"
return " i2cp.encryptLeaseSet=false "
}
func (c *Client) dontpublishlease() string {
if c.dontPublishLease {
return "i2cp.dontPublishLeaseSet=true"
return " i2cp.dontPublishLeaseSet=true "
}
return "i2cp.dontPublishLeaseSet=false"
return " i2cp.dontPublishLeaseSet=false "
}
func (c *Client) closeonidle() string {
if c.closeIdle {
return "i2cp.closeOnIdle=true"
return " i2cp.closeOnIdle=true "
}
return "i2cp.closeOnIdle=false"
return " i2cp.closeOnIdle=false "
}
func (c *Client) closeidletime() string {
return fmt.Sprintf("i2cp.closeIdleTime=%d", c.closeIdleTime)
return fmt.Sprintf(" i2cp.closeIdleTime=%d ", c.closeIdleTime)
}
func (c *Client) reduceonidle() string {
if c.reduceIdle {
return "i2cp.reduceOnIdle=true"
return " i2cp.reduceOnIdle=true "
}
return "i2cp.reduceOnIdle=false"
return " i2cp.reduceOnIdle=false "
}
func (c *Client) reduceidletime() string {
return fmt.Sprintf("i2cp.reduceIdleTime=%d", c.reduceIdleTime)
return fmt.Sprintf(" i2cp.reduceIdleTime=%d ", c.reduceIdleTime)
}
func (c *Client) reduceidlecount() string {
return fmt.Sprintf("i2cp.reduceIdleQuantity=%d", c.reduceIdleQuantity)
return fmt.Sprintf(" i2cp.reduceIdleQuantity=%d ", c.reduceIdleQuantity)
}
func (c *Client) compresion() string {
if c.compression {
return "i2cp.gzip=true"
return " i2cp.gzip=true "
}
return "i2cp.gzip=false"
return " i2cp.gzip=false "
}
//return all options as string ready for passing to sendcmd
func (c *Client) allOptions() string {
return c.inlength() + " " +
c.outlength() + " " +
c.invariance() + " " +
c.outvariance() + " " +
c.inquantity() + " " +
c.outquantity() + " " +
c.inbackups() + " " +
c.outbackups() + " " +
c.dontpublishlease() + " " +
c.encryptlease() + " " +
c.reduceonidle() + " " +
c.reduceidletime() + " " +
c.reduceidlecount() + " " +
c.closeonidle() + " " +
c.closeidletime() + " " +
c.compresion()
return c.inlength() +
c.outlength() +
c.invariance() +
c.outvariance() +
c.inquantity() +
c.outquantity() +
c.inbackups() +
c.outbackups() +
c.dontpublishlease() +
c.encryptlease() +
c.reduceonidle() +
c.reduceidletime() +
c.reduceidlecount() +
c.closeonidle() +
c.closeidletime() +
c.compresion()
}

View File

@ -19,7 +19,13 @@ func (c *Client) CreateStreamSession(dest string) (int32, string, error) {
}
id := rand.Int31n(math.MaxInt32)
r, err := c.sendCmd("SESSION CREATE STYLE=STREAM ID=%d DESTINATION=%s %s\n", id, dest, c.allOptions())
r, err := c.sendCmd(
"SESSION CREATE STYLE=STREAM ID=%d DESTINATION=%s %s %s\n",
id,
dest,
c.sigtype(),
c.allOptions(),
)
if err != nil {
return -1, "", err
}