github.com/iDigitalFlame/xmt@v0.5.4/c2/xz_key_no_implant.go (about) 1 //go:build !implant && !nokeyset 2 // +build !implant,!nokeyset 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package c2 21 22 import ( 23 "github.com/iDigitalFlame/xmt/c2/cout" 24 "github.com/iDigitalFlame/xmt/com" 25 "github.com/iDigitalFlame/xmt/data" 26 "github.com/iDigitalFlame/xmt/util/bugtrack" 27 ) 28 29 func (s *Session) keyListenerRegenerate(l string, n *com.Packet) error { 30 if err := s.keys.Read(n); err != nil { 31 if cout.Enabled { 32 s.log.Error("[%s:%s/Crypt] Reading KeyPair failed: %s!", l, s.ID, err) 33 } 34 return err 35 } 36 if err := s.keys.Sync(); err != nil { 37 if cout.Enabled { 38 s.log.Error("[%s:%s/Crypt] Syncing KeyPair failed: %s!", l, s.ID, err) 39 } 40 return err 41 } 42 if cout.Enabled { 43 bugtrack.Track("c2.(*Session).keyListenerRegenerate(): %s KeyPair details updated! [Public %s, Shared: %v]", s.ID, s.keys.Public, s.keys.Shared()) 44 } 45 return nil 46 } 47 func (s *Session) keyCryptAndUpdate(l string, n *com.Packet, d bool) error { 48 if d { 49 n.KeyCrypt(s.keys) 50 } 51 if n.Flags&com.FlagCrypt == 0 || n.Empty() { 52 return nil 53 } 54 return s.keyListenerRegenerate(l, n) 55 } 56 func (s *Session) keyListenerInit(k data.PrivateKey, l string, n *com.Packet) error { 57 if err := s.keys.Read(n); err != nil { 58 if cout.Enabled { 59 s.log.Error("[%s:%s/Crypt] Generating KeyPair failed: %s!", l, s.ID, err) 60 } 61 return err 62 } 63 if err := s.keys.FillPrivate(k); err != nil { 64 if cout.Enabled { 65 s.log.Error("[%s:%s/Crypt] Syncing KeyPair failed: %s!", l, s.ID, err) 66 } 67 return err 68 } 69 if cout.Enabled { 70 bugtrack.Track("c2.(*Session).keyListenerInit(): %s KeyPair details updated! [Public: %s, Shared: %v]", s.ID, s.keys.Public, s.keys.Shared()) 71 } 72 return nil 73 }