MCPcopy Create free account
hub / github.com/WICG/webpackage / SignWithIntegrityBlock

Function SignWithIntegrityBlock

go/bundle/cmd/sign-bundle/integrityblock.go:115–159  ·  view source on GitHub ↗

SignWithIntegrityBlock creates a CBOR integrity block containing a signature matching the hash of the web bundle read from `bundleFileIn`. Finally it writes the new signed web bundle into `bundleFileOut`. More details can be found in [Integrity Block Explainer](https://github.com/WICG/webpackage/blo

(bundleFileIn, bundleFileOut *os.File, signingStrategy integrityblock.ISigningStrategy)

Source from the content-addressed store, hash-verified

113// writes the new signed web bundle into `bundleFileOut`. More details can be
114// found in [Integrity Block Explainer](https://github.com/WICG/webpackage/blob/main/explainers/integrity-signature.md).
115func SignWithIntegrityBlock(bundleFileIn, bundleFileOut *os.File, signingStrategy integrityblock.ISigningStrategy) error {
116 integrityBlock, offset, err := integrityblock.ObtainIntegrityBlock(bundleFileIn)
117 if err != nil {
118 return err
119 }
120
121 webBundleHash, err := integrityblock.ComputeWebBundleSha512(bundleFileIn, offset)
122 if err != nil {
123 return err
124 }
125
126 ibs := integrityblock.IntegrityBlockSigner{
127 SigningStrategy: signingStrategy,
128 WebBundleHash: webBundleHash,
129 IntegrityBlock: integrityBlock,
130 }
131
132 ed25519publicKey, err := ibs.SigningStrategy.GetPublicKey()
133 if err != nil {
134 return err
135 }
136
137 signatureAttributes := integrityblock.GenerateSignatureAttributesWithPublicKey(ed25519publicKey)
138
139 err = ibs.SignAndAddNewSignature(ed25519publicKey, signatureAttributes)
140 if err != nil {
141 return err
142 }
143
144 // Update the integrity block bytes with the new integrity block.
145 integrityBlockBytes, err := integrityBlock.CborBytes()
146 if err != nil {
147 return err
148 }
149
150 err = cbor.Deterministic(integrityBlockBytes)
151 if err != nil {
152 return err
153 }
154
155 webBundleId := webbundleid.GetWebBundleId(ed25519publicKey)
156 fmt.Println("Web Bundle ID: " + webBundleId)
157
158 return writeOutput(bundleFileIn, integrityBlockBytes, offset, bundleFileOut)
159}

Callers 1

Calls 9

ObtainIntegrityBlockFunction · 0.92
ComputeWebBundleSha512Function · 0.92
DeterministicFunction · 0.92
GetWebBundleIdFunction · 0.92
writeOutputFunction · 0.85
CborBytesMethod · 0.80
GetPublicKeyMethod · 0.65

Tested by

no test coverage detected