39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package rabbitproxy
|
|
|
|
import "encoding/binary"
|
|
|
|
// Strict readonly permits passive inspection but never delivery or acknowledgement.
|
|
func readonlyAllowed(f frame) bool {
|
|
if f.kind == 8 {
|
|
return f.channel == 0 && len(f.body) == 0
|
|
}
|
|
if f.kind != 1 || len(f.body) < 4 {
|
|
return false
|
|
}
|
|
class, id := binary.BigEndian.Uint16(f.body), binary.BigEndian.Uint16(f.body[2:])
|
|
switch class {
|
|
case 10:
|
|
return id == 50 || id == 51 // connection.close / close-ok
|
|
case 20:
|
|
return id == 10 || id == 20 || id == 21 || id == 40 || id == 41
|
|
case 40, 50:
|
|
if id != 10 || len(f.body) < 7 {
|
|
return false
|
|
}
|
|
name, rest, err := short(f.body[6:])
|
|
if err != nil || name == "" {
|
|
return false
|
|
}
|
|
if class == 40 {
|
|
_, rest, err = short(rest) // exchange type precedes flags
|
|
}
|
|
// Only passive inspection, never active declaration or auto-delete.
|
|
if err != nil || len(rest) < 5 || rest[0]&1 == 0 || rest[0]&^byte(1|2|16) != 0 {
|
|
return false
|
|
}
|
|
_, tail, err := long(rest[1:])
|
|
return err == nil && len(tail) == 0
|
|
}
|
|
return false
|
|
}
|