Implement new go-hibp package

This commit is contained in:
Winni Neessen 2021-09-21 14:03:09 +02:00
parent 7871b4307b
commit 2087a4b60c
Signed by: wneessen
GPG key ID: 385AC9889632126E
7 changed files with 24 additions and 251 deletions

8
.idea/.gitignore vendored
View file

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View file

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/apg.go.iml" filepath="$PROJECT_DIR$/.idea/apg.go.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/apg-go.iml" filepath="$PROJECT_DIR$/.idea/apg-go.iml" />
</modules>
</component>
</project>

View file

@ -4,279 +4,58 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="fbb0c733-4aa1-4d27-87d5-c7276d8aa613" name="Default Changelist" comment="Updated WS" />
<list default="true" id="4f2cb9e2-b3a4-4e84-b99e-efc626c48d46" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/apg.go.iml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/apg/apg.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/apg/apg.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
<option value="Go Application" />
</list>
</option>
</component>
<component name="GOROOT" url="file://$PROJECT_DIR$/../../go1.17.1" />
<component name="GOROOT" url="file://$USER_HOME$/go/go1.17.1" />
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="main" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="GitSEFilterConfiguration">
<file-type-list>
<filtered-out-file-type name="LOCAL_BRANCH" />
<filtered-out-file-type name="REMOTE_BRANCH" />
<filtered-out-file-type name="TAG" />
<filtered-out-file-type name="COMMIT_BY_MESSAGE" />
</file-type-list>
</component>
<component name="GoLibraries">
<option name="indexEntireGoPath" value="false" />
</component>
<component name="ProjectId" id="1pxyItB9dnh8hLHpqlNK6NktVaL" />
<component name="ProjectLevelVcsManager">
<OptionsSetting value="false" id="Update" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="ProjectId" id="1yRb7lIdCn8c4b6dwTlP2QjBzYh" />
<component name="PropertiesComponent">
<property name="DefaultGoTemplateProperty" value="Go Application" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="configurable..is.expanded" value="false" />
<property name="configurable.GoLibrariesConfigurable.is.expanded" value="true" />
<property name="go.formatter.settings.were.checked" value="true" />
<property name="go.import.settings.migrated" value="true" />
<property name="go.modules.go.list.on.any.changes.was.set" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="inlay.hints.go" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/chars" />
<recent name="$PROJECT_DIR$/hibp" />
<recent name="$PROJECT_DIR$/spelling" />
<recent name="$PROJECT_DIR$/config" />
<recent name="$PROJECT_DIR$/random" />
</key>
</component>
<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$" />
<parameters value="-h" />
<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 (show version string)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-v" />
<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 excludes)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-m 20 -x 20 -C -E abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!]" />
<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 and multiple pws)" 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" />
<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, 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$" />
<parameters value="-m 10 -x 10 -M SLNU -l" />
<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)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-M slNU" />
<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 params)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-m 20 -x 20 -C" />
<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" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/wneessen/apg-go/cmd/apg" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<component name="RunManager">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<module name="apg-go" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind value="PACKAGE" />
<package value="apg-go" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="Benchmark Application" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/wneessen/apg-go/cmd/apg" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gobench" />
<method v="2" />
</configuration>
<configuration name="Test Application" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/wneessen/apg-go/cmd/apg" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="apg.go" />
<module name="apg-go" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind value="DIRECTORY" />
<package value="apg-go" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
<list>
<item itemvalue="Go Build.Run Application" />
<item itemvalue="Go Build.Run Application (with params)" />
<item itemvalue="Go Build.Run Application (with excludes)" />
<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" />
<item itemvalue="Go Test.Benchmark Application" />
</list>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="FILTERS">
<map>
<entry key="branch">
<value>
<list>
<option value="main" />
</list>
</value>
</entry>
</map>
</option>
</State>
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Updated README and gitignore files" />
<MESSAGE value="v0.2.1: Support for more platforms added" />
<MESSAGE value="v0.2.3: More chars, cleanup and better test coverage&#10;- Added more special characters&#10;- Fixed issue with ` character&#10;- Added lots of tests&#10;- Moved character range generation into it's own function&#10;- Better error handling&#10;- A bit of code cleanup" />
<MESSAGE value="Split up functions into seperate files" />
<MESSAGE value="Added spelling of pws. Ready for v0.2.4" />
<MESSAGE value="Fixes in getCharRange() tests" />
<MESSAGE value="excludeChars are now escaped before using them as regExp" />
<MESSAGE value="Added sane defaults" />
<MESSAGE value="Updates README.md. We are ready for v0.2.5" />
<MESSAGE value="Break the switch/case" />
<MESSAGE value="v0.2.6 - converted to go module structure&#10;- Better logging&#10;- Better error handling&#10;- Removed Makefile since github takes care of building/releasing" />
<MESSAGE value="Tests cleanup. Used structs for tests instead of repeating code" />
<MESSAGE value="v0.2.7: Switched global config to it's own package" />
<MESSAGE value="Updated .gitignore" />
<MESSAGE value="Removed .idea from .gitignore" />
<MESSAGE value="Let's have centralized IDE config" />
<MESSAGE value="New DEV branch" />
<MESSAGE value="v0.2.9: Replaced standard go-help with custom usage text" />
<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" />
<MESSAGE value="Major refactor so that cmd and lib are separated" />
<MESSAGE value="Updated build files for Arch and OpenBSD" />
<MESSAGE value="v0.3.3: Separated HIBP code into its own module" />
<MESSAGE value="Updated WS" />
<option name="LAST_COMMIT_MESSAGE" value="Updated WS" />
</component>
<component name="VgoProject">
<integration-enabled>true</integration-enabled>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/apg_go$TestGetRandNum_in_github_com_wneessen_apg_go__1_.out" NAME="TestGetRandNum in github.com/wneessen/apg.go (1) Coverage Results" MODIFIED="1616594443133" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="GoCoverage" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
<SUITE FILE_PATH="coverage/apg_go$BenchmarkGetRandNum_in_apg_go.out" NAME="BenchmarkGetRandNum in apg.go Coverage Results" MODIFIED="1616342745320" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="GoCoverage" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
<SUITE FILE_PATH="coverage/apg_go$Test_Application.out" NAME="Test Application Coverage Results" MODIFIED="1616765230426" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="GoCoverage" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
</component>
</project>

View file

@ -10,6 +10,7 @@ import (
hibp "github.com/wneessen/go-hibp"
"log"
"os"
"time"
)
const VersionString string = "0.3.3"
@ -84,11 +85,12 @@ func main() {
}
if cfgObj.CheckHibp {
isPwned, err := hibp.Check(pwString)
hc := hibp.New(hibp.WithHttpTimeout(time.Second * 2))
pwnObj, _, err := hc.PwnedPassword.CheckPassword(pwString)
if err != nil {
log.Printf("unable to check HIBP database: %v", err)
}
if isPwned {
if pwnObj != nil && pwnObj.Count != 0 {
fmt.Print("^-- !!WARNING: The previously generated password was found in HIPB database. Do not use it!!\n")
}
}

2
go.mod
View file

@ -2,4 +2,4 @@ module github.com/wneessen/apg-go
go 1.16
require github.com/wneessen/go-hibp v0.0.1
require github.com/wneessen/go-hibp v0.1.1

4
go.sum
View file

@ -1,2 +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=
github.com/wneessen/go-hibp v0.1.1 h1:tq/bLNqGIns3r2b1dAT7PcVdYRsF70qBTs7tQh6sfRo=
github.com/wneessen/go-hibp v0.1.1/go.mod h1:Ldg6DQg4fMCveVKgL+RL9Jy+9TsljjAP704Ix8X3jOw=