net.nim: support for TLS-PSK ciphersuites
This commit is contained in:
parent
3ebf27ddd2
commit
ba61a8d00a
4 changed files with 144 additions and 13 deletions
20
examples/ssl/pskserver.nim
Normal file
20
examples/ssl/pskserver.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Accept connection encrypted using preshared key (TLS-PSK).
|
||||
import net
|
||||
|
||||
static: assert defined(ssl)
|
||||
|
||||
let sock = newSocket()
|
||||
sock.bindAddr(Port(8800))
|
||||
sock.listen()
|
||||
|
||||
let context = newContext(cipherList="PSK-AES256-CBC-SHA")
|
||||
context.pskIdentityHint = "hello"
|
||||
context.serverGetPskFunc = proc(identity: string): string = "psk-of-" & identity
|
||||
|
||||
while true:
|
||||
var client = new(Socket)
|
||||
sock.accept(client)
|
||||
sock.setSockOpt(OptReuseAddr, true)
|
||||
echo "accepted connection"
|
||||
context.wrapConnectedSocket(client, handshakeAsServer)
|
||||
echo "got connection with identity ", client.getPskIdentity()
|
||||
Loading…
Add table
Add a link
Reference in a new issue