| 1 | package tlsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/" |
| 5 | "crypto/rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/" |
| 6 | "crypto/x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/" |
| 7 | "crypto/x509/pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/" |
| 8 | "encoding/pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/" |
| 9 | "math/bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/" |
| 10 | "osscip-go gomod github.com/golang/go/src go1.16 os/" |
| 11 | "strconvscip-go gomod github.com/golang/go/src go1.16 strconv/" |
| 12 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 13 | |
| 14 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 15 | ) |
| 16 | |
| 17 | type CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig# struct { |
| 18 | Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits. int |
| 19 | Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country. string |
| 20 | Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality. string |
| 21 | Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization. string |
| 22 | OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit. string |
| 23 | CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName. string |
| 24 | } |
| 25 | |
| 26 | var ( |
| 27 | DefaultLegitConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/DefaultLegitConfig. = CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#{ |
| 28 | Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits.: 4096, |
| 29 | Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country.: "US", |
| 30 | Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality.: "", |
| 31 | Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization.: "bettercap devteam", |
| 32 | OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit.: "https://bettercap.org/", |
| 33 | CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName.: "bettercap", |
| 34 | } |
| 35 | DefaultSpoofConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/DefaultSpoofConfig. = CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#{ |
| 36 | Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits.: 4096, |
| 37 | Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country.: "US", |
| 38 | Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality.: "Scottsdale", |
| 39 | Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization.: "GoDaddy.com, Inc.", |
| 40 | OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit.: "https://certs.godaddy.com/repository/", |
| 41 | CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName.: "Go Daddy Secure Certificate Authority - G2", |
| 42 | } |
| 43 | ) |
| 44 | |
| 45 | func CertConfigToModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfigToModule().(prefix string, m *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#, defaults CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#) { |
| 46 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewIntParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewIntParameter().(prefix+".certificate.bits", strconvscip-go gomod github.com/golang/go/src go1.16 strconv/.Itoascip-go gomod github.com/golang/go/src go1.16 strconv/Itoa().(defaults.Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits.), |
| 47 | "Number of bits of the RSA private key of the generated HTTPS certificate.")) |
| 48 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().(prefix+".certificate.country", defaults.Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country., ".*", |
| 49 | "Country field of the generated HTTPS certificate.")) |
| 50 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().(prefix+".certificate.locality", defaults.Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality., ".*", |
| 51 | "Locality field of the generated HTTPS certificate.")) |
| 52 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().(prefix+".certificate.organization", defaults.Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization., ".*", |
| 53 | "Organization field of the generated HTTPS certificate.")) |
| 54 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().(prefix+".certificate.organizationalunit", defaults.OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit., ".*", |
| 55 | "Organizational Unit field of the generated HTTPS certificate.")) |
| 56 | m.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().(prefix+".certificate.commonname", defaults.CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName., ".*", |
| 57 | "Common Name field of the generated HTTPS certificate.")) |
| 58 | } |
| 59 | |
| 60 | func CertConfigFromModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfigFromModule().(prefix string, m sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#) (cfg CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#, err error) { |
| 61 | if err, cfg.Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits. = m.IntParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#IntParam().(prefix + ".certificate.bits"); err != nil { |
| 62 | return cfg, err |
| 63 | } else if err, cfg.Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country. = m.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().(prefix + ".certificate.country"); err != nil { |
| 64 | return cfg, err |
| 65 | } else if err, cfg.Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality. = m.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().(prefix + ".certificate.locality"); err != nil { |
| 66 | return cfg, err |
| 67 | } else if err, cfg.Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization. = m.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().(prefix + ".certificate.organization"); err != nil { |
| 68 | return cfg, err |
| 69 | } else if err, cfg.OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit. = m.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().(prefix + ".certificate.organizationalunit"); err != nil { |
| 70 | return cfg, err |
| 71 | } else if err, cfg.CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName. = m.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().(prefix + ".certificate.commonname"); err != nil { |
| 72 | return cfg, err |
| 73 | } |
| 74 | return cfg, err |
| 75 | } |
| 76 | |
| 77 | func CreateCertificatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CreateCertificate().(cfg CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#, ca bool) (*rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#, []byte, error) { |
| 78 | priv, err := rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/GenerateKey().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., cfg.Bitsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Bits.) |
| 79 | if err != nil { |
| 80 | return nil, nil, err |
| 81 | } |
| 82 | |
| 83 | notBefore := timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().() |
| 84 | aYear := timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration#(365*24) * timescip-go gomod github.com/golang/go/src go1.16 time/.Hourscip-go gomod github.com/golang/go/src go1.16 time/Hour. |
| 85 | notAfter := notBefore.Addscip-go gomod github.com/golang/go/src go1.16 time/Time#Add().(aYear) |
| 86 | serialNumberLimit := new(bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#).Lshscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Lsh().(bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(1), 128) |
| 87 | serialNumber, err := randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Intscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Int().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., serialNumberLimit) |
| 88 | if err != nil { |
| 89 | return nil, nil, err |
| 90 | } |
| 91 | |
| 92 | template := x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#{ |
| 93 | SerialNumberscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#SerialNumber.: serialNumber, |
| 94 | Subjectscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#Subject.: pkixscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/.Namescip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#{ |
| 95 | Countryscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#Country.: []string{cfg.Countryscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Country.}, |
| 96 | Localityscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#Locality.: []string{cfg.Localityscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Locality.}, |
| 97 | Organizationscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#Organization.: []string{cfg.Organizationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#Organization.}, |
| 98 | OrganizationalUnitscip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#OrganizationalUnit.: []string{cfg.OrganizationalUnitscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#OrganizationalUnit.}, |
| 99 | CommonNamescip-go gomod github.com/golang/go/src go1.16 `crypto/x509/pkix`/Name#CommonName.: cfg.CommonNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#CommonName., |
| 100 | }, |
| 101 | NotBeforescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#NotBefore.: notBefore, |
| 102 | NotAfterscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#NotAfter.: notAfter, |
| 103 | KeyUsagescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#KeyUsage.: x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.KeyUsageKeyEnciphermentscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/KeyUsageKeyEncipherment. | x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.KeyUsageDigitalSignaturescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/KeyUsageDigitalSignature. | x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.KeyUsageCertSignscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/KeyUsageCertSign., |
| 104 | ExtKeyUsagescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#ExtKeyUsage.: []x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.ExtKeyUsagescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/ExtKeyUsage#{x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.ExtKeyUsageClientAuthscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/ExtKeyUsageClientAuth., x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.ExtKeyUsageServerAuthscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/ExtKeyUsageServerAuth.}, |
| 105 | BasicConstraintsValidscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#BasicConstraintsValid.: true, |
| 106 | IsCAscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/Certificate#IsCA.: ca, |
| 107 | } |
| 108 | |
| 109 | cert, err := x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.CreateCertificatescip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/CreateCertificate().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., &template, &template, &priv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey., priv) |
| 110 | if err != nil { |
| 111 | return nil, nil, err |
| 112 | } |
| 113 | |
| 114 | return priv, cert, err |
| 115 | } |
| 116 | |
| 117 | func Generatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/Generate().(cfg CertConfigscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CertConfig#, certPath string, keyPath string, ca bool) error { |
| 118 | keyFile, err := osscip-go gomod github.com/golang/go/src go1.16 os/.Createscip-go gomod github.com/golang/go/src go1.16 os/Create().(keyPath) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | defer keyFile.Closescip-go gomod github.com/golang/go/src go1.16 os/File#Close().() |
| 123 | |
| 124 | certFile, err := osscip-go gomod github.com/golang/go/src go1.16 os/.Createscip-go gomod github.com/golang/go/src go1.16 os/Create().(certPath) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | defer certFile.Closescip-go gomod github.com/golang/go/src go1.16 os/File#Close().() |
| 129 | |
| 130 | priv, cert, err := CreateCertificatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/tls`/CreateCertificate().(cfg, ca) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | if err := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Encodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Encode().(keyFile, &pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#{Typescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Type.: "RSA PRIVATE KEY", Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.: x509scip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/.MarshalPKCS1PrivateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/x509`/MarshalPKCS1PrivateKey().(priv)}); err != nil { |
| 136 | return err |
| 137 | } |
| 138 | |
| 139 | return pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Encodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Encode().(certFile, &pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#{Typescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Type.: "CERTIFICATE", Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.: cert}) |
| 140 | } |