MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Open

Method Open

pkg/sys/trust.go:251–287  ·  view source on GitHub ↗

Open opens the catalog and acquires the hash for the given file. If the file is catalog-signed, a valid catalog handle is stored internally.

(filename string)

Source from the content-addressed store, hash-verified

249// Open opens the catalog and acquires the hash for the given file. If the
250// file is catalog-signed, a valid catalog handle is stored internally.
251func (c *Cat) Open(filename string) error {
252 runtime.LockOSThread()
253 defer runtime.UnlockOSThread()
254 // acquire handle to a catalog administrator context
255 err := CryptCatalogAdminAcquireContext(&c.admin, nil, nil, 0, 0)
256 if err != nil {
257 return err
258 }
259 // calculate file hash
260 c.file, err = os.Open(filename)
261 if err != nil {
262 return err
263 }
264 err = CryptCatalogAdminCalcHashFromFileHandle(
265 c.admin,
266 c.file.Fd(),
267 &c.size,
268 uintptr(unsafe.Pointer(&c.hash[0])), 0,
269 )
270 if err != nil {
271 return err
272 }
273 // enumerate catalogs that contain the calculated hash.
274 // If no catalogs are found, we can deduce the file is
275 // not catalog signed
276 c.catalog = CryptCatalogAdminEnumCatalogFromHash(
277 c.admin,
278 uintptr(unsafe.Pointer(&c.hash[0])),
279 c.size, 0, nil,
280 )
281 c.catalogInfo.Size = uint32(unsafe.Sizeof(c.catalogInfo))
282 err = CryptCatalogInfoFromContext(c.catalog, &c.catalogInfo, 0)
283 if err != nil {
284 return err
285 }
286 return nil
287}
288
289// IsCatalogSigned determines if the file is catalog-signed.
290func (c *Cat) IsCatalogSigned() bool {

Callers

nothing calls this directly

Tested by

no test coverage detected