srp

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 21 Imported by: 19

README

go-srp

Introduction

Golang implementation of the SRP protocol, used for authentication of ProtonMail users.

License

Copyright (c) 2019 Proton Technologies AG

Please see LICENSE file for the license.

Doc

.NET Wrapper

The windows folder contains the wrapper for .net.

Build for mobile apps

Setup Go Mobile and build/bind the source code:

Go Mobile repo: https://github.com/golang/mobile

Go Mobile wiki: https://github.com/golang/go/wiki/Mobile

  1. Install Go: brew install go

  2. Install Gomobile: go get -u golang.org/x/mobile/cmd/gomobile

  3. Install Gobind: go install golang.org/x/mobile/cmd/gobind

  4. Install Android SDK and NDK using Android Studio

  5. Set env: export ANDROID_HOME="/AndroidSDK" (path to your SDK)

  6. Init gomobile: gomobile init -ndk /AndroidSDK/ndk-bundle/ (path to your NDK)

  7. Copy Go module dependencies to the vendor directory: go mod vendor

  8. Build examples: gomobile build -target=android #or ios

    Bind examples: gomobile bind -target ios -o frameworks/name.framework gomobile bind -target android

    The bind will create framework for iOS and jar&aar files for Android (x86_64 and ARM).

Other notes

If you wish to use build.sh, you may need to modify the paths in it.

go mod vendor
./build.sh

Dependencies

github.com/ProtonMail/bcrypt (fork of github.com/jameskeane/bcrypt)

golang.org/x/mobile

github.com/ProtonMail/go-crypto

github.com/cronokirby/saferith

Documentation

Index

Constants

View Source
const Version string = "0.0.7"

Variables

View Source
var (
	// ErrDataAfterModulus found extra data after decode the modulus
	ErrDataAfterModulus = errors.New("pm-srp: extra data after modulus")

	// ErrInvalidSignature invalid modulus signature
	ErrInvalidSignature = errors.New("pm-srp: invalid modulus signature")

	RandReader = rand.Reader
)
View Source
var DeadlineExceeded error = deadlineExceededError{}

Implementation following the "context" package

Functions

func Argon2PreimageChallenge added in v0.0.4

func Argon2PreimageChallenge(b64Challenge string, deadlineUnixMilli int64) (b64Solution string, err error)

Argon2PreimageChallenge computes the base64 solution for a given Argon2 base64 challenge within deadlineUnixMilli milliseconds, if any was found. Deadlines are measured on the wall clock, not the monotonic clock, due to unreliability on mobile devices. deadlineUnixMilli = -1 means unlimited time.

func ECDLPChallenge

func ECDLPChallenge(b64Challenge string, deadlineUnixMilli int64) (b64Solution string, err error)

ECDLPChallenge computes the base64 solution for a given ECDLP base64 challenge within deadlineUnixMilli milliseconds, if any was found. Deadlines are measured on the wall clock, not the monotonic clock, due to unreliability on mobile devices. deadlineUnixMilli = -1 means unlimited time.

func GetModulusKey

func GetModulusKey() string

func HashPassword

func HashPassword(authVersion int, password []byte, userName string, salt, modulus []byte) ([]byte, error)

HashPassword returns the hash of password argument. Based on version number following arguments are used in addition to password: * 0, 1, 2: userName and modulus * 3, 4: salt and modulus

func MailboxPassword

func MailboxPassword(password []byte, salt []byte) (hashed []byte, err error)

MailboxPassword get mailbox password hash

Parameters:

  • password []byte: a mailbox password
  • salt []byte: a salt is random 128 bits data

Returns:

  • hashed []byte: a hashed password
  • err error: throw error

func RandomBits

func RandomBits(bits int) ([]byte, error)

func RandomBytes

func RandomBytes(byes int) (raw []byte, err error)

func VersionNumber

func VersionNumber() string

VersionNumber get current library version

Types

type Auth

type Auth struct {
	Modulus, ServerEphemeral, HashedPassword []byte
	Version                                  int
}

Auth stores byte data for the calculation of SRP proofs.

  • Changed SrpAuto to Auth because the name will be used as srp.SrpAuto by other packages and as SrpSrpAuth on mobile
  • Also the data from the API called Auth. it could be match the meaning and reduce the confusion

func NewAuth

func NewAuth(version int, username string, password []byte, b64salt, signedModulus, serverEphemeral string) (auth *Auth, err error)

NewAuth Creates new Auth from strings input. Salt and server ephemeral are in base64 format. Modulus is base64 with signature attached. The signature is verified against server key. The version controls password hash algorithm.

Parameters:

  • version int: The *x* component of the vector.
  • username string: The *y* component of the vector.
  • password []byte: The *z* component of the vector.
  • b64salt string: The std-base64 formatted salt

Returns:

  • auth *Auth: the pre calculated auth information
  • err error: throw error

Usage:

Warnings:

  • Be careful! Poos can hurt.

func NewAuthForVerifier

func NewAuthForVerifier(password []byte, signedModulus string, rawSalt []byte) (auth *Auth, err error)

NewAuthForVerifier Creates new Auth from strings input. Salt and server ephemeral are in base64 format. Modulus is base64 with signature attached. The signature is verified against server key. The version controls password hash algorithm.

Parameters:

  • version int: The *x* component of the vector.
  • username string: The *y* component of the vector.
  • password []byte: The *z* component of the vector.
  • salt string:

Returns:

  • auth *Auth: the pre calculated auth information
  • err error: throw error

Usage:

Warnings:

  • none.

func (*Auth) GenerateProofs

func (s *Auth) GenerateProofs(bitLength int) (*Proofs, error)

GenerateProofs calculates SPR proofs.

func (*Auth) GenerateVerifier

func (s *Auth) GenerateVerifier(bitLength int) ([]byte, error)

GenerateVerifier verifier for update pwds and create accounts

type Proofs

type Proofs struct {
	ClientProof, ClientEphemeral, ExpectedServerProof []byte
	// contains filtered or unexported fields
}

Proofs Srp Proofs object. Changed SrpProofs to Proofs because the name will be used as srp.SrpProofs by other packages and as SrpSrpProofs on mobile ClientProof []byte client proof ClientEphemeral []byte calculated from ExpectedServerProof []byte

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server stores the internal state for the validation of SRP proofs.

func NewServer

func NewServer(modulusBytes, verifier []byte, bitLength int) (*Server, error)

NewServer creates a new server instance from the raw binary data.

func NewServerFromSigned

func NewServerFromSigned(signedModulus string, verifier []byte, bitLength int) (*Server, error)

NewServerFromSigned creates a new server instance from the signed modulus and the binary verifier.

func NewServerWithSecret

func NewServerWithSecret(modulusBytes, verifier, secretBytes []byte, bitLength int) (*Server, error)

NewServerWithSecret creates a new server instance without generating a random secret from the raw binary data. Use with caution as the secret should not be reused.

func (*Server) GenerateChallenge

func (s *Server) GenerateChallenge() (serverEphemeral []byte, err error)

GenerateChallenge is the first step for SRP exchange, and generates a valid challenge for the provided verifier.

func (*Server) GetSharedSession

func (s *Server) GetSharedSession() ([]byte, error)

GetSharedSession returns the shared secret as byte if the session has concluded in valid state.

func (*Server) IsCompleted

func (s *Server) IsCompleted() bool

IsCompleted returns true if the exchange has been concluded in valid state.

func (*Server) VerifyProofs

func (s *Server) VerifyProofs(clientEphemeralBytes, clientProofBytes []byte) (serverProof []byte, err error)

VerifyProofs Verifies the client proof and - if valid - generates the shared secret and returnd the server proof. It concludes the exchange in valid state if successful.

Directories

Path Synopsis
dist
windows

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL