...
1 package goodkey
2
3 import (
4 "crypto/rsa"
5 "encoding/hex"
6 "math/big"
7 "os"
8 "path/filepath"
9 "testing"
10
11 "github.com/letsencrypt/boulder/test"
12 )
13
14 func TestKnown(t *testing.T) {
15 modBytes, err := hex.DecodeString("D673252AF6723C3F72529403EAB7C30DEF3C52F97E799825F4A70191C616ADCF1ECE1113F1625971074C492C592025FDEADBDB146A081826BDF0D77C3C913DCF1B6F0B3B78F5108D2E493AD0EEE8CA5C021711ADC13D358E61133870FCD19C8E5C22403959782AA82E72AEE53A3D491E3912CE27B27E1A85EA69C19A527D28F7934C9823B7E56FDD657DAC83FDC65BB22A98D843DF73238919781B714C81A5E2AFEC71F5C54AA2A27C590AD94C03C1062D50EFCFFAC743E3C8A3AE056846A1D756EB862BF4224169D467C35215ADE0AFCC11E85FE629AFB802C4786FF2E9C929BCCF502B3D3B8876C6A11785CC398B389F1D86BDD9CB0BD4EC13956EC3FA270D")
16 test.AssertNotError(t, err, "Failed to decode modulus bytes")
17 mod := &big.Int{}
18 mod.SetBytes(modBytes)
19 testKey := rsa.PublicKey{N: mod}
20 otherKey := rsa.PublicKey{N: big.NewInt(2020)}
21
22 wk := &WeakRSAKeys{suffixes: make(map[truncatedHash]struct{})}
23 err = wk.addSuffix("8df20e6961a16398b85a")
24
25 test.AssertNotError(t, err, "WeakRSAKeys.addSuffix failed")
26 test.Assert(t, wk.Known(&testKey), "WeakRSAKeys.Known failed to find suffix that has been added")
27 test.Assert(t, !wk.Known(&otherKey), "WeakRSAKeys.Known found a suffix that has not been added")
28 }
29
30 func TestLoadKeys(t *testing.T) {
31 modBytes, err := hex.DecodeString("D673252AF6723C3F72529403EAB7C30DEF3C52F97E799825F4A70191C616ADCF1ECE1113F1625971074C492C592025FDEADBDB146A081826BDF0D77C3C913DCF1B6F0B3B78F5108D2E493AD0EEE8CA5C021711ADC13D358E61133870FCD19C8E5C22403959782AA82E72AEE53A3D491E3912CE27B27E1A85EA69C19A527D28F7934C9823B7E56FDD657DAC83FDC65BB22A98D843DF73238919781B714C81A5E2AFEC71F5C54AA2A27C590AD94C03C1062D50EFCFFAC743E3C8A3AE056846A1D756EB862BF4224169D467C35215ADE0AFCC11E85FE629AFB802C4786FF2E9C929BCCF502B3D3B8876C6A11785CC398B389F1D86BDD9CB0BD4EC13956EC3FA270D")
32 test.AssertNotError(t, err, "Failed to decode modulus bytes")
33 mod := &big.Int{}
34 mod.SetBytes(modBytes)
35 testKey := rsa.PublicKey{N: mod}
36 tempDir := t.TempDir()
37 tempPath := filepath.Join(tempDir, "a.json")
38 err = os.WriteFile(tempPath, []byte("[\"8df20e6961a16398b85a\"]"), os.ModePerm)
39 test.AssertNotError(t, err, "Failed to create temporary file")
40
41 wk, err := LoadWeakRSASuffixes(tempPath)
42 test.AssertNotError(t, err, "Failed to load suffixes from directory")
43 test.Assert(t, wk.Known(&testKey), "WeakRSAKeys.Known failed to find suffix that has been added")
44 }
45
View as plain text