share/ticket/lib/sendsafely.rb
def download_urls(file_id, package_code, start_segment=1, end_segment=25)
    timestamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S+0000")

    resp = Faraday.post("#{@sendsafely_url}/#{API}/package/#{@thread}/file/#{file_id}/download-urls/") do |req|
      req.headers['Content-Type'] = 'application/json'
      req.headers['ss-api-key'] = @sendsafely_key_id
      req.headers['ss-request-timestamp'] = timestamp

      req.body = {
        # Use the following inputs for your PBKDF2 function:
        # Hashing Algorithm - SHA-256
        # Password  - Use the keycode for this value
        # Salt - Use the Package Code for this value
        # Iteration Count - 1024
        # Key Length - 32 bytes
        # https://ruby-doc.org/stdlib-2.4.3/libdoc/openssl/rdoc/OpenSSL/KDF.html#method-c-pbkdf2_hmac
        # pbkdf2_hmac(pass, salt:, iterations:, length:, hash:)
        'checksum' => OpenSSL::KDF.pbkdf2_hmac(@key_code, salt: package_code, iterations: 1024, length: 32, hash: 'SHA256').unpack('H*').first,
        'startSegment' => start_segment,
        'endSegment' => end_segment
        # NOTE: Up to 25 download URLS for each file can be obtained at once. You can use the startSegment parameter to tell the server which file part you would like as the starting point for each request. Note that each URL contains a time-stamped authentication token that is only valid for 60 minutes, so in general you should not obtain these URLs until you are ready to use them.
      }.to_json

      req.headers['ss-request-signature'] = OpenSSL::HMAC.hexdigest("SHA256", @sendsafely_key_secret, @sendsafely_key_id+"/#{API}/package/#{@thread}/file/#{file_id}/download-urls/"+timestamp+req.body)
    end
  end
# Each file is split into multiple smaller "parts" for faster processing. The number of "parts" associated with each file is included as a property within the files array from Step 1.
# Each part has its own URL, which can be obtained from the download-urls endpoint:
#
# https://bump.sh/doc/sendsafely-rest-api#operation-post-package-parameter-file-parameter-download-urls
Each file is split into multiple smaller "parts" for faster processing. The number of "parts" associated with each file is included as a property within the files array from Step 1.
Each part has its own URL, which can be obtained from the download-urls endpoint.


Each file is split into multiple smaller " parts " for faster processing . The number of " parts " associated with each file is included as a property within the files array from Step 1 . Each part has its own URL which can be obtained from the download - urls endpoint .
def download_urls(file_id, package_code, start_segment=1, end_segment=25)
    timestamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S+0000")
    resp = Faraday.post("#{@sendsafely_url}/#{API}/package/#{@thread}/file/#{file_id}/download-urls/") do |req|
      req.headers['Content-Type'] = 'application/json'
      req.headers['ss-api-key'] = @sendsafely_key_id
      req.headers['ss-request-timestamp'] = timestamp
      req.body = {
        'checksum' => OpenSSL::KDF.pbkdf2_hmac(@key_code, salt: package_code, iterations: 1024, length: 32, hash: 'SHA256').unpack('H*').first,
        'startSegment' => start_segment,
        'endSegment' => end_segment
      }.to_json
      req.headers['ss-request-signature'] = OpenSSL::HMAC.hexdigest("SHA256", @sendsafely_key_secret, @sendsafely_key_id+"/#{API}/package/#{@thread}/file/#{file_id}/download-urls/"+timestamp+req.body)
    end
  end
def download_urls ( file_id , package_code , start_segment = 1 , end_segment = 25 ) timestamp = Time . now . utc . strftime ( "%Y-%m-%dT%H:%M:%S+0000" ) resp = Faraday . post ( "#{@sendsafely_url}/#{API}/package/#{@thread}/file/#{file_id}/download-urls/" ) do | req | req . headers [ 'Content-Type' ] = 'application/json' req . headers [ 'ss-api-key' ] = @sendsafely_key_id req . headers [ 'ss-request-timestamp' ] = timestamp req . body = { 'checksum' => OpenSSL :: KDF . pbkdf2_hmac ( @key_code , salt : package_code , iterations : 1024 , length : 32 , hash : 'SHA256' ) . unpack ( 'H*' ) . first , 'startSegment' => start_segment , 'endSegment' => end_segment } . to_json req . headers [ 'ss-request-signature' ] = OpenSSL :: HMAC . hexdigest ( "SHA256" , @sendsafely_key_secret , @sendsafely_key_id + "/#{API}/package/#{@thread}/file/#{file_id}/download-urls/" + timestamp + req . body ) end end
Each file is split into multiple smaller "parts" for faster processing.
Each file is split into multiple smaller " parts " for faster processing .
# Use the following inputs for your PBKDF2 function: # Hashing Algorithm - SHA-256 # Password  - Use the keycode for this value # Salt - Use the Package Code for this value # Iteration Count - 1024 # Key Length - 32 bytes # https://ruby-doc.org/stdlib-2.4.3/libdoc/openssl/rdoc/OpenSSL/KDF.html#method-c-pbkdf2_hmac # pbkdf2_hmac(pass, salt:, iterations:, length:, hash:) # NOTE: Up to 25 download URLS for each file can be obtained at once. You can use the startSegment parameter to tell the server which file part you would like as the starting point for each request. Note that each URL contains a time-stamped authentication token that is only valid for 60 minutes, so in general you should not obtain these URLs until you are ready to use them.
file_id
package_code
start_segment
end_segment