Skip to content

Commit 336118a

Browse files
committed
smb2: share: export application key
1 parent a5dd82e commit 336118a

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

client.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ type Share struct {
227227
ctx context.Context
228228
}
229229

230+
func (fs *Share) ApplicationKey() []byte {
231+
key := make([]byte, len(fs.applicationKey))
232+
copy(key, fs.applicationKey)
233+
return key
234+
}
235+
230236
func (fs *Share) WithContext(ctx context.Context) *Share {
231237
if ctx == nil {
232238
panic("nil context")
@@ -667,13 +673,12 @@ func (fs *Share) Stat(name string) (os.FileInfo, error) {
667673
return nil, &os.PathError{Op: "stat", Path: name, Err: err}
668674
}
669675

670-
fi, err := f.fileStat, nil
671-
if e := f.close(); err == nil {
672-
err = e
673-
}
674-
if err != nil {
676+
fi := f.fileStat
677+
678+
if err := f.close(); err != nil {
675679
return nil, &os.PathError{Op: "stat", Path: name, Err: err}
676680
}
681+
677682
return fi, nil
678683
}
679684

@@ -1881,6 +1886,35 @@ func (f *File) WriteString(s string) (n int, err error) {
18811886
return f.Write([]byte(s))
18821887
}
18831888

1889+
type encoderBytes []byte
1890+
1891+
func (e encoderBytes) Size() int {
1892+
return len(([]byte)(e))
1893+
}
1894+
1895+
func (e encoderBytes) Encode(buf []byte) {
1896+
copy(buf, ([]byte)(e))
1897+
}
1898+
1899+
var _ Encoder = encoderBytes(nil)
1900+
1901+
// Transcieve function is used to send a request and receive a response in a single call.
1902+
func (f *File) Transcieve(p []byte, out []byte) (int, error) {
1903+
output, err := f.ioctl(&IoctlRequest{
1904+
CtlCode: FSCTL_PIPE_TRANSCEIVE,
1905+
OutputOffset: 0,
1906+
OutputCount: 0,
1907+
MaxInputResponse: 0,
1908+
MaxOutputResponse: uint32(len(out)),
1909+
Flags: SMB2_0_IOCTL_IS_FSCTL,
1910+
Input: (encoderBytes)(p),
1911+
})
1912+
if err != nil {
1913+
return 0, err
1914+
}
1915+
return copy(out, output), nil
1916+
}
1917+
18841918
func (f *File) encodeSize(e Encoder) int {
18851919
if e == nil {
18861920
return 0

session.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func sessionSetup(conn *conn, i Initiator, ctx context.Context) (*session, error
145145
s.signer = cmac.New(ciph)
146146
s.verifier = cmac.New(ciph)
147147

148-
// s.applicationKey = kdf(sessionKey, []byte("SMB2APP\x00"), []byte("SmbRpc\x00"))
148+
s.applicationKey = kdf(sessionKey, []byte("SMB2APP\x00"), []byte("SmbRpc\x00"))
149149

150150
encryptionKey := kdf(sessionKey, []byte("SMB2AESCCM\x00"), []byte("ServerIn \x00"))
151151
decryptionKey := kdf(sessionKey, []byte("SMB2AESCCM\x00"), []byte("ServerOut\x00"))
@@ -184,7 +184,7 @@ func sessionSetup(conn *conn, i Initiator, ctx context.Context) (*session, error
184184
s.signer = cmac.New(ciph)
185185
s.verifier = cmac.New(ciph)
186186

187-
// s.applicationKey = kdf(sessionKey, []byte("SMBAppKey\x00"), preauthIntegrityHashValue)
187+
s.applicationKey = kdf(sessionKey, []byte("SMBAppKey\x00"), s.preauthIntegrityHashValue[:])
188188

189189
encryptionKey := kdf(sessionKey, []byte("SMBC2SCipherKey\x00"), s.preauthIntegrityHashValue[:])
190190
decryptionKey := kdf(sessionKey, []byte("SMBS2CCipherKey\x00"), s.preauthIntegrityHashValue[:])
@@ -275,7 +275,7 @@ type session struct {
275275
encrypter cipher.AEAD
276276
decrypter cipher.AEAD
277277

278-
// applicationKey []byte
278+
applicationKey []byte
279279
}
280280

281281
func (s *session) logoff(ctx context.Context) error {

0 commit comments

Comments
 (0)