mirror of https://github.com/portainer/portainer
fix(fips): encrypt the chisel private key file for fips [be-12132] (#1143)
parent
54f6add45d
commit
6abfbe8553
|
@ -389,3 +389,18 @@ func aesDecryptOFB(input io.Reader, passphrase []byte) (io.Reader, error) {
|
||||||
|
|
||||||
return reader, nil
|
return reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasEncryptedHeader checks if the data has an encrypted header, note that fips
|
||||||
|
// mode changes this behavior and so will only recognize data encrypted by the
|
||||||
|
// same mode (fips enabled or disabled)
|
||||||
|
func HasEncryptedHeader(data []byte) bool {
|
||||||
|
return hasEncryptedHeader(data, fips.FIPSMode())
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasEncryptedHeader(data []byte, fipsMode bool) bool {
|
||||||
|
if fipsMode {
|
||||||
|
return bytes.HasPrefix(data, []byte(aesGcmFIPSHeader))
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes.HasPrefix(data, []byte(aesGcmHeader))
|
||||||
|
}
|
||||||
|
|
|
@ -364,3 +364,62 @@ func legacyAesEncrypt(input io.Reader, output io.Writer, passphrase []byte) erro
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_hasEncryptedHeader(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
data []byte
|
||||||
|
fipsMode bool
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "non-FIPS mode with valid header",
|
||||||
|
data: []byte("AES256-GCM" + "some encrypted data"),
|
||||||
|
fipsMode: false,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-FIPS mode with FIPS header",
|
||||||
|
data: []byte("FIPS-AES256-GCM" + "some encrypted data"),
|
||||||
|
fipsMode: false,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FIPS mode with valid header",
|
||||||
|
data: []byte("FIPS-AES256-GCM" + "some encrypted data"),
|
||||||
|
fipsMode: true,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FIPS mode with non-FIPS header",
|
||||||
|
data: []byte("AES256-GCM" + "some encrypted data"),
|
||||||
|
fipsMode: true,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid header",
|
||||||
|
data: []byte("INVALID-HEADER" + "some data"),
|
||||||
|
fipsMode: false,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty data",
|
||||||
|
data: []byte{},
|
||||||
|
fipsMode: false,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nil data",
|
||||||
|
data: nil,
|
||||||
|
fipsMode: false,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := hasEncryptedHeader(tt.data, tt.fipsMode)
|
||||||
|
assert.Equal(t, tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -848,7 +848,7 @@ func defaultMTLSCertPathUnderFileStore() (string, string, string) {
|
||||||
return caCertPath, certPath, keyPath
|
return caCertPath, certPath, keyPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultChiselPrivateKeyPath returns the chisle private key path
|
// GetDefaultChiselPrivateKeyPath returns the chisel private key path
|
||||||
func (service *Service) GetDefaultChiselPrivateKeyPath() string {
|
func (service *Service) GetDefaultChiselPrivateKeyPath() string {
|
||||||
privateKeyPath := defaultChiselPrivateKeyPathUnderFileStore()
|
privateKeyPath := defaultChiselPrivateKeyPathUnderFileStore()
|
||||||
return service.wrapFileStore(privateKeyPath)
|
return service.wrapFileStore(privateKeyPath)
|
||||||
|
|
Loading…
Reference in New Issue