add signature type support
This commit is contained in:
15
client.go
15
client.go
@ -16,6 +16,8 @@ type Client struct {
|
|||||||
SamConn net.Conn
|
SamConn net.Conn
|
||||||
rd *bufio.Reader
|
rd *bufio.Reader
|
||||||
|
|
||||||
|
sigType string
|
||||||
|
|
||||||
inLength uint
|
inLength uint
|
||||||
inVariance int
|
inVariance int
|
||||||
inQuantity uint
|
inQuantity uint
|
||||||
@ -36,11 +38,19 @@ type Client struct {
|
|||||||
closeIdle bool
|
closeIdle bool
|
||||||
closeIdleTime uint
|
closeIdleTime uint
|
||||||
|
|
||||||
compression bool
|
compression bool
|
||||||
|
|
||||||
debug 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
|
// NewDefaultClient creates a new client, connecting to the default host:port at localhost:7656
|
||||||
func NewDefaultClient() (*Client, error) {
|
func NewDefaultClient() (*Client, error) {
|
||||||
return NewClient("localhost:7656")
|
return NewClient("localhost:7656")
|
||||||
@ -72,6 +82,7 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
|||||||
c.closeIdle = true
|
c.closeIdle = true
|
||||||
c.closeIdleTime = 600000
|
c.closeIdleTime = 600000
|
||||||
c.debug = false
|
c.debug = false
|
||||||
|
c.sigType = ""
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&c); err != nil {
|
if err := o(&c); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -96,7 +107,7 @@ func (c *Client) samaddr() string {
|
|||||||
|
|
||||||
// send the initial handshake command and check that the reply is ok
|
// send the initial handshake command and check that the reply is ok
|
||||||
func (c *Client) hello() error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
debian/changelog
vendored
2
debian/changelog
vendored
@ -3,4 +3,4 @@ golang-github-eyedeekay-gosam (0.1.0+git20190221.2896c83-1) unstable; urgency=me
|
|||||||
[ idk ]
|
[ idk ]
|
||||||
* Initial release (Closes: TODO)
|
* 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
|
||||||
|
105
options.go
105
options.go
@ -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.
|
//return the inbound length as a string.
|
||||||
func (c *Client) inlength() 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.
|
//return the outbound length as a string.
|
||||||
func (c *Client) outlength() 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.
|
//return the inbound length variance as a string.
|
||||||
func (c *Client) invariance() 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.
|
//return the outbound length variance as a string.
|
||||||
func (c *Client) outvariance() 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.
|
//return the inbound tunnel quantity as a string.
|
||||||
func (c *Client) inquantity() 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.
|
//return the outbound tunnel quantity as a string.
|
||||||
func (c *Client) outquantity() 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.
|
//return the inbound tunnel quantity as a string.
|
||||||
func (c *Client) inbackups() 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.
|
//return the outbound tunnel quantity as a string.
|
||||||
func (c *Client) outbackups() 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 {
|
func (c *Client) encryptlease() string {
|
||||||
if c.encryptLease {
|
if c.encryptLease {
|
||||||
return "i2cp.encryptLeaseSet=true"
|
return " i2cp.encryptLeaseSet=true "
|
||||||
}
|
}
|
||||||
return "i2cp.encryptLeaseSet=false"
|
return " i2cp.encryptLeaseSet=false "
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) dontpublishlease() string {
|
func (c *Client) dontpublishlease() string {
|
||||||
if c.dontPublishLease {
|
if c.dontPublishLease {
|
||||||
return "i2cp.dontPublishLeaseSet=true"
|
return " i2cp.dontPublishLeaseSet=true "
|
||||||
}
|
}
|
||||||
return "i2cp.dontPublishLeaseSet=false"
|
return " i2cp.dontPublishLeaseSet=false "
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) closeonidle() string {
|
func (c *Client) closeonidle() string {
|
||||||
if c.closeIdle {
|
if c.closeIdle {
|
||||||
return "i2cp.closeOnIdle=true"
|
return " i2cp.closeOnIdle=true "
|
||||||
}
|
}
|
||||||
return "i2cp.closeOnIdle=false"
|
return " i2cp.closeOnIdle=false "
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) closeidletime() string {
|
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 {
|
func (c *Client) reduceonidle() string {
|
||||||
if c.reduceIdle {
|
if c.reduceIdle {
|
||||||
return "i2cp.reduceOnIdle=true"
|
return " i2cp.reduceOnIdle=true "
|
||||||
}
|
}
|
||||||
return "i2cp.reduceOnIdle=false"
|
return " i2cp.reduceOnIdle=false "
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) reduceidletime() string {
|
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 {
|
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 {
|
func (c *Client) compresion() string {
|
||||||
if c.compression {
|
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
|
//return all options as string ready for passing to sendcmd
|
||||||
func (c *Client) allOptions() string {
|
func (c *Client) allOptions() string {
|
||||||
return c.inlength() + " " +
|
return c.inlength() +
|
||||||
c.outlength() + " " +
|
c.outlength() +
|
||||||
c.invariance() + " " +
|
c.invariance() +
|
||||||
c.outvariance() + " " +
|
c.outvariance() +
|
||||||
c.inquantity() + " " +
|
c.inquantity() +
|
||||||
c.outquantity() + " " +
|
c.outquantity() +
|
||||||
c.inbackups() + " " +
|
c.inbackups() +
|
||||||
c.outbackups() + " " +
|
c.outbackups() +
|
||||||
c.dontpublishlease() + " " +
|
c.dontpublishlease() +
|
||||||
c.encryptlease() + " " +
|
c.encryptlease() +
|
||||||
c.reduceonidle() + " " +
|
c.reduceonidle() +
|
||||||
c.reduceidletime() + " " +
|
c.reduceidletime() +
|
||||||
c.reduceidlecount() + " " +
|
c.reduceidlecount() +
|
||||||
c.closeonidle() + " " +
|
c.closeonidle() +
|
||||||
c.closeidletime() + " " +
|
c.closeidletime() +
|
||||||
c.compresion()
|
c.compresion()
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,13 @@ func (c *Client) CreateStreamSession(dest string) (int32, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := rand.Int31n(math.MaxInt32)
|
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 {
|
if err != nil {
|
||||||
return -1, "", err
|
return -1, "", err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user