Skip to content

Commit 599353e

Browse files
committed
Check for unsupported encryption algorithms
The code would blindly assume AES256-CBC, and then crash when encountering files encrypted using other algorithms.
1 parent 3bc9586 commit 599353e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/lcp/lcp.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func listEncryptedFiles(epubRoot fs.FS) ([]FileEntry, error) {
151151

152152
var encryption struct {
153153
EncryptedData []struct {
154+
EncryptionMethod struct {
155+
Algorithm string `xml:"Algorithm,attr"`
156+
}
154157
CipherData struct {
155158
CipherReference struct {
156159
URI string `xml:"URI,attr"`
@@ -173,7 +176,12 @@ func listEncryptedFiles(epubRoot fs.FS) ([]FileEntry, error) {
173176
var res []FileEntry
174177

175178
for _, d := range encryption.EncryptedData {
176-
var isCompressed = false
179+
path := d.CipherData.CipherReference.URI
180+
isCompressed := false
181+
182+
if d.EncryptionMethod.Algorithm != "http://www.w3.org/2001/04/xmlenc#aes256-cbc" {
183+
return nil, fmt.Errorf("unsupported encryption algorithm for file %s: %s", path, d.EncryptionMethod.Algorithm)
184+
}
177185

178186
PropertyLoop:
179187
for _, p := range d.EncryptionProperties.EncryptionProperty {
@@ -185,7 +193,7 @@ func listEncryptedFiles(epubRoot fs.FS) ([]FileEntry, error) {
185193
}
186194
}
187195

188-
res = append(res, FileEntry{Path: d.CipherData.CipherReference.URI, IsCompressed: isCompressed})
196+
res = append(res, FileEntry{Path: path, IsCompressed: isCompressed})
189197
}
190198

191199
return res, nil

0 commit comments

Comments
 (0)