Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ch04/lfsr/exploit_lfsr/exploit_lfsr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,17 @@ func TestKnownPlaintextAttack(t *testing.T) {

remainingCiphertext := ciphertext[len(AttackMessageKnownPrefix):]
for i := 1; i < MaxLfsrLength; i++ {
if clonedLfsr, err := RecoverLFSRWithKnownLengthFromObservedBits(keystreamBits, i); err == nil {
decrypted := clonedLfsr.Encrypt(remainingCiphertext)
if parsedTs, err := time.Parse(time.RFC822, string(decrypted)); err != nil {
t.Logf("Incorrect decrypted message: %s", decrypted)
continue
} else {
t.Logf("Decrypted message: %s%s\n", AttackMessageKnownPrefix, parsedTs)
return
}
clonedLfsr, err := RecoverLFSRWithKnownLengthFromObservedBits(keystreamBits, i)
if err != nil {
continue
}
decrypted := clonedLfsr.Encrypt(remainingCiphertext)
if parsedTs, err := time.Parse(time.RFC822, string(decrypted)); err == nil {
t.Logf("Decrypted message: %s%s\n", AttackMessageKnownPrefix, parsedTs)
return
}

t.Logf("Incorrect decrypted message: %s", decrypted)
}

t.Fatalf("Could not decrypt message")
Expand Down
10 changes: 4 additions & 6 deletions ch05/beast/exploit_beast/exploit_beast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ func TestEncryptedHTTPSession(t *testing.T) {

t.Logf("recoveredSessionId: %s\n", recoveredSessionId)

if impl_beast.ValidateSessionId(host, recoveredSessionId) {
t.Logf("recoveredSessionId verified successfully against host %s", host)
} else {
if !impl_beast.ValidateSessionId(host, recoveredSessionId) {
t.Fatalf("recoveredSessionId is incorrect, does not match the one stored for host %s", host)
}
t.Logf("recoveredSessionId verified successfully against host %s", host)

differentHost := "someotherhost.com"
_, _, _ = impl_beast.NewEncryptedHTTPSession(differentHost, "/")
if !impl_beast.ValidateSessionId(differentHost, recoveredSessionId) {
t.Logf("recoveredSessionId is correctly invalid for a different host")
} else {
if impl_beast.ValidateSessionId(differentHost, recoveredSessionId) {
t.Fatalf("recoveredSessionId is incorrectly valid for a different host")
}
t.Logf("recoveredSessionId is correctly invalid for a different host")
}
17 changes: 7 additions & 10 deletions ch06/length_ext/impl_length_ext/impl_length_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ func (b *Bank) authenticateRequest(r *http.Request) (uint32, error) {
}
clientId32 := uint32(clientId)

var clientSecret string
if v, ok := b.clientSecrets[clientId32]; ok {
clientSecret = v
} else {
clientSecret, ok := b.clientSecrets[clientId32]
if !ok {
return 0, errors.New("client not found")
}

Expand All @@ -106,13 +104,13 @@ func (b *Bank) authenticateRequest(r *http.Request) (uint32, error) {
reqTime,
currentTime,
currentTime-reqTime))
} else {
fmt.Printf("\trequest authenticated successfully, requestTime: %d, currentTime: %d, delta: %d (µs)\n",
reqTime,
currentTime,
currentTime-reqTime)
}

fmt.Printf("\trequest authenticated successfully, requestTime: %d, currentTime: %d, delta: %d (µs)\n",
reqTime,
currentTime,
currentTime-reqTime)

return clientId32, nil
}

Expand Down Expand Up @@ -169,7 +167,6 @@ func (b *Bank) NewClient(
}
clientId = newClientResponse["clientId"]
clientSecret = newClientResponse["clientSecret"]
return
}

func (b *Bank) CheckBalanceHttpHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ func ForgeSignatureForPublicExponent3(pubKey *rsa.PublicKey, hashAlg crypto.Hash

sigNum := new(big.Int).SetBytes(sig)
sigCleartext := new(big.Int).Exp(sigNum, big.NewInt(3), nil).Bytes()
if bytes.IndexByte(sigCleartext[:len(sigCleartext)-len(suffix)], byte(0x00)) != -1 {
fmt.Printf("sigCleartext has a zero byte, retrying\n")
} else {
if bytes.IndexByte(sigCleartext[:len(sigCleartext)-len(suffix)], byte(0x00)) == -1 {
return sig, nil
}
fmt.Printf("sigCleartext has a zero byte, retrying\n")
}
}