-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ba0f3/channel-binding
Add Channel binding supports
- Loading branch information
Showing
10 changed files
with
375 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
[![Build Status](https://travis-ci.org/ba0f3/scram.nim.svg?branch=master)](https://travis-ci.org/ba0f3/scram.nim) | ||
|
||
# scram | ||
# scram.nim | ||
Salted Challenge Response Authentication Mechanism (SCRAM) | ||
|
||
|
||
```nim | ||
var s = newScramClient[Sha256Digest]() | ||
s.clientNonce = "VeAOLsQ22fn/tjalHQIz7cQT" | ||
### Supported Mechanisms: | ||
* SCRAM-SHA-1 | ||
* SCRAM-SHA-1-PLUS | ||
* SCRAM-SHA-256 | ||
* SCRAM-SHA-256-PLUS | ||
* SCRAM-SHA-384 | ||
* SCRAM-SHA-384-PLUS | ||
* SCRAM-SHA-512 | ||
* SCRAM-SHA-512-PLUS | ||
* SCRAM-SHA3-512 | ||
* SCRAM-SHA3-512-PLUS | ||
|
||
### Supported Channel Binding Types | ||
* TLS_UNIQUE | ||
* TLS_SERVER_END_POINT | ||
|
||
### Examples | ||
|
||
echo s.prepareFirstMessage("bob") | ||
let finalMessage = s.prepareFinalMessage("secret", "r=VeAOLsQ22fn/tjalHQIz7cQTmeE5qJh8qKEe8wALMut1,s=ldZSefTzKxPNJhP73AmW/A==,i=4096") | ||
echo finalMessage | ||
assert(finalMessage == "c=biws,r=VeAOLsQ22fn/tjalHQIz7cQTmeE5qJh8qKEe8wALMut1,p=AtNtxGzsMA8evcWBM0MXFjxN8OcG1KRkLkFyoHlupOU=") | ||
#### Client | ||
```nim | ||
var client = newScramClient[Sha256Digest]() | ||
assert client.prepareFirstMessage(user) == cfirst, "incorrect first message" | ||
let fmsg = client.prepareFinalMessage(password, sfirst) | ||
assert fmsg == cfinal, "incorrect final message" | ||
assert client.verifyServerFinalMessage(sfinal), "incorrect server final message" | ||
``` | ||
|
||
#### Channel Binding | ||
|
||
Helper proc `getChannelBindingData` added to helps you getting channel binding data from existing Socket/AsyncSocket | ||
|
||
```nim | ||
var | ||
ctx = newContext() | ||
socket = newSocket() | ||
ctx.wrapSocket(socket) | ||
socket.connect(...) | ||
# .... | ||
let cbData = getChannelBindingData(TLS_UNIQUE, socket) | ||
var client = newScramClient[Sha256Digest]() | ||
client.setChannelBindingType(TLS_UNIQUE) | ||
client.setChannelBindingData(cbData) | ||
echo client.prepareFirstMessage(user) | ||
``` |
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
Oops, something went wrong.