summary refs log tree commit diff stats
path: root/examples/ssl/pskserver.nim
blob: 859eaa875c11cf18e00dffa869cf123a95d2da2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()