mirror of https://github.com/zlatinb/muwire
verify links on creation
parent
08d9bf881a
commit
01e19381c1
|
@ -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)
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue