Class AssemblylineClient

java.lang.Object
ca.gc.cyber.ops.assemblyline.java.client.clients.AssemblylineClient
All Implemented Interfaces:
IAssemblylineClient

public class AssemblylineClient extends Object implements IAssemblylineClient
  • Field Details

    • session

      protected String session
    • webClient

      protected org.springframework.web.reactive.function.client.WebClient webClient
    • mapper

      protected com.fasterxml.jackson.databind.ObjectMapper mapper
    • assemblylineAuthenticationMethod

      protected AssemblylineAuthenticationMethod assemblylineAuthenticationMethod
    • addSession

      protected org.springframework.web.reactive.function.client.ExchangeFilterFunction addSession
  • Constructor Details

    • AssemblylineClient

      @Deprecated(forRemoval=true, since="1.11") public AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper defaultMapper, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Allowing external code to supply an ObjectMapper can cause issues if the provided mapper is configured in a way that is not compatible with the JSON produced/consumed by AssemblyLine. Use AssemblylineClient(AssemblylineClientProperties, HttpClient, AssemblylineAuthenticationMethod) instead.
      Constructs a new instance of AssemblylineClient.
      Parameters:
      assemblylineClientProperties - Properties to use when configuring the AssemblylineClient instance.
      httpClient - The HTTP client to be used to communicate with AssemblyLine.
      defaultMapper - A base ObjectMapper that will be copied and then configured for use with AssemblyLine. This constructor is deprecated because of this parameter; users of this constructor may inadvertently introduce a misconfigured ObjectMapper.
      assemblylineAuthenticationMethod - The authentication method to use when connecting to AssemblyLine.
    • AssemblylineClient

      public AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
      Constructs a new instance of AssemblylineClient.
      Parameters:
      assemblylineClientProperties - Properties to use when configuring the AssemblylineClient instance.
      httpClient - The HTTP client to be used to communicate with AssemblyLine.
      assemblylineAuthenticationMethod - The authentication method to use when connecting to AssemblyLine.
  • Method Details

    • withAuthBearerToken

      public AssemblylineClient withAuthBearerToken(String authBearerToken)
      Creates a copy of the current AssemblylineClient that will use the given authentication bearer token.
      Specified by:
      withAuthBearerToken in interface IAssemblylineClient
      Parameters:
      authBearerToken - The authentication bearer token for the new client to use.
      Returns:
      the new client.
    • buildWebClient

      protected void buildWebClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient)
    • login

      public reactor.core.publisher.Mono<LoginResponse> login()
      Specified by:
      login in interface IAssemblylineClient
    • isSubmissionComplete

      public reactor.core.publisher.Mono<Boolean> isSubmissionComplete(String sid)
      Specified by:
      isSubmissionComplete in interface IAssemblylineClient
    • getFileInfo

      public reactor.core.publisher.Mono<FileInfo> getFileInfo(String sha256)
      Specified by:
      getFileInfo in interface IAssemblylineClient
    • getFileResults

      public reactor.core.publisher.Mono<FileResults> getFileResults(String sha256)
      Specified by:
      getFileResults in interface IAssemblylineClient
    • getFileResultForService

      public reactor.core.publisher.Mono<FileResultForService> getFileResultForService(String sha256, String serviceName)
      Specified by:
      getFileResultForService in interface IAssemblylineClient
    • getResult

      public reactor.core.publisher.Mono<ResultBlock> getResult(String cacheKey)
      Specified by:
      getResult in interface IAssemblylineClient
    • getSubmissionFileResults

      public reactor.core.publisher.Mono<SubmissionFileResults> getSubmissionFileResults(String sid, String sha256)
      Specified by:
      getSubmissionFileResults in interface IAssemblylineClient
    • getSubmissionTree

      public reactor.core.publisher.Mono<SubmissionTree> getSubmissionTree(String sid)
      Specified by:
      getSubmissionTree in interface IAssemblylineClient
    • getSubmission

      public reactor.core.publisher.Mono<Submission> getSubmission(String sid)
      Specified by:
      getSubmission in interface IAssemblylineClient
    • getSubmissionFull

      public reactor.core.publisher.Mono<SubmissionFull> getSubmissionFull(String sid)
      Specified by:
      getSubmissionFull in interface IAssemblylineClient
    • ingestUrlOrSha256

      public reactor.core.publisher.Mono<IngestResponse> ingestUrlOrSha256(NonBinaryIngest ingest)
      Specified by:
      ingestUrlOrSha256 in interface IAssemblylineClient
    • ingestBinary

      public reactor.core.publisher.Mono<IngestResponse> ingestBinary(BinaryFile<IngestBase> binaryIngest)
      Specified by:
      ingestBinary in interface IAssemblylineClient
    • ingestAsyncBinary

      public reactor.core.publisher.Mono<IngestResponse> ingestAsyncBinary(AsyncBinaryFile<IngestBase> asyncBinaryIngest)
      Specified by:
      ingestAsyncBinary in interface IAssemblylineClient
    • getIngestMessageList

      public reactor.core.publisher.Flux<IngestSubmissionResponse> getIngestMessageList(String notification)
      Specified by:
      getIngestMessageList in interface IAssemblylineClient
    • submitUrlOrSha256

      public reactor.core.publisher.Mono<Submission> submitUrlOrSha256(NonBinarySubmit submit)
      Specified by:
      submitUrlOrSha256 in interface IAssemblylineClient
    • submitBinary

      public reactor.core.publisher.Mono<Submission> submitBinary(BinaryFile<SubmitMetadata> binaryIngest)
      Specified by:
      submitBinary in interface IAssemblylineClient
    • submitAsyncBinary

      public reactor.core.publisher.Mono<Submission> submitAsyncBinary(AsyncBinaryFile<SubmitMetadata> binaryIngest)
      Specified by:
      submitAsyncBinary in interface IAssemblylineClient
    • downloadFile

      public InputStream downloadFile(String sha256)
      Specified by:
      downloadFile in interface IAssemblylineClient
    • downloadFile

      public InputStream downloadFile(String sha256, DownloadFileParams params)
      Specified by:
      downloadFile in interface IAssemblylineClient
    • getHashSearchDataSources

      public reactor.core.publisher.Mono<List<String>> getHashSearchDataSources()
      Specified by:
      getHashSearchDataSources in interface IAssemblylineClient
    • hashSearch

      public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash, List<String> dataSources, Integer maxTimeout)
      Search for a hash in multiple data sources.
      Specified by:
      hashSearch in interface IAssemblylineClient
      Parameters:
      fileHash - Hash to search in the multiple data sources (MD5, SHA1 or SHA256)
      dataSources - list of data sources. Set to null to use server default.
      maxTimeout - Maximum execution time for the call in seconds. Set to null to use server default.
      Returns:
      Search results
      See Also:
    • hashSearch

      public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash)
      Search for a hash in multiple data sources, using default values for optional parameters.
      Specified by:
      hashSearch in interface IAssemblylineClient
      Parameters:
      fileHash - Hash to search in the multiple data sources (MD5, SHA1 or SHA256)
      Returns:
      Search results
      See Also:
    • setSession

      protected void setSession(org.springframework.web.reactive.function.client.ClientResponse clientResponse)
    • retryWrapper

      protected <T> reactor.core.publisher.Mono<T> retryWrapper(reactor.core.publisher.Mono<T> monoContent)
    • get

      protected <T> reactor.core.publisher.Mono<T> get(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType)
      Helper method to perform a JSON GET request. This helper covers the most common GET requests. For more specialized requests, use webClient directly.
      Type Parameters:
      T - The type of data that will be in the response.
      Parameters:
      uriBuilder - UriBuilder that will generate the URI to GET.
      responseType - A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example, new ParameterizedTypeReference<ALApiResponse<Boolean>> is OK, but new ParameterizedTypeReference<ALApiResponse<T>> (where T is a type parameter on a method) is not OK.
      Returns:
      The content of the "api_response" section of the response.
    • post

      protected <T> reactor.core.publisher.Mono<T> post(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType, org.springframework.web.reactive.function.BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> bodyInserter, org.springframework.http.MediaType contentType)
      Helper method to perform a JSON POST request. This helper covers the most common POST requests. For more specialized requests, use webClient directly.
      Type Parameters:
      T - The type of data that will be in the response.
      Parameters:
      uriBuilder - UriBuilder that will generate the URI to POST.
      responseType - A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example, new ParameterizedTypeReference<ALApiResponse<Boolean>> is OK, but new ParameterizedTypeReference<ALApiResponse<T>> (where T is a type parameter on a method) is not OK.
      bodyInserter - BodyInserter to construct the body of the Post Request
      contentType - MediaType of the request body
      Returns:
      The content of the "api_response" section of the response.
    • clientResponseToMono

      protected <T> reactor.core.publisher.Mono<T> clientResponseToMono(org.springframework.web.reactive.function.client.ClientResponse clientResponse, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> type)
      Convert ClientResponse to AssemblylineApiResponse content mono.

      Type Parameters:
      T - The type of data that will be in the response.
      Parameters:
      clientResponse - ClientResponse returned by call
      type - A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example, new ParameterizedTypeReference<ALApiResponse<Boolean>> is OK, but new ParameterizedTypeReference<ALApiResponse<T>> (where T is a type parameter on a method) is not OK.
      Returns:
      Mono of clientResponse body