mirror of
https://github.com/pgsty/minio.git
synced 2026-08-10 16:23:28 +03:00
ca6b4773ed
This change adds server-side-encryption support for HEAD, GET and PUT
operations. This PR only addresses single-part PUTs and GETs without
HTTP ranges.
Further this change adds the concept of reserved object metadata which is required
to make encrypted objects tamper-proof and provide API compatibility to AWS S3.
This PR adds the following reserved metadata entries:
- X-Minio-Internal-Server-Side-Encryption-Iv ('guarantees' tamper-proof property)
- X-Minio-Internal-Server-Side-Encryption-Kdf (makes Key-MAC computation negotiable in future)
- X-Minio-Internal-Server-Side-Encryption-Key-Mac (provides AWS S3 API compatibility)
The prefix `X-Minio_Internal` specifies an internal metadata entry which must not
send to clients. All client requests containing a metadata key starting with `X-Minio-Internal`
must also rejected. This is implemented by a generic-handler.
This PR implements SSE-C separated from client-side-encryption (CSE). This cannot decrypt
server-side-encrypted objects on the client-side. However, clients can encrypted the same object
with CSE and SSE-C.
This PR does not address:
- SSE-C Copy and Copy part
- SSE-C GET with HTTP ranges
- SSE-C multipart PUT
- SSE-C Gateway
Each point must be addressed in a separate PR.
Added to vendor dir:
- x/crypto/chacha20poly1305
- x/crypto/poly1305
- github.com/minio/sio
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package chacha20poly1305
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
"golang.org/x/crypto/chacha20poly1305/internal/chacha20"
|
|
"golang.org/x/crypto/poly1305"
|
|
)
|
|
|
|
func roundTo16(n int) int {
|
|
return 16 * ((n + 15) / 16)
|
|
}
|
|
|
|
func (c *chacha20poly1305) sealGeneric(dst, nonce, plaintext, additionalData []byte) []byte {
|
|
var counter [16]byte
|
|
copy(counter[4:], nonce)
|
|
|
|
var polyKey [32]byte
|
|
chacha20.XORKeyStream(polyKey[:], polyKey[:], &counter, &c.key)
|
|
|
|
ret, out := sliceForAppend(dst, len(plaintext)+poly1305.TagSize)
|
|
counter[0] = 1
|
|
chacha20.XORKeyStream(out, plaintext, &counter, &c.key)
|
|
|
|
polyInput := make([]byte, roundTo16(len(additionalData))+roundTo16(len(plaintext))+8+8)
|
|
copy(polyInput, additionalData)
|
|
copy(polyInput[roundTo16(len(additionalData)):], out[:len(plaintext)])
|
|
binary.LittleEndian.PutUint64(polyInput[len(polyInput)-16:], uint64(len(additionalData)))
|
|
binary.LittleEndian.PutUint64(polyInput[len(polyInput)-8:], uint64(len(plaintext)))
|
|
|
|
var tag [poly1305.TagSize]byte
|
|
poly1305.Sum(&tag, polyInput, &polyKey)
|
|
copy(out[len(plaintext):], tag[:])
|
|
|
|
return ret
|
|
}
|
|
|
|
func (c *chacha20poly1305) openGeneric(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
|
|
var tag [poly1305.TagSize]byte
|
|
copy(tag[:], ciphertext[len(ciphertext)-16:])
|
|
ciphertext = ciphertext[:len(ciphertext)-16]
|
|
|
|
var counter [16]byte
|
|
copy(counter[4:], nonce)
|
|
|
|
var polyKey [32]byte
|
|
chacha20.XORKeyStream(polyKey[:], polyKey[:], &counter, &c.key)
|
|
|
|
polyInput := make([]byte, roundTo16(len(additionalData))+roundTo16(len(ciphertext))+8+8)
|
|
copy(polyInput, additionalData)
|
|
copy(polyInput[roundTo16(len(additionalData)):], ciphertext)
|
|
binary.LittleEndian.PutUint64(polyInput[len(polyInput)-16:], uint64(len(additionalData)))
|
|
binary.LittleEndian.PutUint64(polyInput[len(polyInput)-8:], uint64(len(ciphertext)))
|
|
|
|
ret, out := sliceForAppend(dst, len(ciphertext))
|
|
if !poly1305.Verify(&tag, polyInput, &polyKey) {
|
|
for i := range out {
|
|
out[i] = 0
|
|
}
|
|
return nil, errOpen
|
|
}
|
|
|
|
counter[0] = 1
|
|
chacha20.XORKeyStream(out, ciphertext, &counter, &c.key)
|
|
return ret, nil
|
|
}
|