-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable automatic auth to pubkey with no-auth addresses
- Loading branch information
Showing
9 changed files
with
61 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package realy | ||
|
||
import ( | ||
"realy.lol/ec/schnorr" | ||
"strings" | ||
"realy.lol/web" | ||
"realy.lol/hex" | ||
) | ||
|
||
// checkNoAuth examines whether the server has been configured to allow the | ||
// client to have access based on their IP address, and optionally automatically | ||
// stores their public key as the authed pubkey, thus automatically assuming that | ||
// connections from this address are for a client using a given address. | ||
// | ||
// This is somewhat insecure, in that other apps that connect to this relay will | ||
// be treated as though they are logged in with the provided key, meaning a | ||
// malware or other malicious nostr-savvy app that knows the relay is connected | ||
// to an address that is whitelisted, could then gain access to privileged | ||
// messages. But this is only a small vulnerability, said attacker will not be | ||
// able to sign for the key to fabricate events unless the signer is | ||
// misconfigured. | ||
func (s *Server) checkNoAuth(ws *web.Socket) (noAuth bo) { | ||
if len(ws.Authed()) == 0 { | ||
for _, v := range s.noAuthAddresses { | ||
if strings.HasPrefix(v, ws.RealRemote()) { | ||
// we are not requiring auth from this address (should be private address) | ||
if strings.Contains(v, ":") { | ||
// If there is a colon in the field then the second field should be a hex encoded | ||
// public key. Anything else will be silently ignored. | ||
split := strings.Split(v, ":") | ||
if len(split) == 2 { | ||
var k by | ||
var err er | ||
// check that the key is proper | ||
if k, err = hex.Dec(split[1]); !chk.E(err) { | ||
if len(k) == schnorr.PubKeyBytesLen { | ||
log.I.S("whitelisted address has pubkey", split[1]) | ||
ws.SetAuthed(st(k)) | ||
noAuth = true | ||
} | ||
} | ||
} | ||
} else { | ||
noAuth = true | ||
} | ||
} | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.3.6 | ||
v1.3.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters