-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: fscrypt requires keys of 32 bytes
It seems that fscrypt expects a key with exactly 32 bytes. In order to use a random length key from a KMS, either repeat the key until the length is reached, or trim the key when needed. See: https://github.com/google/fscrypt/tree/v0.3.4#using-a-raw-key-protector Signed-off-by: Niels de Vos <[email protected]>
- Loading branch information
Showing
2 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2025 The Ceph-CSI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package fscrypt | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestResizePassphrase(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
passphrase string | ||
size int | ||
ret string | ||
err error | ||
}{ | ||
{ | ||
"matching passphrase size", | ||
"secret", | ||
6, | ||
"secret", | ||
nil, | ||
}, | ||
{ | ||
"short passphrase", | ||
"secret", | ||
64, | ||
"secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecr", | ||
nil, | ||
}, | ||
{ | ||
"long passphrase", | ||
"secret", | ||
2, | ||
"se", | ||
nil, | ||
}, | ||
{ | ||
"empty passphrase", | ||
"", | ||
16, | ||
"", | ||
ErrEmptyPassphrase, | ||
}, | ||
{ | ||
"zero length requested", | ||
"secret", | ||
0, | ||
"", | ||
ErrEmptyPassphrase, | ||
}, | ||
{ | ||
"negative length requested", | ||
"secret", | ||
-32, | ||
"", | ||
ErrEmptyPassphrase, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ret, err := resizePassphrase(tt.passphrase, tt.size) | ||
if ret != tt.ret { | ||
t.Errorf("resizePassphrase() returned %q of %d bytes, expected %q of %d bytes", tt.ret, len(tt.ret), ret, len(ret)) | ||
} | ||
if !errors.Is(err, tt.err) { | ||
t.Errorf("resizePassphrase() returned %v as error, expected %v", err, tt.err) | ||
} | ||
}) | ||
} | ||
} |