Compare commits
19 Commits
Author | SHA1 | Date |
---|---|---|
Sarah Jamie Lewis | 4129031391 | |
Sarah Jamie Lewis | 139a35c219 | |
Sarah Jamie Lewis | 4e4e3b4422 | |
Dan Ballard | 015307d907 | |
Sarah Jamie Lewis | 13effd5457 | |
Sarah Jamie Lewis | 9012720973 | |
Sarah Jamie Lewis | af2f509711 | |
Dan Ballard | eceddc676d | |
Dan Ballard | bf7a0a4b39 | |
Sarah Jamie Lewis | cefe182b80 | |
Sarah Jamie Lewis | 2da2c98b91 | |
Sarah Jamie Lewis | 7ee88b7ba8 | |
Sarah Jamie Lewis | 2da293f118 | |
Sarah Jamie Lewis | ae04cf7983 | |
Dan Ballard | 0b5a1a4345 | |
Dan Ballard | f610638146 | |
Sarah Jamie Lewis | bacc9a47c4 | |
Sarah Jamie Lewis | db89cf80f3 | |
Dan Ballard | 8f6408433b |
89
.drone.yml
89
.drone.yml
|
@ -1,14 +1,14 @@
|
|||
workspace:
|
||||
base: /go
|
||||
path: src/cwtch.im/tapir
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: linux-test
|
||||
|
||||
pipeline:
|
||||
fetch:
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: [ push, pull_request ]
|
||||
image: golang
|
||||
steps:
|
||||
- name: fetch
|
||||
image: golang:1.17.5
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
commands:
|
||||
- wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/tor
|
||||
- wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc
|
||||
|
@ -16,49 +16,58 @@ pipeline:
|
|||
- export GO111MODULE=on
|
||||
- go mod download
|
||||
- go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
quality:
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: [ push, pull_request ]
|
||||
image: golang
|
||||
- name: quality
|
||||
image: golang:1.17.5
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
commands:
|
||||
- staticcheck ./...
|
||||
units-tests:
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: [ push, pull_request ]
|
||||
image: golang
|
||||
- staticcheck ./...
|
||||
- name: units-tests
|
||||
image: golang:1.17.5
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
commands:
|
||||
- export PATH=$PATH:/go/src/cwtch.im/tapir
|
||||
- export PATH=`pwd`:$PATH
|
||||
- sh testing/tests.sh
|
||||
integ-test:
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: [ push, pull_request ]
|
||||
image: golang
|
||||
- name: integ-test
|
||||
image: golang:1.17.5
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
commands:
|
||||
- export PATH=$PATH:/go/src/cwtch.im/tapir
|
||||
- export PATH=`pwd`:$PATH
|
||||
- go test -race -v git.openprivacy.ca/cwtch.im/tapir/testing
|
||||
notify-email:
|
||||
- name: notify-email
|
||||
image: drillster/drone-email
|
||||
host: build.openprivacy.ca
|
||||
port: 25
|
||||
skip_verify: true
|
||||
from: drone@openprivacy.ca
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: [ push, pull_request ]
|
||||
status: [ failure ]
|
||||
notify-gogs:
|
||||
- name: notify-gogs
|
||||
image: openpriv/drone-gogs
|
||||
pull: if-not-exists
|
||||
when:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event: pull_request
|
||||
status: [ success, changed, failure ]
|
||||
secrets: [gogs_account_token]
|
||||
gogs_url: https://git.openprivacy.ca
|
||||
environment:
|
||||
GOGS_ACCOUNT_TOKEN:
|
||||
from_secret: gogs_account_token
|
||||
settings:
|
||||
gogs_url: https://git.openprivacy.ca
|
||||
|
||||
volumes:
|
||||
# gopath where bin and pkg lives to persist across steps
|
||||
- name: deps
|
||||
temp: {}
|
||||
|
||||
trigger:
|
||||
repo: cwtch.im/tapir
|
||||
branch: master
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
- tag
|
|
@ -78,6 +78,8 @@ func (powapp *ProofOfWorkApplication) solveChallenge(challenge []byte, prng core
|
|||
log.Errorf("error completing challenge: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
//lint:ignore SA1019 API this is "deprecated", but without it it will cause an allocation on every single check
|
||||
solution = next.Encode(encodedSolution)
|
||||
|
||||
copy(solve[0:], solution[:])
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
torProvider "git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
@ -78,7 +77,7 @@ func TestTokenBoardApp(t *testing.T) {
|
|||
builder.WithSocksPort(9059).WithControlPort(9060).WithHashedPassword("tapir-integration-test").Build("./tor/torrc")
|
||||
torDataDir := ""
|
||||
var err error
|
||||
if torDataDir, err = ioutil.TempDir("./tor/", "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp("./tor/", "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
|
22
go.mod
22
go.mod
|
@ -1,13 +1,21 @@
|
|||
module git.openprivacy.ca/cwtch.im/tapir
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.3
|
||||
filippo.io/edwards25519 v1.0.0
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.6
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gtank/merlin v0.1.1
|
||||
github.com/gtank/ristretto255 v0.1.2
|
||||
go.etcd.io/bbolt v1.3.4
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
|
||||
)
|
||||
github.com/gtank/ristretto255 v0.1.3-0.20210930101514-6bb39798585c
|
||||
go.etcd.io/bbolt v1.3.6
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d
|
||||
)
|
||||
|
||||
require (
|
||||
git.openprivacy.ca/openprivacy/bine v0.0.4 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
|
||||
)
|
||||
|
|
50
go.sum
50
go.sum
|
@ -1,16 +1,10 @@
|
|||
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
|
||||
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
|
||||
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=
|
||||
git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.6.0 h1:j44Kya3GBH4BDGh0f5JD/eNAb77XiQreIZtzcY8Gn28=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.6.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.1 h1:OjWy+JTAvlrstY8PnGPBp7Ho04JaKHaQ+YdoLwSdaCo=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.1/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.2 h1:uCFnrJXsTh3ne4GcgvamoxomQ6fMishD3C2nQGpgdMY=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.2/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.3 h1:bWM8aQHqHIpobYQcLQ9OsNPoIl+H+4JFWbYGdG0nHlg=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.3/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.6 h1:g74PyDGvpMZ3+K0dXy3mlTJh+e0rcwNk0XF8owzkmOA=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.6/go.mod h1:Hn1gpOx/bRZp5wvCtPQVJPXrfeUH0EGiG/Aoa0vjGLg=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -18,41 +12,45 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is=
|
||||
github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
|
||||
github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc=
|
||||
github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o=
|
||||
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0=
|
||||
github.com/gtank/ristretto255 v0.1.3-0.20210930101514-6bb39798585c h1:gkfmnY4Rlt3VINCo4uKdpvngiibQyoENVj5Q88sxXhE=
|
||||
github.com/gtank/ristretto255 v0.1.3-0.20210930101514-6bb39798585c/go.mod h1:tDPFhGdt3hJWqtKwx57i9baiB1Cj0yAg22VOPUqm5vY=
|
||||
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM=
|
||||
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b h1:QrHweqAtyJ9EwCaGHBu1fghwxIPiopAHV06JlXrMHjk=
|
||||
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b/go.mod h1:xxLb2ip6sSUts3g1irPVHyk/DGslwQsNOo9I7smJfNU=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
|
||||
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
|
||||
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
|
@ -15,13 +16,14 @@ import (
|
|||
|
||||
// BaseOnionService is a concrete implementation of the service interface over Tor onion services.
|
||||
type BaseOnionService struct {
|
||||
connections sync.Map
|
||||
acn connectivity.ACN
|
||||
id *primitives.Identity
|
||||
privateKey ed25519.PrivateKey
|
||||
ls connectivity.ListenService
|
||||
lock sync.Mutex
|
||||
port int
|
||||
connections sync.Map
|
||||
acn connectivity.ACN
|
||||
id *primitives.Identity
|
||||
privateKey ed25519.PrivateKey
|
||||
ls connectivity.ListenService
|
||||
lock sync.Mutex
|
||||
port int
|
||||
shutdownChannel chan bool
|
||||
}
|
||||
|
||||
// Metrics provides a report of useful information about the status of the service e.g. the number of active
|
||||
|
@ -53,6 +55,25 @@ func (s *BaseOnionService) Init(acn connectivity.ACN, sk ed25519.PrivateKey, id
|
|||
s.id = id
|
||||
s.privateKey = sk
|
||||
s.port = 9878
|
||||
// blocking so we can wait on shutdown for closing of this goroutine
|
||||
s.shutdownChannel = make(chan bool)
|
||||
go func() {
|
||||
for s.waitOrTimeout() {
|
||||
s.GarbageCollect()
|
||||
}
|
||||
log.Debugf("closing down garbage collection goroutine")
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *BaseOnionService) waitOrTimeout() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
select {
|
||||
case <-s.shutdownChannel:
|
||||
return false
|
||||
case <-ctx.Done():
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// SetPort configures the port that the service uses.
|
||||
|
@ -183,6 +204,20 @@ func (s *BaseOnionService) GetConnection(hostname string) (tapir.Connection, err
|
|||
return conn[0], nil
|
||||
}
|
||||
|
||||
// GarbageCollect iterates through the connection pool and cleans up any connections that are closed
|
||||
// that haven't been removed from the map.
|
||||
func (s *BaseOnionService) GarbageCollect() {
|
||||
log.Debugf("running garbage collection...")
|
||||
s.connections.Range(func(key, value interface{}) bool {
|
||||
connection := value.(tapir.Connection)
|
||||
if connection.IsClosed() {
|
||||
// Delete this Closed Connection
|
||||
s.connections.Delete(key)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// Connect initializes a new outbound connection to the given peer, using the defined Application
|
||||
func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (bool, error) {
|
||||
currconn, _ := s.GetConnection(hostname)
|
||||
|
@ -263,11 +298,16 @@ func (s *BaseOnionService) Shutdown() {
|
|||
if s.ls != nil {
|
||||
s.ls.Close()
|
||||
}
|
||||
|
||||
// close all existing connections manually
|
||||
s.connections.Range(func(key, value interface{}) bool {
|
||||
connection := value.(tapir.Connection)
|
||||
connection.Close()
|
||||
return true
|
||||
})
|
||||
|
||||
// wait for the return of our garbage collection goroutine
|
||||
s.shutdownChannel <- true
|
||||
}
|
||||
|
||||
// Broadcast sends a message to all connections who possess the given capability
|
||||
|
|
|
@ -25,7 +25,6 @@ type State struct {
|
|||
Messages []Message
|
||||
}
|
||||
|
||||
//
|
||||
const (
|
||||
auditableDataStoreProtocol = "auditable-data-store"
|
||||
newMessage = "new-message"
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
// Transcript provides a consistent transcript primitive for our protocols
|
||||
//
|
||||
// We have the following goals:
|
||||
// - Allow sequential proofs over a common transcript (ensuring a single proof cannot be extracted standalone)
|
||||
// - be able to produce a human-readable transcript for auditing.
|
||||
// - Allow sequential proofs over a common transcript (ensuring a single proof cannot be extracted standalone)
|
||||
// - be able to produce a human-readable transcript for auditing.
|
||||
//
|
||||
// The design of this API was inspired by Merlin: https://docs.rs/crate/merlin/
|
||||
type Transcript struct {
|
||||
|
@ -39,7 +39,7 @@ func (t *Transcript) AddToTranscript(label string, b []byte) {
|
|||
// AddElementToTranscript appends a value to the transcript with the given label
|
||||
// This binds the given data to the label.
|
||||
func (t *Transcript) AddElementToTranscript(label string, element *ristretto.Element) {
|
||||
t.AddToTranscript(label, element.Encode([]byte{}))
|
||||
t.AddToTranscript(label, element.Bytes())
|
||||
}
|
||||
|
||||
// OutputTranscriptToAudit outputs a human-readable copy of the transcript so far.
|
||||
|
@ -74,7 +74,7 @@ func (prng *PRNG) Next(buf []byte, next *ristretto.Scalar) error {
|
|||
log.Errorf("could not read prng: %v %v", n, err)
|
||||
return fmt.Errorf("error fetching complete output from prng: %v", err)
|
||||
}
|
||||
next.FromUniformBytes(buf)
|
||||
next.SetUniformBytes(buf)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,8 @@ func (t *Transcript) CommitToPRNG(label string) PRNG {
|
|||
// CommitToGenerator derives a verifiably random generator from the transcript
|
||||
func (t *Transcript) CommitToGenerator(label string) *ristretto.Element {
|
||||
c := t.CommitToTranscript(label)
|
||||
return new(ristretto.Element).FromUniformBytes(c)
|
||||
result, _ := new(ristretto.Element).SetUniformBytes(c)
|
||||
return result
|
||||
}
|
||||
|
||||
// CommitToGenerators derives a set of verifiably random generators from the transcript
|
||||
|
@ -104,6 +105,6 @@ func (t *Transcript) CommitToGenerators(label string, n int) (generators []*rist
|
|||
func (t *Transcript) CommitToTranscriptScalar(label string) *ristretto.Scalar {
|
||||
c := t.CommitToTranscript(label)
|
||||
s := new(ristretto.Scalar)
|
||||
s.FromUniformBytes(c[:])
|
||||
s.SetUniformBytes(c[:])
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
// DLEQProof encapsulates a Chaum-Pedersen DLEQ Proof
|
||||
//gut In Ernest F. Brickell, editor,CRYPTO’92,volume 740 ofLNCS, pages 89–105. Springer, Heidelberg,August 1993
|
||||
// gut In Ernest F. Brickell, editor,CRYPTO’92,volume 740 ofLNCS, pages 89–105. Springer, Heidelberg,August 1993
|
||||
type DLEQProof struct {
|
||||
C *ristretto.Scalar
|
||||
S *ristretto.Scalar
|
||||
|
@ -16,26 +16,29 @@ type DLEQProof struct {
|
|||
// DiscreteLogEquivalenceProof constructs a valid DLEQProof for the given parameters and transcript
|
||||
// Given Y = kX & Q = kP
|
||||
// Peggy: t := choose randomly from Zq
|
||||
// A := tX
|
||||
// B := tP
|
||||
// c := H(transcript(X,Y,P,Q,A,B))
|
||||
// s := (t + ck) mod q
|
||||
//
|
||||
// A := tX
|
||||
// B := tP
|
||||
// c := H(transcript(X,Y,P,Q,A,B))
|
||||
// s := (t + ck) mod q
|
||||
//
|
||||
// Sends c,s to Vicky
|
||||
func DiscreteLogEquivalenceProof(k *ristretto.Scalar, X *ristretto.Element, Y *ristretto.Element, P *ristretto.Element, Q *ristretto.Element, transcript *core.Transcript) DLEQProof {
|
||||
private := make([]byte, 64)
|
||||
rand.Read(private)
|
||||
t := new(ristretto.Scalar)
|
||||
t.FromUniformBytes(private)
|
||||
t, err := new(ristretto.Scalar).SetUniformBytes(private)
|
||||
if err != nil {
|
||||
return DLEQProof{ristretto.NewScalar(), ristretto.NewScalar()}
|
||||
}
|
||||
A := new(ristretto.Element).ScalarMult(t, X)
|
||||
B := new(ristretto.Element).ScalarMult(t, P)
|
||||
|
||||
transcript.AddToTranscript(DLEQX, X.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQY, Y.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQP, P.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQQ, Q.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQA, A.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQB, B.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQX, X.Bytes())
|
||||
transcript.AddToTranscript(DLEQY, Y.Bytes())
|
||||
transcript.AddToTranscript(DLEQP, P.Bytes())
|
||||
transcript.AddToTranscript(DLEQQ, Q.Bytes())
|
||||
transcript.AddToTranscript(DLEQA, A.Bytes())
|
||||
transcript.AddToTranscript(DLEQB, B.Bytes())
|
||||
|
||||
c := transcript.CommitToTranscriptScalar("c")
|
||||
s := new(ristretto.Scalar).Subtract(t, new(ristretto.Scalar).Multiply(c, k))
|
||||
|
@ -45,12 +48,14 @@ func DiscreteLogEquivalenceProof(k *ristretto.Scalar, X *ristretto.Element, Y *r
|
|||
// VerifyDiscreteLogEquivalenceProof verifies the DLEQ for the given parameters and transcript
|
||||
// Given Y = kX & Q = kP and Proof = (c,s)
|
||||
// Vicky: X' := sX
|
||||
// Y' := cY
|
||||
// P' := sP
|
||||
// Q' := cQ
|
||||
// A' = X'+Y' == sX + cY ?= sG + ckG == (s+ck)X == tX == A
|
||||
// B' = P'+Q' == sP + cQ ?= sP + ckP == (s+ck)P == tP == B
|
||||
// c' := H(transcript(X,Y,P,Q,A',B'))
|
||||
//
|
||||
// Y' := cY
|
||||
// P' := sP
|
||||
// Q' := cQ
|
||||
// A' = X'+Y' == sX + cY ?= sG + ckG == (s+ck)X == tX == A
|
||||
// B' = P'+Q' == sP + cQ ?= sP + ckP == (s+ck)P == tP == B
|
||||
// c' := H(transcript(X,Y,P,Q,A',B'))
|
||||
//
|
||||
// Tests c ?= c
|
||||
func VerifyDiscreteLogEquivalenceProof(dleq DLEQProof, X *ristretto.Element, Y *ristretto.Element, P *ristretto.Element, Q *ristretto.Element, transcript *core.Transcript) bool {
|
||||
|
||||
|
@ -62,12 +67,12 @@ func VerifyDiscreteLogEquivalenceProof(dleq DLEQProof, X *ristretto.Element, Y *
|
|||
A := new(ristretto.Element).Add(Xs, Yc)
|
||||
B := new(ristretto.Element).Add(Ps, Qc)
|
||||
|
||||
transcript.AddToTranscript(DLEQX, X.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQY, Y.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQP, P.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQQ, Q.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQA, A.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQB, B.Encode(nil))
|
||||
transcript.AddToTranscript(DLEQX, X.Bytes())
|
||||
transcript.AddToTranscript(DLEQY, Y.Bytes())
|
||||
transcript.AddToTranscript(DLEQP, P.Bytes())
|
||||
transcript.AddToTranscript(DLEQQ, Q.Bytes())
|
||||
transcript.AddToTranscript(DLEQA, A.Bytes())
|
||||
transcript.AddToTranscript(DLEQB, B.Bytes())
|
||||
|
||||
return transcript.CommitToTranscriptScalar("c").Equal(dleq.C) == 1
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package privacypass
|
|||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/cwtch.im/tapir/primitives/core"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
|
@ -55,10 +56,10 @@ func (t *Token) GenBlindedToken() BlindedToken {
|
|||
t.r = new(ristretto.Scalar)
|
||||
b := make([]byte, 64)
|
||||
rand.Read(b)
|
||||
t.r.FromUniformBytes(b)
|
||||
t.r.SetUniformBytes(b)
|
||||
|
||||
Ht := sha3.Sum512(t.t)
|
||||
T := new(ristretto.Element).FromUniformBytes(Ht[:])
|
||||
T, _ := new(ristretto.Element).SetUniformBytes(Ht[:])
|
||||
P := new(ristretto.Element).ScalarMult(t.r, T)
|
||||
return BlindedToken{P}
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ func (t *Token) unblindSignedToken(token SignedToken) {
|
|||
|
||||
// SpendToken binds the token with data and then redeems the token
|
||||
func (t *Token) SpendToken(data []byte) SpentToken {
|
||||
key := sha3.Sum256(append(t.t, t.W.Encode(nil)...))
|
||||
key := sha3.Sum256(append(t.t, t.W.Bytes()...))
|
||||
mac := hmac.New(sha3.New512, key[:])
|
||||
mac.Write(data)
|
||||
return SpentToken{t.t, mac.Sum(nil)}
|
||||
|
@ -88,13 +89,13 @@ func GenerateBlindedTokenBatch(num int) (tokens []*Token, blindedTokens []Blinde
|
|||
// verifyBatchProof verifies a given batch proof (see also UnblindSignedTokenBatch)
|
||||
func verifyBatchProof(dleq DLEQProof, Y *ristretto.Element, blindedTokens []BlindedToken, signedTokens []SignedToken, transcript *core.Transcript) bool {
|
||||
transcript.NewProtocol(BatchProofProtocol)
|
||||
transcript.AddToTranscript(BatchProofX, new(ristretto.Element).Base().Encode(nil))
|
||||
transcript.AddToTranscript(BatchProofY, Y.Encode(nil))
|
||||
transcript.AddToTranscript(BatchProofX, ristretto.NewGeneratorElement().Bytes())
|
||||
transcript.AddToTranscript(BatchProofY, Y.Bytes())
|
||||
transcript.AddToTranscript(BatchProofPVector, []byte(fmt.Sprintf("%v", blindedTokens)))
|
||||
transcript.AddToTranscript(BatchProofQVector, []byte(fmt.Sprintf("%v", signedTokens)))
|
||||
prng := transcript.CommitToPRNG("w")
|
||||
M := new(ristretto.Element).Zero()
|
||||
Z := new(ristretto.Element).Zero()
|
||||
M := ristretto.NewIdentityElement()
|
||||
Z := ristretto.NewIdentityElement()
|
||||
buf := make([]byte, 64)
|
||||
c := new(ristretto.Scalar)
|
||||
for i := range blindedTokens {
|
||||
|
@ -106,7 +107,7 @@ func verifyBatchProof(dleq DLEQProof, Y *ristretto.Element, blindedTokens []Blin
|
|||
M = new(ristretto.Element).Add(new(ristretto.Element).ScalarMult(c, blindedTokens[i].P), M)
|
||||
Z = new(ristretto.Element).Add(new(ristretto.Element).ScalarMult(c, signedTokens[i].Q), Z)
|
||||
}
|
||||
return VerifyDiscreteLogEquivalenceProof(dleq, new(ristretto.Element).Base(), Y, M, Z, transcript)
|
||||
return VerifyDiscreteLogEquivalenceProof(dleq, ristretto.NewGeneratorElement(), Y, M, Z, transcript)
|
||||
}
|
||||
|
||||
// UnblindSignedTokenBatch taking in a set of tokens, their blinded & signed counterparts, a server public key (Y), a DLEQ proof and a transcript
|
||||
|
@ -122,3 +123,16 @@ func UnblindSignedTokenBatch(tokens []*Token, blindedTokens []BlindedToken, sign
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MarshalJSON - in order to store tokens in a serialized form we need to expose the private, unexported value
|
||||
// `t`. Note that `r` is not needed to spend the token, and as such we effectively destroy it when we serialize.
|
||||
// Ideally, go would let us do this with an annotation, alas.
|
||||
func (t Token) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(struct {
|
||||
T []byte `json:"t"`
|
||||
W *ristretto.Element
|
||||
}{
|
||||
T: t.t,
|
||||
W: t.W,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func TestToken_ConstrainToToken(t *testing.T) {
|
|||
token2 := new(Token)
|
||||
blindedToken2 := token2.GenBlindedToken()
|
||||
Ht := sha3.Sum512(token.t)
|
||||
T := new(ristretto255.Element).FromUniformBytes(Ht[:])
|
||||
T, _ := new(ristretto255.Element).SetUniformBytes(Ht[:])
|
||||
// Constraint forces T = kW to be part of the batch proof
|
||||
// And because the batch proof must prove that *all* inputs share the same key and also checks the servers public key
|
||||
// We get a consistency check for almost free.
|
||||
|
@ -75,7 +75,7 @@ func TestGenerateBlindedTokenBatch(t *testing.T) {
|
|||
db.Open("tokens.db")
|
||||
|
||||
fakeRand := sha512.Sum512([]byte{})
|
||||
k := ristretto255.NewScalar().FromUniformBytes(fakeRand[:])
|
||||
k, _ := ristretto255.NewScalar().SetUniformBytes(fakeRand[:])
|
||||
server := NewTokenServerFromStore(k, db)
|
||||
defer server.Close()
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func NewTokenServer() *TokenServer {
|
|||
// unable to generate secure random numbers
|
||||
panic("unable to generate secure random numbers")
|
||||
}
|
||||
k.FromUniformBytes(b)
|
||||
k.SetUniformBytes(b)
|
||||
return &TokenServer{k, new(ristretto.Element).ScalarBaseMult(k), make(map[string]bool), nil, sync.Mutex{}}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,10 @@ func (ts *TokenServer) SignBlindedTokenBatchWithConstraint(blindedTokens []Blind
|
|||
signedTokens = append(signedTokens, ts.SignBlindedToken(bt))
|
||||
}
|
||||
Ht := sha3.Sum512(constraintToken)
|
||||
T := new(ristretto.Element).FromUniformBytes(Ht[:])
|
||||
T, err := new(ristretto.Element).SetUniformBytes(Ht[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// W == kT
|
||||
W := new(ristretto.Element).ScalarMult(ts.k, T)
|
||||
blindedTokens = append(blindedTokens, BlindedToken{P: T})
|
||||
|
@ -107,14 +110,14 @@ func (ts *TokenServer) SignBlindedTokenBatchWithConstraint(blindedTokens []Blind
|
|||
// constructBatchProof construct a batch proof that all the signed tokens have been signed correctly
|
||||
func (ts *TokenServer) constructBatchProof(blindedTokens []BlindedToken, signedTokens []SignedToken, transcript *core.Transcript) (*DLEQProof, error) {
|
||||
transcript.NewProtocol(BatchProofProtocol)
|
||||
transcript.AddToTranscript(BatchProofX, new(ristretto.Element).Base().Encode(nil))
|
||||
transcript.AddToTranscript(BatchProofY, ts.Y.Encode(nil))
|
||||
transcript.AddToTranscript(BatchProofX, ristretto.NewGeneratorElement().Bytes())
|
||||
transcript.AddToTranscript(BatchProofY, ts.Y.Bytes())
|
||||
transcript.AddToTranscript(BatchProofPVector, []byte(fmt.Sprintf("%v", blindedTokens)))
|
||||
transcript.AddToTranscript(BatchProofQVector, []byte(fmt.Sprintf("%v", signedTokens)))
|
||||
prng := transcript.CommitToPRNG("w")
|
||||
|
||||
M := new(ristretto.Element).Zero()
|
||||
Z := new(ristretto.Element).Zero()
|
||||
M := ristretto.NewIdentityElement()
|
||||
Z := ristretto.NewIdentityElement()
|
||||
|
||||
buf := make([]byte, 64)
|
||||
c := new(ristretto.Scalar)
|
||||
|
@ -127,7 +130,7 @@ func (ts *TokenServer) constructBatchProof(blindedTokens []BlindedToken, signedT
|
|||
M = new(ristretto.Element).Add(new(ristretto.Element).ScalarMult(c, blindedTokens[i].P), M)
|
||||
Z = new(ristretto.Element).Add(new(ristretto.Element).ScalarMult(c, signedTokens[i].Q), Z)
|
||||
}
|
||||
proof := DiscreteLogEquivalenceProof(ts.k, new(ristretto.Element).Base(), ts.Y, M, Z, transcript)
|
||||
proof := DiscreteLogEquivalenceProof(ts.k, ristretto.NewGeneratorElement(), ts.Y, M, Z, transcript)
|
||||
return &proof, nil
|
||||
}
|
||||
|
||||
|
@ -146,9 +149,12 @@ func (ts *TokenServer) SpendToken(token SpentToken, data []byte) error {
|
|||
}
|
||||
}
|
||||
Ht := sha3.Sum512(token.T)
|
||||
T := new(ristretto.Element).FromUniformBytes(Ht[:])
|
||||
T, err := new(ristretto.Element).SetUniformBytes(Ht[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
W := new(ristretto.Element).ScalarMult(ts.k, T)
|
||||
key := sha3.Sum256(append(token.T, W.Encode(nil)...))
|
||||
key := sha3.Sum256(append(token.T, W.Bytes()...))
|
||||
mac := hmac.New(sha3.New512, key[:])
|
||||
mac.Write(data)
|
||||
computedMAC := mac.Sum(nil)
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
torProvider "git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -68,7 +68,7 @@ func TestTapir(t *testing.T) {
|
|||
|
||||
torDataDir := ""
|
||||
var err error
|
||||
if torDataDir, err = ioutil.TempDir("./tor/", "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp("./tor/", "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
@ -103,14 +103,19 @@ func TestTapir(t *testing.T) {
|
|||
go connectclient(t, client, id.PublicKey(), wg)
|
||||
CheckConnection(service, clienthostname, wg)
|
||||
wg.Wait()
|
||||
// Wait for Server to Sync
|
||||
time.Sleep(time.Second * 2)
|
||||
// Wait for Garbage Collection...
|
||||
time.Sleep(time.Second * 60)
|
||||
log.Infof("Closing ACN...")
|
||||
client.Shutdown()
|
||||
service.Shutdown()
|
||||
acn.Close()
|
||||
sg.Wait()
|
||||
time.Sleep(time.Second * 2)
|
||||
time.Sleep(time.Second * 5)
|
||||
log.Infof("Number of goroutines open at close: %d", runtime.NumGoroutine())
|
||||
if numRoutinesStart != runtime.NumGoroutine() {
|
||||
|
||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
|
||||
t.Errorf("Potential goroutine leak: Num Start:%v NumEnd: %v", numRoutinesStart, runtime.NumGoroutine())
|
||||
}
|
||||
if !AuthSuccess {
|
||||
|
@ -137,6 +142,10 @@ func connectclient(t *testing.T, client tapir.Service, key ed25519.PublicKey, gr
|
|||
conn, _ := client.GetConnection(torProvider.GetTorV3Hostname(key))
|
||||
log.Debugf("Client has Auth: %v", conn.HasCapability(applications.AuthCapability))
|
||||
|
||||
if conn.HasCapability(applications.AuthCapability) == false {
|
||||
t.Errorf("tapir auth failed")
|
||||
}
|
||||
|
||||
// attempt to send a message that is too long
|
||||
var long [8195]byte
|
||||
err := conn.Send(long[:])
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
torProvider "git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
@ -30,7 +29,7 @@ func TestTapirMaliciousRemote(t *testing.T) {
|
|||
|
||||
torDataDir := ""
|
||||
var err error
|
||||
if torDataDir, err = ioutil.TempDir("./tor/", "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp("./tor/", "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
@ -71,6 +70,8 @@ func TestTapirMaliciousRemote(t *testing.T) {
|
|||
// Wait for Server to Sync
|
||||
time.Sleep(time.Second * 2)
|
||||
log.Infof("closing ACN...")
|
||||
client.Shutdown()
|
||||
service.Shutdown()
|
||||
acn.Close()
|
||||
sg.Wait()
|
||||
time.Sleep(time.Second * 5) // wait for goroutines to finish...
|
||||
|
|
|
@ -2,9 +2,9 @@ package utils
|
|||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"filippo.io/edwards25519"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// EDH implements diffie hellman using curve25519 keys derived from ed25519 keys
|
||||
|
@ -16,68 +16,23 @@ func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) ([]by
|
|||
var curve25519priv [32]byte
|
||||
|
||||
PrivateKeyToCurve25519(&curve25519priv, &privKeyBytes)
|
||||
curve25519pub := ed25519PublicKeyToCurve25519(remotePublicKey)
|
||||
secret, err := curve25519.X25519(curve25519priv[:], curve25519pub[:])
|
||||
remoteCurve25519pub, err := ed25519PublicKeyToCurve25519New(remotePublicKey)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
secret, err := curve25519.X25519(curve25519priv[:], remoteCurve25519pub[:])
|
||||
return secret, err
|
||||
}
|
||||
|
||||
// https://github.com/FiloSottile/age/blob/master/internal/age/ssh.go#L174
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions are
|
||||
//met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
//notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
//copyright notice, this list of conditions and the following disclaimer
|
||||
//in the documentation and/or other materials provided with the
|
||||
//distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
//contributors may be used to endorse or promote products derived from
|
||||
//this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
//A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
//OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
//LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
//DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
//THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
//(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
var curve25519P, _ = new(big.Int).SetString("57896044618658097711785492504343953926634992332820282019728792003956564819949", 10)
|
||||
|
||||
func ed25519PublicKeyToCurve25519(pk ed25519.PublicKey) []byte {
|
||||
// ed25519.PublicKey is a little endian representation of the y-coordinate,
|
||||
// with the most significant bit set based on the sign of the x-coordinate.
|
||||
bigEndianY := make([]byte, ed25519.PublicKeySize)
|
||||
for i, b := range pk {
|
||||
bigEndianY[ed25519.PublicKeySize-i-1] = b
|
||||
// reproduced from https://github.com/FiloSottile/age/blob/main/agessh/agessh.go#L190
|
||||
func ed25519PublicKeyToCurve25519New(pk ed25519.PublicKey) ([]byte, error) {
|
||||
// See https://blog.filippo.io/using-ed25519-keys-for-encryption and
|
||||
// https://pkg.go.dev/filippo.io/edwards25519#Point.BytesMontgomery.
|
||||
p, err := new(edwards25519.Point).SetBytes(pk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bigEndianY[0] &= 0b0111_1111
|
||||
|
||||
// The Montgomery u-coordinate is derived through the bilinear map
|
||||
//
|
||||
// u = (1 + y) / (1 - y)
|
||||
//
|
||||
// See https://blog.filippo.io/using-ed25519-keys-for-encryption.
|
||||
y := new(big.Int).SetBytes(bigEndianY)
|
||||
denom := big.NewInt(1)
|
||||
denom.ModInverse(denom.Sub(denom, y), curve25519P) // 1 / (1 - y)
|
||||
u := y.Mul(y.Add(y, big.NewInt(1)), denom)
|
||||
u.Mod(u, curve25519P)
|
||||
|
||||
out := make([]byte, curve25519.PointSize)
|
||||
uBytes := u.Bytes()
|
||||
for i, b := range uBytes {
|
||||
out[len(uBytes)-i-1] = b
|
||||
}
|
||||
|
||||
return out
|
||||
return p.BytesMontgomery(), nil
|
||||
}
|
||||
|
||||
// PrivateKeyToCurve25519 converts an ed25519 private key into a corresponding
|
||||
|
|
Loading…
Reference in New Issue