@@ -20,7 +20,10 @@ import (
20
20
"fmt"
21
21
"time"
22
22
23
- "maunium.net/go/mautrix/crypto/olm"
23
+ "go.mau.fi/util/exerrors"
24
+
25
+ "maunium.net/go/mautrix/crypto/goolm/session"
26
+ "maunium.net/go/mautrix/crypto/libolm"
24
27
"maunium.net/go/mautrix/id"
25
28
)
26
29
@@ -92,38 +95,42 @@ func decryptKeyExport(passphrase string, exportData []byte) ([]ExportedSession,
92
95
return sessionsJSON , nil
93
96
}
94
97
95
- func (mach * OlmMachine ) importExportedRoomKey (ctx context.Context , session ExportedSession ) (bool , error ) {
96
- if session .Algorithm != id .AlgorithmMegolmV1 {
98
+ func (mach * OlmMachine ) importExportedRoomKey (ctx context.Context , sess ExportedSession ) (bool , error ) {
99
+ if sess .Algorithm != id .AlgorithmMegolmV1 {
97
100
return false , ErrInvalidExportedAlgorithm
98
101
}
99
102
100
- igsInternal , err := olm .InboundGroupSessionImport ([]byte (session .SessionKey ))
103
+ igsInternal , err := libolm .InboundGroupSessionImport ([]byte (sess .SessionKey ))
101
104
if err != nil {
102
105
return false , fmt .Errorf ("failed to import session: %w" , err )
103
- } else if igsInternal .ID () != session .SessionID {
106
+ } else if igsInternal .ID () != sess .SessionID {
104
107
return false , ErrMismatchingExportedSessionID
105
108
}
106
109
igs := & InboundGroupSession {
107
- Internal : igsInternal ,
108
- SigningKey : session .SenderClaimedKeys .Ed25519 ,
109
- SenderKey : session .SenderKey ,
110
- RoomID : session .RoomID ,
110
+ InternalLibolm : igsInternal ,
111
+ InternalGoolm : exerrors .Must (session .NewMegolmInboundSessionFromExport ([]byte (sess .SessionKey ))),
112
+ SigningKey : sess .SenderClaimedKeys .Ed25519 ,
113
+ SenderKey : sess .SenderKey ,
114
+ RoomID : sess .RoomID ,
111
115
// TODO should we add something here to mark the signing key as unverified like key requests do?
112
- ForwardingChains : session .ForwardingChains ,
116
+ ForwardingChains : sess .ForwardingChains ,
113
117
114
118
ReceivedAt : time .Now ().UTC (),
115
119
}
116
120
existingIGS , _ := mach .CryptoStore .GetGroupSession (ctx , igs .RoomID , igs .ID ())
117
- firstKnownIndex := igs .Internal .FirstKnownIndex ()
118
- if existingIGS != nil && existingIGS .Internal .FirstKnownIndex () <= firstKnownIndex {
121
+ firstKnownIndex := igs .InternalLibolm .FirstKnownIndex ()
122
+ if firstKnownIndex != igs .InternalGoolm .FirstKnownIndex () {
123
+ panic ("indexes different" )
124
+ }
125
+ if existingIGS != nil && existingIGS .InternalLibolm .FirstKnownIndex () <= firstKnownIndex {
119
126
// We already have an equivalent or better session in the store, so don't override it.
120
127
return false , nil
121
128
}
122
129
err = mach .CryptoStore .PutGroupSession (ctx , igs )
123
130
if err != nil {
124
131
return false , fmt .Errorf ("failed to store imported session: %w" , err )
125
132
}
126
- mach .markSessionReceived (ctx , session .RoomID , igs .ID (), firstKnownIndex )
133
+ mach .markSessionReceived (ctx , sess .RoomID , igs .ID (), firstKnownIndex )
127
134
return true , nil
128
135
}
129
136
0 commit comments