Debian Codegraph @

x509/x509_test.go

raw symbols SCIP
1 // Copyright 2009 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 x509scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/
6
7 import (
8 "bytesscip-go gomod github.com/golang/go/src go1.16 bytes/"
9 "crypto/ecdsascip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/"
10 "crypto/ellipticscip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/"
11 "crypto/randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/"
12 "crypto/rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/"
13 _ "crypto/sha256scip-go gomod github.com/golang/go/src go1.16 `crypto/sha256`/"
14 _ "crypto/sha512scip-go gomod github.com/golang/go/src go1.16 `crypto/sha512`/"
15 "encoding/base64scip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/"
16 "encoding/hexscip-go gomod github.com/golang/go/src go1.16 `encoding/hex`/"
17 "encoding/pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/"
18 "ioscip-go gomod github.com/golang/go/src go1.16 io/"
19 "io/ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/"
20 "math/bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/"
21 "netscip-go gomod github.com/golang/go/src go1.16 net/"
22 "os/execscip-go gomod github.com/golang/go/src go1.16 `os/exec`/"
23 "reflectscip-go gomod github.com/golang/go/src go1.16 reflect/"
24 "runtimescip-go gomod github.com/golang/go/src go1.16 runtime/"
25 "testingscip-go gomod github.com/golang/go/src go1.16 testing/"
26 "timescip-go gomod github.com/golang/go/src go1.16 time/"
27
28 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/assert`/"
29 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/"
30 "github.com/zmap/zcrypto/dsascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/"
31 "github.com/zmap/zcrypto/encoding/asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/"
32 "github.com/zmap/zcrypto/x509/pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/"
33 "golang.org/x/crypto/curve25519scip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/curve25519`/"
34 "golang.org/x/crypto/ed25519scip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/ed25519`/"
35 )
36
37 func TestParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParsePKCS1PrivateKey().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
38 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
39 priv, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
40 if err != nil {
41 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Failed to parse private key: %s", err)
42 return
43 }
44 if priv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey..PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N.) != 0 ||
45 priv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E. != rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey..PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E. ||
46 priv.Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey..Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D.) != 0 ||
47 priv.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[0].Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey..Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[0]) != 0 ||
48 priv.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[1].Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey..Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[1]) != 0 {
49 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("got:%+v want:%+v", priv, rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey.)
50 }
51 }
52
53 func TestParsePKIXPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParsePKIXPublicKey().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
54 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPublicKey.))
55 pub, err := ParsePKIXPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKIXPublicKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
56 if err != nil {
57 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Failed to parse RSA public key: %s", err)
58 return
59 }
60 rsaPub, ok := pub.(*rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#)
61 if !ok {
62 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Value returned from ParsePKIXPublicKey was not an RSA public key")
63 return
64 }
65
66 pubBytes2, err := MarshalPKIXPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/MarshalPKIXPublicKey().(rsaPub)
67 if err != nil {
68 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Failed to marshal RSA public key for the second time: %s", err)
69 return
70 }
71 if !bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Equalscip-go gomod github.com/golang/go/src go1.16 bytes/Equal().(pubBytes2, block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.) {
72 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Reserialization of public key didn't match. got %x, want %x", pubBytes2, block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
73 }
74 }
75
76 var pemPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPublicKey. = `-----BEGIN PUBLIC KEY-----
77 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3VoPN9PKUjKFLMwOge6+
78 wnDi8sbETGIx2FKXGgqtAKpzmem53kRGEQg8WeqRmp12wgp74TGpkEXsGae7RS1k
79 enJCnma4fii+noGH7R0qKgHvPrI2Bwa9hzsH8tHxpyM3qrXslOmD45EH9SxIDUBJ
80 FehNdaPbLP1gFyahKMsdfxFJLUvbUycuZSJ2ZnIgeVxwm4qbSvZInL9Iu4FzuPtg
81 fINKcbbovy1qq4KvPIrXzhbY3PWDc6btxCf3SE0JdE1MCPThntB62/bLMSQ7xdDR
82 FF53oIpvxe/SCOymfWq/LW849Ytv3Xwod0+wzAP8STXG4HSELS4UedPYeHJJJYcZ
83 +QIDAQAB
84 -----END PUBLIC KEY-----
85 `
86
87 var pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey. = `-----BEGIN RSA PRIVATE KEY-----
88 MIIBOgIBAAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0
89 fd7Ai2KW5ToIwzFofvJcS/STa6HA5gQenRUCAwEAAQJBAIq9amn00aS0h/CrjXqu
90 /ThglAXJmZhOMPVn4eiu7/ROixi9sex436MaVeMqSNf7Ex9a8fRNfWss7Sqd9eWu
91 RTUCIQDasvGASLqmjeffBNLTXV2A5g4t+kLVCpsEIZAycV5GswIhANEPLmax0ME/
92 EO+ZJ79TJKN5yiGBRsv5yvx5UiHxajEXAiAhAol5N4EUyq6I9w1rYdhPMGpLfk7A
93 IU2snfRJ6Nq2CQIgFrPsWRCkV+gOYcajD17rEqmuLrdIRexpg8N1DOSXoJ8CIGlS
94 tAboUGBxTDq3ZroNism3DaMIbKPyYrAqhKov1h5V
95 -----END RSA PRIVATE KEY-----
96 `
97
98 func bigFromStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromString().(s string) *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# {
99 ret := new(bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#)
100 ret.SetStringscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#SetString().(s, 10)
101 return ret
102 }
103
104 func fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().(base10 string) *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# {
105 i := new(bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#)
106 i.SetStringscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#SetString().(base10, 10)
107 return i
108 }
109
110 func bigFromHexStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromHexString().(s string) *bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int# {
111 ret := new(bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#)
112 ret.SetStringscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#SetString().(s, 16)
113 return ret
114 }
115
116 var rsaPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/rsaPrivateKey. = &rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#{
117 PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey.: rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#{
118 Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N.: bigFromStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromString().("9353930466774385905609975137998169297361893554149986716853295022578535724979677252958524466350471210367835187480748268864277464700638583474144061408845077"),
119 Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E.: 65537,
120 },
121 Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D.: bigFromStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromString().("7266398431328116344057699379749222532279343923819063639497049039389899328538543087657733766554155839834519529439851673014800261285757759040931985506583861"),
122 Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.: []*bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#{
123 bigFromStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromString().("98920366548084643601728869055592650835572950932266967461790948584315647051443"),
124 bigFromStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromString().("94560208308847015747498523884063394671606671904944666360068158221458669711639"),
125 },
126 }
127
128 func TestMarshalRSAPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestMarshalRSAPrivateKey().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
129 priv := &rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#{
130 PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey.: rsascip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#{
131 Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N.: fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().("16346378922382193400538269749936049106320265317511766357599732575277382844051791096569333808598921852351577762718529818072849191122419410612033592401403764925096136759934497687765453905884149505175426053037420486697072448609022753683683718057795566811401938833367954642951433473337066311978821180526439641496973296037000052546108507805269279414789035461158073156772151892452251106173507240488993608650881929629163465099476849643165682709047462010581308719577053905787496296934240246311806555924593059995202856826239801816771116902778517096212527979497399966526283516447337775509777558018145573127308919204297111496233"),
132 Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E.: 3,
133 },
134 Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D.: fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().("10897585948254795600358846499957366070880176878341177571733155050184921896034527397712889205732614568234385175145686545381899460748279607074689061600935843283397424506622998458510302603922766336783617368686090042765718290914099334449154829375179958369993407724946186243249568928237086215759259909861748642124071874879861299389874230489928271621259294894142840428407196932444474088857746123104978617098858619445675532587787023228852383149557470077802718705420275739737958953794088728369933811184572620857678792001136676902250566845618813972833750098806496641114644760255910789397593428910198080271317419213080834885003"),
135 Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.: []*bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#{
136 fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().("1025363189502892836833747188838978207017355117492483312747347695538428729137306368764177201532277413433182799108299960196606011786562992097313508180436744488171474690412562218914213688661311117337381958560443"),
137 fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().("3467903426626310123395340254094941045497208049900750380025518552334536945536837294961497712862519984786362199788654739924501424784631315081391467293694361474867825728031147665777546570788493758372218019373"),
138 fromBase10scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase10().("4597024781409332673052708605078359346966325141767460991205742124888960305710298765592730135879076084498363772408626791576005136245060321874472727132746643162385746062759369754202494417496879741537284589047"),
139 },
140 }
141
142 derBytes := MarshalPKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/MarshalPKCS1PrivateKey().(priv)
143
144 priv2, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(derBytes)
145 if err != nil {
146 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("error parsing serialized key: %s", err)
147 return
148 }
149 if priv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(priv2.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Nscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#N.) != 0 ||
150 priv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E. != priv2.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey..Escip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PublicKey#E. ||
151 priv.Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(priv2.Dscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#D.) != 0 ||
152 len(priv2.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.) != 3 ||
153 priv.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[0].Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(priv2.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[0]) != 0 ||
154 priv.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[1].Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(priv2.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[1]) != 0 ||
155 priv.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[2].Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(priv2.Primesscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#Primes.[2]) != 0 {
156 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("got:%+v want:%+v", priv, priv2)
157 }
158 }
159
160 type matchHostnamesTestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTest# struct {
161 patternscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTest#pattern., hostscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTest#host. string
162 okscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTest#ok. bool
163 }
164
165 var matchHostnamesTestsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTests. = []matchHostnamesTestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/matchHostnamesTest#{
166 {"a.b.c", "a.b.c", true},
167 {"a.b.c", "b.b.c", false},
168 {"", "b.b.c", false},
169 {"a.b.c", "", false},
170 {"example.com", "example.com", true},
171 {"example.com", "www.example.com", false},
172 {"*.example.com", "www.example.com", true},
173 {"*.example.com", "xyz.www.example.com", false},
174 {"*.*.example.com", "xyz.www.example.com", true},
175 {"*.www.*.com", "xyz.www.example.com", true},
176 }
177
178 func TestCertificateParsescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCertificateParse().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
179 s, _ := hexscip-go gomod github.com/golang/go/src go1.16 `encoding/hex`/.DecodeStringscip-go gomod github.com/golang/go/src go1.16 `encoding/hex`/DecodeString().(certBytesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/certBytes.)
180 certs, err := ParseCertificatesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificates().(s)
181 if err != nil {
182 t.Errorscip-go gomod github.com/golang/go/src go1.16 testing/common#Error().(err)
183 }
184 if len(certs) != 2 {
185 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Wrong number of certs: got %d want 2", len(certs))
186 return
187 }
188
189 err = certs[0].CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(certs[1])
190 if err != nil {
191 t.Errorscip-go gomod github.com/golang/go/src go1.16 testing/common#Error().(err)
192 }
193
194 const expectedExtensions = 4
195 if n := len(certs[0].Extensionsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Extensions.); n != expectedExtensions {
196 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("want %d extensions, got %d", expectedExtensions, n)
197 }
198
199 if extMap := certs[0].ExtensionsMapscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtensionsMap.; extMap == nil {
200 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().("expected non-nil ExtensionsMap, got nil")
201 } else if len(extMap) != expectedExtensions {
202 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("wanted %d extensions in ExtensionsMap, got %d",
203 expectedExtensions, len(extMap))
204 }
205
206 expectedOIDs := []string{
207 "2.5.29.31",
208 "1.3.6.1.5.5.7.1.1",
209 "2.5.29.19",
210 "2.5.29.37",
211 }
212 for _, expectedOID := range expectedOIDs {
213 if ext, present := certs[0].ExtensionsMapscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtensionsMap.[expectedOID]; !present {
214 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("expected oid %q missing in ExtensionsMap", expectedOID)
215 } else if ext.Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id..Stringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#String().() != expectedOID {
216 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("expected oid %q in ExtensionsMap to key "+
217 "pkix.Extension with same oid, got %q",
218 expectedOID, ext.Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id..Stringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#String().())
219 }
220 }
221 }
222
223 var certBytesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/certBytes. = "308203223082028ba00302010202106edf0d9499fd4533dd1297fc42a93be1300d06092a864886" +
224 "f70d0101050500304c310b3009060355040613025a4131253023060355040a131c546861777465" +
225 "20436f6e73756c74696e67202850747929204c74642e311630140603550403130d546861777465" +
226 "20534743204341301e170d3039303332353136343932395a170d3130303332353136343932395a" +
227 "3069310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630" +
228 "140603550407130d4d6f756e7461696e205669657731133011060355040a130a476f6f676c6520" +
229 "496e63311830160603550403130f6d61696c2e676f6f676c652e636f6d30819f300d06092a8648" +
230 "86f70d010101050003818d0030818902818100c5d6f892fccaf5614b064149e80a2c9581a218ef" +
231 "41ec35bd7a58125ae76f9ea54ddc893abbeb029f6b73616bf0ffd868791fba7af9c4aebf3706ba" +
232 "3eeaeed27435b4ddcfb157c05f351d66aa87fee0de072d66d773affbd36ab78bef090e0cc861a9" +
233 "03ac90dd98b51c9c41566c017f0beec3bff391051ffba0f5cc6850ad2a590203010001a381e730" +
234 "81e430280603551d250421301f06082b0601050507030106082b06010505070302060960864801" +
235 "86f842040130360603551d1f042f302d302ba029a0278625687474703a2f2f63726c2e74686177" +
236 "74652e636f6d2f54686177746553474343412e63726c307206082b060105050701010466306430" +
237 "2206082b060105050730018616687474703a2f2f6f6373702e7468617774652e636f6d303e0608" +
238 "2b060105050730028632687474703a2f2f7777772e7468617774652e636f6d2f7265706f736974" +
239 "6f72792f5468617774655f5347435f43412e637274300c0603551d130101ff04023000300d0609" +
240 "2a864886f70d01010505000381810062f1f3050ebc105e497c7aedf87e24d2f4a986bb3b837bd1" +
241 "9b91ebcad98b065992f6bd2b49b7d6d3cb2e427a99d606c7b1d46352527fac39e6a8b6726de5bf" +
242 "70212a52cba07634a5e332011bd1868e78eb5e3c93cf03072276786f207494feaa0ed9d53b2110" +
243 "a76571f90209cdae884385c882587030ee15f33d761e2e45a6bc308203233082028ca003020102" +
244 "020430000002300d06092a864886f70d0101050500305f310b3009060355040613025553311730" +
245 "15060355040a130e566572695369676e2c20496e632e31373035060355040b132e436c61737320" +
246 "33205075626c6963205072696d6172792043657274696669636174696f6e20417574686f726974" +
247 "79301e170d3034303531333030303030305a170d3134303531323233353935395a304c310b3009" +
248 "060355040613025a4131253023060355040a131c54686177746520436f6e73756c74696e672028" +
249 "50747929204c74642e311630140603550403130d5468617774652053474320434130819f300d06" +
250 "092a864886f70d010101050003818d0030818902818100d4d367d08d157faecd31fe7d1d91a13f" +
251 "0b713cacccc864fb63fc324b0794bd6f80ba2fe10493c033fc093323e90b742b71c403c6d2cde2" +
252 "2ff50963cdff48a500bfe0e7f388b72d32de9836e60aad007bc4644a3b847503f270927d0e62f5" +
253 "21ab693684317590f8bfc76c881b06957cc9e5a8de75a12c7a68dfd5ca1c875860190203010001" +
254 "a381fe3081fb30120603551d130101ff040830060101ff020100300b0603551d0f040403020106" +
255 "301106096086480186f842010104040302010630280603551d110421301fa41d301b3119301706" +
256 "035504031310507269766174654c6162656c332d313530310603551d1f042a30283026a024a022" +
257 "8620687474703a2f2f63726c2e766572697369676e2e636f6d2f706361332e63726c303206082b" +
258 "0601050507010104263024302206082b060105050730018616687474703a2f2f6f6373702e7468" +
259 "617774652e636f6d30340603551d25042d302b06082b0601050507030106082b06010505070302" +
260 "06096086480186f8420401060a6086480186f845010801300d06092a864886f70d010105050003" +
261 "81810055ac63eadea1ddd2905f9f0bce76be13518f93d9052bc81b774bad6950a1eededcfddb07" +
262 "e9e83994dcab72792f06bfab8170c4a8edea5334edef1e53d906c7562bd15cf4d18a8eb42bb137" +
263 "9048084225c53e8acb7feb6f04d16dc574a2f7a27c7b603c77cd0ece48027f012fb69b37e02a2a" +
264 "36dcd585d6ace53f546f961e05af"
265
266 func TestCreateSelfSignedCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCreateSelfSignedCertificate().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
267 random := randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.
268
269 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
270 rsaPriv, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
271 if err != nil {
272 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse private key: %s", err)
273 }
274
275 ecdsaPriv, err := ecdsascip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/GenerateKey().(ellipticscip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/.P256scip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/P256().(), randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.)
276 if err != nil {
277 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to generate ECDSA key: %s", err)
278 }
279
280 byt := make([]byte, 0)
281 null := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.BitStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/BitString#{Bytesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/BitString#Bytes.: byt, BitLengthscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/BitString#BitLength.: 0}
282
283 ed25519Pub, ed25519Priv, err := ed25519scip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/ed25519`/.GenerateKeyscip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/ed25519`/GenerateKey().(nil)
284 if err != nil {
285 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to generate Ed25519 key: %s", err)
286 }
287 var pubkey, privkey [32]byte
288 if _, err := ioscip-go gomod github.com/golang/go/src go1.16 io/.ReadFullscip-go gomod github.com/golang/go/src go1.16 io/ReadFull().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., privkey[:]); err != nil {
289 panic(err)
290 }
291 curve25519scip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/curve25519`/.ScalarBaseMultscip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/curve25519`/ScalarBaseMult().(&pubkey, &privkey)
292 x25519Pub := X25519PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/X25519PublicKey#(pubkey[:])
293
294 tests := []struct {
295 name string
296 pub, priv interface{}
297 checkSig bool
298 sigAlgo SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SignatureAlgorithm#
299 selfSigned bool
300 }{
301 {"RSA/RSA", &rsaPriv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey., rsaPriv, true, SHA1WithRSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SHA1WithRSA., true},
302 {"RSA/ECDSA", &rsaPriv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey., ecdsaPriv, false, ECDSAWithSHA384scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA384., false},
303 {"ECDSA/RSA", &AugmentedECDSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#{Pubscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#Pub.: &ecdsaPriv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/PrivateKey#PublicKey., Rawscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#Raw.: null}, rsaPriv, false, SHA256WithRSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SHA256WithRSA., false},
304 {"ECDSA/ECDSA", &AugmentedECDSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#{Pubscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#Pub.: &ecdsaPriv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/PrivateKey#PublicKey., Rawscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#Raw.: null}, ecdsaPriv, true, ECDSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA1., true},
305 {"Ed25519/Ed25519", ed25519Pub, ed25519Priv, true, Ed25519Sigscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Ed25519Sig., true},
306 {"X25519/Ed25519", x25519Pub, ed25519Priv, false, Ed25519Sigscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Ed25519Sig., false},
307 }
308
309 testExtKeyUsage := []ExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ExtKeyUsage#{ExtKeyUsageClientAuthscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ExtKeyUsageClientAuth., ExtKeyUsageServerAuthscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ExtKeyUsageServerAuth.}
310 testUnknownExtKeyUsage := []asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#{[]int{1, 2, 3}, []int{2, 59, 1}}
311 extraExtensionData := []byte("extra extension")
312
313 for _, test := range tests {
314 commonName := "test.example.com"
315 template := Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#{
316 SerialNumberscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SerialNumber.: bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(1),
317 Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Subject.: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Namescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#{
318 CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName.: commonName,
319 Organizationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Organization.: []string{"Σ Acme Co"},
320 },
321 NotBeforescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#NotBefore.: timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(1000, 0),
322 NotAfterscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#NotAfter.: timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(100000, 0),
323
324 SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm.: test.sigAlgo,
325
326 SubjectKeyIdscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SubjectKeyId.: []byte{1, 2, 3, 4},
327 KeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#KeyUsage.: KeyUsageCertSignscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/KeyUsageCertSign.,
328
329 ExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtKeyUsage.: testExtKeyUsage,
330 UnknownExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#UnknownExtKeyUsage.: testUnknownExtKeyUsage,
331
332 BasicConstraintsValidscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#BasicConstraintsValid.: true,
333 IsCAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IsCA.: true,
334
335 OCSPServerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#OCSPServer.: []string{"http://ocsp.example.com"},
336 IssuingCertificateURLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IssuingCertificateURL.: []string{"http://crt.example.com/ca1.crt"},
337
338 DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#DNSNames.: []string{"test.example.com"},
339 EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#EmailAddresses.: []string{"[email protected]"},
340 IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IPAddresses.: []netscip-go gomod github.com/golang/go/src go1.16 net/.IPscip-go gomod github.com/golang/go/src go1.16 net/IP#{netscip-go gomod github.com/golang/go/src go1.16 net/.IPv4scip-go gomod github.com/golang/go/src go1.16 net/IPv4().(127, 0, 0, 1).To4scip-go gomod github.com/golang/go/src go1.16 net/IP#To4().(), netscip-go gomod github.com/golang/go/src go1.16 net/.ParseIPscip-go gomod github.com/golang/go/src go1.16 net/ParseIP().("2001:4860:0:2001::68")},
341
342 PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers.: []asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#{[]int{1, 2, 3}, []int{2, 23, 140, 1, 1}},
343 PermittedDNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PermittedDNSNames.: []GeneralSubtreeStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/GeneralSubtreeString#{{Datascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/GeneralSubtreeString#Data.: ".example.com"}, {Datascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/GeneralSubtreeString#Data.: "example.com"}},
344
345 CRLDistributionPointsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CRLDistributionPoints.: []string{"http://crl1.example.com/ca1.crl", "http://crl2.example.com/ca1.crl"},
346
347 ExtraExtensionsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtraExtensions.: []pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{
348 {
349 Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id.: []int{1, 2, 3, 4},
350 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: extraExtensionData,
351 },
352 // This extension should override the SubjectKeyId, above.
353 {
354 Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id.: oidExtensionSubjectKeyIdscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionSubjectKeyId.,
355 Criticalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Critical.: false,
356 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: []byte{0x04, 0x04, 4, 3, 2, 1},
357 },
358 },
359 }
360
361 derBytes, err := CreateCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CreateCertificate().(random, &template, &template, test.pub, test.priv)
362 if err != nil {
363 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to create certificate: %s", test.name, err)
364 continue
365 }
366
367 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(derBytes)
368 if err != nil {
369 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to parse certificate: %s", test.name, err)
370 continue
371 }
372
373 if len(cert.PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers.) != 2 || !cert.PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers.[0].Equalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#Equal().(template.PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers.[0]) {
374 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to parse policy identifiers: got:%#v want:%#v", test.name, cert.PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers., template.PolicyIdentifiersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PolicyIdentifiers.)
375 }
376
377 if len(cert.PermittedDNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PermittedDNSNames.) != 2 || cert.PermittedDNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PermittedDNSNames.[0].Datascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/GeneralSubtreeString#Data. != ".example.com" || cert.PermittedDNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PermittedDNSNames.[1].Datascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/GeneralSubtreeString#Data. != "example.com" {
378 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to parse name constraints: %#v", test.name, cert.PermittedDNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PermittedDNSNames.)
379 }
380
381 if cert.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Subject..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName. != commonName {
382 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: subject wasn't correctly copied from the template. Got %s, want %s", test.name, cert.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Subject..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName., commonName)
383 }
384
385 if cert.Issuerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Issuer..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName. != commonName {
386 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: issuer wasn't correctly copied from the template. Got %s, want %s", test.name, cert.Issuerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Issuer..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName., commonName)
387 }
388
389 if cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm. != test.sigAlgo {
390 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: SignatureAlgorithm wasn't copied from template. Got %v, want %v", test.name, cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm., test.sigAlgo)
391 }
392
393 if cert.SelfSignedscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SelfSigned. != test.selfSigned {
394 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: SelfSigned was not set properly. Got %v, want %v", test.name, cert.SelfSignedscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SelfSigned., test.selfSigned)
395 }
396
397 if !cert.SelfSignedscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SelfSigned. {
398 if cert.ValidationLevelscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ValidationLevel. != EVscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/EV. {
399 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: ValidationLevel was not set properly. Got %s, want %s", test.name, cert.ValidationLevelscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ValidationLevel..Stringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertValidationLevel#String().(), EVscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/EV..Stringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertValidationLevel#String().())
400 }
401 }
402
403 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.ExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtKeyUsage., testExtKeyUsage) {
404 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: extkeyusage wasn't correctly copied from the template. Got %v, want %v", test.name, cert.ExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#ExtKeyUsage., testExtKeyUsage)
405 }
406
407 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.UnknownExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#UnknownExtKeyUsage., testUnknownExtKeyUsage) {
408 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: unknown extkeyusage wasn't correctly copied from the template. Got %v, want %v", test.name, cert.UnknownExtKeyUsagescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#UnknownExtKeyUsage., testUnknownExtKeyUsage)
409 }
410
411 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.OCSPServerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#OCSPServer., template.OCSPServerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#OCSPServer.) {
412 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: OCSP servers differ from template. Got %v, want %v", test.name, cert.OCSPServerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#OCSPServer., template.OCSPServerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#OCSPServer.)
413 }
414
415 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.IssuingCertificateURLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IssuingCertificateURL., template.IssuingCertificateURLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IssuingCertificateURL.) {
416 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: Issuing certificate URLs differ from template. Got %v, want %v", test.name, cert.IssuingCertificateURLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IssuingCertificateURL., template.IssuingCertificateURLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IssuingCertificateURL.)
417 }
418
419 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#DNSNames., template.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#DNSNames.) {
420 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: SAN DNS names differ from template. Got %v, want %v", test.name, cert.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#DNSNames., template.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#DNSNames.)
421 }
422
423 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#EmailAddresses., template.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#EmailAddresses.) {
424 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: SAN emails differ from template. Got %v, want %v", test.name, cert.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#EmailAddresses., template.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#EmailAddresses.)
425 }
426
427 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IPAddresses., template.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IPAddresses.) {
428 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: SAN IPs differ from template. Got %v, want %v", test.name, cert.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IPAddresses., template.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IPAddresses.)
429 }
430
431 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(cert.CRLDistributionPointsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CRLDistributionPoints., template.CRLDistributionPointsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CRLDistributionPoints.) {
432 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: CRL distribution points differ from template. Got %v, want %v", test.name, cert.CRLDistributionPointsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CRLDistributionPoints., template.CRLDistributionPointsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CRLDistributionPoints.)
433 }
434
435 if !bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Equalscip-go gomod github.com/golang/go/src go1.16 bytes/Equal().(cert.SubjectKeyIdscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SubjectKeyId., []byte{4, 3, 2, 1}) {
436 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: ExtraExtensions didn't override SubjectKeyId", test.name)
437 }
438
439 if bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Indexscip-go gomod github.com/golang/go/src go1.16 bytes/Index().(derBytes, extraExtensionData) == -1 {
440 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: didn't find extra extension in DER output", test.name)
441 }
442
443 if test.checkSig {
444 err = cert.CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(cert)
445 if err != nil {
446 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: signature verification failed: %s", test.name, err)
447 }
448 }
449 }
450 }
451
452 // Self-signed certificate using ECDSA with SHA1 & secp256r1
453 var ecdsaSHA1CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA1CertPem. = `
454 -----BEGIN CERTIFICATE-----
455 MIICDjCCAbUCCQDF6SfN0nsnrjAJBgcqhkjOPQQBMIGPMQswCQYDVQQGEwJVUzET
456 MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEVMBMG
457 A1UECgwMR29vZ2xlLCBJbmMuMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTEjMCEG
458 CSqGSIb3DQEJARYUZ29sYW5nLWRldkBnbWFpbC5jb20wHhcNMTIwNTIwMjAyMDUw
459 WhcNMjIwNTE4MjAyMDUwWjCBjzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlm
460 b3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFTATBgNVBAoMDEdvb2dsZSwg
461 SW5jLjEXMBUGA1UEAwwOd3d3Lmdvb2dsZS5jb20xIzAhBgkqhkiG9w0BCQEWFGdv
462 bGFuZy1kZXZAZ21haWwuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/Wgn
463 WQDo5+bz71T0327ERgd5SDDXFbXLpzIZDXTkjpe8QTEbsF+ezsQfrekrpDPC4Cd3
464 P9LY0tG+aI8IyVKdUjAJBgcqhkjOPQQBA0gAMEUCIGlsqMcRqWVIWTD6wXwe6Jk2
465 DKxL46r/FLgJYnzBEH99AiEA3fBouObsvV1R3oVkb4BQYnD4/4LeId6lAT43YvyV
466 a/A=
467 -----END CERTIFICATE-----
468 `
469
470 // Self-signed certificate using ECDSA with SHA256 & secp256r1
471 var ecdsaSHA256p256CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA256p256CertPem. = `
472 -----BEGIN CERTIFICATE-----
473 MIICDzCCAbYCCQDlsuMWvgQzhTAKBggqhkjOPQQDAjCBjzELMAkGA1UEBhMCVVMx
474 EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFTAT
475 BgNVBAoMDEdvb2dsZSwgSW5jLjEXMBUGA1UEAwwOd3d3Lmdvb2dsZS5jb20xIzAh
476 BgkqhkiG9w0BCQEWFGdvbGFuZy1kZXZAZ21haWwuY29tMB4XDTEyMDUyMTAwMTkx
477 NloXDTIyMDUxOTAwMTkxNlowgY8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxp
478 Zm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRUwEwYDVQQKDAxHb29nbGUs
479 IEluYy4xFzAVBgNVBAMMDnd3dy5nb29nbGUuY29tMSMwIQYJKoZIhvcNAQkBFhRn
480 b2xhbmctZGV2QGdtYWlsLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABPMt
481 2ErhxAty5EJRu9yM+MTy+hUXm3pdW1ensAv382KoGExSXAFWP7pjJnNtHO+XSwVm
482 YNtqjcAGFKpweoN//kQwCgYIKoZIzj0EAwIDRwAwRAIgIYSaUA/IB81gjbIw/hUV
483 70twxJr5EcgOo0hLp3Jm+EYCIFDO3NNcgmURbJ1kfoS3N/0O+irUtoPw38YoNkqJ
484 h5wi
485 -----END CERTIFICATE-----
486 `
487
488 // Self-signed certificate using ECDSA with SHA256 & secp384r1
489 var ecdsaSHA256p384CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA256p384CertPem. = `
490 -----BEGIN CERTIFICATE-----
491 MIICSjCCAdECCQDje/no7mXkVzAKBggqhkjOPQQDAjCBjjELMAkGA1UEBhMCVVMx
492 EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFDAS
493 BgNVBAoMC0dvb2dsZSwgSW5jMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTEjMCEG
494 CSqGSIb3DQEJARYUZ29sYW5nLWRldkBnbWFpbC5jb20wHhcNMTIwNTIxMDYxMDM0
495 WhcNMjIwNTE5MDYxMDM0WjCBjjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlm
496 b3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFDASBgNVBAoMC0dvb2dsZSwg
497 SW5jMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTEjMCEGCSqGSIb3DQEJARYUZ29s
498 YW5nLWRldkBnbWFpbC5jb20wdjAQBgcqhkjOPQIBBgUrgQQAIgNiAARRuzRNIKRK
499 jIktEmXanNmrTR/q/FaHXLhWRZ6nHWe26Fw7Rsrbk+VjGy4vfWtNn7xSFKrOu5ze
500 qxKnmE0h5E480MNgrUiRkaGO2GMJJVmxx20aqkXOk59U8yGA4CghE6MwCgYIKoZI
501 zj0EAwIDZwAwZAIwBZEN8gvmRmfeP/9C1PRLzODIY4JqWub2PLRT4mv9GU+yw3Gr
502 PU9A3CHMdEcdw/MEAjBBO1lId8KOCh9UZunsSMfqXiVurpzmhWd6VYZ/32G+M+Mh
503 3yILeYQzllt/g0rKVRk=
504 -----END CERTIFICATE-----
505 `
506
507 // Self-signed certificate using ECDSA with SHA384 & secp521r1
508 var ecdsaSHA384p521CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA384p521CertPem. = `
509 -----BEGIN CERTIFICATE-----
510 MIICljCCAfcCCQDhp1AFD/ahKjAKBggqhkjOPQQDAzCBjjELMAkGA1UEBhMCVVMx
511 EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFDAS
512 BgNVBAoMC0dvb2dsZSwgSW5jMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTEjMCEG
513 CSqGSIb3DQEJARYUZ29sYW5nLWRldkBnbWFpbC5jb20wHhcNMTIwNTIxMTUwNDI5
514 WhcNMjIwNTE5MTUwNDI5WjCBjjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlm
515 b3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFDASBgNVBAoMC0dvb2dsZSwg
516 SW5jMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTEjMCEGCSqGSIb3DQEJARYUZ29s
517 YW5nLWRldkBnbWFpbC5jb20wgZswEAYHKoZIzj0CAQYFK4EEACMDgYYABACqx9Rv
518 IssRs1LWYcNN+WffwlHw4Tv3y8/LIAA9MF1ZScIonU9nRMxt4a2uGJVCPDw6JHpz
519 PaYc0E9puLoE9AfKpwFr59Jkot7dBg55SKPEFkddoip/rvmN7NPAWjMBirOwjOkm
520 8FPthvPhGPqsu9AvgVuHu3PosWiHGNrhh379pva8MzAKBggqhkjOPQQDAwOBjAAw
521 gYgCQgEHNmswkUdPpHqrVxp9PvLVl+xxPuHBkT+75z9JizyxtqykHQo9Uh6SWCYH
522 BF9KLolo01wMt8DjoYP5Fb3j5MH7xwJCAbWZzTOp4l4DPkIvAh4LeC4VWbwPPyqh
523 kBg71w/iEcSY3wUKgHGcJJrObZw7wys91I5kENljqw/Samdr3ka+jBJa
524 -----END CERTIFICATE-----
525 `
526
527 var ecdsaTestsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests. = []struct {
528 sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests:sigAlgo. SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SignatureAlgorithm#
529 pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests:pemCert. string
530 }{
531 {ECDSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA1., ecdsaSHA1CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA1CertPem.},
532 {ECDSAWithSHA256scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA256., ecdsaSHA256p256CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA256p256CertPem.},
533 {ECDSAWithSHA256scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA256., ecdsaSHA256p384CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA256p384CertPem.},
534 {ECDSAWithSHA384scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA384., ecdsaSHA384p521CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaSHA384p521CertPem.},
535 }
536
537 func TestECDSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestECDSA().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
538 for i, test := range ecdsaTestsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests. {
539 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(test.pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests:pemCert.))
540 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
541 if err != nil {
542 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: failed to parse certificate: %s", i, err)
543 continue
544 }
545 if sa := cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm.; sa != test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests:sigAlgo. {
546 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: signature algorithm is %v, want %v", i, sa, test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ecdsaTests:sigAlgo.)
547 }
548 if parsedKey, ok := cert.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKey..(*AugmentedECDSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/AugmentedECDSA#); !ok {
549 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: wanted an AugmentedECDSA public key but found: %#v", i, parsedKey)
550 }
551 // if parsedKey, ok := cert.PublicKey.Pub(*ecdsa.PublicKey); !ok {
552 // t.Errorf("%d: wanted an ECDSA public key but found: %#v", i, parsedKey)
553 // }
554 // if parsedKey, ok := cert.PublicKey.Raw(*asn.BitString); !ok {
555 // t.Errorf("%d: wanted an ECDSA public key but found: %#v", i, parsedKey)
556 // }
557 if pka := cert.PublicKeyAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKeyAlgorithm.; pka != ECDSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSA. {
558 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: public key algorithm is %v, want ECDSA", i, pka)
559 }
560 if err = cert.CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(cert); err != nil {
561 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: certificate verification failed: %s", i, err)
562 }
563 }
564 }
565
566 var ed25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519CertPem. = `-----BEGIN CERTIFICATE-----
567 MIIBFTCByKADAgECAghNZYIhB/z9UjAFBgMrZXAwDzENMAsGA1UEAxMEcm9vdDAe
568 Fw0xNzAyMTIxOTQ5NDVaFw0xNzAyMTMxOTQ5NDVaMA8xDTALBgNVBAMTBHJvb3Qw
569 KjAFBgMrZXADIQB1mSjGpYU8nliw5Ah7Uq6pElOk/QofMn476Lr4CII0zKNCMEAw
570 DgYDVR0PAQH/BAQDAgKEMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFKeTKKir
571 Wabr+CP52M0stAf7KInwMAUGAytlcANBAFRwyNSg/F3Zfeqiptn99pbeQsoIApvb
572 zKfb2zXCmF6OdhUSWrtHFY0y5rsCo1ha7cQQttRjOGiuKSKkjkmzHAg=
573 -----END CERTIFICATE-----`
574 var x25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519CertPem. = `-----BEGIN CERTIFICATE-----
575 MIIBTDCB/6ADAgECAgh4YpoPXz8WTzAFBgMrZXAwDzENMAsGA1UEAxMEcm9vdDAe
576 Fw0xNzAyMTIxOTQ5NDVaFw0xNzAyMTMxOTQ5NDVaMBMxETAPBgNVBAMTCHRlc3Qu
577 Y29tMCowBQYDK2VuAyEAFKwi3LTY6apEQDNMrx2WagCHpGVFL7tIB/uTwzoyUiCj
578 dTBzMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMB
579 Af8EAjAAMB0GA1UdDgQWBBQG9I1UYG2pAHSs6nYKQFo/YTAkpTAfBgNVHSMEGDAW
580 gBSnkyioq1mm6/gj+djNLLQH+yiJ8DAFBgMrZXADQQBbuoByEYlgzxTskoUtCwBo
581 dVaJPEZmR+AHGHAFcBTEISEK5sl6h9Z923i6xMwHTjWbYw3JYwqeuJUfm3qCncQL
582 -----END CERTIFICATE-----`
583 var ed25519Testsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests. = []struct {
584 sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:sigAlgo. SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SignatureAlgorithm#
585 pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:pemCert. string
586 signerCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:signerCert. string
587 }{
588 {Ed25519Sigscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Ed25519Sig., ed25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519CertPem., ed25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519CertPem.},
589 }
590
591 func Test25519scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Test25519().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
592 for i, test := range ed25519Testsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests. {
593 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(test.pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:pemCert.))
594 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
595 if err != nil {
596 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: failed to parse certificate: %s", i, err)
597 continue
598 }
599 pemBlock, _ = pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(test.signerCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:signerCert.))
600 signerCert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
601 if err != nil {
602 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: failed to parse certificate: %s", i, err)
603 continue
604 }
605 if sa := cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm.; sa != test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:sigAlgo. {
606 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: signature algorithm is %v, want %v", i, sa, test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519Tests:sigAlgo.)
607 }
608 if parsedKey, ok := cert.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKey..(ed25519scip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto v0.23.0 `golang.org/x/crypto/ed25519`/PublicKey#); !ok {
609 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: wanted an Ed25519 public key but found: %#v", i, parsedKey)
610 }
611 if pka := cert.PublicKeyAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKeyAlgorithm.; pka != Ed25519scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Ed25519. {
612 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: public key algorithm is %v, want Ed25519", i, pka)
613 }
614 if err = cert.CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(signerCert); err != nil {
615 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: certificate verification failed: %s", i, err)
616 }
617 }
618 }
619
620 var x25519Testsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests. = []struct {
621 sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:sigAlgo. SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SignatureAlgorithm#
622 pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:pemCert. string
623 signerCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:signerCert. string
624 }{
625 {Ed25519Sigscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Ed25519Sig., x25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519CertPem., ed25519CertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ed25519CertPem.},
626 }
627
628 func TestX25519scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestX25519().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
629 for i, test := range x25519Testsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests. {
630 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(test.pemCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:pemCert.))
631 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
632 if err != nil {
633 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: failed to parse certificate: %s", i, err)
634 continue
635 }
636 pemBlock, _ = pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(test.signerCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:signerCert.))
637 signerCert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
638 if err != nil {
639 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: failed to parse certificate: %s", i, err)
640 continue
641 }
642 if sa := cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm.; sa != test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:sigAlgo. {
643 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: signature algorithm is %v, want %v", i, sa, test.sigAlgoscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/x25519Tests:sigAlgo.)
644 }
645 if parsedKey, ok := cert.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKey..(X25519PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/X25519PublicKey#); !ok {
646 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: wanted an Ed25519 public key but found: %#v", i, parsedKey)
647 }
648 if pka := cert.PublicKeyAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKeyAlgorithm.; pka != X25519scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/X25519. {
649 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: public key algorithm is %v, want Ed25519", i, pka)
650 }
651 if err = cert.CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(signerCert); err != nil {
652 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%d: certificate verification failed: %s", i, err)
653 }
654 }
655 }
656
657 // Self-signed certificate using DSA with SHA1
658 var dsaCertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/dsaCertPem. = `-----BEGIN CERTIFICATE-----
659 MIIEDTCCA82gAwIBAgIJALHPghaoxeDhMAkGByqGSM44BAMweTELMAkGA1UEBhMC
660 VVMxCzAJBgNVBAgTAk5DMQ8wDQYDVQQHEwZOZXd0b24xFDASBgNVBAoTC0dvb2ds
661 ZSwgSW5jMRIwEAYDVQQDEwlKb24gQWxsaWUxIjAgBgkqhkiG9w0BCQEWE2pvbmFs
662 bGllQGdvb2dsZS5jb20wHhcNMTEwNTE0MDMwMTQ1WhcNMTEwNjEzMDMwMTQ1WjB5
663 MQswCQYDVQQGEwJVUzELMAkGA1UECBMCTkMxDzANBgNVBAcTBk5ld3RvbjEUMBIG
664 A1UEChMLR29vZ2xlLCBJbmMxEjAQBgNVBAMTCUpvbiBBbGxpZTEiMCAGCSqGSIb3
665 DQEJARYTam9uYWxsaWVAZ29vZ2xlLmNvbTCCAbcwggEsBgcqhkjOOAQBMIIBHwKB
666 gQC8hLUnQ7FpFYu4WXTj6DKvXvz8QrJkNJCVMTpKAT7uBpobk32S5RrPKXocd4gN
667 8lyGB9ggS03EVlEwXvSmO0DH2MQtke2jl9j1HLydClMf4sbx5V6TV9IFw505U1iW
668 jL7awRMgxge+FsudtJK254FjMFo03ZnOQ8ZJJ9E6AEDrlwIVAJpnBn9moyP11Ox5
669 Asc/5dnjb6dPAoGBAJFHd4KVv1iTVCvEG6gGiYop5DJh28hUQcN9kul+2A0yPUSC
670 X93oN00P8Vh3eYgSaCWZsha7zDG53MrVJ0Zf6v/X/CoZNhLldeNOepivTRAzn+Rz
671 kKUYy5l1sxYLHQKF0UGNCXfFKZT0PCmgU+PWhYNBBMn6/cIh44vp85ideo5CA4GE
672 AAKBgFmifCafzeRaohYKXJgMGSEaggCVCRq5xdyDCat+wbOkjC4mfG01/um3G8u5
673 LxasjlWRKTR/tcAL7t0QuokVyQaYdVypZXNaMtx1db7YBuHjj3aP+8JOQRI9xz8c
674 bp5NDJ5pISiFOv4p3GZfqZPcqckDt78AtkQrmnal2txhhjF6o4HeMIHbMB0GA1Ud
675 DgQWBBQVyyr7hO11ZFFpWX50298Sa3V+rzCBqwYDVR0jBIGjMIGggBQVyyr7hO11
676 ZFFpWX50298Sa3V+r6F9pHsweTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk5DMQ8w
677 DQYDVQQHEwZOZXd0b24xFDASBgNVBAoTC0dvb2dsZSwgSW5jMRIwEAYDVQQDEwlK
678 b24gQWxsaWUxIjAgBgkqhkiG9w0BCQEWE2pvbmFsbGllQGdvb2dsZS5jb22CCQCx
679 z4IWqMXg4TAMBgNVHRMEBTADAQH/MAkGByqGSM44BAMDLwAwLAIUPtn/5j8Q1jJI
680 7ggOIsgrhgUdjGQCFCsmDq1H11q9+9Wp9IMeGrTSKHIM
681 -----END CERTIFICATE-----
682 `
683
684 func TestParseCertificateWithDsaPublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseCertificateWithDsaPublicKey().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
685 expectedKey := &dsascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#{
686 Parametersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#Parameters.: dsascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/.Parametersscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#{
687 Pscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#P.: bigFromHexStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromHexString().("00BC84B52743B169158BB85974E3E832AF5EFCFC42B264349095313A4A013EEE069A1B937D92E51ACF297A1C77880DF25C8607D8204B4DC45651305EF4A63B40C7D8C42D91EDA397D8F51CBC9D0A531FE2C6F1E55E9357D205C39D395358968CBEDAC11320C607BE16CB9DB492B6E78163305A34DD99CE43C64927D13A0040EB97"),
688 Qscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#Q.: bigFromHexStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromHexString().("009A67067F66A323F5D4EC7902C73FE5D9E36FA74F"),
689 Gscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#G.: bigFromHexStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromHexString().("009147778295BF5893542BC41BA806898A29E43261DBC85441C37D92E97ED80D323D44825FDDE8374D0FF15877798812682599B216BBCC31B9DCCAD527465FEAFFD7FC2A193612E575E34E7A98AF4D10339FE47390A518CB9975B3160B1D0285D1418D0977C52994F43C29A053E3D685834104C9FAFDC221E38BE9F3989D7A8E42"),
690 },
691 Yscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#Y.: bigFromHexStringscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/bigFromHexString().("59A27C269FCDE45AA2160A5C980C19211A820095091AB9C5DC8309AB7EC1B3A48C2E267C6D35FEE9B71BCBB92F16AC8E559129347FB5C00BEEDD10BA8915C90698755CA965735A32DC7575BED806E1E38F768FFBC24E41123DC73F1C6E9E4D0C9E692128853AFE29DC665FA993DCA9C903B7BF00B6442B9A76A5DADC6186317A"),
692 }
693 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(dsaCertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/dsaCertPem.))
694 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
695 if err != nil {
696 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse certificate: %s", err)
697 }
698 if cert.PublicKeyAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKeyAlgorithm. != DSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/DSA. {
699 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Parsed key algorithm was not DSA")
700 }
701 parsedKey, ok := cert.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#PublicKey..(*dsascip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/.PublicKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#)
702 if !ok {
703 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Parsed key was not a DSA key: %s", err)
704 }
705 if expectedKey.Yscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#Y..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(parsedKey.Yscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/PublicKey#Y.) != 0 ||
706 expectedKey.Pscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#P..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(parsedKey.Pscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#P.) != 0 ||
707 expectedKey.Qscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#Q..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(parsedKey.Qscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#Q.) != 0 ||
708 expectedKey.Gscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#G..Cmpscip-go gomod github.com/golang/go/src go1.16 `math/big`/Int#Cmp().(parsedKey.Gscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/dsa`/Parameters#G.) != 0 {
709 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().("Parsed key differs from expected key")
710 }
711 }
712
713 func TestParseCertificateWithDSASignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseCertificateWithDSASignatureAlgorithm().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
714 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(dsaCertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/dsaCertPem.))
715 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
716 if err != nil {
717 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse certificate: %s", err)
718 }
719 if cert.SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SignatureAlgorithm. != DSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/DSAWithSHA1. {
720 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Parsed signature algorithm was not DSAWithSHA1")
721 }
722 }
723
724 func TestVerifyCertificateWithDSASignaturescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestVerifyCertificateWithDSASignature().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
725 pemBlock, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(dsaCertPemscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/dsaCertPem.))
726 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(pemBlock.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
727 if err != nil {
728 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse certificate: %s", err)
729 }
730 // test cert is self-signed
731 if err = cert.CheckSignatureFromscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CheckSignatureFrom().(cert); err != nil {
732 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("DSA Certificate verification failed: %s", err)
733 }
734 }
735
736 const pemCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemCertificate. = `-----BEGIN CERTIFICATE-----
737 MIIB5DCCAZCgAwIBAgIBATALBgkqhkiG9w0BAQUwLTEQMA4GA1UEChMHQWNtZSBDbzEZMBcGA1UE
738 AxMQdGVzdC5leGFtcGxlLmNvbTAeFw03MDAxMDEwMDE2NDBaFw03MDAxMDIwMzQ2NDBaMC0xEDAO
739 BgNVBAoTB0FjbWUgQ28xGTAXBgNVBAMTEHRlc3QuZXhhbXBsZS5jb20wWjALBgkqhkiG9w0BAQED
740 SwAwSAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0fd7Ai2KW5ToIwzFo
741 fvJcS/STa6HA5gQenRUCAwEAAaOBnjCBmzAOBgNVHQ8BAf8EBAMCAAQwDwYDVR0TAQH/BAUwAwEB
742 /zANBgNVHQ4EBgQEAQIDBDAPBgNVHSMECDAGgAQBAgMEMBsGA1UdEQQUMBKCEHRlc3QuZXhhbXBs
743 ZS5jb20wDwYDVR0gBAgwBjAEBgIqAzAqBgNVHR4EIzAhoB8wDoIMLmV4YW1wbGUuY29tMA2CC2V4
744 YW1wbGUuY29tMAsGCSqGSIb3DQEBBQNBAHKZKoS1wEQOGhgklx4+/yFYQlnqwKXvar/ZecQvJwui
745 0seMQnwBhwdBkHfVIU2Fu5VUMRyxlf0ZNaDXcpU581k=
746 -----END CERTIFICATE-----`
747
748 func TestCRLCreationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCRLCreation().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
749 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
750 priv, _ := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
751 block, _ = pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemCertificate.))
752 cert, _ := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
753
754 now := timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(1000, 0)
755 expiry := timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(10000, 0)
756
757 revokedCerts := []pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.RevokedCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/RevokedCertificate#{
758 {
759 SerialNumberscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/RevokedCertificate#SerialNumber.: bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(1),
760 RevocationTimescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/RevokedCertificate#RevocationTime.: now,
761 },
762 {
763 SerialNumberscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/RevokedCertificate#SerialNumber.: bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(42),
764 RevocationTimescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/RevokedCertificate#RevocationTime.: now,
765 },
766 }
767
768 crlBytes, err := cert.CreateCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#CreateCRL().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., priv, revokedCerts, now, expiry)
769 if err != nil {
770 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("error creating CRL: %s", err)
771 }
772
773 _, err = ParseDERCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseDERCRL().(crlBytes)
774 if err != nil {
775 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("error reparsing CRL: %s", err)
776 }
777 }
778
779 func fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(in string) []byte {
780 out := make([]byte, base64scip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/StdEncoding..DecodedLenscip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/Encoding#DecodedLen().(len(in)))
781 n, err := base64scip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/StdEncoding..Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/base64`/Encoding#Decode().(out, []byte(in))
782 if err != nil {
783 panic("failed to base64 decode")
784 }
785 return out[:n]
786 }
787
788 func TestParseDERCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseDERCRL().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
789 derBytes := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(derCRLBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/derCRLBase64.)
790 certList, err := ParseDERCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseDERCRL().(derBytes)
791 if err != nil {
792 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("error parsing: %s", err)
793 return
794 }
795 numCerts := len(certList.TBSCertListscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/CertificateList#TBSCertList..RevokedCertificatesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/TBSCertificateList#RevokedCertificates.)
796 expected := 88
797 if numCerts != expected {
798 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("bad number of revoked certificates. got: %d want: %d", numCerts, expected)
799 }
800
801 if certList.HasExpiredscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/CertificateList#HasExpired().(timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(1302517272, 0)) {
802 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("CRL has expired (but shouldn't have)")
803 }
804
805 // Can't check the signature here without a package cycle.
806 }
807
808 func TestCRLWithoutExpiryscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCRLWithoutExpiry().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
809 derBytes := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().("MIHYMIGZMAkGByqGSM44BAMwEjEQMA4GA1UEAxMHQ2FybERTUxcNOTkwODI3MDcwMDAwWjBpMBMCAgDIFw05OTA4MjIwNzAwMDBaMBMCAgDJFw05OTA4MjIwNzAwMDBaMBMCAgDTFw05OTA4MjIwNzAwMDBaMBMCAgDSFw05OTA4MjIwNzAwMDBaMBMCAgDUFw05OTA4MjQwNzAwMDBaMAkGByqGSM44BAMDLwAwLAIUfmVSdjP+NHMX0feW+aDU2G1cfT0CFAJ6W7fVWxjBz4fvftok8yqDnDWh")
810 certList, err := ParseDERCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseDERCRL().(derBytes)
811 if err != nil {
812 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
813 }
814 if !certList.TBSCertListscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/CertificateList#TBSCertList..NextUpdatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/TBSCertificateList#NextUpdate..IsZeroscip-go gomod github.com/golang/go/src go1.16 time/Time#IsZero().() {
815 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("NextUpdate is not the zero value")
816 }
817 }
818
819 func TestParsePEMCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParsePEMCRL().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
820 pemBytes := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(pemCRLBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemCRLBase64.)
821 certList, err := ParseCRLscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCRL().(pemBytes)
822 if err != nil {
823 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("error parsing: %s", err)
824 return
825 }
826 numCerts := len(certList.TBSCertListscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/CertificateList#TBSCertList..RevokedCertificatesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/TBSCertificateList#RevokedCertificates.)
827 expected := 2
828 if numCerts != expected {
829 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("bad number of revoked certificates. got: %d want: %d", numCerts, expected)
830 }
831
832 if certList.HasExpiredscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/CertificateList#HasExpired().(timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(1302517272, 0)) {
833 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("CRL has expired (but shouldn't have)")
834 }
835
836 // Can't check the signature here without a package cycle.
837 }
838
839 func TestImportsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestImports().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
840 switch runtimescip-go gomod github.com/golang/go/src go1.16 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.16 runtime/GOOS. {
841 case "android", "nacl":
842 t.Skipfscip-go gomod github.com/golang/go/src go1.16 testing/common#Skipf().("skipping on %s", runtimescip-go gomod github.com/golang/go/src go1.16 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.16 runtime/GOOS.)
843 }
844
845 if err := execscip-go gomod github.com/golang/go/src go1.16 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.16 `os/exec`/Command().("go", "run", "x509_test_import.go").Runscip-go gomod github.com/golang/go/src go1.16 `os/exec`/Cmd#Run().(); err != nil {
846 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("failed to run x509_test_import.go: %s", err)
847 }
848 }
849
850 const derCRLBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/derCRLBase64. = "MIINqzCCDJMCAQEwDQYJKoZIhvcNAQEFBQAwVjEZMBcGA1UEAxMQUEtJIEZJTk1FQ0NBTklDQTEVMBMGA1UEChMMRklOTUVDQ0FOSUNBMRUwEwYDVQQLEwxGSU5NRUNDQU5JQ0ExCzAJBgNVBAYTAklUFw0xMTA1MDQxNjU3NDJaFw0xMTA1MDQyMDU3NDJaMIIMBzAhAg4Ze1od49Lt1qIXBydAzhcNMDkwNzE2MDg0MzIyWjAAMCECDl0HSL9bcZ1Ci/UHJ0DPFw0wOTA3MTYwODQzMTNaMAAwIQIOESB9tVAmX3cY7QcnQNAXDTA5MDcxNjA4NDUyMlowADAhAg4S1tGAQ3mHt8uVBydA1RcNMDkwODA0MTUyNTIyWjAAMCECDlQ249Y7vtC25ScHJ0DWFw0wOTA4MDQxNTI1MzdaMAAwIQIOISMop3NkA4PfYwcnQNkXDTA5MDgwNDExMDAzNFowADAhAg56/BMoS29KEShTBydA2hcNMDkwODA0MTEwMTAzWjAAMCECDnBp/22HPH5CSWoHJ0DbFw0wOTA4MDQxMDU0NDlaMAAwIQIOV9IP+8CD8bK+XAcnQNwXDTA5MDgwNDEwNTcxN1owADAhAg4v5aRz0IxWqYiXBydA3RcNMDkwODA0MTA1NzQ1WjAAMCECDlOU34VzvZAybQwHJ0DeFw0wOTA4MDQxMDU4MjFaMAAwIAINO4CD9lluIxcwBydBAxcNMDkwNzIyMTUzMTU5WjAAMCECDgOllfO8Y1QA7/wHJ0ExFw0wOTA3MjQxMTQxNDNaMAAwIQIOJBX7jbiCdRdyjgcnQUQXDTA5MDkxNjA5MzAwOFowADAhAg5iYSAgmDrlH/RZBydBRRcNMDkwOTE2MDkzMDE3WjAAMCECDmu6k6srP3jcMaQHJ0FRFw0wOTA4MDQxMDU2NDBaMAAwIQIOX8aHlO0V+WVH4QcnQVMXDTA5MDgwNDEwNTcyOVowADAhAg5flK2rg3NnsRgDBydBzhcNMTEwMjAxMTUzMzQ2WjAAMCECDg35yJDL1jOPTgoHJ0HPFw0xMTAyMDExNTM0MjZaMAAwIQIOMyFJ6+e9iiGVBQcnQdAXDTA5MDkxODEzMjAwNVowADAhAg5Emb/Oykucmn8fBydB1xcNMDkwOTIxMTAxMDQ3WjAAMCECDjQKCncV+MnUavMHJ0HaFw0wOTA5MjIwODE1MjZaMAAwIQIOaxiFUt3dpd+tPwcnQfQXDTEwMDYxODA4NDI1MVowADAhAg5G7P8nO0tkrMt7BydB9RcNMTAwNjE4MDg0MjMwWjAAMCECDmTCC3SXhmDRst4HJ0H2Fw0wOTA5MjgxMjA3MjBaMAAwIQIOHoGhUr/pRwzTKgcnQfcXDTA5MDkyODEyMDcyNFowADAhAg50wrcrCiw8mQmPBydCBBcNMTAwMjE2MTMwMTA2WjAAMCECDifWmkvwyhEqwEcHJ0IFFw0xMDAyMTYxMzAxMjBaMAAwIQIOfgPmlW9fg+osNgcnQhwXDTEwMDQxMzA5NTIwMFowADAhAg4YHAGuA6LgCk7tBydCHRcNMTAwNDEzMDk1MTM4WjAAMCECDi1zH1bxkNJhokAHJ0IsFw0xMDA0MTMwOTU5MzBaMAAwIQIOMipNccsb/wo2fwcnQi0XDTEwMDQxMzA5NTkwMFowADAhAg46lCmvPl4GpP6ABydCShcNMTAwMTE5MDk1MjE3WjAAMCECDjaTcaj+wBpcGAsHJ0JLFw0xMDAxMTkwOTUyMzRaMAAwIQIOOMC13EOrBuxIOQcnQloXDTEwMDIwMTA5NDcwNVowADAhAg5KmZl+krz4RsmrBydCWxcNMTAwMjAxMDk0NjQwWjAAMCECDmLG3zQJ/fzdSsUHJ0JiFw0xMDAzMDEwOTUxNDBaMAAwIQIOP39ksgHdojf4owcnQmMXDTEwMDMwMTA5NTExN1owADAhAg4LDQzvWNRlD6v9BydCZBcNMTAwMzAxMDk0NjIyWjAAMCECDkmNfeclaFhIaaUHJ0JlFw0xMDAzMDEwOTQ2MDVaMAAwIQIOT/qWWfpH/m8NTwcnQpQXDTEwMDUxMTA5MTgyMVowADAhAg5m/ksYxvCEgJSvBydClRcNMTAwNTExMDkxODAxWjAAMCECDgvf3Ohq6JOPU9AHJ0KWFw0xMDA1MTEwOTIxMjNaMAAwIQIOKSPas10z4jNVIQcnQpcXDTEwMDUxMTA5MjEwMlowADAhAg4mCWmhoZ3lyKCDBydCohcNMTEwNDI4MTEwMjI1WjAAMCECDkeiyRsBMK0Gvr4HJ0KjFw0xMTA0MjgxMTAyMDdaMAAwIQIOa09b/nH2+55SSwcnQq4XDTExMDQwMTA4Mjk0NlowADAhAg5O7M7iq7gGplr1BydCrxcNMTEwNDAxMDgzMDE3WjAAMCECDjlT6mJxUjTvyogHJ0K1Fw0xMTAxMjcxNTQ4NTJaMAAwIQIODS/l4UUFLe21NAcnQrYXDTExMDEyNzE1NDgyOFowADAhAg5lPRA0XdOUF6lSBydDHhcNMTEwMTI4MTQzNTA1WjAAMCECDixKX4fFGGpENwgHJ0MfFw0xMTAxMjgxNDM1MzBaMAAwIQIORNBkqsPnpKTtbAcnQ08XDTEwMDkwOTA4NDg0MlowADAhAg5QL+EMM3lohedEBydDUBcNMTAwOTA5MDg0ODE5WjAAMCECDlhDnHK+HiTRAXcHJ0NUFw0xMDEwMTkxNjIxNDBaMAAwIQIOdBFqAzq/INz53gcnQ1UXDTEwMTAxOTE2MjA0NFowADAhAg4OjR7s8MgKles1BydDWhcNMTEwMTI3MTY1MzM2WjAAMCECDmfR/elHee+d0SoHJ0NbFw0xMTAxMjcxNjUzNTZaMAAwIQIOBTKv2ui+KFMI+wcnQ5YXDTEwMDkxNTEwMjE1N1owADAhAg49F3c/GSah+oRUBydDmxcNMTEwMTI3MTczMjMzWjAAMCECDggv4I61WwpKFMMHJ0OcFw0xMTAxMjcxNzMyNTVaMAAwIQIOXx/Y8sEvwS10LAcnQ6UXDTExMDEyODExMjkzN1owADAhAg5LSLbnVrSKaw/9BydDphcNMTEwMTI4MTEyOTIwWjAAMCECDmFFoCuhKUeACQQHJ0PfFw0xMTAxMTExMDE3MzdaMAAwIQIOQTDdFh2fSPF6AAcnQ+AXDTExMDExMTEwMTcxMFowADAhAg5B8AOXX61FpvbbBydD5RcNMTAxMDA2MTAxNDM2WjAAMCECDh41P2Gmi7PkwI4HJ0PmFw0xMDEwMDYxMDE2MjVaMAAwIQIOWUHGLQCd+Ale9gcnQ/0XDTExMDUwMjA3NTYxMFowADAhAg5Z2c9AYkikmgWOBydD/hcNMTEwNTAyMDc1NjM0WjAAMCECDmf/UD+/h8nf+74HJ0QVFw0xMTA0MTUwNzI4MzNaMAAwIQIOICvj4epy3MrqfwcnRBYXDTExMDQxNTA3Mjg1NlowADAhAg4bouRMfOYqgv4xBydEHxcNMTEwMzA4MTYyNDI1WjAAMCECDhebWHGoKiTp7pEHJ0QgFw0xMTAzMDgxNjI0NDhaMAAwIQIOX+qnxxAqJ8LtawcnRDcXDTExMDEzMTE1MTIyOFowADAhAg4j0fICqZ+wkOdqBydEOBcNMTEwMTMxMTUxMTQxWjAAMCECDhmXjsV4SUpWtAMHJ0RLFw0xMTAxMjgxMTI0MTJaMAAwIQIODno/w+zG43kkTwcnREwXDTExMDEyODExMjM1MlowADAhAg4b1gc88767Fr+LBydETxcNMTEwMTI4MTEwMjA4WjAAMCECDn+M3Pa1w2nyFeUHJ0RQFw0xMTAxMjgxMDU4NDVaMAAwIQIOaduoyIH61tqybAcnRJUXDTEwMTIxNTA5NDMyMlowADAhAg4nLqQPkyi3ESAKBydElhcNMTAxMjE1MDk0MzM2WjAAMCECDi504NIMH8578gQHJ0SbFw0xMTAyMTQxNDA1NDFaMAAwIQIOGuaM8PDaC5u1egcnRJwXDTExMDIxNDE0MDYwNFowADAhAg4ehYq/BXGnB5PWBydEnxcNMTEwMjA0MDgwOTUxWjAAMCECDkSD4eS4FxW5H20HJ0SgFw0xMTAyMDQwODA5MjVaMAAwIQIOOCcb6ilYObt1egcnRKEXDTExMDEyNjEwNDEyOVowADAhAg58tISWCCwFnKGnBydEohcNMTEwMjA0MDgxMzQyWjAAMCECDn5rjtabY/L/WL0HJ0TJFw0xMTAyMDQxMTAzNDFaMAAwDQYJKoZIhvcNAQEFBQADggEBAGnF2Gs0+LNiYCW1Ipm83OXQYP/bd5tFFRzyz3iepFqNfYs4D68/QihjFoRHQoXEB0OEe1tvaVnnPGnEOpi6krwekquMxo4H88B5SlyiFIqemCOIss0SxlCFs69LmfRYvPPvPEhoXtQ3ZThe0UvKG83GOklhvGl6OaiRf4Mt+m8zOT4Wox/j6aOBK6cw6qKCdmD+Yj1rrNqFGg1CnSWMoD6S6mwNgkzwdBUJZ22BwrzAAo4RHa2Uy3ef1FjwD0XtU5N3uDSxGGBEDvOe5z82rps3E22FpAA8eYl8kaXtmWqyvYU0epp4brGuTxCuBMCAsxt/OjIjeNNQbBGkwxgfYA0="
851
852 const pemCRLBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemCRLBase64. = "LS0tLS1CRUdJTiBYNTA5IENSTC0tLS0tDQpNSUlCOWpDQ0FWOENBUUV3RFFZSktvWklodmNOQVFFRkJRQXdiREVhTUJnR0ExVUVDaE1SVWxOQklGTmxZM1Z5DQphWFI1SUVsdVl5NHhIakFjQmdOVkJBTVRGVkpUUVNCUWRXSnNhV01nVW05dmRDQkRRU0IyTVRFdU1Dd0dDU3FHDQpTSWIzRFFFSkFSWWZjbk5oYTJWdmJuSnZiM1J6YVdkdVFISnpZWE5sWTNWeWFYUjVMbU52YlJjTk1URXdNakl6DQpNVGt5T0RNd1doY05NVEV3T0RJeU1Ua3lPRE13V2pDQmpEQktBaEVBckRxb2g5RkhKSFhUN09QZ3V1bjQrQmNODQpNRGt4TVRBeU1UUXlOekE1V2pBbU1Bb0dBMVVkRlFRRENnRUpNQmdHQTFVZEdBUVJHQTh5TURBNU1URXdNakUwDQpNalExTlZvd1BnSVJBTEd6blowOTVQQjVhQU9MUGc1N2ZNTVhEVEF5TVRBeU16RTBOVEF4TkZvd0dqQVlCZ05WDQpIUmdFRVJnUE1qQXdNakV3TWpNeE5EVXdNVFJhb0RBd0xqQWZCZ05WSFNNRUdEQVdnQlQxVERGNlVRTS9MTmVMDQpsNWx2cUhHUXEzZzltekFMQmdOVkhSUUVCQUlDQUlRd0RRWUpLb1pJaHZjTkFRRUZCUUFEZ1lFQUZVNUFzNk16DQpxNVBSc2lmYW9iUVBHaDFhSkx5QytNczVBZ2MwYld5QTNHQWR4dXI1U3BQWmVSV0NCamlQL01FSEJXSkNsQkhQDQpHUmNxNXlJZDNFakRrYUV5eFJhK2k2N0x6dmhJNmMyOUVlNks5cFNZd2ppLzdSVWhtbW5Qclh0VHhsTDBsckxyDQptUVFKNnhoRFJhNUczUUE0Q21VZHNITnZicnpnbUNZcHZWRT0NCi0tLS0tRU5EIFg1MDkgQ1JMLS0tLS0NCg0K"
853
854 func TestCreateCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCreateCertificateRequest().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
855 random := randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.
856
857 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
858 rsaPriv, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
859 if err != nil {
860 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse private key: %s", err)
861 }
862
863 ecdsa256Priv, err := ecdsascip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/GenerateKey().(ellipticscip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/.P256scip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/P256().(), randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.)
864 if err != nil {
865 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to generate ECDSA key: %s", err)
866 }
867
868 ecdsa384Priv, err := ecdsascip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/GenerateKey().(ellipticscip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/.P384scip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/P384().(), randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.)
869 if err != nil {
870 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to generate ECDSA key: %s", err)
871 }
872
873 ecdsa521Priv, err := ecdsascip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/ecdsa`/GenerateKey().(ellipticscip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/.P521scip-go gomod github.com/golang/go/src go1.16 `crypto/elliptic`/P521().(), randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader.)
874 if err != nil {
875 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to generate ECDSA key: %s", err)
876 }
877
878 tests := []struct {
879 name string
880 priv interface{}
881 sigAlgo SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SignatureAlgorithm#
882 }{
883 {"RSA", rsaPriv, SHA1WithRSAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/SHA1WithRSA.},
884 {"ECDSA-256", ecdsa256Priv, ECDSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA1.},
885 {"ECDSA-384", ecdsa384Priv, ECDSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA1.},
886 {"ECDSA-521", ecdsa521Priv, ECDSAWithSHA1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ECDSAWithSHA1.},
887 }
888
889 for _, test := range tests {
890 template := CertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#{
891 Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject.: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Namescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#{
892 CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName.: "test.example.com",
893 Organizationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Organization.: []string{"Σ Acme Co"},
894 },
895 SignatureAlgorithmscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#SignatureAlgorithm.: test.sigAlgo,
896 DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.: []string{"test.example.com"},
897 EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.: []string{"[email protected]"},
898 IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#IPAddresses.: []netscip-go gomod github.com/golang/go/src go1.16 net/.IPscip-go gomod github.com/golang/go/src go1.16 net/IP#{netscip-go gomod github.com/golang/go/src go1.16 net/.IPv4scip-go gomod github.com/golang/go/src go1.16 net/IPv4().(127, 0, 0, 1).To4scip-go gomod github.com/golang/go/src go1.16 net/IP#To4().(), netscip-go gomod github.com/golang/go/src go1.16 net/.ParseIPscip-go gomod github.com/golang/go/src go1.16 net/ParseIP().("2001:4860:0:2001::68")},
899 }
900
901 derBytes, err := CreateCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CreateCertificateRequest().(random, &template, test.priv)
902 if err != nil {
903 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to create certificate request: %s", test.name, err)
904 continue
905 }
906
907 out, err := ParseCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificateRequest().(derBytes)
908 if err != nil {
909 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: failed to create certificate request: %s", test.name, err)
910 continue
911 }
912
913 if out.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName. != template.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName. {
914 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: output subject common name and template subject common name don't match", test.name)
915 } else if len(out.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..Organizationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Organization.) != len(template.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..Organizationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Organization.) {
916 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: output subject organisation and template subject organisation don't match", test.name)
917 } else if len(out.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.) != len(template.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.) {
918 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: output DNS names and template DNS names don't match", test.name)
919 } else if len(out.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.) != len(template.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.) {
920 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: output email addresses and template email addresses don't match", test.name)
921 } else if len(out.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#IPAddresses.) != len(template.IPAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#IPAddresses.) {
922 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("%s: output IP addresses and template IP addresses names don't match", test.name)
923 }
924 }
925 }
926
927 func marshalAndParseCSRscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalAndParseCSR().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#, template *CertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#) *CertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest# {
928 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
929 rsaPriv, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
930 if err != nil {
931 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
932 }
933
934 derBytes, err := CreateCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CreateCertificateRequest().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., template, rsaPriv)
935 if err != nil {
936 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
937 }
938
939 csr, err := ParseCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificateRequest().(derBytes)
940 if err != nil {
941 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
942 }
943
944 return csr
945 }
946
947 func TestCertificateRequestOverridesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestCertificateRequestOverrides().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
948 sanContents, err := marshalSANsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalSANs().([]string{"foo.example.com"}, nil, nil)
949 if err != nil {
950 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
951 }
952
953 template := CertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#{
954 Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject.: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Namescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#{
955 CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName.: "test.example.com",
956 Organizationscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Organization.: []string{"Σ Acme Co"},
957 },
958 DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.: []string{"test.example.com"},
959
960 // An explicit extension should override the DNSNames from the
961 // template.
962 ExtraExtensionsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#ExtraExtensions.: []pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{
963 {
964 Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id.: oidExtensionSubjectAltNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionSubjectAltName.,
965 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: sanContents,
966 },
967 },
968 }
969
970 csr := marshalAndParseCSRscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalAndParseCSR().(t, &template)
971
972 if len(csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.) != 1 || csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.[0] != "foo.example.com" {
973 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Extension did not override template. Got %v\n", csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.)
974 }
975
976 // If there is already an attribute with X.509 extensions then the
977 // extra extensions should be added to it rather than creating a CSR
978 // with two extension attributes.
979
980 template.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes. = []pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.AttributeTypeAndValueSETscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#{
981 {
982 Typescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Type.: oidExtensionRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionRequest.,
983 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Value.: [][]pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.AttributeTypeAndValuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#{
984 {
985 {
986 Typescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#Type.: oidExtensionAuthorityInfoAccessscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionAuthorityInfoAccess.,
987 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#Value.: []byte("foo"),
988 },
989 },
990 },
991 },
992 }
993
994 csr = marshalAndParseCSRscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalAndParseCSR().(t, &template)
995 if l := len(csr.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.); l != 1 {
996 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("incorrect number of attributes: %d\n", l)
997 }
998
999 if !csr.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.[0].Typescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Type..Equalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#Equal().(oidExtensionRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionRequest.) ||
1000 len(csr.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.[0].Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Value.) != 1 ||
1001 len(csr.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.[0].Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Value.[0]) != 2 {
1002 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("bad attributes: %#v\n", csr.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.)
1003 }
1004
1005 sanContents2, err := marshalSANsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalSANs().([]string{"foo2.example.com"}, nil, nil)
1006 if err != nil {
1007 t.Fatalscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatal().(err)
1008 }
1009
1010 // Extensions in Attributes should override those in ExtraExtensions.
1011 template.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.[0].Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Value.[0] = append(template.Attributesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Attributes.[0].Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValueSET#Value.[0], pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.AttributeTypeAndValuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#{
1012 Typescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#Type.: oidExtensionSubjectAltNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionSubjectAltName.,
1013 Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/AttributeTypeAndValue#Value.: sanContents2,
1014 })
1015
1016 csr = marshalAndParseCSRscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/marshalAndParseCSR().(t, &template)
1017
1018 if len(csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.) != 1 || csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.[0] != "foo2.example.com" {
1019 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Attributes did not override ExtraExtensions. Got %v\n", csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.)
1020 }
1021 }
1022
1023 func TestParseCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseCertificateRequest().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1024 csrBytes := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(csrBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/csrBase64.)
1025 csr, err := ParseCertificateRequestscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificateRequest().(csrBytes)
1026 if err != nil {
1027 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("failed to parse CSR: %s", err)
1028 }
1029
1030 if len(csr.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.) != 1 || csr.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.[0] != "[email protected]" {
1031 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("incorrect email addresses found: %v", csr.EmailAddressesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#EmailAddresses.)
1032 }
1033
1034 if len(csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.) != 1 || csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.[0] != "test.example.com" {
1035 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("incorrect DNS names found: %v", csr.DNSNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#DNSNames.)
1036 }
1037
1038 if len(csr.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..Countryscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Country.) != 1 || csr.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject..Countryscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#Country.[0] != "AU" {
1039 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("incorrect Subject name: %v", csr.Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Subject.)
1040 }
1041
1042 found := false
1043 for _, e := range csr.Extensionsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CertificateRequest#Extensions. {
1044 if e.Idscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Id..Equalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#Equal().(oidExtensionBasicConstraintsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/oidExtensionBasicConstraints.) {
1045 found = true
1046 break
1047 }
1048 }
1049 if !found {
1050 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("basic constraints extension not found in CSR")
1051 }
1052 }
1053
1054 func TestMaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestMaxPathLen().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1055 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().([]byte(pemPrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/pemPrivateKey.))
1056 rsaPriv, err := ParsePKCS1PrivateKeyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
1057 if err != nil {
1058 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("Failed to parse private key: %s", err)
1059 }
1060
1061 template := &Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#{
1062 SerialNumberscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#SerialNumber.: bigscip-go gomod github.com/golang/go/src go1.16 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.16 `math/big`/NewInt().(1),
1063 Subjectscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#Subject.: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Namescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#{
1064 CommonNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Name#CommonName.: "Σ Acme Co",
1065 },
1066 NotBeforescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#NotBefore.: timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(1000, 0),
1067 NotAfterscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#NotAfter.: timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(100000, 0),
1068
1069 BasicConstraintsValidscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#BasicConstraintsValid.: true,
1070 IsCAscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#IsCA.: true,
1071 }
1072
1073 serialiseAndParse := func(template *Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#) *Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate# {
1074 derBytes, err := CreateCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/CreateCertificate().(randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Reader., template, template, &rsaPriv.PublicKeyscip-go gomod github.com/golang/go/src go1.16 `crypto/rsa`/PrivateKey#PublicKey., rsaPriv)
1075 if err != nil {
1076 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("failed to create certificate: %s", err)
1077 return nil
1078 }
1079
1080 cert, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(derBytes)
1081 if err != nil {
1082 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("failed to parse certificate: %s", err)
1083 return nil
1084 }
1085
1086 return cert
1087 }
1088
1089 cert1 := serialiseAndParse(template)
1090 if m := cert1.MaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLen.; m != -1 {
1091 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Omitting MaxPathLen didn't turn into -1, got %d", m)
1092 }
1093 if cert1.MaxPathLenZeroscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLenZero. {
1094 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Omitting MaxPathLen resulted in MaxPathLenZero")
1095 }
1096
1097 template.MaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLen. = 1
1098 cert2 := serialiseAndParse(template)
1099 if m := cert2.MaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLen.; m != 1 {
1100 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Setting MaxPathLen didn't work. Got %d but set 1", m)
1101 }
1102 if cert2.MaxPathLenZeroscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLenZero. {
1103 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Setting MaxPathLen resulted in MaxPathLenZero")
1104 }
1105
1106 template.MaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLen. = 0
1107 template.MaxPathLenZeroscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLenZero. = true
1108 cert3 := serialiseAndParse(template)
1109 if m := cert3.MaxPathLenscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLen.; m != 0 {
1110 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Setting MaxPathLenZero didn't work, got %d", m)
1111 }
1112 if !cert3.MaxPathLenZeroscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#MaxPathLenZero. {
1113 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("Setting MaxPathLen to zero didn't result in MaxPathLenZero")
1114 }
1115 }
1116
1117 // This CSR was generated with OpenSSL:
1118 //
1119 // openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key -config openssl.cnf
1120 //
1121 // The openssl.cnf needs to include this section:
1122 //
1123 // [ v3_req ]
1124 // basicConstraints = CA:FALSE
1125 // keyUsage = nonRepudiation, digitalSignature, keyEncipherment
1126 // subjectAltName = email:[email protected],DNS:test.example.com
1127 const csrBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/csrBase64. = "MIIC4zCCAcsCAQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOY+MVedRg2JEnyeLcSzcsMv2VcsTfkB5+Etd6hihAh6MrGezNyASMMKuQN6YhCX1icQDiQtGsDLTtheNnSXK06tAhHjAP/hGlszRJp+5+rP2M58fDBAkUBEhskbCUWwpY14jFtVuGNJ8vF8h8IeczdolvQhX9lVai9G0EUXJMliMKdjA899H0mRs9PzHyidyrXFNiZlQXfD8Kg7gETn2Ny965iyI6ujAIYSCvam6TnxRHYH2MBKyVGvsYGbPYUQJCsgdgyajEg6ekihvQY3SzO1HSAlZAd7d1QYO4VeWJ2mY6Wu3Jpmh+AmG19S9CcHqGjd0bhuAX9cpPOKgnEmqn0CAwEAAaBZMFcGCSqGSIb3DQEJDjFKMEgwCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwLgYDVR0RBCcwJYERZ29waGVyQGdvbGFuZy5vcmeCEHRlc3QuZXhhbXBsZS5jb20wDQYJKoZIhvcNAQEFBQADggEBAC9+QpKfdabxwCWwf4IEe1cKjdXLS1ScSuw27a3kZzQiPV78WJMa6dB8dqhdH5BRwGZ/qsgLrO6ZHlNeIv2Ib41Ccq71ecHW/nXc94A1BzJ/bVdI9LZcmTUvR1/m1jCpN7UqQ0ml1u9VihK7Pe762hEYxuWDQzYEU0l15S/bXmqeq3eF1A59XT/2jwe5+NV0Wwf4UQlkTXsAQMsJ+KzrQafd8Qv2A49o048uRvmjeJDrXLawGVianZ7D5A6Fpd1rZh6XcjqBpmgLw41DRQWENOdzhy+HyphKRv1MlY8OLkNqpGMhu8DdgJVGoT16DGiickoEa7Z3UCPVNgdTkT9jq7U="
1128
1129 const sanManyOtherNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyOtherName. = "MEmgEAYIKwYBBAHZWy6gBAICAc2CCHRlc3QuZ292oA8GCCsGAQQB2VsuoAMCASqCB2dvdi5nb3agEQYIKwYBBAHZWy6gBQIDAXUA"
1130
1131 func TestParseGeneralNamesOtherNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesOtherName().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1132 sanMultipleOther := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(sanManyOtherNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyOtherName.)
1133 otherNames, dnsNames, emailAddresses, URIs, directoryNames, ediPartyNames, ipAddresses, registeredIDs, _, err := parseGeneralNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/parseGeneralNames().(sanMultipleOther)
1134
1135 if err != nil {
1136 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned error %v", err)
1137 }
1138 if emailAddresses != nil || directoryNames != nil || URIs != nil || ediPartyNames != nil || ipAddresses != nil || registeredIDs != nil {
1139 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected name type from sanManyOtherName")
1140 }
1141 if len(dnsNames) != 2 || dnsNames[0] != "test.gov" || dnsNames[1] != "gov.gov" {
1142 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected dnsNames from sanManyOtherName: %v", dnsNames)
1143 }
1144 if len(otherNames) != 3 {
1145 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected # of otherName in sanManyOtherName: %v (expected 3)", len(otherNames))
1146 }
1147 var otherInts [3]int
1148 var expectedInts [3]int = [3]int{461, 42, 95488}
1149 for x := 0; x < 3; x++ {
1150 rest, err := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Unmarshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Unmarshal().(otherNames[x].Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/OtherName#Value..Bytesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/RawValue#Bytes., &(otherInts[x]))
1151 if err != nil {
1152 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("unexpected error in unmarshaling otherName %v", err)
1153 }
1154 if len(rest) != 0 {
1155 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("unexpected extra bytes in otherName")
1156 }
1157 }
1158 for i := range otherInts {
1159 if otherInts[i] != expectedInts[i] {
1160 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("otherName contained unexpected value %v, expected %v", otherInts[i], expectedInts[i])
1161 }
1162 }
1163
1164 }
1165
1166 const sanManyDirectoryNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyDirectoryName. = "MIHtpBwwGjEYMBYGA1UEChMPRXh0cmVtZSBEaXNjb3JkgggqLmdvdi51c6SBnDCBmTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkZMMRQwEgYDVQQHEwtUYWxsYWhhc3NlZTEcMBoGA1UECRMTMzIxMCBIb2xseSBNaWxsIFJ1bjEOMAwGA1UEERMFMzAwNjIxGDAWBgNVBAoTD0V4dHJlbWUgRGlzY29yZDEOMAwGA1UECxMFQ2hhb3MxDzANBgNVBAMTBmdvdi51c4IGZ292LnVzpBwwGjEYMBYGA1UEChMPRXh0cmVtZSBEaXNjb3Jk"
1167
1168 func TestParseGeneralNamesDirectoryNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesDirectoryName().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1169 // TODO: This needs to test that we can parse a GeneralName that contains a
1170 // DirectoryName, not that we can parse DirectoryNames correctly, which is
1171 // what it was previously doing. DirectoryName parsing falls under pkix.Name,
1172 // and should be tested in the pkix package.
1173 }
1174
1175 const sanManyURIscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyURI. = "MF6GGGh0dHA6Ly9nb3YudXMvaW5kZXguaHRtbIIIKi5nb3YudXOGE2h0dHA6Ly9nb3YudXMvaG9tZS+CBmdvdi51c4YbaHR0cDovL2dvdi51cy9ob21lL2NhcGl0b2wv"
1176
1177 func TestParseGeneralNamesUniformResourceIdentifierscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesUniformResourceIdentifier().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1178 sanMultipleURI := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(sanManyURIscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyURI.)
1179 otherNames, dnsNames, emailAddresses, URIs, directoryNames, ediPartyNames, ipAddresses, registeredIDs, _, err := parseGeneralNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/parseGeneralNames().(sanMultipleURI)
1180
1181 if err != nil {
1182 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned error %v", err)
1183 }
1184 if emailAddresses != nil || otherNames != nil || directoryNames != nil || ediPartyNames != nil || ipAddresses != nil || registeredIDs != nil {
1185 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected name type from sanManyURI")
1186 }
1187 if len(dnsNames) != 2 || dnsNames[0] != "*.gov.us" || dnsNames[1] != "gov.us" {
1188 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected dnsNames from sanManyURI: %v", dnsNames)
1189 }
1190 if len(URIs) != 3 {
1191 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected # of uniformResourceIdentifier in sanManyURI: %v (expected 3)", len(URIs))
1192 }
1193
1194 var expectedNames [3]string = [3]string{"http://gov.us/index.html", "http://gov.us/home/", "http://gov.us/home/capitol/"}
1195 for i := range URIs {
1196 if URIs[i] != expectedNames[i] {
1197 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("uniformResourceIdentifier contained unexpected value %v, expected %v", URIs[i], expectedNames[i])
1198 }
1199 }
1200 }
1201
1202 const sanManyRegisteredIDscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyRegisteredID. = "MDGICCsGAQUFBw0Bggh0ZXN0LmdvdogIKwYBBAHZWyqCB2dvdi5nb3aICCsGAQUFBw0D"
1203
1204 func TestParseGeneralNamesRegisteredIDscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesRegisteredID().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1205 sanMultipleRID := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(sanManyRegisteredIDscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyRegisteredID.)
1206 otherNames, dnsNames, emailAddresses, URIs, directoryNames, ediPartyNames, ipAddresses, registeredIDs, _, err := parseGeneralNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/parseGeneralNames().(sanMultipleRID)
1207
1208 if err != nil {
1209 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned error %v", err)
1210 }
1211 if emailAddresses != nil || otherNames != nil || directoryNames != nil || ediPartyNames != nil || ipAddresses != nil || URIs != nil {
1212 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected name type from sanManyRegisteredID")
1213 }
1214 if len(dnsNames) != 2 || dnsNames[0] != "test.gov" || dnsNames[1] != "gov.gov" {
1215 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected dnsNames from sanManyRegisteredID: %v", dnsNames)
1216 }
1217 if len(registeredIDs) != 3 {
1218 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected # of registeredIDs in sanManyRegisteredID: %v (expected 3)", len(registeredIDs))
1219 }
1220
1221 var expectedNames [3]asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier# = [3]asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#{{1, 3, 6, 1, 5, 5, 7, 13, 1}, {1, 3, 6, 1, 4, 1, 11483, 42}, {1, 3, 6, 1, 5, 5, 7, 13, 3}}
1222 for i := range registeredIDs {
1223 if !registeredIDs[i].Equalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/ObjectIdentifier#Equal().(expectedNames[i]) {
1224 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("registeredID contained unexpected value %v, expected %v", registeredIDs[i], expectedNames[i])
1225 }
1226 }
1227 }
1228
1229 const sanManyEDIscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyEDI. = "MIGjpRigBwwFRWFydGihDQwLVW5kZXJncm91bmSCCHRlc3QuZ292pQ6hDBMKZ292ZXJubWVudKUNoQsMCXNvdmVyZWlnboIHZ292LmdvdqUjoAoTCHVuaXZlcnNloRUME1N1cHJlbWUgTGVnaXNsYXR1cmWBDWFkbWluQGdvdi5nb3alIaAKEwh1bml2ZXJzZaETExFTdXByZW1lIEV4ZWN1dGl2ZQ=="
1230
1231 func TestParseGeneralNamesEDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesEDIPartyName().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1232 sanMultipleEDI := fromBase64scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/fromBase64().(sanManyEDIscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanManyEDI.)
1233 otherNames, dnsNames, emailAddresses, URIs, directoryNames, ediPartyNames, ipAddresses, registeredIDs, _, err := parseGeneralNamesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/parseGeneralNames().(sanMultipleEDI)
1234
1235 if err != nil {
1236 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned error %v", err)
1237 }
1238 if registeredIDs != nil || otherNames != nil || directoryNames != nil || ipAddresses != nil || URIs != nil {
1239 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected name type from sanManyEDI")
1240 }
1241 if len(dnsNames) != 2 || dnsNames[0] != "test.gov" || dnsNames[1] != "gov.gov" {
1242 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected dnsNames from sanManyEDI: %v (expected 2)", dnsNames)
1243 }
1244 if len(emailAddresses) != 1 || emailAddresses[0] != "[email protected]" {
1245 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected rfc822Names from sanManyEDI: %v", emailAddresses)
1246 }
1247 if len(ediPartyNames) != 5 {
1248 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("parseGeneralNames returned unexpected # of ediPartyNames in sanManyEDI: %v (expected 5)", len(ediPartyNames))
1249 }
1250
1251 var expectedNames [5]pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#
1252 expectedNames[0] = pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#{NameAssignerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#NameAssigner.: "Earth", PartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#PartyName.: "Underground"}
1253 expectedNames[1] = pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#{PartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#PartyName.: "government"}
1254 expectedNames[2] = pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#{PartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#PartyName.: "sovereign"}
1255 expectedNames[3] = pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#{NameAssignerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#NameAssigner.: "universe", PartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#PartyName.: "Supreme Legislature"}
1256 expectedNames[4] = pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.EDIPartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#{NameAssignerscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#NameAssigner.: "universe", PartyNamescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/EDIPartyName#PartyName.: "Supreme Executive"}
1257
1258 for i := range ediPartyNames {
1259 if !reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.16 reflect/DeepEqual().(ediPartyNames[i], expectedNames[i]) {
1260 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("ediPartyName contained unexpected value %v, expected %v", ediPartyNames[i], expectedNames[i])
1261 }
1262 }
1263 }
1264
1265 const sanAllSuportedscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/sanAllSuported. = "MIGXiAkrBgEEAdlbgzqkHDAaMRgwFgYDVQQKEw9FeHRyZW1lIERpc2NvcmSgEQYIKwYBBAHZWy6gBQIDCCoJpR6gDxMNTW90aGVyIE5hdHVyZaELEwlwYXJ0eU5hbWWCCCouZ292LnVzggZnb3YudXOBDGFkbWluQGdvdi51c4YTaHR0cHM6Ly9nb3YudXMvaG9tZYcEwMAAAQ=="
1266
1267 func TestParseGeneralNamesAllscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseGeneralNamesAll().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1268 // TODO: This should test we can parse a GeneralName that contains all
1269 // possible types of GeneralName, not that we can parse a DN correctly. We
1270 // should not rely on implementation details of pkix.Name to handle parsing a
1271 // GeneralName. More broadly, we should consider refactoring how GeneralName
1272 // is handled, and maybe move it to the pkix package.
1273 }
1274
1275 func TestTimeInValidityPeriodscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestTimeInValidityPeriod().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1276 fileBytes, _ := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().("testdata/davidadrian.org.cert")
1277 p, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().(fileBytes)
1278 c, err := ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(p.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
1279 if err != nil {
1280 t.Fatalfscip-go gomod github.com/golang/go/src go1.16 testing/common#Fatalf().("unable to parse PEM: %s", err)
1281 }
1282 tests := []struct {
1283 unixTime int64
1284 expected bool
1285 }{
1286 {
1287 unixTime: 946684800, // 2000-01-01 00:00:00
1288 expected: false,
1289 },
1290 {
1291 unixTime: 0,
1292 expected: false,
1293 },
1294 {
1295 unixTime: 2208988800, // 2040-01-01 00:00:00
1296 expected: false,
1297 },
1298 {
1299 unixTime: 1420070400, // 2015-01-01 00:00:00
1300 expected: true,
1301 },
1302 }
1303 for idx, test := range tests {
1304 timestamp := timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(test.unixTime, 0)
1305 if actual := c.TimeInValidityPeriodscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#TimeInValidityPeriod().(timestamp); actual != test.expected {
1306 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("#%d: for time %d got %t, expected %v", idx, test.unixTime, actual, test.expected)
1307 }
1308 }
1309 }
1310
1311 func TestParseSignedCertificateTimestampListErrorsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseSignedCertificateTimestampListErrors().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1312 incompleteList, _ := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Marshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Marshal().([]byte{0x00})
1313 nodataList, _ := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Marshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Marshal().([]byte{0x00, 0x00})
1314 trailingDataList, _ := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Marshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Marshal().([]byte{0x00, 0x00, 0x00})
1315 incompleteSCTList, _ := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Marshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Marshal().([]byte{0x00, 0x00, 0x00, 0x99})
1316 badSCTList, _ := asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.Marshalscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/Marshal().([]byte{0x00, 0x00, 0x00, 0x00, 0x00})
1317
1318 testCases := []struct {
1319 name string
1320 ext pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#
1321 expectedErrMsg string
1322 }{
1323 {
1324 name: "incomplete len",
1325 ext: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: incompleteList},
1326 expectedErrMsg: "malformed SCT extension: incomplete length field",
1327 },
1328 {
1329 name: "trailing data",
1330 ext: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: trailingDataList},
1331 expectedErrMsg: "malformed SCT extension: trailing data",
1332 },
1333 {
1334 name: "incomplete SCT in list",
1335 ext: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: incompleteSCTList},
1336 expectedErrMsg: "malformed SCT extension: incomplete SCT",
1337 },
1338 {
1339 name: "bad SCT in list",
1340 ext: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: badSCTList},
1341 expectedErrMsg: "malformed SCT extension: SCT parse err: EOF",
1342 },
1343 {
1344 name: "no data",
1345 ext: pkixscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/.Extensionscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#{Valuescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509/pkix`/Extension#Value.: nodataList},
1346 },
1347 }
1348
1349 for _, tc := range testCases {
1350 t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1351 out := &Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/Certificate#{}
1352 err := parseSignedCertificateTimestampListscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/parseSignedCertificateTimestampList().(out, tc.ext)
1353
1354 if err != nil && err.Error() != tc.expectedErrMsg {
1355 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("expected err %q got %q", tc.expectedErrMsg, err.Error())
1356 } else if err == nil && tc.expectedErrMsg != "" {
1357 t.Errorfscip-go gomod github.com/golang/go/src go1.16 testing/common#Errorf().("expected err %q got nil", tc.expectedErrMsg)
1358 }
1359 })
1360 }
1361 }
1362
1363 func TestParseCertscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/TestParseCert().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1364 tcases := []string{
1365 "testdata/parsecert1.pem",
1366 "testdata/parsecert2.pem",
1367 "testdata/parsecert3.pem",
1368 "testdata/parsecert4-time.pem",
1369 "testdata/parsecert5-printable.pem",
1370 "testdata/parsecert6-explicittag.pem",
1371 "testdata/parsecert7-tagmatch.pem",
1372 "testdata/parsecert8-rsapositive.pem",
1373 "testdata/parsecert9-intminlen.pem",
1374 "testdata/parsecert10-tag.pem",
1375 "testdata/parsecert11-ia5.pem",
1376 "testdata/parsecert12-minlen.pem",
1377 }
1378
1379 for _, tc := range tcases {
1380 t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().(tc, func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1381 b, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().(tc)
1382 requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err)
1383
1384 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().(b)
1385 requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NotNil().(t, block)
1386
1387 _, err = ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
1388 assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/assert`/Error().(t, err)
1389 })
1390 }
1391
1392 asn1scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/.AllowPermissiveParsingscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/encoding/asn1`/AllowPermissiveParsing. = true
1393
1394 for _, tc := range tcases {
1395 t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().(tc, func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) {
1396 b, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().(tc)
1397 requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err)
1398
1399 block, _ := pemscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Decode().(b)
1400 requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NotNil().(t, block)
1401
1402 _, err = ParseCertificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/x509`/ParseCertificate().(block.Bytesscip-go gomod github.com/golang/go/src go1.16 `encoding/pem`/Block#Bytes.)
1403 assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/assert`/NoError().(t, err)
1404 })
1405 }
1406 }