github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/code.google.com/p/go.crypto/ocsp/ocsp_test.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ocsp 6 7 import ( 8 "bytes" 9 "encoding/hex" 10 "reflect" 11 "testing" 12 "time" 13 ) 14 15 func TestOCSPDecode(t *testing.T) { 16 responseBytes, _ := hex.DecodeString(ocspResponseHex) 17 resp, err := ParseResponse(responseBytes) 18 if err != nil { 19 t.Error(err) 20 } 21 22 expected := Response{ 23 Status: 0, 24 SerialNumber: []byte{0x1, 0xd0, 0xfa}, 25 RevocationReason: 0, 26 ThisUpdate: time.Date(2010, 7, 7, 15, 1, 5, 0, time.UTC), 27 NextUpdate: time.Date(2010, 7, 7, 18, 35, 17, 0, time.UTC), 28 } 29 30 if !reflect.DeepEqual(resp.ThisUpdate, expected.ThisUpdate) { 31 t.Errorf("resp.ThisUpdate: got %d, want %d", resp.ThisUpdate, expected.ThisUpdate) 32 } 33 34 if !reflect.DeepEqual(resp.NextUpdate, expected.NextUpdate) { 35 t.Errorf("resp.NextUpdate: got %d, want %d", resp.NextUpdate, expected.NextUpdate) 36 } 37 38 if resp.Status != expected.Status { 39 t.Errorf("resp.Status: got %d, want %d", resp.Status, expected.Status) 40 } 41 42 if !bytes.Equal(resp.SerialNumber, expected.SerialNumber) { 43 t.Errorf("resp.SerialNumber: got %x, want %x", resp.SerialNumber, expected.SerialNumber) 44 } 45 46 if resp.RevocationReason != expected.RevocationReason { 47 t.Errorf("resp.RevocationReason: got %d, want %d", resp.RevocationReason, expected.RevocationReason) 48 } 49 } 50 51 // This OCSP response was taken from Thawte's public OCSP responder. 52 // To recreate: 53 // $ openssl s_client -tls1 -showcerts -servername www.google.com -connect www.google.com:443 54 // Copy and paste the first certificate into /tmp/cert.crt and the second into 55 // /tmp/intermediate.crt 56 // $ openssl ocsp -issuer /tmp/intermediate.crt -cert /tmp/cert.crt -url http://ocsp.thawte.com -resp_text -respout /tmp/ocsp.der 57 // Then hex encode the result: 58 // $ python -c 'print file("/tmp/ocsp.der", "r").read().encode("hex")' 59 60 const ocspResponseHex = "308206bc0a0100a08206b5308206b106092b0601050507300101048206a23082069e3081" + 61 "c9a14e304c310b300906035504061302494c31163014060355040a130d5374617274436f" + 62 "6d204c74642e312530230603550403131c5374617274436f6d20436c6173732031204f43" + 63 "5350205369676e6572180f32303130303730373137333531375a30663064303c30090605" + 64 "2b0e03021a050004146568874f40750f016a3475625e1f5c93e5a26d580414eb4234d098" + 65 "b0ab9ff41b6b08f7cc642eef0e2c45020301d0fa8000180f323031303037303731353031" + 66 "30355aa011180f32303130303730373138333531375a300d06092a864886f70d01010505" + 67 "000382010100ab557ff070d1d7cebbb5f0ec91a15c3fed22eb2e1b8244f1b84545f013a4" + 68 "fb46214c5e3fbfbebb8a56acc2b9db19f68fd3c3201046b3824d5ba689f99864328710cb" + 69 "467195eb37d84f539e49f859316b32964dc3e47e36814ce94d6c56dd02733b1d0802f7ff" + 70 "4eebdbbd2927dcf580f16cbc290f91e81b53cb365e7223f1d6e20a88ea064104875e0145" + 71 "672b20fc14829d51ca122f5f5d77d3ad6c83889c55c7dc43680ba2fe3cef8b05dbcabdc0" + 72 "d3e09aaf9725597f8c858c2fa38c0d6aed2e6318194420dd1a1137445d13e1c97ab47896" + 73 "17a4e08925f46f867b72e3a4dc1f08cb870b2b0717f7207faa0ac512e628a029aba7457a" + 74 "e63dcf3281e2162d9349a08204ba308204b6308204b23082039aa003020102020101300d" + 75 "06092a864886f70d010105050030818c310b300906035504061302494c31163014060355" + 76 "040a130d5374617274436f6d204c74642e312b3029060355040b13225365637572652044" + 77 "69676974616c204365727469666963617465205369676e696e6731383036060355040313" + 78 "2f5374617274436f6d20436c6173732031205072696d61727920496e7465726d65646961" + 79 "746520536572766572204341301e170d3037313032353030323330365a170d3132313032" + 80 "333030323330365a304c310b300906035504061302494c31163014060355040a130d5374" + 81 "617274436f6d204c74642e312530230603550403131c5374617274436f6d20436c617373" + 82 "2031204f435350205369676e657230820122300d06092a864886f70d0101010500038201" + 83 "0f003082010a0282010100b9561b4c45318717178084e96e178df2255e18ed8d8ecc7c2b" + 84 "7b51a6c1c2e6bf0aa3603066f132fe10ae97b50e99fa24b83fc53dd2777496387d14e1c3" + 85 "a9b6a4933e2ac12413d085570a95b8147414a0bc007c7bcf222446ef7f1a156d7ea1c577" + 86 "fc5f0facdfd42eb0f5974990cb2f5cefebceef4d1bdc7ae5c1075c5a99a93171f2b0845b" + 87 "4ff0864e973fcfe32f9d7511ff87a3e943410c90a4493a306b6944359340a9ca96f02b66" + 88 "ce67f028df2980a6aaee8d5d5d452b8b0eb93f923cc1e23fcccbdbe7ffcb114d08fa7a6a" + 89 "3c404f825d1a0e715935cf623a8c7b59670014ed0622f6089a9447a7a19010f7fe58f841" + 90 "29a2765ea367824d1c3bb2fda308530203010001a382015c30820158300c0603551d1301" + 91 "01ff04023000300b0603551d0f0404030203a8301e0603551d250417301506082b060105" + 92 "0507030906092b0601050507300105301d0603551d0e0416041445e0a36695414c5dd449" + 93 "bc00e33cdcdbd2343e173081a80603551d230481a030819d8014eb4234d098b0ab9ff41b" + 94 "6b08f7cc642eef0e2c45a18181a47f307d310b300906035504061302494c311630140603" + 95 "55040a130d5374617274436f6d204c74642e312b3029060355040b132253656375726520" + 96 "4469676974616c204365727469666963617465205369676e696e67312930270603550403" + 97 "13205374617274436f6d2043657274696669636174696f6e20417574686f726974798201" + 98 "0a30230603551d12041c301a8618687474703a2f2f7777772e737461727473736c2e636f" + 99 "6d2f302c06096086480186f842010d041f161d5374617274436f6d205265766f63617469" + 100 "6f6e20417574686f72697479300d06092a864886f70d01010505000382010100182d2215" + 101 "8f0fc0291324fa8574c49bb8ff2835085adcbf7b7fc4191c397ab6951328253fffe1e5ec" + 102 "2a7da0d50fca1a404e6968481366939e666c0a6209073eca57973e2fefa9ed1718e8176f" + 103 "1d85527ff522c08db702e3b2b180f1cbff05d98128252cf0f450f7dd2772f4188047f19d" + 104 "c85317366f94bc52d60f453a550af58e308aaab00ced33040b62bf37f5b1ab2a4f7f0f80" + 105 "f763bf4d707bc8841d7ad9385ee2a4244469260b6f2bf085977af9074796048ecc2f9d48" + 106 "a1d24ce16e41a9941568fec5b42771e118f16c106a54ccc339a4b02166445a167902e75e" + 107 "6d8620b0825dcd18a069b90fd851d10fa8effd409deec02860d26d8d833f304b10669b42"