| 1 | // |
| 2 | // Copyright (c) SAS Institute Inc. |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | package appmanifestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ |
| 18 | |
| 19 | import ( |
| 20 | "bytesscip-go gomod github.com/golang/go/src go1.18 bytes/" |
| 21 | "cryptoscip-go gomod github.com/golang/go/src go1.18 crypto/" |
| 22 | "encoding/base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/" |
| 23 | "encoding/hexscip-go gomod github.com/golang/go/src go1.18 `encoding/hex`/" |
| 24 | "errorsscip-go gomod github.com/golang/go/src go1.18 errors/" |
| 25 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 26 | |
| 27 | "github.com/beevik/etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/" |
| 28 | |
| 29 | "github.com/sassoftware/relic/v7/lib/certloaderscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/" |
| 30 | "github.com/sassoftware/relic/v7/lib/pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/" |
| 31 | "github.com/sassoftware/relic/v7/lib/pkcs9scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/" |
| 32 | "github.com/sassoftware/relic/v7/lib/xmldsigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/" |
| 33 | ) |
| 34 | |
| 35 | const ( |
| 36 | NsMsRelscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsMsRel. = "http://schemas.microsoft.com/windows/rel/2005/reldata" |
| 37 | NsMpeg21scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsMpeg21. = "urn:mpeg:mpeg21:2003:01-REL-R-NS" |
| 38 | NsAuthenticodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsAuthenticode. = "http://schemas.microsoft.com/windows/pki/2005/Authenticode" |
| 39 | ) |
| 40 | |
| 41 | type SignedManifestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest# struct { |
| 42 | ManifestSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#ManifestSignature. |
| 43 | Signedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#Signed. []byte |
| 44 | EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#EncryptedDigest. []byte |
| 45 | } |
| 46 | |
| 47 | // Sign an application manifest |
| 48 | func Signscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/Sign().(manifest []byte, cert *certloaderscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/.Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#, opts cryptoscip-go gomod github.com/golang/go/src go1.18 crypto/.SignerOptsscip-go gomod github.com/golang/go/src go1.18 crypto/SignerOpts#) (*SignedManifestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#, error) { |
| 49 | doc := etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.NewDocumentscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/NewDocument().() |
| 50 | if err := doc.ReadFromStringscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#ReadFromString().(string(manifest)); err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | root := doc.Rootscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#Root().() |
| 54 | // Update signer-related attributes |
| 55 | asi, err := setAssemblyIdentityscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setAssemblyIdentity().(root, cert) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | subjectName, err := setPublisherIdentityscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setPublisherIdentity().(root, cert) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | // Primary signature |
| 64 | sigopts := xmldsigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/.SignOptionsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/SignOptions#{MsCompatHashNamesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/SignOptions#MsCompatHashNames.: true, IncludeKeyValuescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/SignOptions#IncludeKeyValue.: true} |
| 65 | if err := xmldsigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/.Signscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/Sign().(root, root, opts.HashFuncscip-go gomod github.com/golang/go/src go1.18 crypto/SignerOpts#HashFunc().(), cert.Signerscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Signer().(), cert.Chainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Chain().(), sigopts); err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | sig, keyinfo := setSigIdsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setSigIds().(root, "StrongNameSignature", "StrongNameKeyInfo") |
| 69 | // Create authenticode structure |
| 70 | manifestHash := makeManifestHashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/makeManifestHash().(sig) |
| 71 | license, sigDestNode := makeLicensescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/makeLicense().(asi, subjectName, manifestHash) |
| 72 | // Sign authenticode structure |
| 73 | sigopts.IncludeX509scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/SignOptions#IncludeX509. = true |
| 74 | if err := xmldsigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/.Signscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/Sign().(license, sigDestNode, opts.HashFuncscip-go gomod github.com/golang/go/src go1.18 crypto/SignerOpts#HashFunc().(), cert.Signerscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Signer().(), cert.Chainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Chain().(), sigopts); err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | aSig, _ := setSigIdsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setSigIds().(sigDestNode, "AuthenticodeSignature", "") |
| 78 | // Attach authenticode to the primary document |
| 79 | license.AddChildscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#AddChild().(sigDestNode) |
| 80 | reldata := keyinfo.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("msrel:RelData") |
| 81 | reldata.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("xmlns:msrel", NsMsRelscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsMsRel.) |
| 82 | reldata.AddChildscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#AddChild().(license) |
| 83 | // Serialize |
| 84 | signed, err := doc.WriteToBytesscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#WriteToBytes().() |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | // Get authenticode signature value for timestamping |
| 89 | encryptedDigest, _ := base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/Encoding#DecodeString().(aSig.SelectElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectElement().("SignatureValue").Textscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#Text().()) |
| 90 | return &SignedManifestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#{ |
| 91 | Signedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#Signed.: signed, |
| 92 | EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#EncryptedDigest.: encryptedDigest, |
| 93 | ManifestSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#ManifestSignature.: ManifestSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#{ |
| 94 | Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#Signature.: &pkcs9scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/.TimestampedSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#{Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#Signature.: pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#{ |
| 95 | Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#Certificate.: cert.Leafscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Leaf., |
| 96 | Intermediatesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#Intermediates.: cert.Chainscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Chain().(), |
| 97 | }}, |
| 98 | AssemblyNamescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#AssemblyName.: asi.SelectAttrValuescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectAttrValue().("name", ""), |
| 99 | AssemblyVersionscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#AssemblyVersion.: asi.SelectAttrValuescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectAttrValue().("version", ""), |
| 100 | Hashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#Hash.: opts.HashFuncscip-go gomod github.com/golang/go/src go1.18 crypto/SignerOpts#HashFunc().(), |
| 101 | PublicKeyTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#PublicKeyToken.: asi.SelectAttrValuescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectAttrValue().("publicKeyToken", ""), |
| 102 | }}, nil |
| 103 | } |
| 104 | |
| 105 | // Update the assemblyIdentity element with the actual signer public key. Only |
| 106 | // the top-level one is updated, not the ones underneath individual manifest |
| 107 | // entries. |
| 108 | func setAssemblyIdentityscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setAssemblyIdentity().(root *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, cert *certloaderscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/.Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#) (*etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, error) { |
| 109 | token, err := PublicKeyTokenscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/PublicKeyToken().(cert.Leafscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#Leaf..PublicKeyscip-go gomod github.com/golang/go/src go1.18 `crypto/x509`/Certificate#PublicKey.) |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | asi := root.SelectElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectElement().("assemblyIdentity") |
| 114 | if asi == nil { |
| 115 | return nil, errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("manifest has no top-level assemblyIdentity element") |
| 116 | } |
| 117 | asi.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("publicKeyToken", token) |
| 118 | return asi, nil |
| 119 | } |
| 120 | |
| 121 | // Add/replace the publisherIdentity element |
| 122 | func setPublisherIdentityscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setPublisherIdentity().(root *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, cert *certloaderscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/.Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/certloader`/Certificate#) (string, error) { |
| 123 | // add or replace publisherIdentity |
| 124 | subjectName, issuerKeyHash, err := PublisherIdentityscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/PublisherIdentity().(cert) |
| 125 | if err != nil { |
| 126 | return "", err |
| 127 | } |
| 128 | xmldsigscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/.RemoveElementsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/xmldsig`/RemoveElements().(root, "publisherIdentity") |
| 129 | ident := root.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("publisherIdentity") |
| 130 | ident.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("name", subjectName) |
| 131 | ident.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("issuerKeyHash", issuerKeyHash) |
| 132 | return subjectName, nil |
| 133 | } |
| 134 | |
| 135 | // Create the "license" block that goes inside the inner signature |
| 136 | func makeLicensescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/makeLicense().(asi *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, subjectName, manifestHash string) (*etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#) { |
| 137 | license := etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.NewElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/NewElement().("r:license") |
| 138 | license.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("xmlns:r", NsMpeg21scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsMpeg21.) |
| 139 | license.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("xmlns:as", NsAuthenticodescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/NsAuthenticode.) |
| 140 | |
| 141 | grant := license.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("r:grant") |
| 142 | minfo := grant.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("as:ManifestInformation") |
| 143 | minfo.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("Hash", manifestHash) |
| 144 | minfo.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("Description", "") |
| 145 | minfo.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("Url", "") |
| 146 | massy := asi.Copyscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#Copy().() |
| 147 | massy.Spacescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#Space. = "as" |
| 148 | minfo.AddChildscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#AddChild().(massy) |
| 149 | grant.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("as:SignedBy") |
| 150 | grant.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("as:AuthenticodePublisher").CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("as:X509SubjectName").SetTextscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SetText().(subjectName) |
| 151 | |
| 152 | issuer := license.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("r:issuer") |
| 153 | return license, issuer |
| 154 | } |
| 155 | |
| 156 | // ManifestInformation contains a hash value which is, for some inane reason, |
| 157 | // the same hash that the outer signature references but in reverse byte order. |
| 158 | func makeManifestHashscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/makeManifestHash().(sig *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#) string { |
| 159 | dv := sig.FindElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#FindElement().(".//DigestValue") |
| 160 | blob, _ := base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/Encoding#DecodeString().(dv.Textscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#Text().()) |
| 161 | for i := 0; i < len(blob)/2; i++ { |
| 162 | j := len(blob) - i - 1 |
| 163 | blob[i], blob[j] = blob[j], blob[i] |
| 164 | } |
| 165 | return hexscip-go gomod github.com/golang/go/src go1.18 `encoding/hex`/.EncodeToStringscip-go gomod github.com/golang/go/src go1.18 `encoding/hex`/EncodeToString().(blob) |
| 166 | } |
| 167 | |
| 168 | // Set Id attributes on signature elements |
| 169 | func setSigIdsscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/setSigIds().(root *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#, sigName, keyinfoName string) (sig, keyinfo *etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.Elementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#) { |
| 170 | sig = root.SelectElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectElement().("Signature") |
| 171 | if sigName != "" { |
| 172 | sig.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("Id", sigName) |
| 173 | } |
| 174 | keyinfo = sig.SelectElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SelectElement().("KeyInfo") |
| 175 | if keyinfoName != "" { |
| 176 | keyinfo.CreateAttrscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateAttr().("Id", keyinfoName) |
| 177 | } |
| 178 | return sig, keyinfo |
| 179 | } |
| 180 | |
| 181 | // Attach a timestamp counter-signature |
| 182 | func (m *SignedManifestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#) AddTimestampscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#AddTimestamp().(token *pkcs7scip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/.ContentInfoSignedDatascip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#) error { |
| 183 | doc := etreescip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/.NewDocumentscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/NewDocument().() |
| 184 | if err := doc.ReadFromStringscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#ReadFromString().(string(m.Signedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#Signed.)); err != nil { |
| 185 | return err |
| 186 | } |
| 187 | aSig := doc.Rootscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#Root().().FindElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#FindElement().("Signature/KeyInfo/msrel:RelData/r:license/r:issuer/Signature") |
| 188 | if aSig == nil { |
| 189 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("manifest has no authenticode signature") |
| 190 | } |
| 191 | siblob, err := token.Marshalscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/ContentInfoSignedData#Marshal().() |
| 192 | if err != nil { |
| 193 | return err |
| 194 | } |
| 195 | lines := (47 + len(siblob)) / 48 |
| 196 | buf := bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.18 bytes/NewBuffer().(make([]byte, 0, (64+2)*lines)) |
| 197 | for len(siblob) > 0 { |
| 198 | n := len(siblob) |
| 199 | if n > 48 { |
| 200 | n = 48 |
| 201 | } |
| 202 | chunk := siblob[:n] |
| 203 | siblob = siblob[n:] |
| 204 | |
| 205 | buf.WriteStringscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#WriteString().(base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/StdEncoding..EncodeToStringscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/Encoding#EncodeToString().(chunk)) |
| 206 | buf.WriteStringscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#WriteString().("\r\n") |
| 207 | } |
| 208 | aSig.CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("Object").CreateElementscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#CreateElement().("as:Timestamp").SetTextscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Element#SetText().(buf.Stringscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#String().()) |
| 209 | signed, err := doc.WriteToBytesscip-go gomod github.com/beevik/etree v1.1.0 `github.com/beevik/etree`/Document#WriteToBytes().() |
| 210 | if err != nil { |
| 211 | return err |
| 212 | } |
| 213 | cs, err := VerifyTimestampscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/VerifyTimestamp().(token, m.EncryptedDigestscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#EncryptedDigest., m.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#Signature..Intermediatesscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs7`/Signature#Intermediates.) |
| 214 | if err != nil { |
| 215 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("failed to validate timestamp: %w", err) |
| 216 | } |
| 217 | m.Signedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/SignedManifest#Signed. = signed |
| 218 | m.Signaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/appmanifest`/ManifestSignature#Signature..CounterSignaturescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/lib/pkcs9`/TimestampedSignature#CounterSignature. = cs |
| 219 | return nil |
| 220 | } |