summary refs log tree commit diff stats
path: root/examples/ssl/pskclient.nim
blob: c83f27fbc949d0c7f0eff6712506ad2ff17d8ad8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Create connection encrypted using preshared key (TLS-PSK).
import net

static: assert defined(ssl)

let sock = newSocket()
sock.connect("localhost", Port(8800))

proc clientFunc(identityHint: string): tuple[identity: string, psk: string] =
  echo "identity hint ", identityHint.repr
  return ("foo", "psk-of-foo")

let context = newContext(cipherList="PSK-AES256-CBC-SHA")
context.clientGetPskFunc = clientFunc
context.wrapConnectedSocket(sock, handshakeAsClient)
context.destroyContext()