Swap base58 libraries (#472)

* Swap base58 libraries

This doesn't reduce binary size but it removes a metric ton of
dependencies.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-26 14:01:49 -04:00
1 parent c30fd5620e
commit cf3fa4522d
10 files changed
+44 -35

No files matched your search

+7 -2
View File
@@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
"github.com/hashicorp/boundary/internal/gen/controller/tokens"
@@ -23,6 +22,7 @@ import (
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/kr/pretty"
"github.com/mr-tron/base58"
"google.golang.org/protobuf/proto"
)
@@ -500,7 +500,12 @@ func (v *verifier) decryptToken() {
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
marshaledToken := base58.Decode(v.requestInfo.EncryptedToken[len(globals.ServiceTokenV1):])
marshaledToken, err := base58.FastBase58Decoding(v.requestInfo.EncryptedToken[len(globals.ServiceTokenV1):])
if err != nil {
v.logger.Trace("decrypt bearer token: error unmarshaling base58 token; continuing as anonymous user", "error", err)
v.requestInfo.TokenFormat = AuthTokenTypeUnknown
return
}
blobInfo := new(wrapping.EncryptedBlobInfo)
if err := proto.Unmarshal(marshaledToken, blobInfo); err != nil {
+4 -2
View File
@@ -6,7 +6,6 @@ import (
mathrand "math/rand"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/authtoken/store"
"github.com/hashicorp/boundary/internal/db"
@@ -15,6 +14,7 @@ import (
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-kms-wrapping/structwrapping"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/mr-tron/base58"
"google.golang.org/protobuf/proto"
)
@@ -133,5 +133,7 @@ func EncryptToken(ctx context.Context, kmsCache *kms.Kms, scopeId, publicId, tok
return "", fmt.Errorf("error marshaling encrypted token: %w", err)
}
return globals.ServiceTokenV1 + base58.Encode(marshaledBlob), nil
encoded := base58.FastBase58Encoding(marshaledBlob)
return globals.ServiceTokenV1 + encoded, nil
}
+7 -4
View File
@@ -3,6 +3,7 @@ package base
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
@@ -15,7 +16,6 @@ import (
"sync"
"syscall"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authtokens"
"github.com/hashicorp/boundary/sdk/wrapper"
@@ -219,10 +219,13 @@ func (c *Command) Client(opt ...Option) (*api.Client, error) {
token = ""
}
if token != "" {
tokenBytes := base58.Decode(token)
if len(tokenBytes) == 0 {
tokenBytes, err := base64.RawStdEncoding.DecodeString(token)
switch {
case err != nil:
c.UI.Error(fmt.Errorf("Error base64-unmarshaling stored token from system credential store: %w", err).Error())
case len(tokenBytes) == 0:
c.UI.Error("Zero length token after decoding stored token from system credential store")
} else {
default:
var authToken authtokens.AuthToken
if err := json.Unmarshal(tokenBytes, &authToken); err != nil {
c.UI.Error(fmt.Sprintf("Error unmarshaling stored token information after reading from system credential store: %s", err))
@@ -1,13 +1,13 @@
package authenticate
import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"strings"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/cmd/base"
@@ -165,7 +165,7 @@ func (c *PasswordCommand) Run(args []string) int {
c.UI.Error(fmt.Sprintf("Error marshaling auth token to save to system credential store: %s", err))
return 1
}
if err := keyring.Set("HashiCorp Boundary Auth Token", tokenName, base58.Encode(marshaled)); err != nil {
if err := keyring.Set("HashiCorp Boundary Auth Token", tokenName, base64.RawStdEncoding.EncodeToString(marshaled)); err != nil {
c.UI.Error(fmt.Sprintf("Error saving auth token to system credential store: %s", err))
return 1
}
+6 -2
View File
@@ -20,7 +20,6 @@ import (
"syscall"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/globals"
@@ -30,6 +29,7 @@ import (
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/mitchellh/cli"
"github.com/mr-tron/base58"
"github.com/posener/complete"
"go.uber.org/atomic"
"google.golang.org/protobuf/proto"
@@ -391,7 +391,11 @@ func (c *Command) Run(args []string) (retCode int) {
authzString = sa.AuthorizationToken
}
marshaled := base58.Decode(authzString)
marshaled, err := base58.FastBase58Decoding(authzString)
if err != nil {
c.UI.Error(fmt.Errorf("Unable to base58-decode authorization data: %w", err).Error())
return 1
}
if len(marshaled) == 0 {
c.UI.Error("Zero length authorization information after decoding")
return 1
@@ -78,6 +78,7 @@ func TestGetSession(t *testing.T) {
ExpirationTime: sess.ExpirationTime.GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()},
States: []*pb.SessionState{{Status: session.StatusPending.String(), StartTime: sess.CreateTime.GetTimestamp()}},
Certificate: sess.Certificate,
}
cases := []struct {
@@ -191,6 +192,7 @@ func TestList(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: pWithSessions.GetPublicId(), Type: scope.Project.String()},
Status: status,
States: states,
Certificate: sess.Certificate,
})
}
@@ -299,6 +301,7 @@ func TestCancel(t *testing.T) {
ExpirationTime: sess.ExpirationTime.GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()},
Status: session.StatusCanceling.String(),
Certificate: sess.Certificate,
}
version := wireSess.GetVersion()
@@ -7,7 +7,6 @@ import (
"math/rand"
"net/url"
"github.com/btcsuite/btcutil/base58"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
@@ -25,6 +24,7 @@ import (
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/mr-tron/base58"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -401,13 +401,15 @@ HostSetIterationLoop:
if err != nil {
return nil, err
}
encodedMarshaledSad := base58.FastBase58Encoding(marshaledSad)
ret := &pb.SessionAuthorization{
SessionId: sess.PublicId,
TargetId: t.GetPublicId(),
Scope: authResults.Scope,
CreatedTime: sess.CreateTime.GetTimestamp(),
Type: t.GetType(),
AuthorizationToken: base58.Encode(marshaledSad),
AuthorizationToken: string(encodedMarshaledSad),
UserId: authResults.UserId,
HostId: chosenId.hostId,
HostSetId: chosenId.hostSetId,