Use base58 for a few more user-facing values (#356)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-12 21:43:08 -04:00
1 parent 1f80edbffc
commit 2914b4c14c
5 files changed
+17 -16

No files matched your search

+4 -4
View File
@@ -3,7 +3,6 @@ package base
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
@@ -16,6 +15,7 @@ import (
"sync"
"syscall"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authtokens"
"github.com/hashicorp/boundary/sdk/recovery"
@@ -224,9 +224,9 @@ func (c *Command) Client(opt ...Option) (*api.Client, error) {
token = ""
}
if token != "" {
tokenBytes, err := base64.RawStdEncoding.DecodeString(token)
if err != nil {
c.UI.Error(fmt.Sprintf("Error unmarshaling stored token from system credential store: %s", err))
tokenBytes := base58.Decode(token)
if len(tokenBytes) == 0 {
c.UI.Error("Zero length token after decoding stored token from system credential store")
} else {
var authToken authtokens.AuthToken
if err := json.Unmarshal(tokenBytes, &authToken); err != nil {
@@ -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/authmethods"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/vault/sdk/helper/password"
@@ -156,7 +156,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, base64.RawStdEncoding.EncodeToString(marshaled)); err != nil {
if err := keyring.Set("HashiCorp Boundary Auth Token", tokenName, base58.Encode(marshaled)); err != nil {
c.UI.Error(fmt.Sprintf("Error saving auth token to system credential store: %s", err))
return 1
}
+4 -4
View File
@@ -4,7 +4,6 @@ import (
"crypto/ed25519"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
@@ -14,6 +13,7 @@ import (
"strings"
"sync"
"github.com/btcsuite/btcutil/base58"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
@@ -141,9 +141,9 @@ func (c *Command) Run(args []string) int {
c.flagAuth = string(authBytes)
}
marshaled, err := base64.RawStdEncoding.DecodeString(c.flagAuth)
if err != nil {
c.UI.Error(fmt.Errorf("Unable to decode authorization string: %w", err).Error())
marshaled := base58.Decode(c.flagAuth)
if len(marshaled) == 0 {
c.UI.Error("Zero length authorization information after decoding")
return 1
}
+2 -2
View File
@@ -4,7 +4,6 @@ import (
"context"
"crypto/rand"
"crypto/x509"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
@@ -15,6 +14,7 @@ import (
"strings"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/globals"
@@ -408,7 +408,7 @@ func jobTestingHandler(c *Controller) http.Handler {
return
}
if _, err := w.Write([]byte(base64.RawStdEncoding.EncodeToString(marshaled))); err != nil {
if _, err := w.Write([]byte(base58.Encode(marshaled))); err != nil {
errorResp(err)
return
}
+5 -4
View File
@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/btcsuite/btcutil/base58"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-uuid"
"google.golang.org/protobuf/proto"
@@ -57,7 +58,7 @@ func formatToken(ctx context.Context, wrapper wrapping.Wrapper, info *Info) (str
return "", fmt.Errorf("error marshaling encrypted blob: %w", err)
}
return fmt.Sprintf("r_%s", base64.RawStdEncoding.EncodeToString(marshaledBlob)), nil
return fmt.Sprintf("r_%s", base58.Encode(marshaledBlob)), nil
}
func ParseRecoveryToken(ctx context.Context, wrapper wrapping.Wrapper, token string) (*Info, error) {
@@ -70,9 +71,9 @@ func ParseRecoveryToken(ctx context.Context, wrapper wrapping.Wrapper, token str
}
token = strings.TrimPrefix(token, "r_")
marshaledBlob, err := base64.RawStdEncoding.DecodeString(token)
if err != nil {
return nil, fmt.Errorf("error base64-decoding token: %w", err)
marshaledBlob := base58.Decode(token)
if len(marshaledBlob) == 0 {
return nil, fmt.Errorf("length zero after base58-decoding token")
}
blobInfo := new(wrapping.EncryptedBlobInfo)