зеркало из https://github.com/mozilla/mig.git
429 строки
14 KiB
Go
429 строки
14 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
//
|
|
// Contributor: Aaron Meihm ameihm@mozilla.com [:alm]
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"mig.ninja/mig"
|
|
)
|
|
|
|
var keyValidUser1 = `
|
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
Version: GnuPG v1
|
|
|
|
mQENBFe2DpMBCADW6v/EsrimvQJhMDhoUEuf21Gc9j6c69fKW3Fa5Hvt/Tp1pb2v
|
|
IW7HeL/qVadZ49xfxMCoyJ+Ygf0tzcWwsgOFeVLRU2Okl5knZx9Uo7vP5EvhiRlM
|
|
GtNCYYB5dDQnYcz+LrkRFOsfKr7v66acjOSiuxfbKmg+iLfJRc6zrTN6Ql5g7fkJ
|
|
SahnbbAKo1qNOAyZEwBq/zHuTkZiBWcigQuFtc1dzLnk3cfDQ2qWf5p1z3jlxxP6
|
|
Qz5EIXaNf187BtrwEC0tqlZxfNYvx1Yka4D4MkG/YT3Vfmx89jT2EswkDZUY4jpl
|
|
9r1v/M0Amd+CXb7+k2ZSyRKo4s+LwK/XhB3pABEBAAG0CnZhbGlkdXNlcjGJATgE
|
|
EwECACIFAle2DpMCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJENodUeWs
|
|
y21/Z7gIAJsBFPk5j+Y5kflCNIj3a7qgZOVz0XEy9GZw5WafwDcAIbYw1UkPWnxd
|
|
blsly05R3QVHJdzsSLkGS3NbljPvi07+A4ld2n0QqySX4rIzhzcKKYwYLnmfMb3o
|
|
MRgAJijHF3Ddzfc5KBQmphgEScKK34tGyffrCORUPBmXG53skr9zlBnS7VAuLKYi
|
|
HJ72vlpUJ2n7YNJGQ07wvPgEuG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kfPRQTVO/g4fa3SnRw4L0I
|
|
9q/3OB+gxtaimV05nJFA4dmEccmsiDCXxQyR89KPNEJEb7ZT56NWYWmoerUIEVpc
|
|
ADOLIkgFZ529i+s0BnPqn7hCMy1ujcDtzWWFHTIRS292OLqfbQ6AeX0vE5ZAZVzr
|
|
QZXJ2IeDh4ZWZ2+DC1+mOhRZ1SpuEId5MgIFtcLrvhFDBljX2ItZg4W//VGZALmL
|
|
jVWqBem9ujvb1/c=
|
|
=ReHd
|
|
-----END PGP PUBLIC KEY BLOCK-----`
|
|
|
|
var manInsufficientSigs = `
|
|
{
|
|
"loader_name": "",
|
|
"entries": [
|
|
{
|
|
"name": "mig-loader",
|
|
"sha256": "355b34f99acaeb1ab18a7e08b7f19d54b7915fb234777bee828ed5e34b30c9de"
|
|
},
|
|
{
|
|
"name": "configuration",
|
|
"sha256": "6dcf3bc90eb5c76528edcb1f71bed7dccb886463a5c0c19b33bc1e8d25ce82d8"
|
|
},
|
|
{
|
|
"name": "mig-agent",
|
|
"sha256": "ce7e7588073021d590ede399dcf31f9148da969e333085a3e58ef78f9d8c31f2"
|
|
},
|
|
{
|
|
"name": "agentcert",
|
|
"sha256": "017525f2f851311e9b0e26a139252c13b186a6507206cbd0dcc1ca35258b9566"
|
|
},
|
|
{
|
|
"name": "cacert",
|
|
"sha256": "215394a591db4dbf2bbbb17a4d45b5bc6d335d15a7d2c42876d4b27f8269bda9"
|
|
},
|
|
{
|
|
"name": "agentkey",
|
|
"sha256": "88df8f032916dfa0ae6c4778fd2aa2084c1aac017aab70f7d4bc6f4327c5c24c"
|
|
}
|
|
],
|
|
"signatures": [
|
|
"wsBcBAABCAAQBQJXthNjCRDaHVHlrMttfwAAxaoIAFq4OSBL0kGGLqVhobmHXqqxLvEbOhdpcT5PsYM
|
|
hi+CMzE429mPatqB2PukZrTjg9z2dJgCOreGMk3PdeEG3HttfHZoXKc73jheZiwewSXGkopWxlBNs35t
|
|
+FqurpGggJTJ9M8MtK7orCxFE/ei3AYRu6vELhUz+0A5EpI2Fwuo5stiGQGxpNQG4QhZIphbZng7PThb
|
|
9Y2f1WkwUoyiDRmzjnrDCt9XYXbrywUSfWawWMmBW/Qmq58IQNmxWGK3mZq1/oQJdextS24J1LJeuCR4
|
|
1+EcqsLS9P7ujFyQD3fbKOPvk8krzFdVHpRafevXwaORc6j2hO9vVV/kgzZ2Ym8A==hdtT"
|
|
]
|
|
}`
|
|
|
|
var manCorrectSigs = `
|
|
{
|
|
"loader_name": "",
|
|
"entries": [
|
|
{
|
|
"name": "mig-loader",
|
|
"sha256": "355b34f99acaeb1ab18a7e08b7f19d54b7915fb234777bee828ed5e34b30c9de"
|
|
},
|
|
{
|
|
"name": "configuration",
|
|
"sha256": "6dcf3bc90eb5c76528edcb1f71bed7dccb886463a5c0c19b33bc1e8d25ce82d8"
|
|
},
|
|
{
|
|
"name": "mig-agent",
|
|
"sha256": "ce7e7588073021d590ede399dcf31f9148da969e333085a3e58ef78f9d8c31f2"
|
|
},
|
|
{
|
|
"name": "agentcert",
|
|
"sha256": "017525f2f851311e9b0e26a139252c13b186a6507206cbd0dcc1ca35258b9566"
|
|
},
|
|
{
|
|
"name": "cacert",
|
|
"sha256": "215394a591db4dbf2bbbb17a4d45b5bc6d335d15a7d2c42876d4b27f8269bda9"
|
|
},
|
|
{
|
|
"name": "agentkey",
|
|
"sha256": "88df8f032916dfa0ae6c4778fd2aa2084c1aac017aab70f7d4bc6f4327c5c24c"
|
|
}
|
|
],
|
|
"signatures": [
|
|
"wsBcBAABCAAQBQJXthNjCRDaHVHlrMttfwAAxaoIAFq4OSBL0kGGLqVhobmHXqqxLvEbOhdpcT5Ps
|
|
YMhi+CMzE429mPatqB2PukZrTjg9z2dJgCOreGMk3PdeEG3HttfHZoXKc73jheZiwewSXGkopWxlBN
|
|
s35t+FqurpGggJTJ9M8MtK7orCxFE/ei3AYRu6vELhUz+0A5EpI2Fwuo5stiGQGxpNQG4QhZIphbZn
|
|
g7PThb9Y2f1WkwUoyiDRmzjnrDCt9XYXbrywUSfWawWMmBW/Qmq58IQNmxWGK3mZq1/oQJdextS24J
|
|
1LJeuCR41+EcqsLS9P7ujFyQD3fbKOPvk8krzFdVHpRafevXwaORc6j2hO9vVV/kgzZ2Ym8A==hdtT",
|
|
"wsBcBAABCAAQBQJXtiG4CRC57/dAM4kP1wAAxpIIAAqsrcnBWgci5PLkqjdEorUX6J4Dm+G6VXc6f
|
|
U8mKd+jHNWxYwMj42eRY+byEHCNkWY0gyCm9epKNltZ5fLv9LmcQZrqqy7mk37MbZKubiSrMSvFyfO
|
|
mrFkKsYS+JdTzXukkmWc/nU5WUtvfe3cnvGhs8FFBuf3v9Xo/d0m0yqPKszNYkb12ZiXFynu1MhdB8
|
|
vQp4u0JrEBhyR+MC2wLhYv/zfzIMLA4CJZaleUfgHyBSAc6FeJyuR7E0e1g6ORHcDJmt8fpJpH7heU
|
|
Kr2/aLMtK8fnqijIt5UDEcxzWEVjbYY5/elofrgEAgaf3V/e4ILHSBve9tc7LN9ZwsHYvsyE==HYI1"
|
|
]
|
|
}`
|
|
|
|
var manOneInvalidSigner = `
|
|
{
|
|
"loader_name": "",
|
|
"entries": [
|
|
{
|
|
"name": "mig-loader",
|
|
"sha256": "355b34f99acaeb1ab18a7e08b7f19d54b7915fb234777bee828ed5e34b30c9de"
|
|
},
|
|
{
|
|
"name": "configuration",
|
|
"sha256": "6dcf3bc90eb5c76528edcb1f71bed7dccb886463a5c0c19b33bc1e8d25ce82d8"
|
|
},
|
|
{
|
|
"name": "mig-agent",
|
|
"sha256": "ce7e7588073021d590ede399dcf31f9148da969e333085a3e58ef78f9d8c31f2"
|
|
},
|
|
{
|
|
"name": "agentcert",
|
|
"sha256": "017525f2f851311e9b0e26a139252c13b186a6507206cbd0dcc1ca35258b9566"
|
|
},
|
|
{
|
|
"name": "cacert",
|
|
"sha256": "215394a591db4dbf2bbbb17a4d45b5bc6d335d15a7d2c42876d4b27f8269bda9"
|
|
},
|
|
{
|
|
"name": "agentkey",
|
|
"sha256": "88df8f032916dfa0ae6c4778fd2aa2084c1aac017aab70f7d4bc6f4327c5c24c"
|
|
}
|
|
],
|
|
"signatures": [
|
|
"wsBcBAABCAAQBQJXtiKTCRC57/dAM4kP1wAAsPcIAH2vraXci+ZxkOtzjdBraZjx+CK3a/GB4GIid
|
|
oteZ+nwzBI98gg8byWl2VsOgR+8DrwMxmtbVykzu5eg9KvdZlOFMAm79MD23TfJL+iFu/2uwzK8IWk
|
|
TD7rJ6PuFQzZu/KhqnLvM+96xsUke5BASpDbnwSz+JYZH/PgtY7qYuGvS2DnKjEDXFczIjnDWAaSvh
|
|
1/kwOhzAiKtRnlO/PmE4vzI3/mGX2pdX3XFQY1LMW2oE6fOgbz40+VXwBh+GRYQmb0nDaC22i10iLB
|
|
e4V0AGGQiKa5SacEcqBgSg1TYd1T9JgBLD8dOvwUGPcTdct9Cm23LTjXJyl4fMLpgvQVuCcY==mD86",
|
|
"wsBcBAABCAAQBQJXtiKmCRAomVNUrOPCwQAAt9oIABm0y5zOg/kM6/eWOxA245W6Tqs51ERP5pbXZ
|
|
cCni6ozQZPQw0DI3xa8RyupYlyRi4Ud6GdXNaakYLesHXQPu4ICZxLejtEo9gYFTczl04qfLr+vAB1
|
|
nMU6XkLw3T3GZPYdGbKcfZ/+P8Yo/DywayzkYiYBQsK50xunGwADfHUcoNNjJij/oPm5lKmEF6fi2U
|
|
HwX2ugHGcjGtanytPyNJVaWwtf3zOHPK9xkY9JzjsmVqD+lAjRMe63WzpZxp8MIrwWT7G++a54ohD6
|
|
ficeOKtuRb1yYo3Z2jwPBHyVFXuKwKUDM0xqEK7JuG39Q098d7wF6YsyyAnTEka9d58XiZXM==/JuZ"
|
|
]
|
|
}`
|
|
|
|
var manNoSignature = `
|
|
{
|
|
"loader_name": "",
|
|
"entries": [
|
|
{
|
|
"name": "mig-loader",
|
|
"sha256": "355b34f99acaeb1ab18a7e08b7f19d54b7915fb234777bee828ed5e34b30c9de"
|
|
},
|
|
{
|
|
"name": "configuration",
|
|
"sha256": "6dcf3bc90eb5c76528edcb1f71bed7dccb886463a5c0c19b33bc1e8d25ce82d8"
|
|
},
|
|
{
|
|
"name": "mig-agent",
|
|
"sha256": "ce7e7588073021d590ede399dcf31f9148da969e333085a3e58ef78f9d8c31f2"
|
|
},
|
|
{
|
|
"name": "agentcert",
|
|
"sha256": "017525f2f851311e9b0e26a139252c13b186a6507206cbd0dcc1ca35258b9566"
|
|
},
|
|
{
|
|
"name": "cacert",
|
|
"sha256": "215394a591db4dbf2bbbb17a4d45b5bc6d335d15a7d2c42876d4b27f8269bda9"
|
|
},
|
|
{
|
|
"name": "agentkey",
|
|
"sha256": "88df8f032916dfa0ae6c4778fd2aa2084c1aac017aab70f7d4bc6f4327c5c24c"
|
|
}
|
|
],
|
|
"signatures": []
|
|
}`
|
|
|
|
var manDupSigs = `
|
|
{
|
|
"loader_name": "",
|
|
"entries": [
|
|
{
|
|
"name": "mig-loader",
|
|
"sha256": "355b34f99acaeb1ab18a7e08b7f19d54b7915fb234777bee828ed5e34b30c9de"
|
|
},
|
|
{
|
|
"name": "configuration",
|
|
"sha256": "6dcf3bc90eb5c76528edcb1f71bed7dccb886463a5c0c19b33bc1e8d25ce82d8"
|
|
},
|
|
{
|
|
"name": "mig-agent",
|
|
"sha256": "ce7e7588073021d590ede399dcf31f9148da969e333085a3e58ef78f9d8c31f2"
|
|
},
|
|
{
|
|
"name": "agentcert",
|
|
"sha256": "017525f2f851311e9b0e26a139252c13b186a6507206cbd0dcc1ca35258b9566"
|
|
},
|
|
{
|
|
"name": "cacert",
|
|
"sha256": "215394a591db4dbf2bbbb17a4d45b5bc6d335d15a7d2c42876d4b27f8269bda9"
|
|
},
|
|
{
|
|
"name": "agentkey",
|
|
"sha256": "88df8f032916dfa0ae6c4778fd2aa2084c1aac017aab70f7d4bc6f4327c5c24c"
|
|
}
|
|
],
|
|
"signatures": [
|
|
"wsBcBAABCAAQBQJXthNjCRDaHVHlrMttfwAAxaoIAFq4OSBL0kGGLqVhobmHXqqxLvEbOhdpcT5Ps
|
|
YMhi+CMzE429mPatqB2PukZrTjg9z2dJgCOreGMk3PdeEG3HttfHZoXKc73jheZiwewSXGkopWxlBN
|
|
s35t+FqurpGggJTJ9M8MtK7orCxFE/ei3AYRu6vELhUz+0A5EpI2Fwuo5stiGQGxpNQG4QhZIphbZn
|
|
g7PThb9Y2f1WkwUoyiDRmzjnrDCt9XYXbrywUSfWawWMmBW/Qmq58IQNmxWGK3mZq1/oQJdextS24J
|
|
1LJeuCR41+EcqsLS9P7ujFyQD3fbKOPvk8krzFdVHpRafevXwaORc6j2hO9vVV/kgzZ2Ym8A==hdtT",
|
|
"wsBcBAABCAAQBQJXthNjCRDaHVHlrMttfwAAxaoIAFq4OSBL0kGGLqVhobmHXqqxLvEbOhdpcT5Ps
|
|
YMhi+CMzE429mPatqB2PukZrTjg9z2dJgCOreGMk3PdeEG3HttfHZoXKc73jheZiwewSXGkopWxlBN
|
|
s35t+FqurpGggJTJ9M8MtK7orCxFE/ei3AYRu6vELhUz+0A5EpI2Fwuo5stiGQGxpNQG4QhZIphbZn
|
|
g7PThb9Y2f1WkwUoyiDRmzjnrDCt9XYXbrywUSfWawWMmBW/Qmq58IQNmxWGK3mZq1/oQJdextS24J
|
|
1LJeuCR41+EcqsLS9P7ujFyQD3fbKOPvk8krzFdVHpRafevXwaORc6j2hO9vVV/kgzZ2Ym8A==hdtT"
|
|
]
|
|
}`
|
|
|
|
func getLogs() {
|
|
ctx.Channels.Log = make(chan mig.Log, 0)
|
|
go func() {
|
|
for {
|
|
_ = <-ctx.Channels.Log
|
|
}
|
|
}()
|
|
}
|
|
|
|
func manResponse(in string) (mr mig.ManifestResponse, err error) {
|
|
buf := strings.Replace(in, " ", "", -1)
|
|
buf = strings.Replace(buf, "\n", "", -1)
|
|
err = json.Unmarshal([]byte(buf), &mr)
|
|
return
|
|
}
|
|
|
|
func TestInsufficientSigs(t *testing.T) {
|
|
var (
|
|
keys []string
|
|
)
|
|
getLogs()
|
|
keys = append(keys, keyValidUser1)
|
|
keys = append(keys, keyValidUser2)
|
|
REQUIREDSIGNATURES = 2
|
|
mr, err := manResponse(string(manInsufficientSigs))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = checkManifestSignature(&mr, keys)
|
|
if err == nil {
|
|
t.Fatal("signature check passed")
|
|
}
|
|
if !strings.Contains(err.Error(), "Not enough valid signatures") {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestCorrectSigs(t *testing.T) {
|
|
var (
|
|
keys []string
|
|
)
|
|
getLogs()
|
|
keys = append(keys, keyValidUser1)
|
|
keys = append(keys, keyValidUser2)
|
|
REQUIREDSIGNATURES = 2
|
|
mr, err := manResponse(string(manCorrectSigs))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = checkManifestSignature(&mr, keys)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestOneInvalidSigner(t *testing.T) {
|
|
var (
|
|
keys []string
|
|
)
|
|
getLogs()
|
|
keys = append(keys, keyValidUser1)
|
|
keys = append(keys, keyValidUser2)
|
|
REQUIREDSIGNATURES = 2
|
|
mr, err := manResponse(string(manOneInvalidSigner))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = checkManifestSignature(&mr, keys)
|
|
if err == nil {
|
|
t.Fatal("signature check passed")
|
|
}
|
|
if !strings.Contains(err.Error(), "unknown entity") {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestNoSignature(t *testing.T) {
|
|
var (
|
|
keys []string
|
|
)
|
|
getLogs()
|
|
keys = append(keys, keyValidUser1)
|
|
keys = append(keys, keyValidUser2)
|
|
REQUIREDSIGNATURES = 2
|
|
mr, err := manResponse(string(manNoSignature))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = checkManifestSignature(&mr, keys)
|
|
if err == nil {
|
|
t.Fatal("signature check passed")
|
|
}
|
|
if !strings.Contains(err.Error(), "got 0, need 2") {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestDupSignature(t *testing.T) {
|
|
var (
|
|
keys []string
|
|
)
|
|
getLogs()
|
|
keys = append(keys, keyValidUser1)
|
|
keys = append(keys, keyValidUser2)
|
|
REQUIREDSIGNATURES = 2
|
|
mr, err := manResponse(string(manDupSigs))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = checkManifestSignature(&mr, keys)
|
|
if err == nil {
|
|
t.Fatal("signature check passed")
|
|
}
|
|
if !strings.Contains(err.Error(), "duplicate signature") {
|
|
t.Fatal(err)
|
|
}
|
|
}
|