github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/pgp_key_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "strings" 8 "testing" 9 10 "github.com/keybase/go-crypto/openpgp" 11 ) 12 13 // See Issue #40: https://github.com/keybase/client/issues/40 14 func TestPGPGetPrimaryUID(t *testing.T) { 15 16 armored := ` 17 -----BEGIN PGP PUBLIC KEY BLOCK----- 18 Comment: GPGTools - https://gpgtools.org 19 20 mI0EVUubbgEEAKvIPrcQksiZW/dIX3sfZCSxfZqS8nojN/307rZ7323oAPTG6W7Y 21 EHfdgpKxUfMrdiNiWtujbybT8XUFhZwuPZF06BMIVmXESBr7rHLZ1Up41HmjvTtR 22 n1ejyy/tMl9zjydTIxjXsML9mPe3k3KVlrfgrbvadeM6PdYw+oE8tLZRABEBAAG0 23 IVByaW1hcnkgUHJpbWFyeSA8cHJpbWFyeUB1aWQuY29tPoi8BBMBCgAmAhsDBwsJ 24 CAcDAgEGFQgCCQoLBBYCAwECHgECF4AFAlVLm6YCGQEACgkQ5+9u0rO5NRk/4wP/ 25 WBY3/C1keVxQMdma/F6l+yeP8SQvzqTLWZKRu1tPyi2DWYu8HnVw5/Upazj/UC8u 26 4Q7OzBsU0dn+5TUrwSfuTATY7OOSgWo/Nf++rqTU2z4h8kmV/qelGTrBKvshAEMk 27 /9ejJhPcErXocHHkAGCB+V4lSC70lBsAYoriEg2jmvW0J1NlY29uZGFyeSBTZWNv 28 bmRhcnkgPHNlY29uZGFyeUB1aWQuY29tPoi5BBMBCgAjBQJVS5uBAhsDBwsJCAcD 29 AgEGFQgCCQoLBBYCAwECHgECF4AACgkQ5+9u0rO5NRmZzwP/UnO2OBcaT3doVDbz 30 o246Ur3M/USz9XVhBMabCpd4iANXswi/9iJyFW0rMn3DXAUO3Qj8yh/077FfMqUj 31 srcmbC4qtscd3X1V7hQ4rOsiEghUu2ZG8XsFxBh01NpDYxrTXQfmJeegUMAirgrA 32 r8WBLqMoZo8TarCDCw/6ygTxV6y0JFRlcnRpYXJ5IFRlcnRpYXJ5IDx0ZXJ0aWFy 33 eUB1aWQuY29tPoi5BBMBCgAjBQJVS5uVAhsDBwsJCAcDAgEGFQgCCQoLBBYCAwEC 34 HgECF4AACgkQ5+9u0rO5NRlZegP8Dl2IGu3WwF4w2Qxj/WzhTeiaLQoTzEsF0IPy 35 +f+IBO/uC/5bw/b3uNAhGK1wK3hy77II+py2x7/EvJAz2w1Ua9IMD6YuZBQaSzwV 36 tRhoHOnptdxLNDZPvZVuPl8G6p4yKLqelGymtdtpkObz9w8f+KTcieEUVeM7HbI8 37 /dwF7da4jQRVS5tuAQQAy0uPwJBoQeXz/uv5ifdXJG39cYFTaONQxa6U3/Wtx3oV 38 ibdqyygmFliHJJJyx0wjMohVbDT2sl8bHr0gpZxnkDF7+Gmcwcn/ohfKf0h7hrmL 39 W4nGNdiQiD6QZZz7ebEBuqzUmkAYg33lsYZ8MLI6wLK3sMmzA468di06YUa9eksA 40 EQEAAYifBBgBCgAJBQJVS5tuAhsMAAoJEOfvbtKzuTUZMFMD/28lUOflsdcLvJyL 41 L22yGWeoUlKMQmdbreSUo3Ibcdkpsy9ZHDHxWRBN5s/cxHtX6nna5IeHSNIdDruX 42 HKfiyXs8709e067vsE5FCTMvZCq4vt/lkEJ59xn58QBfEILMwQDNLqVGyA54MPwh 43 +NwHX7807fKQwvqyVixJoZ3yS6Js 44 =RH/W 45 -----END PGP PUBLIC KEY BLOCK----- 46 ` 47 expected := "Primary Primary <primary@uid.com>" 48 for i := 0; i < 100; i++ { 49 key, _, err := ReadOneKeyFromString(armored) 50 if err != nil { 51 t.Error(err) 52 } 53 primary := key.GetPrimaryUID() 54 if primary != expected { 55 t.Errorf("Expected '%s' as a primary UID; got '%s'", expected, primary) 56 } 57 } 58 } 59 60 func TestOpenPGPMultipleArmored(t *testing.T) { 61 // openpgp.ReadArmoredKeyRing only returns the first key block, despite what its 62 // comment says. Here's a test for that: 63 r := strings.NewReader(issue454Keys) 64 el, err := openpgp.ReadArmoredKeyRing(r) 65 if err != nil { 66 t.Fatal(err) 67 } 68 // len(el) should be 2, but it's 1: 69 /* 70 if len(el) != 2 { 71 t.Errorf("number of entities: %d, expected 2", len(el)) 72 } 73 */ 74 75 // we'll make sure that this bug still exists in openpgp, so if it ever 76 // gets fixed we can take appropriate action: 77 if len(el) != 1 { 78 if len(el) == 2 { 79 t.Errorf("openpgp.ReadArmoredKeyRing multiple keys bug fixed!") 80 } else { 81 t.Errorf("openpgp.ReadArmoredKeyRing bug changed...number entities: %d, expected 1.", len(el)) 82 } 83 } 84 } 85 86 func TestMultipleArmored(t *testing.T) { 87 88 // ReadOneKeyFromString will return the public key for issue454Keys 89 b1, _, err := ReadOneKeyFromString(issue454Keys) 90 if err != nil { 91 t.Fatal(err) 92 } 93 if b1.HasSecretKey() { 94 t.Errorf("ReadOneKeyFromString returned a private key for issue454Keys. Expected just the public key (the first one).") 95 } 96 97 // ReadPrivateKeyFromString should skip the first public key in issue454Keys 98 // and use the private key that follows it. 99 b2, _, err := ReadPrivateKeyFromString(issue454Keys) 100 if err != nil { 101 t.Fatal(err) 102 } 103 if !b2.HasSecretKey() { 104 t.Errorf("ReadPrivateKeyFromString returned only a public key for issue454Keys. Expected a private key.") 105 } 106 } 107 108 const issue454Keys = `-----BEGIN PGP PUBLIC KEY BLOCK----- 109 Comment: GPGTools - http://gpgtools.org 110 111 mQINBFVo5d8BEADByJSWkOrCQsjZcPurVIPIDSz6Fz3C7Pu+0/ZDbCDSAtZKINkN 112 OEh+YeFXENa5wrKWjXB3A3r9+X73wGztocnHRSJ688Sf6J03jCDneh2CutUELFRV 113 MXf3r63Fr3RoemF+D+AN+m5hgj7pVfw614ncBYITMQLLbOLjI2N90BLn6V2Txqg8 114 cInL2IIAoT8neySO+/0D86+89tq4OiIIbcBZwvUJS6i8ArZuw2aJC36u9/oAnPNS 115 H6K9AF7RJBMOLKExeBOiHS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UP8OHMo1s/gMNFqYo 148 oWCI0EQUT1zRjgV7PnQE550hOY2T1Gnh51UBqvTsOZXQki4cJnq7ppglIw3nG06h 149 SemxEv1SfrS/776bbXJ7gmBT5SBkY5PsztSMPdQqiVnQ103//jay3vrXZRxJqiYj 150 fwxrGQyqYbhTkIWe2QmrK4uAOgIOBc7fmMa+rDiIy5WKphaC9ELBH2JyFcPsIZZJ 151 OBAF/iTG89lyv6MuxBwOcW/gYP562vNRLhDVP+s7CXC+1cPY7w33V3fQdHdV2461 152 v1BjVH6VWtKEt8SaOHvkc/3AyZ1gc3Uc8hcUgwN6iefcAFhj2iOzMmVQ1bVot3ue 153 43rK7kZeXpuHGjz2+PxfbrOIOCGBwRRQPz0h72/kfHXtkcxrhL0StmYAAooSpq2y 154 NVRPRJ2tsXKK06ovtdgJRL9MFrND88bjLMsbxXA7ejqLyhhGTnPydDtFrzsGkw3Q 155 z5r1K2p88A2mGkix3/H0CnkcSSTxI/ID2OQndQOZ0+fFJjM8GzlFJYkW61yqV4kF 156 BNmRPFd1/mM6ofRbJ/ec6LUQkV6of9mRtSHtNTzZLpRtxqDTDVA6H/R+dqEhg/ni 157 2jAapEr4VzIbew== 158 =pyUo 159 -----END PGP PUBLIC KEY BLOCK----- 160 -----BEGIN PGP PRIVATE KEY BLOCK----- 161 Comment: GPGTools - http://gpgtools.org 162 163 lQc+BFVo5d8BEADByJSWkOrCQsjZcPurVIPIDSz6Fz3C7Pu+0/ZDbCDSAtZKINkN 164 OEh+YeFXENa5wrKWjXB3A3r9+X73wGztocnHRSJ688Sf6J03jCDneh2CutUELFRV 165 MXf3r63Fr3RoemF+D+AN+m5hgj7pVfw614ncBYITMQLLbOLjI2N90BLn6V2Txqg8 166 cInL2IIAoT8neySO+/0D86+89tq4OiIIbcBZwvUJS6i8ArZuw2aJC36u9/oAnPNS 167 H6K9AF7RJBMOLKExeBOiHSJBhnitlzqYYp24a85stpMX1XEi38pueVufs9lqzOgM 168 k6e4cfyNRLLElay2BPZ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zIbew== 265 =bXrj 266 -----END PGP PRIVATE KEY BLOCK-----` 267 268 func TestReadOneKeyFromBytes(t *testing.T) { 269 270 t.Log("If this test panics for you, then you need to update github.com/keybase/go-crypto/openpgp") 271 // found by go-fuzz: 272 // (errors are ok, panics are not...these all caused panics with an older version of 273 // openpgp) 274 _, _, err := ReadOneKeyFromBytes([]byte("\x9900\x03000000\x01\x00\x00\x00\x030")) 275 if err != nil { 276 t.Log(err) 277 } 278 _, _, err = ReadOneKeyFromBytes([]byte("\xd1\x1b\x0000000000000000000" + "000000000")) 279 if err != nil { 280 t.Log(err) 281 } 282 _, _, err = ReadOneKeyFromBytes([]byte("0\xd1\x03\x0000")) 283 if err != nil { 284 t.Log(err) 285 } 286 } 287 288 func TestPGPSubkeyWarning(t *testing.T) { 289 290 const missingCrossSignatureKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- 291 Charset: UTF-8 292 293 mQENBFMYynYBCACVOZ3/e8Bm2b9KH9QyIlHGo/i1bnkpqsgXj8tpJ2MIUOnXMMAY 294 ztW7kKFLCmgVdLIC0vSoLA4yhaLcMojznh/2CcUglZeb6Ao8Gtelr//Rd5DRfPpG 295 zqcfUo+m+eO1co2Orabw0tZDfGpg5p3AYl0hmxhUyYSc/xUq93xL1UJzBFgYXY54 296 QsM8dgeQgFseSk/YvdP5SMx1ev+eraUyiiUtWzWrWC1TdyRa5p4UZg6Rkoppf+WJ 297 QrW6BWrhAtqATHc8ozV7uJjeONjUEq24roRc/OFZdmQQGK6yrzKnnbA6MdHhqpdo 298 9kWDcXYb7pSE63Lc+OBa5X2GUVvXJLS/3nrtABEBAAG0F2ludmFsaWQtc2lnbmlu 299 Zy1zdWJrZXlziQEoBBMBAgASBQJTnKB5AhsBAgsHAhUIAh4BAAoJEO3UDQUIHpI/ 300 dN4H/idX4FQ1LIZCnpHS/oxoWQWfpRgdKAEM0qCqjMgiipJeEwSQbqjTCynuh5/R 301 JlODDz85ABR06aoF4l5ebGLQWFCYifPnJZ/Yf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EY BLOCK-----` 320 321 _, w, err := ReadOneKeyFromString(missingCrossSignatureKey) 322 if err != nil { 323 t.Error(err) 324 } 325 326 if w.IsEmpty() { 327 t.Errorf("Expected a bad subkey warning") 328 } 329 }