verify links on creation

dbus-notify
Zlatin Balevsky 2022-08-05 00:05:53 +01:00
parent 08d9bf881a
commit 01e19381c1
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 9 additions and 6 deletions

View File

@ -95,8 +95,6 @@ class MainFrameController {
if(search.startsWith("muwire://")) { if(search.startsWith("muwire://")) {
try { try {
MuLink link = MuLink.parse(search) MuLink link = MuLink.parse(search)
if(!link.verify())
throw new InvalidMuLinkException("failed verification")
if (link.getLinkType() == MuLink.LinkType.FILE) if (link.getLinkType() == MuLink.LinkType.FILE)
downloadLink((FileMuLink)link) downloadLink((FileMuLink)link)
else if (link.getLinkType() == MuLink.LinkType.COLLECTION) else if (link.getLinkType() == MuLink.LinkType.COLLECTION)

View File

@ -37,7 +37,7 @@ abstract class MuLink {
} }
boolean verify() { private boolean verify() {
ByteArrayOutputStream baos = new ByteArrayOutputStream() ByteArrayOutputStream baos = new ByteArrayOutputStream()
baos.write(infoHash.getRoot()) baos.write(infoHash.getRoot())
@ -110,12 +110,17 @@ abstract class MuLink {
if (sigBytes.length != Constants.SIG_TYPE.getSigLen()) if (sigBytes.length != Constants.SIG_TYPE.getSigLen())
throw new InvalidMuLinkException("invalid sig key") throw new InvalidMuLinkException("invalid sig key")
MuLink rv
if (linkType == LinkType.FILE) if (linkType == LinkType.FILE)
return new FileMuLink(p, ih, n, sigBytes, query) rv = new FileMuLink(p, ih, n, sigBytes, query)
else if (linkType == LinkType.COLLECTION) else if (linkType == LinkType.COLLECTION)
return new CollectionMuLink(p, ih, n, sigBytes, query) rv = new CollectionMuLink(p, ih, n, sigBytes, query)
else
throw new InvalidMuLinkException("unknown type $linkType") throw new InvalidMuLinkException("unknown type $linkType")
if (!rv.verify())
throw new InvalidMuLinkException("failed verification")
return rv
} catch (InvalidMuLinkException e) { } catch (InvalidMuLinkException e) {
throw e throw e
} catch (Exception e) { } catch (Exception e) {