Skip to content
Snippets Groups Projects
Commit 26605a15 authored by Sebastian's avatar Sebastian
Browse files

Check contact link validity more strictly

parent 46c61d9e
No related branches found
No related tags found
1 merge request!109Check contact link validity more strictly
Pipeline #9265 passed
......@@ -63,16 +63,23 @@ constructor(
}
private fun addPendingContact(link: String, alias: String) {
if (_handshakeLink.value == link) {
LOG.warn { "Please enter contact's link, not your own" }
// TODO: show warning to user
return
}
if (remoteHandshakeLinkIsInvalid(link)) {
// ignore preceding and trailing whitespace
val matcher = HandshakeLinkConstants.LINK_REGEX.matcher(link.trim())
// check if the link is well-formed
if (!matcher.matches()) {
LOG.warn { "Remote handshake link is invalid" }
// TODO: show message to user
return
}
// compare with own link
val withoutSchema = matcher.group(2)
val withSchema = "briar://$withoutSchema"
if (_handshakeLink.value == withSchema) {
LOG.warn { "Please enter contact's link, not your own" }
// TODO: show warning to user
return
}
if (aliasIsInvalid(alias)) {
LOG.warn { "Alias is invalid" }
// TODO: show message to user
......@@ -106,10 +113,6 @@ constructor(
}
}
private fun remoteHandshakeLinkIsInvalid(link: String): Boolean {
return !HandshakeLinkConstants.LINK_REGEX.matcher(link).find()
}
private fun aliasIsInvalid(alias: String): Boolean {
val aliasUtf8 = StringUtils.toUtf8(alias)
return aliasUtf8.isEmpty() || aliasUtf8.size > AuthorConstants.MAX_AUTHOR_NAME_LENGTH
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment