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