Coder Social home page Coder Social logo

ba0f3 / scram.nim Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 6.0 62 KB

Salted Challenge Response Authentication Mechanism [SCRAM-SHA-1(-PLUS) SCRAM-SHA-224 SCRAM-SHA-256(-PLUS) SCRAM-SHA-384 SCRAM-SHA-512(-PLUS) SCRAM-SHA3-512(-PLUS)]

Home Page: https://tools.ietf.org/html/rfc5802

License: MIT License

Nim 100.00%
sasl authentication salt challenge mechanism scram-sha-1 scram-sha-256 scram-sha-512 rfc5802 scram-sha-224

scram.nim's Introduction

Build Status

scram.nim

Salted Challenge Response Authentication Mechanism (SCRAM)

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

Standards

Examples

Client

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

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)

scram.nim's People

Contributors

ba0f3 avatar inv2004 avatar johnad avatar mildred avatar q-master avatar sinkingsugar avatar timotheecour avatar yglukhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

scram.nim's Issues

No way to extract UserData in server code (please mark some fields public)

UserData* = object
salt: string
iterations: int
serverKey: string
storedKey: string

The above type definition keeps the UserData fields private. In case the server wants to store the user data instead of the password in clear text, it cannot get the UserData values from the above type.

I suggest those fields be marked public or a function be added to access or serialize them.

The function to create a UserData object from these values already exists.

scram/scram/private/utils.nim(17, 13) Error: undeclared identifier: 'MD5Digest'

after fixing #5 I get:

scram/scram/private/utils.nim(17, 13) Error: undeclared identifier: 'MD5Digest'

this causes SSPkrolik/nimongo#56

rnim scram/private/utils.nim
nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r scram/private/utils.nim
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/config.nims' [Conf]
/Users/timothee/.config/nim/config.nims [config.nims used]
/Users/timothee/git_clone/nim/scram/scram/private/utils.nim(16, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/scram/scram/private/utils.nim(17, 13) Error: undeclared identifier: 'MD5Digest'
    when T is MD5Digest:
              ^

Create a 0.1.10 release

Mind adding a 0.1.10 release? The latest 0.1.9 release does not work with the newly released Nim version 1.2. However, the most recent commits fix the compatibility issues.

So, a new release will let nimble users see the compatible code.

And, for me, this would allow my mongopool library to require scram 0.1.10 which brings mongopool up to 1.2 compatibility also.

Is scram.nim still operational?

I'm having considerable problems with the 'nimongo' library, which uses scram.nim for generating the authentication messages back and forth during SCRAM-SHA-1 authentication. I've created 3 accounts on different public MongoDB providers and am seeing the same problem with all three.

So, I dove down and started doing diagnostics; added "echo" statements all over the place to deduce the point of failure.

The information received back from prepareFinalMessage is being rejected by the servers.

I went ahead and found an equivalent algo on a python library and compared the results. Given the same password digest and first message (the unencoded payload), the python library returns a different result.

Looking even deeper, the python equivalent of line 55's:

saltedPassword = hi[T](password, salt, iterations)

is also returning a different result given the exact same inputs.

So, I was wondering if you are seeing any different behavior of the library when compiled with Nim's most recent standard libraries. (Among other things, the 'std/sha1' algorithm was changed completely back on October 9, 2018.)

I'll still keep looking for answers; but I figured I'd ask. Unfortunately the library does not have any unit tests to check against. I might do a PR with some once I get my bearings. Right now I've been diagnosing this for over 12 hours and my eyes are losing focus.

(Off-topic, sort of: on line 15 of utils.nim, the salt is appended with a 00 00 00 01. I assume this is because MongoDB tends to send a salt of 16 bytes instead of 20? Also, why the 01 at the end? I was under the impression that the algo called for all-zeroes for salt padding.)

Add other SCRAM?

In more SHA-1/SHA-256/SHA-512, can you add SHA-224/SHA-384 and SHA3-512?

And do not forget -PLUS variants for all?

Can you list:


"When using the SASL SCRAM mechanism, the SCRAM-SHA-256-PLUS variant SHOULD be preferred over the SCRAM-SHA-256 variant, and SHA-256 variants [RFC7677] SHOULD be preferred over SHA-1 variants [RFC5802]".

https://xmpp.org/extensions/inbox/hash-recommendations.html

-PLUS variants:

LDAP:

  • RFC5803: Lightweight Directory Access Protocol (LDAP) Schema for Storing Salted: Challenge Response Authentication Mechanism (SCRAM) Secrets: https://tools.ietf.org/html/rfc5803

HTTP:

2FA:

IANA:

Linked to:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.