Skip to content

Commit

Permalink
add template sign/parse methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Oct 27, 2023
1 parent 9b88cd5 commit 949d935
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nuclei

import (
"bufio"
"bytes"
"io"

"github.com/projectdiscovery/httpx/common/httpx"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine"
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
"github.com/projectdiscovery/nuclei/v3/pkg/templates/signer"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
"github.com/projectdiscovery/ratelimit"
"github.com/projectdiscovery/retryablehttp-go"
Expand Down Expand Up @@ -127,6 +129,39 @@ func (e *NucleiEngine) LoadTargetsFromReader(reader io.Reader, probeNonHttp bool
}
}

// GetExecuterOptions returns the nuclei executor options
func (e *NucleiEngine) GetExecuterOptions() *protocols.ExecutorOptions {
return &e.executerOpts
}

// ParseTemplate parses a template from given data
// template verification status can be accessed from template.Verified
func (e *NucleiEngine) ParseTemplate(data []byte) (*templates.Template, error) {
return templates.ParseTemplateFromReader(bytes.NewReader(data), nil, e.executerOpts)
}

// SignTemplate signs the tempalate using given signer
func (e *NucleiEngine) SignTemplate(tmplSigner *signer.TemplateSigner, data []byte) ([]byte, error) {
tmpl, err := e.ParseTemplate(data)
if err != nil {
return data, err
}
if tmpl.Verified {
// already signed
return data, nil
}
if len(tmpl.Workflows) > 0 {
return data, templates.ErrNotATemplate
}
signatureData, err := tmplSigner.Sign(data, tmpl)
if err != nil {
return data, err
}
buff := bytes.NewBuffer(signer.RemoveSignatureFromData(data))
buff.WriteString("\n" + signatureData)
return buff.Bytes(), err
}

// Close all resources used by nuclei engine
func (e *NucleiEngine) Close() {
e.interactshClient.Close()
Expand Down

0 comments on commit 949d935

Please sign in to comment.