2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
2018-06-28 15:47:42 -04:00
|
|
|
//
|
2021-04-18 15:41:13 -04:00
|
|
|
// This file is part of MinIO Object Storage stack
|
2018-06-28 15:47:42 -04:00
|
|
|
//
|
2021-04-18 15:41:13 -04:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-06-28 15:47:42 -04:00
|
|
|
//
|
2021-04-18 15:41:13 -04:00
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-06-28 15:47:42 -04:00
|
|
|
|
|
|
|
package crypto
|
|
|
|
|
2020-01-06 19:15:22 -05:00
|
|
|
import (
|
2023-05-25 12:39:06 -04:00
|
|
|
"errors"
|
2020-01-06 19:15:22 -05:00
|
|
|
"fmt"
|
|
|
|
)
|
2018-06-28 15:47:42 -04:00
|
|
|
|
2018-07-16 10:49:50 -04:00
|
|
|
// Error is the generic type for any error happening during decrypting
|
|
|
|
// an object. It indicates that the object itself or its metadata was
|
|
|
|
// modified accidentally or maliciously.
|
2020-01-06 19:15:22 -05:00
|
|
|
type Error struct {
|
2023-05-25 12:39:06 -04:00
|
|
|
msg string
|
|
|
|
cause error
|
2020-01-06 19:15:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Errorf - formats according to a format specifier and returns
|
|
|
|
// the string as a value that satisfies error of type crypto.Error
|
|
|
|
func Errorf(format string, a ...interface{}) error {
|
2023-05-25 12:39:06 -04:00
|
|
|
e := fmt.Errorf(format, a...)
|
|
|
|
ee := Error{}
|
|
|
|
ee.msg = e.Error()
|
|
|
|
ee.cause = errors.Unwrap(e)
|
|
|
|
return ee
|
2020-01-06 19:15:22 -05:00
|
|
|
}
|
2018-07-16 10:49:50 -04:00
|
|
|
|
2020-01-06 19:15:22 -05:00
|
|
|
// Unwrap the internal error.
|
2023-05-25 12:39:06 -04:00
|
|
|
func (e Error) Unwrap() error { return e.cause }
|
2020-01-06 19:15:22 -05:00
|
|
|
|
|
|
|
// Error 'error' compatible method.
|
|
|
|
func (e Error) Error() string {
|
2023-05-25 12:39:06 -04:00
|
|
|
if e.msg == "" {
|
2020-01-06 19:15:22 -05:00
|
|
|
return "crypto: cause <nil>"
|
|
|
|
}
|
2023-05-25 12:39:06 -04:00
|
|
|
return e.msg
|
2020-01-06 19:15:22 -05:00
|
|
|
}
|
2018-07-16 10:49:50 -04:00
|
|
|
|
2018-06-28 15:47:42 -04:00
|
|
|
var (
|
|
|
|
// ErrInvalidEncryptionMethod indicates that the specified SSE encryption method
|
|
|
|
// is not supported.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrInvalidEncryptionMethod = Errorf("The encryption method is not supported")
|
2018-07-18 13:49:26 -04:00
|
|
|
|
|
|
|
// ErrInvalidCustomerAlgorithm indicates that the specified SSE-C algorithm
|
|
|
|
// is not supported.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrInvalidCustomerAlgorithm = Errorf("The SSE-C algorithm is not supported")
|
2018-07-18 13:49:26 -04:00
|
|
|
|
|
|
|
// ErrMissingCustomerKey indicates that the HTTP headers contains no SSE-C client key.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrMissingCustomerKey = Errorf("The SSE-C request is missing the customer key")
|
2018-07-18 13:49:26 -04:00
|
|
|
|
|
|
|
// ErrMissingCustomerKeyMD5 indicates that the HTTP headers contains no SSE-C client key
|
|
|
|
// MD5 checksum.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrMissingCustomerKeyMD5 = Errorf("The SSE-C request is missing the customer key MD5")
|
2018-07-18 13:49:26 -04:00
|
|
|
|
|
|
|
// ErrInvalidCustomerKey indicates that the SSE-C client key is not valid - e.g. not a
|
|
|
|
// base64-encoded string or not 256 bits long.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrInvalidCustomerKey = Errorf("The SSE-C client key is invalid")
|
2018-07-18 13:49:26 -04:00
|
|
|
|
2018-09-06 15:31:12 -04:00
|
|
|
// ErrSecretKeyMismatch indicates that the provided secret key (SSE-C client key / SSE-S3 KMS key)
|
|
|
|
// does not match the secret key used during encrypting the object.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrSecretKeyMismatch = Errorf("The secret key does not match the secret key used during upload")
|
2018-09-06 15:31:12 -04:00
|
|
|
|
2018-07-18 13:49:26 -04:00
|
|
|
// ErrCustomerKeyMD5Mismatch indicates that the SSE-C key MD5 does not match the
|
|
|
|
// computed MD5 sum. This means that the client provided either the wrong key for
|
|
|
|
// a certain MD5 checksum or the wrong MD5 for a certain key.
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrCustomerKeyMD5Mismatch = Errorf("The provided SSE-C key MD5 does not match the computed MD5 of the SSE-C key")
|
2018-08-17 15:52:14 -04:00
|
|
|
// ErrIncompatibleEncryptionMethod indicates that both SSE-C headers and SSE-S3 headers were specified, and are incompatible
|
|
|
|
// The client needs to remove the SSE-S3 header or the SSE-C headers
|
2020-01-06 19:15:22 -05:00
|
|
|
ErrIncompatibleEncryptionMethod = Errorf("Server side encryption specified with both SSE-C and SSE-S3 headers")
|
2022-08-16 14:28:30 -04:00
|
|
|
|
|
|
|
// ErrInvalidEncryptionKeyID returns error when KMS key id contains invalid characters
|
|
|
|
ErrInvalidEncryptionKeyID = Errorf("KMS KeyID contains unsupported characters")
|
2018-06-28 15:47:42 -04:00
|
|
|
)
|
2018-07-18 01:40:34 -04:00
|
|
|
|
2020-01-06 19:15:22 -05:00
|
|
|
var (
|
|
|
|
errMissingInternalIV = Errorf("The object metadata is missing the internal encryption IV")
|
|
|
|
errMissingInternalSealAlgorithm = Errorf("The object metadata is missing the internal seal algorithm")
|
2018-07-25 16:35:54 -04:00
|
|
|
|
2020-01-06 19:15:22 -05:00
|
|
|
errInvalidInternalIV = Errorf("The internal encryption IV is malformed")
|
|
|
|
errInvalidInternalSealAlgorithm = Errorf("The internal seal algorithm is invalid and not supported")
|
2018-07-25 16:35:54 -04:00
|
|
|
)
|
|
|
|
|
2022-01-02 12:15:06 -05:00
|
|
|
// errOutOfEntropy indicates that the a source of randomness (PRNG) wasn't able
|
|
|
|
// to produce enough random data. This is fatal error and should cause a panic.
|
|
|
|
var errOutOfEntropy = Errorf("Unable to read enough randomness from the system")
|