Skip to content

Commit

Permalink
No encryption offlaod support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Reshke committed Jul 22, 2024
1 parent 01650b4 commit 8b5754e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/yproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ var rootCmd = &cobra.Command{

instance := core.NewInstance()

ylogger.ReloadLogger(instanceCnf.LogPath)
if instanceCnf.LogPath != "" {
ylogger.ReloadLogger(instanceCnf.LogPath)
}
if logLevel == "" {
logLevel = instanceCnf.LogLevel
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ func (i *Instance) Run(instanceCnf *config.Instance) error {
&instanceCnf.StorageCnf,
)

cr, err := crypt.NewCrypto(&instanceCnf.CryptoCnf)

var cr crypt.Crypter = nil
if instanceCnf.CryptoCnf.GPGKeyPath != "" {
cr, err = crypt.NewCrypto(&instanceCnf.CryptoCnf)
}

if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
defer yr.Close()

if msg.Decrypt {
if cr == nil {
_ = ycl.ReplyError(err, "failed to decrypt object, decrypter not configured")
ycl.Close()
return nil
}
ylogger.Zero.Debug().Str("object-path", msg.Name).Msg("decrypt object")
contentReader, err = cr.Decrypt(yr)
if err != nil {
Expand Down Expand Up @@ -83,6 +88,12 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl

var ww io.WriteCloser = w
if msg.Encrypt {
if cr == nil {
_ = ycl.ReplyError(err, "failed to encrypt, crypter not configured")
ycl.Close()
return
}

var err error
ww, err = cr.Encrypt(w)
if err != nil {
Expand All @@ -91,6 +102,8 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
ycl.Close()
return
}
} else {
ylogger.Zero.Debug().Str("path", msg.Name).Msg("omit encryption for chunk")
}

defer w.Close()
Expand Down
5 changes: 4 additions & 1 deletion pkg/proc/yrreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ type YRestartReader struct {

// Close implements RestartReader.
func (y *YRestartReader) Close() error {
return y.underlying.Close()
if y.underlying != nil {
return y.underlying.Close()
}
return nil
}

// Read implements RestartReader.
Expand Down

0 comments on commit 8b5754e

Please sign in to comment.