mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 09:04:19 +01:00
onion_store: remove tor V2 + use new OnionStore
The target version of the tor.OnionStore interface methods do not accept onion type as an argument. Further, tor V2 was depreciated in October 2021. We can therefore remove support for tor V2.
This commit is contained in:
@@ -2,7 +2,6 @@ package aperture
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/tor"
|
"github.com/lightningnetwork/lnd/tor"
|
||||||
@@ -14,32 +13,15 @@ const (
|
|||||||
// related information.
|
// related information.
|
||||||
onionDir = "onion"
|
onionDir = "onion"
|
||||||
|
|
||||||
// onionV2Dir is the directory we'll use to store a v2 onion service's
|
// onionV3Dir is the directory we'll use to store a v3 onion service's
|
||||||
// private key, such that it can be restored after restarts.
|
|
||||||
onionV2Dir = "v2"
|
|
||||||
|
|
||||||
// onionV2Dir is the directory we'll use to store a v3 onion service's
|
|
||||||
// private key, such that it can be restored after restarts.
|
// private key, such that it can be restored after restarts.
|
||||||
onionV3Dir = "v3"
|
onionV3Dir = "v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// onionPath returns the full path to an onion service's private key of the
|
// onionPath is the full path to an onion service's private key.
|
||||||
// given type.
|
var onionPath = strings.Join(
|
||||||
func onionPath(onionType tor.OnionType) (string, error) {
|
[]string{topLevelKey, onionDir, onionV3Dir}, etcdKeyDelimeter,
|
||||||
var typeDir string
|
)
|
||||||
switch onionType {
|
|
||||||
case tor.V2:
|
|
||||||
typeDir = onionV2Dir
|
|
||||||
case tor.V3:
|
|
||||||
typeDir = onionV3Dir
|
|
||||||
default:
|
|
||||||
return "", fmt.Errorf("unknown onion type %v", onionType)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(
|
|
||||||
[]string{topLevelKey, onionDir, typeDir}, etcdKeyDelimeter,
|
|
||||||
), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// onionStore is an etcd-based implementation of tor.OnionStore.
|
// onionStore is an etcd-based implementation of tor.OnionStore.
|
||||||
type onionStore struct {
|
type onionStore struct {
|
||||||
@@ -55,26 +37,14 @@ func newOnionStore(client *clientv3.Client) *onionStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StorePrivateKey stores the given private key.
|
// StorePrivateKey stores the given private key.
|
||||||
func (s *onionStore) StorePrivateKey(onionType tor.OnionType,
|
func (s *onionStore) StorePrivateKey(privateKey []byte) error {
|
||||||
privateKey []byte) error {
|
_, err := s.Client.Put(context.Background(), onionPath, string(privateKey))
|
||||||
|
|
||||||
onionPath, err := onionPath(onionType)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.Client.Put(context.Background(), onionPath, string(privateKey))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrivateKey retrieves a stored private key. If it is not found, then
|
// PrivateKey retrieves a stored private key. If it is not found, then
|
||||||
// ErrNoPrivateKey should be returned.
|
// ErrNoPrivateKey should be returned.
|
||||||
func (s *onionStore) PrivateKey(onionType tor.OnionType) ([]byte, error) {
|
func (s *onionStore) PrivateKey() ([]byte, error) {
|
||||||
onionPath, err := onionPath(onionType)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := s.Get(context.Background(), onionPath)
|
resp, err := s.Get(context.Background(), onionPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -87,12 +57,7 @@ func (s *onionStore) PrivateKey(onionType tor.OnionType) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeletePrivateKey securely removes the private key from the store.
|
// DeletePrivateKey securely removes the private key from the store.
|
||||||
func (s *onionStore) DeletePrivateKey(onionType tor.OnionType) error {
|
func (s *onionStore) DeletePrivateKey() error {
|
||||||
onionPath, err := onionPath(onionType)
|
_, err := s.Client.Delete(context.Background(), onionPath)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.Client.Delete(context.Background(), onionPath)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user