srs

package module
v0.0.0-...-501e7d1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 9 Imported by: 1

README

SRS Sender Rewriting Scheme Go/Golang package

Sender Rewriting Scheme is a scheme that allows mail transfer agents (MTA) like Postfix or Exim to remail/forward email message without breakig SPF (Sender Permitted Form) check.

SRS will rewrite email address something like this:

milos@mailspot.com  ->  SRS0=JvSE=IT=mailspot.com=milos@forwarding-domain.com

SRS address contains timestamp and hash signature so only the forwarding domain will be able to reverse the SRS address on bounce and check the integrity.

Here you can find more info on SRS in general and how it works:

Installation

go get github.com/mileusna/srs

Example

    func main() {
        // setting up engine with mandatory params
        srs := srs.SRS{
            Secret: []byte("YourSecretKeyForHashingUniqueAndPermanentPerServer"), 
            Domain: "forwarding-domain.com",
        }
        
        // forwarding
        // this code will produce something like this for fwd address
        // SRS0=JvSE=IT=mailspot.com=milos@forwarding-domain.com        
        fwd, err := srs.Forward("milos@mailspot.com")
        if err != nil {
            log.Error(err)
            return
        }

        // reverse check when emails are bounced back to forwarding server
        rvs, err := srs.Reverse("SRS0=JvSE=IT=mailspot.com=milos@forwarding-domain.com")
        if err != nil {
            // email is not SRS, invalid hash, invalid timestamp, timestamp out of date, etc..
            log.Error(err)
            return
        }

        // rvs is normal email address
        fmt.Println(rvs)
    }

Testing

Since SRS contains timestamp component it is difficult to test package against static expected results because SRS result will change over time. That is the reasons why the tests actually connects to most popular SRS daemon for Postfix, postsrsd, and checks the results. As long as you use the same domain name and same secret key, results should match, although there are some exceptions.

Exceptions

There are some cases which postsrsd will accept, but I find them wrong and they won't be supported by this package. I guess that postsrsd rely on mailserver to reject this type of email addresses so it doesn't check bad email formats.

These are some examples which postsrsd will accept, but this go package will return an error due to bad email formatting:

This types of emails are excluded from testing.

Testing setup

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SRS

type SRS struct {
	// Secret key, mandatory
	Secret []byte
	// Domain is localhost which will forward the emails
	Domain string
	// FirstSeparator after SRS0, optional, can be =+-, default is =
	FirstSeparator string
	// contains filtered or unexported fields
}

SRS engine

func (*SRS) Forward

func (srs *SRS) Forward(email string) (string, error)

Forward returns SRS forward address or error

func (*SRS) Reverse

func (srs *SRS) Reverse(email string) (string, error)

Reverse the SRS email address to regular email addresss or error

Jump to

Keyboard shortcuts

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