Revert accidental inclusion of unrelated code

This commit is contained in:
Roland Shoemaker 2017-02-16 13:20:07 -08:00
parent 811740924a
commit 415aa9598a
2 changed files with 0 additions and 92 deletions

View File

@ -1,59 +0,0 @@
package goodkey
import (
"crypto/sha1"
"encoding/hex"
"io/ioutil"
"path/filepath"
"strings"
)
type weakKeys struct {
suffixes map[[10]byte]struct{}
}
func loadSuffixes(dir string) (*weakKeys, error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
wk := &weakKeys{suffixes: make(map[[10]byte]struct{})}
for _, fh := range files {
if fh.IsDir() {
continue
}
f, err := ioutil.ReadFile(filepath.Join(dir, fh.Name()))
if err != nil {
return nil, err
}
for _, l := range strings.Split(string(f), "\n") {
if strings.HasPrefix(l, "#") {
continue
}
err := wk.addSuffix(l)
if err != nil {
return nil, err
}
}
}
return wk, nil
}
func (wk *weakKeys) addSuffix(str string) error {
var suffix [10]byte
decoded, err := hex.DecodeString(str)
if err != nil {
return err
}
copy(suffix[:], decoded)
wk.suffixes[suffix] = struct{}{}
return nil
}
func (wk *weakKeys) Known(der []byte) bool {
hash := sha1.Sum(der)
var suffix [10]byte
copy(suffix[:], hash[10:])
_, present := wk.suffixes[suffix]
return present
}

View File

@ -1,33 +0,0 @@
package goodkey
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/letsencrypt/boulder/test"
)
func TestKnown(t *testing.T) {
wk := &weakKeys{suffixes: make(map[[10]byte]struct{})}
err := wk.addSuffix("200352313bc059445190")
test.AssertNotError(t, err, "weakKeys.addSuffix failed")
test.Assert(t, wk.Known([]byte("asd")), "weakKeys.Known failed to find suffix that has been added")
test.Assert(t, !wk.Known([]byte("ASD")), "weakKeys.Known found a suffix that has not been added")
}
func TestLoadKeys(t *testing.T) {
tempDir, err := ioutil.TempDir("", "weak-keys")
test.AssertNotError(t, err, "Failed to create temporary directory")
err = ioutil.WriteFile(filepath.Join(tempDir, "a"), []byte("# asd\n200352313bc059445190"), os.ModePerm)
test.AssertNotError(t, err, "Failed to create temporary file")
err = ioutil.WriteFile(filepath.Join(tempDir, "b"), []byte("# asd\ndc47cdf6b45d89e8b2a0"), os.ModePerm)
test.AssertNotError(t, err, "Failed to create temporary file")
wk, err := loadSuffixes(tempDir)
test.AssertNotError(t, err, "Failed to load suffixes from directory")
test.Assert(t, wk.Known([]byte("asd")), "weakKeys.Known failed to find suffix that has been added")
test.Assert(t, wk.Known([]byte("dsa")), "weakKeys.Known failed to find suffix that has been added")
}