aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
2025-01-26lib/goanalysis: package to complement "go vet"Shulhan
Package goanalysis implement go static analysis using [Analyzer] that are not included in the default "go vet", but included in the [passes] directory, including: fieldalignment, nilness, reflectvaluecompare, shadow, sortslice, unusedwrite, and waitgroup. This package is not mean to be imported directly by other package except main, like we have in [cmd/gocheck]. The rest (and previous) of the changes are affect running gocheck on it.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-11-19lib/crypto: trim the password read from SSH_ASKPASSShulhan
If user press enter on the GUI, the returned password will contains line feed, which makes the password invalid.
2023-11-18lib/crypto: add support for reading passphrase using SSH_ASKPASSShulhan
If the library failed to changes os.Stdin to raw, it will try to use a program defined in SSH_ASKPASS environment variable. The SSH_ASKPASS is controlled by environment SSH_ASKPASS_REQUIRE. - If SSH_ASKPASS_REQUIRE is empty the passphrase will read from terminal first, if not possible then using SSH_ASKPASS program. - If SSH_ASKPASS_REQUIRE is set to "never" the passphrase will read from terminal only. - If SSH_ASKPASS_REQUIRE is set to "prefer", the passphrase will read using SSH_ASKPASS program not from terminal, but require DISPLAY environment to be set. - If SSH_ASKPASS_REQUIRE is set to "force", the passphrase will read using SSH_ASKPASS program not from terminal, without checking DISPLAY environment. This changes affect the [ssh.NewClientInteractive] indirectly.
2023-09-26go.mod: remove replace directive for golang.org/x/cryptoShulhan
Using replace directive does not works well if we install binary using "go install". One of the case that we found is when user installing awwan [1] that use "share" module [2] with replace directive, the binary is not build with git.sr.ht/~shulhan/go-x-crypto. /Users/xxx/go/bin/awwan: go1.21.0 path git.sr.ht/~shulhan/awwan/cmd/awwan mod git.sr.ht/~shulhan/awwan v0.7.1-0.20230925173020-40b9fe9b854c h1:629djcSfqM8ITX+CtgGyrybPnKQPpwJ/EceN967bKps= dep git.sr.ht/~shulhan/asciidoctor-go v0.5.0 h1:TfcAjv+7EwBZ83ef8OhX9vfQ4vRFcaJh0P1XXgbsJv0= dep git.sr.ht/~shulhan/ciigo v0.10.0 h1:s1SJ3/NzBcbOLmEZ4z1Cx9Vf7ZdDIvm45b7KMCZKzEY= dep github.com/evanw/esbuild v0.19.3 h1:foPr0xwQM3lBWKBtscauTN9FrmJzRDVI2+EGOs82H/I= dep github.com/shuLhan/share v0.49.2-0.20230923081600-77c41ce992e6 h1:REQDC2UKLaWT1WGd/Iw/rfKLkXb7vtKtyObkeZeHZRk= dep github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA= dep github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= dep golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= dep golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= dep golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= dep golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= dep gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= build -buildmode=exe build -compiler=gc build DefaultGODEBUG=panicnil=1 build CGO_ENABLED=1 build CGO_CFLAGS= build CGO_CPPFLAGS= build CGO_CXXFLAGS= build CGO_LDFLAGS= build GOARCH=arm64 build GOOS=darwin This changes require use to modify lib/cryto and lib/ssh that depends on our patches. [1] https://git.sr.ht/~shulhan/awwan [2] https://github.com/shuLhan/share/commit/77c41ce992e6
2023-09-23lib/crypto: check empty password earlier in LoadPrivateKeyInteractiveShulhan
If the private key is encrypted and the we read empty passphrase from terminal, return ErrEmptyPassphrase before calling ParseRawPrivateKeyWithPassphrase.
2023-09-20lib/crypto: implement RSA encrypt and decryption for large message sizeShulhan
The EncryptOaep extend the [rsa.EncryptOAEP] to make it able to encrypt a message larger than its than (public modulus size - 2*hash.Size - 2). The function signature is the same with [rsa.EncryptOAEP] except the name, to make it distinguishable. The DecryptOaep function extend the [rsa.DecryptOAEP] to make it able to decrypt a message larger than its public modulus size.
2023-09-20lib/crypto: use errors.Is to check for missing passphraseShulhan
This changes require update on go-x-crypto package, because the Is method has not been merged upstream yet.
2023-09-20lib/crypto: add function LoadPrivateKeyInteractiveShulhan
The LoadPrivateKeyInteractive load the private key from file. If the private key file is encrypted, it will prompt for the passphrase from terminal. This function is taken from package lib/ssh with modification by adding parameter io.ReadWriter and removing parameter maxAttempt.
2023-09-20lib/crypto: add parameter passphrase to LoadPrivateKeyShulhan
The passphrase parameter is optional, it will be used only if the private key is encrypted.
2023-09-20lib/crypto: rewrite LoadPrivateKey as wrapper of ssh.ParseRawPrivateShulhan
Previously, the LoadPrivateKey function only able to load private key with PKCS#1 format. This changes make the function as a wrapper for ssh.ParseRawPrivate that can load RSA, DSA, ECDSA, and Ed25519 in PKCS#1, PKCS#8, OpenSSL, and OpenSSH formats.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2019-04-05crypto: new package that provide a wrapper for standard cryptoShulhan
This package provide a function to load private key from file, which is not available in standard crypto package.