aboutsummaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-24 02:13:15 +0700
committerShulhan <ms@kilabit.info>2023-09-26 00:24:08 +0700
commit9ae9a42e37b35e17120045da8bb72b07f6de2a44 (patch)
tree32613a49f0d0f1e2d68ab6475745f791dba9cb37 /session.go
parent8cc52027d243946c03c6b0d1016ca7cc3d7de09a (diff)
downloadawwan-9ae9a42e37b35e17120045da8bb72b07f6de2a44.tar.xz
all: move fields and methods related to encryption to struct cryptoContext
The cryptoContext contains the default hash, loaded privateKey, dummy terminal, base directory, and default label; all of those fields are required for encryption and decryption. The cryptoContext have three methods: encrypt, decrypt, and loadPrivateKey. By moving to separate struct the cryptoContext instance can be shared with Session.
Diffstat (limited to 'session.go')
-rw-r--r--session.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/session.go b/session.go
index 7470624..cff495a 100644
--- a/session.go
+++ b/session.go
@@ -5,7 +5,6 @@ package awwan
import (
"bytes"
- "crypto/rsa"
"errors"
"fmt"
"io/fs"
@@ -27,9 +26,9 @@ import (
// Session manage and cache SSH client and list of scripts.
// One session have one SSH client, but may contains more than one script.
type Session struct {
- privateKey *rsa.PrivateKey
- sftpc *sftp.Client
- sshClient *ssh.Client
+ cryptoc *cryptoContext
+ sftpc *sftp.Client
+ sshClient *ssh.Client
vars ini.Ini
@@ -56,7 +55,7 @@ func NewSession(aww *Awwan, sessionDir string) (ses *Session, err error) {
)
ses = &Session{
- privateKey: aww.privateKey,
+ cryptoc: aww.cryptoc,
BaseDir: aww.BaseDir,
ScriptDir: sessionDir,
@@ -667,7 +666,7 @@ func (ses *Session) loadFileEnv(awwanEnv string, isVault bool) (err error) {
fmt.Printf("--- loading %q ...\n", awwanEnv)
if isVault {
- content, err = decrypt(ses.privateKey, content)
+ content, err = ses.cryptoc.decrypt(content)
if err != nil {
return err
}
@@ -703,7 +702,7 @@ func (ses *Session) loadFileInput(path string) (content []byte, isVault bool, er
return nil, false, err
}
- content, err = decrypt(ses.privateKey, content)
+ content, err = ses.cryptoc.decrypt(content)
if err != nil {
return nil, false, err
}