Merge branch 'hmac_size_fix'
This commit is contained in:
commit
db89cf80f3
|
@ -21,6 +21,27 @@ type BaseOnionService struct {
|
|||
privateKey ed25519.PrivateKey
|
||||
ls connectivity.ListenService
|
||||
lock sync.Mutex
|
||||
port int
|
||||
}
|
||||
|
||||
// Metrics provides a report of useful information about the status of the service e.g. the number of active
|
||||
// connections
|
||||
func (s *BaseOnionService) Metrics() tapir.ServiceMetrics {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
count := 0
|
||||
s.connections.Range(func(key, value interface{}) bool {
|
||||
connection := value.(tapir.Connection)
|
||||
if !connection.IsClosed() {
|
||||
count++
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return tapir.ServiceMetrics{
|
||||
ConnectionCount: count,
|
||||
}
|
||||
}
|
||||
|
||||
// Metrics provide metrics for services
|
||||
|
@ -50,6 +71,12 @@ func (s *BaseOnionService) Init(acn connectivity.ACN, sk ed25519.PrivateKey, id
|
|||
s.acn = acn
|
||||
s.id = id
|
||||
s.privateKey = sk
|
||||
s.port = 9878
|
||||
}
|
||||
|
||||
// SetPort configures the port that the service uses.
|
||||
func (s *BaseOnionService) SetPort(port int) {
|
||||
s.port = port
|
||||
}
|
||||
|
||||
// WaitForCapabilityOrClose blocks until the connection has the given capability or the underlying connection is closed
|
||||
|
@ -145,7 +172,7 @@ func (s *BaseOnionService) Listen(app tapir.Application) error {
|
|||
// accepts a new connection
|
||||
// spins off to a connection struct
|
||||
s.lock.Lock()
|
||||
ls, err := s.acn.Listen(s.privateKey, 9878)
|
||||
ls, err := s.acn.Listen(s.privateKey, s.port)
|
||||
s.ls = ls
|
||||
log.Debugf("Starting a service on %v ", ls.AddressFull())
|
||||
s.lock.Unlock()
|
||||
|
@ -171,7 +198,9 @@ func (s *BaseOnionService) Listen(app tapir.Application) error {
|
|||
func (s *BaseOnionService) Shutdown() {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
s.ls.Close()
|
||||
if s.ls != nil {
|
||||
s.ls.Close()
|
||||
}
|
||||
s.connections.Range(func(key, value interface{}) bool {
|
||||
connection := value.(tapir.Connection)
|
||||
connection.Close()
|
||||
|
|
|
@ -72,7 +72,8 @@ func (t *Token) unblindSignedToken(token SignedToken) {
|
|||
func (t *Token) SpendToken(data []byte) SpentToken {
|
||||
key := sha3.Sum256(append(t.t, t.W.Encode(nil)...))
|
||||
mac := hmac.New(sha3.New512, key[:])
|
||||
return SpentToken{t.t, mac.Sum(data)}
|
||||
mac.Write(data)
|
||||
return SpentToken{t.t, mac.Sum(nil)}
|
||||
}
|
||||
|
||||
// GenerateBlindedTokenBatch generates a batch of blinded tokens (and their unblinded equivalents)
|
||||
|
|
|
@ -136,7 +136,8 @@ func (ts *TokenServer) SpendToken(token SpentToken, data []byte) error {
|
|||
W := new(ristretto.Element).ScalarMult(ts.k, T)
|
||||
key := sha3.Sum256(append(token.T, W.Encode(nil)...))
|
||||
mac := hmac.New(sha3.New512, key[:])
|
||||
computedMAC := mac.Sum(data)
|
||||
mac.Write(data)
|
||||
computedMAC := mac.Sum(nil)
|
||||
result := hmac.Equal(token.MAC, computedMAC)
|
||||
if result == true {
|
||||
if ts.persistanceService == nil {
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// ServiceMetrics are metrics for servers...
|
||||
|
||||
// ServiceMetrics outlines higher level information about the service e.g. counts of connections
|
||||
type ServiceMetrics struct {
|
||||
ConnectionCount int
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue