@@ -96,6 +96,7 @@ func (g *CertificateGenerator) Generate(
|
||||
if signature.SignedAt == nil {
|
||||
return nil, fmt.Errorf("cannot generate certificate: signature %s has no signed_at timestamp", signature.ID)
|
||||
}
|
||||
|
||||
data.SignedAt = signature.SignedAt.UTC().Format(time.RFC3339)
|
||||
|
||||
if len(signature.TSAToken) == 0 {
|
||||
@@ -161,6 +162,7 @@ func tsaAuthorityName(ts *timestamp.Timestamp) string {
|
||||
if cert.Subject.CommonName != "" {
|
||||
return org + " (" + cert.Subject.CommonName + ")"
|
||||
}
|
||||
|
||||
return org
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ func (h *completionCertificateHandler) Claim(ctx context.Context) (coredata.Elec
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return coredata.ElectronicSignature{}, worker.ErrNoTask
|
||||
}
|
||||
|
||||
return coredata.ElectronicSignature{}, err
|
||||
}
|
||||
|
||||
@@ -118,6 +119,7 @@ func (h *completionCertificateHandler) Process(ctx context.Context, signature co
|
||||
if err := h.handleCertFailure(ctx, &signature, scope, err); err != nil {
|
||||
h.logger.ErrorCtx(ctx, "cannot handle certificate failure", log.Error(err))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -148,6 +150,7 @@ func (h *completionCertificateHandler) generateAndCommit(
|
||||
ctx,
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
signature.CertificateFileID = &attachments[1].FileID
|
||||
|
||||
signature.UpdatedAt = time.Now()
|
||||
if err := signature.Update(ctx, tx, scope); err != nil {
|
||||
return fmt.Errorf("cannot update signature: %w", err)
|
||||
@@ -261,12 +264,14 @@ func (h *completionCertificateHandler) generateCertificate(
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot resolve presenter config: %w", err)
|
||||
}
|
||||
|
||||
emailPresenter := emails.NewPresenterFromConfig(h.fileManager, presenterCfg, ref.UnrefOrZero(signature.SignerFullName))
|
||||
|
||||
docName := ref.UnrefOrZero(signature.DocumentName)
|
||||
if docName == "" {
|
||||
docName = signature.DocumentType.DisplayName()
|
||||
}
|
||||
|
||||
subject, textBody, htmlBody, err := emailPresenter.RenderElectronicSignatureCertificate(ctx, ref.UnrefOrZero(signature.SignerFullName), docName)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot render email: %w", err)
|
||||
|
||||
@@ -104,6 +104,7 @@ func (h *sealingHandler) Claim(ctx context.Context) (coredata.ElectronicSignatur
|
||||
signature.ProcessingStartedAt = &now
|
||||
signature.AttemptCount++
|
||||
signature.LastAttemptedAt = &now
|
||||
|
||||
signature.UpdatedAt = now
|
||||
if err := signature.Update(ctx, tx, coredata.NewNoScope()); err != nil {
|
||||
return fmt.Errorf("cannot update signature: %w", err)
|
||||
@@ -115,6 +116,7 @@ func (h *sealingHandler) Claim(ctx context.Context) (coredata.ElectronicSignatur
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return coredata.ElectronicSignature{}, worker.ErrNoTask
|
||||
}
|
||||
|
||||
return coredata.ElectronicSignature{}, err
|
||||
}
|
||||
|
||||
@@ -126,8 +128,10 @@ func (h *sealingHandler) Process(ctx context.Context, signature coredata.Electro
|
||||
if err := h.failSignature(ctx, &signature, err); err != nil {
|
||||
h.logger.ErrorCtx(ctx, "cannot fail signature", log.Error(err))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -175,6 +179,7 @@ func (h *sealingHandler) sealAndCommit(
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %w", ErrComputeSeal, err)
|
||||
}
|
||||
|
||||
signature.Seal = &seal
|
||||
signature.SealVersion = currentSealVersion
|
||||
events = append(
|
||||
@@ -187,10 +192,12 @@ func (h *sealingHandler) sealAndCommit(
|
||||
|
||||
tsaCtx, cancel := context.WithTimeout(ctx, h.tsaTimeout)
|
||||
defer cancel()
|
||||
|
||||
tsaToken, err := h.tsaClient.Timestamp(tsaCtx, []byte(seal))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %w", ErrTSATimestamp, err)
|
||||
}
|
||||
|
||||
signature.TSAToken = tsaToken
|
||||
events = append(
|
||||
events,
|
||||
@@ -213,10 +220,12 @@ func (h *sealingHandler) sealAndCommit(
|
||||
}
|
||||
|
||||
signature.Status = coredata.ElectronicSignatureStatusCompleted
|
||||
|
||||
signature.UpdatedAt = time.Now()
|
||||
if err := signature.Update(ctx, tx, scope); err != nil {
|
||||
return fmt.Errorf("cannot update signature: %w", err)
|
||||
}
|
||||
|
||||
events = append(
|
||||
events,
|
||||
signature.NewEvent(
|
||||
@@ -260,12 +269,14 @@ func (h *sealingHandler) failSignature(
|
||||
errStr := userFacingError(processingError)
|
||||
signature.LastError = &errStr
|
||||
signature.ProcessingStartedAt = nil
|
||||
|
||||
signature.UpdatedAt = time.Now()
|
||||
if signature.AttemptCount >= signature.MaxAttempts {
|
||||
signature.Status = coredata.ElectronicSignatureStatusFailed
|
||||
} else {
|
||||
signature.Status = coredata.ElectronicSignatureStatusAccepted
|
||||
}
|
||||
|
||||
if err := signature.Update(ctx, tx, scope); err != nil {
|
||||
return fmt.Errorf("cannot update signature: %w", err)
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ func (s *Service) Run(ctx context.Context, presenterConfigFunc EmailPresenterCon
|
||||
s.logger.Named("sealing-worker"),
|
||||
nil,
|
||||
)
|
||||
|
||||
g.Go(func() error { return sealingWorker.Run(sealingWorkerCtx) })
|
||||
|
||||
certWorkerCtx, stopCertWorker := context.WithCancel(ctx)
|
||||
@@ -130,6 +131,7 @@ func (s *Service) Run(ctx context.Context, presenterConfigFunc EmailPresenterCon
|
||||
s.bucket,
|
||||
s.logger.Named("completion-certificate-worker"),
|
||||
)
|
||||
|
||||
g.Go(func() error { return certWorker.Run(certWorkerCtx) })
|
||||
|
||||
<-gctx.Done()
|
||||
@@ -148,6 +150,7 @@ func (s *Service) CreateSignature(
|
||||
consentText := req.ConsentText
|
||||
if consentText == "" {
|
||||
var err error
|
||||
|
||||
consentText, err = req.DocumentType.ConsentText()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot derive consent text: %w", err)
|
||||
@@ -500,6 +503,7 @@ func (s *Service) GetEventsBySignatureID(
|
||||
scope = coredata.NewScopeFromObjectID(signatureID)
|
||||
events = coredata.ElectronicSignatureEvents{}
|
||||
)
|
||||
|
||||
err := s.pg.WithConn(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
@@ -510,7 +514,6 @@ func (s *Service) GetEventsBySignatureID(
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ func StampSignatureID(pdfData []byte, signatureID string) ([]byte, error) {
|
||||
}
|
||||
|
||||
reader := bytes.NewReader(pdfData)
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := api.AddWatermarks(reader, &buf, nil, wm, nil); err != nil {
|
||||
|
||||
@@ -57,12 +57,14 @@ func (c *TSAClient) Timestamp(ctx context.Context, data []byte) ([]byte, error)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("esign: cannot build TSA HTTP request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/timestamp-query")
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("esign: TSA request failed: %w", err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
Reference in New Issue
Block a user