v0.3.3: Separated HIBP code into its own module

This commit is contained in:
Winni Neessen 2021-09-19 18:20:16 +02:00
parent 37e9e0cc02
commit b490e9bf98
4 changed files with 23 additions and 55 deletions

View file

@ -4,15 +4,11 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="fbb0c733-4aa1-4d27-87d5-c7276d8aa613" name="Default Changelist" comment="For some reason, the tests on GH fail">
<list default="true" id="fbb0c733-4aa1-4d27-87d5-c7276d8aa613" name="Default Changelist" comment="Updated build files for Arch and OpenBSD">
<change afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apg.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/apg_test.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/chars.go" beforeDir="false" afterPath="$PROJECT_DIR$/chars/chars.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/convert.go" beforeDir="false" afterPath="$PROJECT_DIR$/spelling/spelling.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hibp.go" beforeDir="false" afterPath="$PROJECT_DIR$/hibp/hibp.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/rand.go" beforeDir="false" afterPath="$PROJECT_DIR$/random/random.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hibp/hibp.go" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -79,7 +75,7 @@
<recent name="$PROJECT_DIR$/random" />
</key>
</component>
<component name="RunManager" selected="Go Test.Benchmark Application">
<component name="RunManager" selected="Go Build.Run Application (with newstyle params and spelling, multiple pws and hibp)">
<configuration name="Run Application (show help text)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
@ -120,6 +116,16 @@
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="Run Application (with newstyle params and spelling, multiple pws and hibp)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-m 10 -x 10 -M SLNU -l -n 6 -p" />
<kind value="PACKAGE" />
<package value="github.com/wneessen/apg-go/cmd/apg" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="Run Application (with newstyle params and spelling)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
@ -207,6 +213,7 @@
<item itemvalue="Go Build.Run Application (with newstyle params)" />
<item itemvalue="Go Build.Run Application (with newstyle params and spelling)" />
<item itemvalue="Go Build.Run Application (with newstyle params and spelling and multiple pws)" />
<item itemvalue="Go Build.Run Application (with newstyle params and spelling, multiple pws and hibp)" />
<item itemvalue="Go Build.Run Application (show help text)" />
<item itemvalue="Go Build.Run Application (show version string)" />
<item itemvalue="Go Test.Test Application" />
@ -263,7 +270,9 @@
<MESSAGE value="v0.3.0: Unified the naming convention" />
<MESSAGE value="v0.3.1: New password length behaviour&#10;&#10;To address issue #13, the password length behaviour of the &#10;original APG has been reproduced. Previously, when a minLength&#10;of 5 and a maxLength of 10 was given, apg-go se the pwLength to&#10;the preferred maxLength.&#10;&#10;With v0.3.1 it will choose a random length between minLength and&#10;maxLength instead, same as the original C-lang apg did. For this&#10;the minLength has been defaulted to a sane value of 12 (instead &#10;of the 8 of the original apg). The default for maxLength stayed&#10;at 20.&#10;&#10;Also the default number of generated passwords has been changed &#10;from 1 to 6, to replicate the behaviour of the original apg." />
<MESSAGE value="For some reason, the tests on GH fail" />
<option name="LAST_COMMIT_MESSAGE" value="For some reason, the tests on GH fail" />
<MESSAGE value="Major refactor so that cmd and lib are separated" />
<MESSAGE value="Updated build files for Arch and OpenBSD" />
<option name="LAST_COMMIT_MESSAGE" value="Updated build files for Arch and OpenBSD" />
</component>
<component name="VgoProject">
<integration-enabled>true</integration-enabled>

2
go.mod
View file

@ -1,3 +1,5 @@
module github.com/wneessen/apg-go
go 1.16
require github.com/wneessen/go-hibp v0.0.1

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/wneessen/go-hibp v0.0.1 h1:oZaeSsy1ygufrwh8CI3PWc3XLubaP7erJhZlc1+n6O4=
github.com/wneessen/go-hibp v0.0.1/go.mod h1:Ldg6DQg4fMCveVKgL+RL9Jy+9TsljjAP704Ix8X3jOw=

View file

@ -1,45 +0,0 @@
package hibp
import (
"bufio"
"crypto/sha1"
"fmt"
"log"
"net/http"
"strings"
"time"
)
// Check queries the HIBP database and checks if a given string is was found
func Check(p string) (bool, error) {
shaSum := fmt.Sprintf("%x", sha1.Sum([]byte(p)))
firstPart := shaSum[0:5]
secondPart := shaSum[5:]
isPwned := false
httpClient := &http.Client{Timeout: time.Second * 2}
httpRes, err := httpClient.Get("https://api.pwnedpasswords.com/range/" + firstPart)
if err != nil {
return false, err
}
defer func() {
err := httpRes.Body.Close()
if err != nil {
log.Printf("error while closing HTTP response body: %v\n", err)
}
}()
scanObj := bufio.NewScanner(httpRes.Body)
for scanObj.Scan() {
scanLine := strings.SplitN(scanObj.Text(), ":", 2)
if strings.ToLower(scanLine[0]) == secondPart {
isPwned = true
break
}
}
if err := scanObj.Err(); err != nil {
return isPwned, err
}
return isPwned, nil
}