/* Implementation of Sign() in crypto.Signer iface
 * Contacts cmcd for sign operation */
Implementation of Sign() in crypto.Signer iface
Contacts cmcd for sign operation
/ * Implementation of Sign () in crypto . Signer iface * Contacts cmcd for sign operation * /
func (priv PrivateKey) Sign(random io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
	var req ci.TLSSignRequest
	var resp *ci.TLSSignResponse
	var hash ci.HashFunction
	var err error
	cmcClient, conn, cancel := getCMCServiceConn();
	if cmcClient == nil {
		return nil, errors.New("[PrivateKey] Connection failed. No signing performed")
	}
	defer conn.Close()
	defer cancel()
	log.Trace("[PrivateKey] Contacting backend for Sign Operation")
	hash, err = convertHash(opts)
	if err != nil {
		log.Error(err)
		return nil, errors.New("[Private Key] Sign request creation failed")
	}
	req = ci.TLSSignRequest{
		Id : id,
		Content : digest,
		Hashtype : hash,
	}
	if pssOpts, ok := opts.(*rsa.PSSOptions); ok {
		req.PssOpts = &ci.PSSOptions{SaltLength : int32(pssOpts.SaltLength),}
	}
	resp, err = cmcClient.TLSSign(context.Background(), &req)
	if err != nil {
		log.Error(err)
		return nil, errors.New("[PrivateKey] Sign request failed")
	}
	if resp.GetStatus() != ci.Status_OK {
		return nil, errors.New("[PrivateKey] Signature creation failed")
	}
	log.Info("[PrivateKey] returning signed content of size ", len(resp.GetSignedContent()))
	log.Trace("[PrivateKey] signature: \n ", hex.EncodeToString(resp.GetSignedContent()))
	return resp.GetSignedContent(), nil
}
func ( priv PrivateKey ) Sign ( random io . Reader , digest [ ] byte , opts crypto . SignerOpts ) ( [ ] byte , error ) { var req ci . TLSSignRequest var resp * ci . TLSSignResponse var hash ci . HashFunction var err error cmcClient , conn , cancel := getCMCServiceConn ( ) ; if cmcClient == nil { return nil , errors . New ( " " ) } defer conn . Close ( ) defer cancel ( ) log . Trace ( " " ) hash , err = convertHash ( opts ) if err != nil { log . Error ( err ) return nil , errors . New ( " " ) } req = ci . TLSSignRequest { Id : id , Content : digest , Hashtype : hash , } if pssOpts , ok := opts . ( * rsa . PSSOptions ) ; ok { req . PssOpts = & ci . PSSOptions { SaltLength : int32 ( pssOpts . SaltLength ) , } } resp , err = cmcClient . TLSSign ( context . Background ( ) , & req ) if err != nil { log . Error ( err ) return nil , errors . New ( " " ) } if resp . GetStatus ( ) != ci . Status_OK { return nil , errors . New ( " " ) } log . Info ( " " , len ( resp . GetSignedContent ( ) ) ) log . Trace ( " \n " , hex . EncodeToString ( resp . GetSignedContent ( ) ) ) return resp . GetSignedContent ( ) , nil }
Implementation of Sign() in crypto.Signer iface
Contacts cmcd for sign operation
Implementation of Sign () in crypto . Signer iface Contacts cmcd for sign operation
// Get backend connection // Create Sign request // parse additional signing options - not implemented fields assume recommend defaults // Send Sign request // Check Sign response