use jsoniter for json marshal/unmarshal in KMS (#12146)

Signed-off-by: Harshavardhana <harsha@minio.io>
This commit is contained in:
Harshavardhana 2021-04-26 16:01:52 -07:00 committed by GitHub
parent d501c5e38b
commit 2966823818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -1499,7 +1499,6 @@ func (er erasureObjects) restoreTransitionedObject(ctx context.Context, bucket s
} }
_, err = er.CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts, ObjectOptions{ _, err = er.CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts, ObjectOptions{
VersionID: oi.VersionID,
MTime: oi.ModTime, MTime: oi.ModTime,
Versioned: globalBucketVersioningSys.Enabled(bucket), Versioned: globalBucketVersioningSys.Enabled(bucket),
VersionSuspended: globalBucketVersioningSys.Suspended(bucket), VersionSuspended: globalBucketVersioningSys.Suspended(bucket),

View File

@ -20,6 +20,8 @@ package kms
import ( import (
"encoding" "encoding"
"encoding/json" "encoding/json"
jsoniter "github.com/json-iterator/go"
) )
// KMS is the generic interface that abstracts over // KMS is the generic interface that abstracts over
@ -106,6 +108,7 @@ func (d *DEK) UnmarshalText(text []byte) error {
Ciphertext []byte `json:"ciphertext"` Ciphertext []byte `json:"ciphertext"`
} }
var v JSON var v JSON
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(text, &v); err != nil { if err := json.Unmarshal(text, &v); err != nil {
return err return err
} }

View File

@ -23,12 +23,12 @@ import (
"crypto/hmac" "crypto/hmac"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
jsoniter "github.com/json-iterator/go"
"github.com/secure-io/sio-go/sioutil" "github.com/secure-io/sio-go/sioutil"
"golang.org/x/crypto/chacha20" "golang.org/x/crypto/chacha20"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
@ -152,6 +152,7 @@ func (kms secretKey) GenerateKey(keyID string, context Context) (DEK, error) {
associatedData, _ := context.MarshalText() associatedData, _ := context.MarshalText()
ciphertext := aead.Seal(nil, nonce, plaintext, associatedData) ciphertext := aead.Seal(nil, nonce, plaintext, associatedData)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
ciphertext, err = json.Marshal(encryptedKey{ ciphertext, err = json.Marshal(encryptedKey{
Algorithm: algorithm, Algorithm: algorithm,
IV: iv, IV: iv,
@ -174,9 +175,11 @@ func (kms secretKey) DecryptKey(keyID string, ciphertext []byte, context Context
} }
var encryptedKey encryptedKey var encryptedKey encryptedKey
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(ciphertext, &encryptedKey); err != nil { if err := json.Unmarshal(ciphertext, &encryptedKey); err != nil {
return nil, err return nil, err
} }
if n := len(encryptedKey.IV); n != 16 { if n := len(encryptedKey.IV); n != 16 {
return nil, fmt.Errorf("kms: invalid iv size") return nil, fmt.Errorf("kms: invalid iv size")
} }