From a69ef5ff51b0f34f03cb806d4352a11eaf195971 Mon Sep 17 00:00:00 2001 From: Mads Bram Cordes Date: Thu, 28 Apr 2022 07:56:26 +0200 Subject: [PATCH] Imrpoved code and clean-up License change to MIT --- .gitignore | 1 + LICENSE | 25 +++-------------- README.md | 51 ++++++++++++++++++++++------------- data/sample.png | Bin 0 -> 14618 bytes generator.go | 65 --------------------------------------------- hotp.go | 52 ------------------------------------ main.go | 52 +++++++++++++++++------------------- moths/buffer.go | 21 +++++++++++++++ moths/config.go | 24 +++++++++++++++++ moths/generator.go | 49 ++++++++++++++++++++++++++++++++++ moths/hotp.go | 41 ++++++++++++++++++++++++++++ moths/new.go | 19 +++++++++++++ secret.pem | 1 - 13 files changed, 217 insertions(+), 184 deletions(-) create mode 100644 .gitignore create mode 100644 data/sample.png delete mode 100644 generator.go delete mode 100644 hotp.go create mode 100644 moths/buffer.go create mode 100644 moths/config.go create mode 100644 moths/generator.go create mode 100644 moths/hotp.go create mode 100644 moths/new.go delete mode 100644 secret.pem diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/LICENSE b/LICENSE index 68a49da..416bf9d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,24 +1,7 @@ -This is free and unencumbered software released into the public domain. +Copyright 2022 Mads Cordes -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index c9d1007..efe6625 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,53 @@ # moths -> e**mo**ji au**ths** +> e**mo**jicon au**th**entication**s** -# what +## what -Emojies as TOTP +Emojies as OTP (2FA) -# why +## why -Becasue why not? +Because why not? -# how +## how -Runnig this is quite easy, just run the command: +Runnig this is quite easy. -Download the dependencies: +- Download the dependencies -```sh -go mod download -``` + ```sh + go mod download + ``` -Next-up start the program +- Make a secret -```sh -go run . -``` + ```sh + echo -n "MOTHS_SECRET=" > .env; echo 'moths' | sha256sum | base64 | head -c 32 >> .env + ``` + +- Start the program + + ```sh + go run . + ``` As I said, easy-peasy! -# sample +## sample + +![four generated OTP's](./data/sample.png) + +
+ v0.1 + +A sample out-put might be `πŸ˜»πŸ™€πŸ˜ΊπŸ™€πŸ™€` which would equal the `920811` TOTP-token. Using the super secret secret of `😻` - genereated at `2022/04/28 02:05:42 AM` and a `5`-second interval. + +Can be checked out at [`v0.1`](https://github.com/Mobilpadde/moths/tree/v0.1) -A sample out-put might be `πŸ˜»πŸ™€πŸ˜ΊπŸ™€πŸ™€` which would equal the `920811` TOTP-token. Using the super secret secret specified in [`./secret.pem`](./secret.pem) - genereated at `2022/04/28 02:05:42` and a `5`-second interval. +
-# shoutout +## shoutout I couldn't have done it without the lovely OSS's listed below: diff --git a/data/sample.png b/data/sample.png new file mode 100644 index 0000000000000000000000000000000000000000..2cace64db435ec9af20d27b9864fc565db53264b GIT binary patch literal 14618 zcmZv@bzD_Z*DbsW0YQ+EknTF(~75~RC31S#o~=Fpu2(v5Tq2-4kf=#FpebHDfA z`@7E{2M(Kk_Fj9gImaAhtaZYb6{S#-@sR-lK$VdeR|NprAn?5z5-j*r2>(?V`0J&E zw2m_Xp!NQJ!6Y%D5dZ)wAR{iK?vZhn>F)7n=B|H*y|%6B+JN@6GTbk3mOvMka$FIZ z%hGED6yq-Irl-Sfa{BDBY+6{@uVKGh>SAM;6BK?V+hk_0kPv)JIUKQz52kbwjENaP z{__XwxpNp&t0q+Jy+RkzWyFg2sxXsuz6E%N5Y%O4XMG|c`S+l_cc8iPzeDp_{8%R7 zSqM{EtEt?b`LgSM;%L(7QuXd+nXlkEVy2cQ{+;gtXKs9V>Ob}D8x!5www?buMq|6sTVg+g$PMAn{wIxvkWuys;Ge>mF|B9fzN}wi}LOJDk0eM*S-JVh2;@`eLE>>5B%LxD(mO znyDm&*~6^XBFPYB?ly19EzLcK_KsZ(M=we0SHz0_y%fZ+(GJBBuj=hQ(}sh>r}l^i zKC^t`rQ)r|-7>Ho-8W{%8(C@6cSFJyp4OhJ(l=OXJiRm+hFhN8ju%LmyMm{bwRL_f znfA_-L~djwf6|G12}r}2c~RjLO)v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(tQi#lKK$=2GP)3g zSb=1WrA2+{GkRfEu8e|e@Nv4A!RLQ0-_+l1%ET+eTb)chJRsyr+SNf)EPYzHtEYQZ zi?sd`PVo788cHGD|CPE{3a_0alXR?Sl6`LtcpE-&Mz$ zw!wj}FGPJzw8Le MNGOU|iW&v}f6Ag9i~s-t literal 0 HcmV?d00001 diff --git a/generator.go b/generator.go deleted file mode 100644 index 4b22781..0000000 --- a/generator.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "encoding/binary" - "fmt" - "math" - "math/bits" - "math/rand" - "strings" -) - -// randomBufferFromHOTP generates a random buffer from a HOTP token. -// -// /!\ Modified /!\ -// -// Proudly stolen from https://stackoverflow.com/a/48307199/754471 -func randomBufferFromHOTP(otp string) func(step int) ([]byte, error) { - buf := []byte(fmt.Sprintf("%08s", otp)) - seed := int64(binary.BigEndian.Uint64(buf)) - r := rand.New(rand.NewSource(seed)) - - return func(step int) ([]byte, error) { - buffer := make([]byte, step) - if _, err := r.Read(buffer); err != nil { - return nil, err - } - return buffer, nil - } -} - -// MothsGenerator is essentially the nanoid generator with a few modifications. -// -// /!\ Modified /!\ -// -// https://github.com/aidarkhanov/nanoid/blob/master/nanoid.go -func MothsGenerator(token string, numEmojies int, alphabet ...string) (string, error) { - emojiBytes := 4 - size := emojiBytes * numEmojies - - mask := 2< %s\n", moth, otp) + select {} } diff --git a/moths/buffer.go b/moths/buffer.go new file mode 100644 index 0000000..a005dbc --- /dev/null +++ b/moths/buffer.go @@ -0,0 +1,21 @@ +package moths + +import ( + "encoding/binary" + "fmt" + "math/rand" +) + +func randomBufferFromHOTP(otp string) func(step int) ([]byte, error) { + buf := []byte(fmt.Sprintf("%08s", otp)) + seed := int64(binary.BigEndian.Uint64(buf)) + r := rand.New(rand.NewSource(seed)) + + return func(step int) ([]byte, error) { + buffer := make([]byte, step) + if _, err := r.Read(buffer); err != nil { + return nil, err + } + return buffer, nil + } +} diff --git a/moths/config.go b/moths/config.go new file mode 100644 index 0000000..110221c --- /dev/null +++ b/moths/config.go @@ -0,0 +1,24 @@ +package moths + +import "github.com/enescakir/emoji" + +var ( + ALPHABET_CATSDOG = []string{ + emoji.GrinningCat.String(), + emoji.GrinningCatWithSmilingEyes.String(), + emoji.CatWithTearsOfJoy.String(), + emoji.SmilingCatWithHeartEyes.String(), + emoji.CatWithWrySmile.String(), + emoji.KissingCat.String(), + emoji.WearyCat.String(), + emoji.CryingCat.String(), + emoji.PoutingCat.String(), + emoji.DogFace.String(), + } +) + +type Moths struct { + secret string + interval int + alphabet []string +} diff --git a/moths/generator.go b/moths/generator.go new file mode 100644 index 0000000..24cff49 --- /dev/null +++ b/moths/generator.go @@ -0,0 +1,49 @@ +package moths + +import ( + "errors" + "math" + "math/bits" + "strings" +) + +const emojiBytes = 4 + +func (m *Moths) Next(numEmojies int, alphabet []string) (string, error) { + if len(alphabet) < 1 { + return "", errors.New("alphabet must be at least 1 character") + } + + size := emojiBytes * numEmojies + // https://github.com/tilaklodha/google-authenticator + mask := 2<