| 1 |
package pkcs7scip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytesscip-go gomod github.com/golang/go/src go1.13 bytes/" |
| 5 |
"cryptoscip-go gomod github.com/golang/go/src go1.13 crypto/" |
| 6 |
"crypto/dsascip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/" |
| 7 |
"crypto/x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/" |
| 8 |
"encoding/asn1scip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/" |
| 9 |
"encoding/pemscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/" |
| 10 |
"fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 11 |
"io/ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/" |
| 12 |
"math/bigscip-go gomod github.com/golang/go/src go1.13 `math/big`/" |
| 13 |
"osscip-go gomod github.com/golang/go/src go1.13 os/" |
| 14 |
"os/execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/" |
| 15 |
"testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 16 |
) |
| 17 |
|
| 18 |
func TestSignscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestSign().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 19 |
content := []byte("Hello World") |
| 20 |
sigalgs := []x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SignatureAlgorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SignatureAlgorithm#{ |
| 21 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA1WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA1WithRSA., |
| 22 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA256WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA256WithRSA., |
| 23 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA512WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA512WithRSA., |
| 24 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA1scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA1., |
| 25 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA256scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA256., |
| 26 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA384scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA384., |
| 27 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA512scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA512., |
| 28 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.PureEd25519scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/PureEd25519., |
| 29 |
} |
| 30 |
for _, sigalgroot := range sigalgs { |
| 31 |
rootCert, err := createTestCertificateByIssuerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificateByIssuer().("PKCS7 Test Root CA", nil, sigalgroot, true) |
| 32 |
if err != nil { |
| 33 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s: cannot generate root cert: %s", sigalgroot, err) |
| 34 |
} |
| 35 |
truststore := x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.NewCertPoolscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/NewCertPool().() |
| 36 |
truststore.AddCertscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/CertPool#AddCert().(rootCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate.) |
| 37 |
for _, sigalginter := range sigalgs { |
| 38 |
interCert, err := createTestCertificateByIssuerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificateByIssuer().("PKCS7 Test Intermediate Cert", rootCert, sigalginter, true) |
| 39 |
if err != nil { |
| 40 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot generate intermediate cert: %s", sigalgroot, sigalginter, err) |
| 41 |
} |
| 42 |
var parents []*x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/Certificate# |
| 43 |
parents = append(parents, interCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate.) |
| 44 |
for _, sigalgsigner := range sigalgs { |
| 45 |
signerCert, err := createTestCertificateByIssuerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificateByIssuer().("PKCS7 Test Signer Cert", interCert, sigalgsigner, false) |
| 46 |
if err != nil { |
| 47 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s/%s: cannot generate signer cert: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 48 |
} |
| 49 |
for _, testDetach := range []bool{false, true} { |
| 50 |
toBeSigned, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().(content) |
| 51 |
if err != nil { |
| 52 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s/%s: cannot initialize signed data: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 53 |
} |
| 54 |
|
| 55 |
// Set the digest to match the end entity cert |
| 56 |
signerDigest, _ := GetDigestOIDForSignatureAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/GetDigestOIDForSignatureAlgorithm().(signerCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate..SignatureAlgorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/Certificate#SignatureAlgorithm.) |
| 57 |
toBeSigned.SetDigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#SetDigestAlgorithm().(signerDigest) |
| 58 |
|
| 59 |
if err := toBeSigned.AddSignerChainscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#AddSignerChain().(signerCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., *signerCert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey., parents, SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{}); err != nil { |
| •60 |
t.Skipscip-go gomod github.com/golang/go/src go1.13 testing/common#Skip().("test %s/%s/%s: cannot add signer: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 61 |
} |
| 62 |
if testDetach { |
| 63 |
toBeSigned.Detachscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Detach().() |
| 64 |
} |
| 65 |
signed, err := toBeSigned.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 66 |
if err != nil { |
| 67 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s/%s: cannot finish signing data: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 68 |
} |
| 69 |
p7, err := Parsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Parse().(signed) |
| 70 |
if err != nil { |
| 71 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s/%s: cannot parse signed data: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 72 |
} |
| 73 |
if testDetach { |
| 74 |
p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content. = content |
| 75 |
} |
| 76 |
if !bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Equalscip-go gomod github.com/golang/go/src go1.13 bytes/Equal().(content, p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content.) { |
| 77 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("test %s/%s/%s: content was not found in the parsed data:\n\tExpected: %s\n\tActual: %s", sigalgroot, sigalginter, sigalgsigner, content, p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content.) |
| 78 |
} |
| 79 |
if err := p7.VerifyWithChainscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#VerifyWithChain().(truststore); err != nil { |
| 80 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("test %s/%s/%s: cannot verify signed data: %s", sigalgroot, sigalginter, sigalgsigner, err) |
| 81 |
} |
| 82 |
if !signerDigest.Equalscip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/ObjectIdentifier#Equal().(p7.Signersscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Signers.[0].DigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) { |
| 83 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("test %s/%s/%s: expected digest algorithm %q but got %q", |
| 84 |
sigalgroot, sigalginter, sigalgsigner, signerDigest, p7.Signersscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Signers.[0].DigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
func TestDSASignAndVerifyWithOpenSSLscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestDSASignAndVerifyWithOpenSSL().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 93 |
content := []byte("Hello World") |
| 94 |
// write the content to a temp file |
| 95 |
tmpContentFile, err := ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.TempFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/TempFile().("", "TestDSASignAndVerifyWithOpenSSL_content") |
| 96 |
if err != nil { |
| 97 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 98 |
} |
| 99 |
ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.WriteFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/WriteFile().(tmpContentFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().(), content, 0755) |
| 100 |
|
| 101 |
block, _ := pemscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/Decode().([]byte(dsaPublicCertscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/dsaPublicCert.)) |
| 102 |
if block == nil { |
| 103 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("failed to parse certificate PEM") |
| 104 |
} |
| 105 |
signerCert, err := x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ParseCertificatescip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ParseCertificate().(block.Bytesscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/Block#Bytes.) |
| 106 |
if err != nil { |
| 107 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("failed to parse certificate: " + err.Error()) |
| 108 |
} |
| 109 |
|
| 110 |
// write the signer cert to a temp file |
| 111 |
tmpSignerCertFile, err := ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.TempFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/TempFile().("", "TestDSASignAndVerifyWithOpenSSL_signer") |
| 112 |
if err != nil { |
| 113 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 114 |
} |
| 115 |
ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.WriteFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/WriteFile().(tmpSignerCertFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().(), dsaPublicCertscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/dsaPublicCert., 0755) |
| 116 |
|
| 117 |
priv := dsascip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/PrivateKey#{ |
| 118 |
PublicKeyscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/PrivateKey#PublicKey.: dsascip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/PublicKey#{Parametersscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/PublicKey#Parameters.: dsascip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/.Parametersscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/Parameters#{Pscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/Parameters#P.: fromHexscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/fromHex().("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7"), |
| 119 |
Qscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/Parameters#Q.: fromHexscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/fromHex().("9760508F15230BCCB292B982A2EB840BF0581CF5"), |
| 120 |
Gscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/Parameters#G.: fromHexscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/fromHex().("F7E1A085D69B3DDECBBCAB5C36B857B97994AFBBFA3AEA82F9574C0B3D0782675159578EBAD4594FE67107108180B449167123E84C281613B7CF09328CC8A6E13C167A8B547C8D28E0A3AE1E2BB3A675916EA37F0BFA213562F1FB627A01243BCCA4F1BEA8519089A883DFE15AE59F06928B665E807B552564014C3BFECF492A"), |
| 121 |
}, |
| 122 |
}, |
| 123 |
Xscip-go gomod github.com/golang/go/src go1.13 `crypto/dsa`/PrivateKey#X.: fromHexscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/fromHex().("7D6E1A3DD4019FD809669D8AB8DA73807CEF7EC1"), |
| 124 |
} |
| 125 |
toBeSigned, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().(content) |
| 126 |
if err != nil { |
| 127 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test case: cannot initialize signed data: %s", err) |
| 128 |
} |
| 129 |
if err := toBeSigned.SignWithoutAttrscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#SignWithoutAttr().(signerCert, &priv, SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{}); err != nil { |
| 130 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot add signer: %s", err) |
| 131 |
} |
| 132 |
toBeSigned.Detachscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Detach().() |
| 133 |
signed, err := toBeSigned.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 134 |
if err != nil { |
| 135 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test case: cannot finish signing data: %s", err) |
| 136 |
} |
| 137 |
|
| 138 |
// write the signature to a temp file |
| 139 |
tmpSignatureFile, err := ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.TempFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/TempFile().("", "TestDSASignAndVerifyWithOpenSSL_signature") |
| 140 |
if err != nil { |
| 141 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 142 |
} |
| 143 |
ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.WriteFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/WriteFile().(tmpSignatureFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().(), pemscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/.EncodeToMemoryscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/EncodeToMemory().(&pemscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/Block#{Typescip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/Block#Type.: "PKCS7", Bytesscip-go gomod github.com/golang/go/src go1.13 `encoding/pem`/Block#Bytes.: signed}), 0755) |
| 144 |
|
| 145 |
// call openssl to verify the signature on the content using the root |
| 146 |
opensslCMD := execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Command().("openssl", "smime", "-verify", "-noverify", |
| 147 |
"-in", tmpSignatureFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().(), "-inform", "PEM", |
| 148 |
"-content", tmpContentFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) |
| 149 |
out, err := opensslCMD.CombinedOutputscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#CombinedOutput().() |
| 150 |
if err != nil { |
| 151 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test case: openssl command failed with %s: %s", err, out) |
| 152 |
} |
| 153 |
osscip-go gomod github.com/golang/go/src go1.13 os/.Removescip-go gomod github.com/golang/go/src go1.13 os/Remove().(tmpSignatureFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) // clean up |
| 154 |
osscip-go gomod github.com/golang/go/src go1.13 os/.Removescip-go gomod github.com/golang/go/src go1.13 os/Remove().(tmpContentFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) // clean up |
| 155 |
osscip-go gomod github.com/golang/go/src go1.13 os/.Removescip-go gomod github.com/golang/go/src go1.13 os/Remove().(tmpSignerCertFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) // clean up |
| 156 |
} |
| 157 |
|
| 158 |
func TestSignWithoutAttributesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestSignWithoutAttributes().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 159 |
content := []byte("Hello World") |
| 160 |
sigalgs := []x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SignatureAlgorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SignatureAlgorithm#{ |
| 161 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA1WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA1WithRSA., |
| 162 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA256WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA256WithRSA., |
| 163 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA512WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA512WithRSA., |
| 164 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA1scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA1., |
| 165 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA256scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA256., |
| 166 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA384scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA384., |
| 167 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.ECDSAWithSHA512scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/ECDSAWithSHA512., |
| 168 |
x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.PureEd25519scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/PureEd25519., |
| 169 |
} |
| 170 |
for _, sigalgroot := range sigalgs { |
| 171 |
rootCert, err := createTestCertificateByIssuerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificateByIssuer().("PKCS7 Test Root CA", nil, sigalgroot, true) |
| 172 |
if err != nil { |
| 173 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s: cannot generate root cert: %s", sigalgroot, err) |
| 174 |
} |
| 175 |
truststore := x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.NewCertPoolscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/NewCertPool().() |
| 176 |
truststore.AddCertscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/CertPool#AddCert().(rootCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate.) |
| 177 |
for _, sigalgsigner := range sigalgs { |
| 178 |
signerCert, err := createTestCertificateByIssuerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificateByIssuer().("PKCS7 Test Signer Cert", rootCert, sigalgsigner, false) |
| 179 |
if err != nil { |
| 180 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot generate signer cert: %s", sigalgroot, sigalgsigner, err) |
| 181 |
} |
| 182 |
for _, testDetach := range []bool{false, true} { |
| 183 |
toBeSigned, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().(content) |
| 184 |
if err != nil { |
| 185 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot initialize signed data: %s", sigalgroot, sigalgsigner, err) |
| 186 |
} |
| 187 |
|
| 188 |
// Set the digest to match the end entity cert |
| 189 |
signerDigest, _ := GetDigestOIDForSignatureAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/GetDigestOIDForSignatureAlgorithm().(signerCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate..SignatureAlgorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/Certificate#SignatureAlgorithm.) |
| 190 |
toBeSigned.SetDigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#SetDigestAlgorithm().(signerDigest) |
| 191 |
|
| 192 |
if err := toBeSigned.SignWithoutAttrscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#SignWithoutAttr().(signerCert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., (*signerCert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey.).(cryptoscip-go gomod github.com/golang/go/src go1.13 crypto/.Signerscip-go gomod github.com/golang/go/src go1.13 crypto/Signer#), SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{}); err != nil { |
| 193 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot add signer: %s", sigalgroot, sigalgsigner, err) |
| 194 |
} |
| 195 |
if testDetach { |
| 196 |
toBeSigned.Detachscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Detach().() |
| 197 |
} |
| 198 |
signed, err := toBeSigned.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 199 |
if err != nil { |
| 200 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot finish signing data: %s", sigalgroot, sigalgsigner, err) |
| 201 |
} |
| 202 |
p7, err := Parsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Parse().(signed) |
| 203 |
if err != nil { |
| 204 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("test %s/%s: cannot parse signed data: %s", sigalgroot, sigalgsigner, err) |
| 205 |
} |
| 206 |
if testDetach { |
| 207 |
p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content. = content |
| 208 |
} |
| 209 |
if !bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Equalscip-go gomod github.com/golang/go/src go1.13 bytes/Equal().(content, p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content.) { |
| 210 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("test %s/%s: content was not found in the parsed data:\n\tExpected: %s\n\tActual: %s", sigalgroot, sigalgsigner, content, p7.Contentscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Content.) |
| 211 |
} |
| 212 |
if err := p7.VerifyWithChainscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#VerifyWithChain().(truststore); err != nil { |
| •213 |
t.Skipscip-go gomod github.com/golang/go/src go1.13 testing/common#Skip().("test %s/%s: cannot verify signed data: %s", sigalgroot, sigalgsigner, err) |
| 214 |
} |
| 215 |
if !signerDigest.Equalscip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/ObjectIdentifier#Equal().(p7.Signersscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Signers.[0].DigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) { |
| 216 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("test %s/%s: expected digest algorithm %q but got %q", |
| 217 |
sigalgroot, sigalgsigner, signerDigest, p7.Signersscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Signers.[0].DigestAlgorithmscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/signerInfo#DigestAlgorithm..Algorithmscip-go gomod github.com/golang/go/src go1.13 `crypto/x509/pkix`/AlgorithmIdentifier#Algorithm.) |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
func ExampleSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/ExampleSignedData().() { |
| 225 |
// generate a signing cert or load a key pair |
| 226 |
cert, err := createTestCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificate().(x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA256WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA256WithRSA.) |
| 227 |
if err != nil { |
| 228 |
fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("Cannot create test certificates: %s", err) |
| 229 |
} |
| 230 |
|
| 231 |
// Initialize a SignedData struct with content to be signed |
| 232 |
signedData, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().([]byte("Example data to be signed")) |
| 233 |
if err != nil { |
| 234 |
fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("Cannot initialize signed data: %s", err) |
| 235 |
} |
| 236 |
|
| 237 |
// Add the signing cert and private key |
| 238 |
if err := signedData.AddSignerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#AddSigner().(cert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., cert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey., SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{}); err != nil { |
| 239 |
fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("Cannot add signer: %s", err) |
| 240 |
} |
| 241 |
|
| 242 |
// Call Detach() is you want to remove content from the signature |
| 243 |
// and generate an S/MIME detached signature |
| 244 |
signedData.Detachscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Detach().() |
| 245 |
|
| 246 |
// Finish() to obtain the signature bytes |
| 247 |
_, err = signedData.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 248 |
if err != nil { |
| 249 |
fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("Cannot finish signing data: %s", err) |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
func TestSetContentTypescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestSetContentType().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 254 |
cert, err := createTestCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificate().(x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA256WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA256WithRSA.) |
| 255 |
if err != nil { |
| 256 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot create test certificates: %s", err) |
| 257 |
} |
| 258 |
|
| 259 |
signedData, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().([]byte("Example data to be signed")) |
| 260 |
if err != nil { |
| 261 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot initialize signed data: %s", err) |
| 262 |
} |
| 263 |
|
| 264 |
idctTSTInfo := asn1scip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/ObjectIdentifier#{1, 2, 840, 113549, 1, 9, 16, 1, 4} |
| 265 |
signedData.SetContentTypescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#SetContentType().(idctTSTInfo) |
| 266 |
|
| 267 |
if err := signedData.AddSignerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#AddSigner().(cert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., *cert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey., SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{}); err != nil { |
| 268 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot add signer: %s", err) |
| 269 |
} |
| 270 |
|
| 271 |
_, err = signedData.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 272 |
if err != nil { |
| 273 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot finish signing data: %s", err) |
| 274 |
} |
| 275 |
|
| 276 |
sd := signedData.GetSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#GetSignedData().() |
| 277 |
if !sd.ContentInfoscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/signedData#ContentInfo..ContentTypescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/contentInfo#ContentType..Equalscip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/ObjectIdentifier#Equal().(idctTSTInfo) { |
| 278 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unexpected content type: %s", err) |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
func TestUnmarshalSignedAttributescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestUnmarshalSignedAttribute().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 283 |
cert, err := createTestCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificate().(x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA512WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA512WithRSA.) |
| 284 |
if err != nil { |
| 285 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 286 |
} |
| 287 |
content := []byte("Hello World") |
| 288 |
toBeSigned, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().(content) |
| 289 |
if err != nil { |
| 290 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot initialize signed data: %s", err) |
| 291 |
} |
| 292 |
oidTest := asn1scip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.13 `encoding/asn1`/ObjectIdentifier#{2, 3, 4, 5, 6, 7} |
| 293 |
testValue := "TestValue" |
| 294 |
if err := toBeSigned.AddSignerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#AddSigner().(cert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., *cert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey., SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{ |
| 295 |
ExtraSignedAttributesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#ExtraSignedAttributes.: []Attributescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Attribute#{Attributescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Attribute#{Typescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Attribute#Type.: oidTest, Valuescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Attribute#Value.: testValue}}, |
| 296 |
}); err != nil { |
| 297 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot add signer: %s", err) |
| 298 |
} |
| 299 |
signed, err := toBeSigned.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 300 |
if err != nil { |
| 301 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot finish signing data: %s", err) |
| 302 |
} |
| 303 |
p7, err := Parsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Parse().(signed) |
| 304 |
if err != nil { |
| 305 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot parse signed data: %v", err) |
| 306 |
} |
| 307 |
var actual string |
| 308 |
err = p7.UnmarshalSignedAttributescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#UnmarshalSignedAttribute().(oidTest, &actual) |
| 309 |
if err != nil { |
| 310 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot unmarshal test value: %s", err) |
| 311 |
} |
| 312 |
if testValue != actual { |
| 313 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("Attribute does not match test value\n\tExpected: %s\n\tActual: %s", testValue, actual) |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
func TestDegenerateCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestDegenerateCertificate().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 318 |
cert, err := createTestCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificate().(x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA1WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA1WithRSA.) |
| 319 |
if err != nil { |
| 320 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 321 |
} |
| 322 |
deg, err := DegenerateCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/DegenerateCertificate().(cert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate..Rawscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/Certificate#Raw.) |
| 323 |
if err != nil { |
| 324 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 325 |
} |
| 326 |
testOpenSSLParsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/testOpenSSLParse().(t, deg) |
| 327 |
} |
| 328 |
|
| 329 |
func TestSkipCertificatesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/TestSkipCertificates().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 330 |
cert, err := createTestCertificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/createTestCertificate().(x509scip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/.SHA512WithRSAscip-go gomod github.com/golang/go/src go1.13 `crypto/x509`/SHA512WithRSA.) |
| 331 |
if err != nil { |
| 332 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 333 |
} |
| 334 |
content := []byte("Hello World") |
| 335 |
toBeSigned, err := NewSignedDatascip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/NewSignedData().(content) |
| 336 |
if err != nil { |
| 337 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot initialize signed data: %s", err) |
| 338 |
} |
| 339 |
if err := toBeSigned.AddSignerscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#AddSigner().(cert.Certificatescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#Certificate., *cert.PrivateKeyscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/certKeyPair#PrivateKey., SignerInfoConfigscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#{ |
| 340 |
SkipCertificatesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignerInfoConfig#SkipCertificates.: true, |
| 341 |
}); err != nil { |
| 342 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot add signer: %s", err) |
| 343 |
} |
| 344 |
signed, err := toBeSigned.Finishscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/SignedData#Finish().() |
| 345 |
if err != nil { |
| 346 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot finish signing data: %s", err) |
| 347 |
} |
| 348 |
p7, err := Parsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/Parse().(signed) |
| 349 |
if err != nil { |
| 350 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Cannot parse signed data: %v", err) |
| 351 |
} |
| 352 |
if len(p7.Certificatesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Certificates.) > 0 { |
| 353 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Got %d certificate(s), exected none", len(p7.Certificatesscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/PKCS7#Certificates.)) |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
// writes the cert to a temporary file and tests that openssl can read it. |
| 358 |
func testOpenSSLParsescip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/testOpenSSLParse().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#, certBytes []byte) { |
| 359 |
tmpCertFile, err := ioutilscip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/.TempFilescip-go gomod github.com/golang/go/src go1.13 `io/ioutil`/TempFile().("", "testCertificate") |
| 360 |
if err != nil { |
| 361 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 362 |
} |
| 363 |
defer osscip-go gomod github.com/golang/go/src go1.13 os/.Removescip-go gomod github.com/golang/go/src go1.13 os/Remove().(tmpCertFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) // clean up |
| 364 |
|
| 365 |
if _, err := tmpCertFile.Writescip-go gomod github.com/golang/go/src go1.13 os/File#Write().(certBytes); err != nil { |
| 366 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 367 |
} |
| 368 |
|
| 369 |
opensslCMD := execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Command().("openssl", "pkcs7", "-inform", "der", "-in", tmpCertFile.Namescip-go gomod github.com/golang/go/src go1.13 os/File#Name().()) |
| 370 |
_, err = opensslCMD.Outputscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Output().() |
| 371 |
if err != nil { |
| 372 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 373 |
} |
| 374 |
|
| 375 |
if err := tmpCertFile.Closescip-go gomod github.com/golang/go/src go1.13 os/File#Close().(); err != nil { |
| 376 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 377 |
} |
| 378 |
|
| 379 |
} |
| 380 |
func fromHexscip-go gomod github.com/digitorus/pkcs7 . `github.com/digitorus/pkcs7`/fromHex().(s string) *bigscip-go gomod github.com/golang/go/src go1.13 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.13 `math/big`/Int# { |
| 381 |
result, ok := new(bigscip-go gomod github.com/golang/go/src go1.13 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.13 `math/big`/Int#).SetStringscip-go gomod github.com/golang/go/src go1.13 `math/big`/Int#SetString().(s, 16) |
| 382 |
if !ok { |
| 383 |
panic(s) |
| 384 |
} |
| 385 |
return result |
| 386 |
} |