...

Source file src/github.com/sassoftware/relic/lib/authenticode/msisign.go

Documentation: github.com/sassoftware/relic/lib/authenticode

     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 authenticode
    18  
    19  import (
    20  	"context"
    21  	"crypto"
    22  
    23  	"github.com/sassoftware/relic/lib/certloader"
    24  	"github.com/sassoftware/relic/lib/comdoc"
    25  	"github.com/sassoftware/relic/lib/pkcs9"
    26  )
    27  
    28  // Create the Authenticode structure for a MSI file signature using a previously-calculated digest (imprint).
    29  func SignMSIImprint(ctx context.Context, digest []byte, hash crypto.Hash, cert *certloader.Certificate) (*pkcs9.TimestampedSignature, error) {
    30  	return SignSip(ctx, digest, hash, msiSipInfo, cert)
    31  }
    32  
    33  // Add a signature blob to an open MSI file. The extended signature blob is
    34  // added or updated if provided, or deleted if nil.
    35  func InsertMSISignature(cdf *comdoc.ComDoc, pkcs, exsig []byte) error {
    36  	if len(exsig) > 0 {
    37  		if err := cdf.AddFile(msiDigitalSignatureEx, exsig); err != nil {
    38  			return err
    39  		}
    40  	} else {
    41  		if err := cdf.DeleteFile(msiDigitalSignatureEx); err != nil {
    42  			return err
    43  		}
    44  	}
    45  	return cdf.AddFile(msiDigitalSignature, pkcs)
    46  }
    47  

View as plain text