https://github.com/bodgit/srp
cognito rfc-2945 rfc-5054 srp srp-6a
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bodgit/srp
- Owner: bodgit
- License: bsd-3-clause
- Created: 2022-10-26T23:09:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T19:06:45.000Z (over 1 year ago)
- Last Synced: 2025-02-13T02:18:18.653Z (about 1 year ago)
- Topics: cognito, rfc-2945, rfc-5054, srp, srp-6a
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/bodgit/srp/releases)
[](https://github.com/bodgit/srp/actions?query=workflow%3Abuild)
[](https://coveralls.io/github/bodgit/srp?branch=main)
[](https://goreportcard.com/report/github.com/bodgit/srp)
[](https://godoc.org/github.com/bodgit/srp)


# SRP
An implementation of SRP-6a as documented in [RFC 5054](https://www.rfc-editor.org/rfc/rfc5054) and [RFC 2945](https://www.rfc-editor.org/rfc/rfc2945). It also exports modified versions of routines allowing it to be used with [AWS Cognito](https://aws.amazon.com/cognito/) which uses a variation of SRP.
Generate the verifier:
```golang
package main
import "github.com/bodgit/srp"
func main() {
g, err := srp.GetGroup(1024)
if err != nil {
panic(err)
}
s, err := srp.NewSRP(crypto.SHA1, g)
if err != nil {
panic(err)
}
i, err := s.NewISV("username", "password")
if err != nil {
panic(err)
}
// Marshal and store i on the server against the identity
}
```
Example client:
```golang
package main
import "github.com/bodgit/srp"
func main() {
g, err := srp.GetGroup(1024)
if err != nil {
panic(err)
}
s, err := srp.NewSRP(crypto.SHA1, g)
if err != nil {
panic(err)
}
client, err := s.NewClient("username", "password")
if err != nil {
panic(err)
}
// Send identity and client.A() to the server, receive salt and B
m1, err := client.Compute(salt, b)
if err != nil {
panic(err)
}
// Send m1 to the server, receive m2
if err := client.Check(m2); err != nil {
panic(err)
}
// Use client.Key()
}
```
Example server:
```golang
package main
import "github.com/bodgit/srp"
func main() {
g, err := srp.GetGroup(1024)
if err != nil {
panic(err)
}
s, err := srp.NewSRP(crypto.SHA1, g)
if err != nil {
panic(err)
}
// Receive identity and A from client, lookup/unmarshal ISV i
server, err := s.NewServer(i, a)
if err != nil {
panic(err)
}
// Send server.Salt() and server.B() to the client, receive m1
m2, err := server.Check(m1)
if err != nil {
panic(err)
}
// Send m2 to the client, use server.Key()
}
```
## Other implementations
* [https://github.com/opencoff/go-srp](https://github.com/opencoff/go-srp) - Calculates verifier value differently compared to RFC so session keys never match
* [https://github.com/Kong/go-srp](https://github.com/Kong/go-srp) - Calculates proof values differently compared to RFC but session keys match
* [https://github.com/posterity/srp](https://github.com/posterity/srp) - Interoperates fine
The last two implementations however assume that the client knows their salt value from the start rather than waiting for the server to provide it which doesn't match the behaviour documented in the RFC.